use NEC to handle gc subject events
This commit is contained in:
parent
1e097fc4d5
commit
ddb27d0e7e
|
@ -1580,12 +1580,6 @@ ConnectionJingle, ConnectionIBBytestream):
|
|||
def dispatch_gc_message(self, msg, frm, msgtxt, jid, tim):
|
||||
has_timestamp = bool(msg.timestamp)
|
||||
|
||||
subject = msg.getSubject()
|
||||
|
||||
if subject is not None:
|
||||
self.dispatch('GC_SUBJECT', (frm, subject, msgtxt, has_timestamp))
|
||||
return
|
||||
|
||||
statusCode = msg.getStatusCode()
|
||||
|
||||
if not msg.getTag('body'): # no <body>
|
||||
|
|
|
@ -1051,6 +1051,7 @@ class GcMessageReceivedEvent(nec.NetworkIncomingEvent):
|
|||
self.msgtxt = self.msg_obj.msgtxt
|
||||
self.jid = self.msg_obj.jid
|
||||
self.room_jid = self.msg_obj.jid
|
||||
self.nickname = self.msg_obj.resource
|
||||
self.timestamp = self.msg_obj.timestamp
|
||||
self.xhtml_msgtxt = self.stanza.getXHTML()
|
||||
|
||||
|
@ -1069,8 +1070,8 @@ class GcMessageReceivedEvent(nec.NetworkIncomingEvent):
|
|||
self.subject = self.stanza.getSubject()
|
||||
|
||||
if self.subject is not None:
|
||||
self.conn.dispatch('GC_SUBJECT', (self.fjid, self.subject,
|
||||
self.msgtxt, self.has_timestamp))
|
||||
gajim.nec.push_incoming_event(GcSubjectReceivedEvent(None,
|
||||
conn=self.conn, msg_event=self))
|
||||
return
|
||||
|
||||
self.status_code = self.stanza.getStatusCode()
|
||||
|
@ -1117,6 +1118,21 @@ class GcMessageReceivedEvent(nec.NetworkIncomingEvent):
|
|||
|
||||
return True
|
||||
|
||||
class GcSubjectReceivedEvent(nec.NetworkIncomingEvent):
|
||||
name = 'gc-subject-received'
|
||||
base_network_events = []
|
||||
|
||||
def generate(self):
|
||||
self.conn = self.msg_event.conn
|
||||
self.stanza = self.msg_event.stanza
|
||||
self.room_jid = self.msg_event.room_jid
|
||||
self.nickname = self.msg_event.nickname
|
||||
self.fjid = self.msg_event.fjid
|
||||
self.subject = self.msg_event.subject
|
||||
self.msgtxt = self.msg_event.msgtxt
|
||||
self.has_timestamp = self.msg_event.has_timestamp
|
||||
return True
|
||||
|
||||
class MessageSentEvent(nec.NetworkIncomingEvent):
|
||||
name = 'message-sent'
|
||||
base_network_events = []
|
||||
|
@ -1479,7 +1495,7 @@ class PrivacyListActiveDefaultEvent(nec.NetworkIncomingEvent):
|
|||
class VcardReceivedEvent(nec.NetworkIncomingEvent):
|
||||
name = 'vcard-received'
|
||||
base_network_events = []
|
||||
|
||||
|
||||
def generate(self):
|
||||
self.nickname = None
|
||||
if 'NICKNAME' in self.vcard_dict:
|
||||
|
|
|
@ -460,6 +460,8 @@ class GroupchatControl(ChatControlBase):
|
|||
self._nec_vcard_published)
|
||||
gajim.ged.register_event_handler('vcard-received', ged.GUI1,
|
||||
self._nec_vcard_received)
|
||||
gajim.ged.register_event_handler('gc-subject-received', ged.GUI1,
|
||||
self._nec_gc_subject_received)
|
||||
gajim.gc_connected[self.account][self.room_jid] = False
|
||||
# disable win, we are not connected yet
|
||||
ChatControlBase.got_disconnected(self)
|
||||
|
@ -1176,6 +1178,19 @@ class GroupchatControl(ChatControlBase):
|
|||
self.subject = subject
|
||||
self.draw_banner_text()
|
||||
|
||||
def _nec_gc_subject_received(self, obj):
|
||||
if obj.conn.name != self.account:
|
||||
return
|
||||
if obj.room_jid != self.room_jid:
|
||||
return
|
||||
self.set_subject(obj.subject)
|
||||
text = _('%(nick)s has set the subject to %(subject)s') % {
|
||||
'nick': obj.nickname, 'subject': obj.subject}
|
||||
if obj.has_timestamp:
|
||||
self.print_old_conversation(text)
|
||||
else:
|
||||
self.print_conversation(text)
|
||||
|
||||
def got_connected(self):
|
||||
# Make autorejoin stop.
|
||||
if self.autorejoin:
|
||||
|
@ -1797,6 +1812,10 @@ class GroupchatControl(ChatControlBase):
|
|||
self._nec_gc_message_received)
|
||||
gajim.ged.remove_event_handler('vcard-published', ged.GUI1,
|
||||
self._nec_vcard_published)
|
||||
gajim.ged.remove_event_handler('vcard-received', ged.GUI1,
|
||||
self._nec_vcard_received)
|
||||
gajim.ged.remove_event_handler('gc-subject-received', ged.GUI1,
|
||||
self._nec_gc_subject_received)
|
||||
|
||||
if self.room_jid in gajim.gc_connected[self.account] and \
|
||||
gajim.gc_connected[self.account][self.room_jid]:
|
||||
|
|
|
@ -593,42 +593,6 @@ class Interface:
|
|||
if self.roster.tooltip.id and self.roster.tooltip.win:
|
||||
self.roster.tooltip.update_last_time(last_time)
|
||||
|
||||
def handle_event_gc_subject(self, account, array):
|
||||
#('GC_SUBJECT', account, (jid, subject, body, has_timestamp))
|
||||
jids = array[0].split('/', 1)
|
||||
jid = jids[0]
|
||||
|
||||
gc_control = self.msg_win_mgr.get_gc_control(jid, account)
|
||||
|
||||
if not gc_control and \
|
||||
jid in self.minimized_controls[account]:
|
||||
gc_control = self.minimized_controls[account][jid]
|
||||
|
||||
contact = gajim.contacts.\
|
||||
get_contact_with_highest_priority(account, jid)
|
||||
if contact:
|
||||
contact.status = array[1]
|
||||
self.roster.draw_contact(jid, account)
|
||||
|
||||
if not gc_control:
|
||||
return
|
||||
gc_control.set_subject(array[1])
|
||||
# Standard way, the message comes from the occupant who set the subject
|
||||
text = None
|
||||
if len(jids) > 1:
|
||||
text = _('%(jid)s has set the subject to %(subject)s') % {
|
||||
'jid': jids[1], 'subject': array[1]}
|
||||
# Workaround for psi bug http://flyspray.psi-im.org/task/595 , to be
|
||||
# deleted one day. We can receive a subject with a body that contains
|
||||
# "X has set the subject to Y" ...
|
||||
elif array[2]:
|
||||
text = array[2]
|
||||
if text is not None:
|
||||
if array[3]:
|
||||
gc_control.print_old_conversation(text)
|
||||
else:
|
||||
gc_control.print_conversation(text)
|
||||
|
||||
def handle_event_gc_config(self, obj):
|
||||
#('GC_CONFIG', account, (jid, form_node)) config is a dict
|
||||
account = obj.conn.name
|
||||
|
@ -1502,7 +1466,6 @@ class Interface:
|
|||
'MSGERROR': [self.handle_event_msgerror],
|
||||
'REGISTER_AGENT_INFO': [self.handle_event_register_agent_info],
|
||||
'AGENT_INFO_ITEMS': [self.handle_event_agent_info_items],
|
||||
'GC_SUBJECT': [self.handle_event_gc_subject],
|
||||
'GC_CONFIG_CHANGE': [self.handle_event_gc_config_change],
|
||||
'FILE_REQUEST': [self.handle_event_file_request],
|
||||
'FILE_REQUEST_ERROR': [self.handle_event_file_request_error],
|
||||
|
|
|
@ -2507,6 +2507,13 @@ class RosterWindow:
|
|||
return
|
||||
self.draw_avatar(obj.jid, obj.conn.name)
|
||||
|
||||
def _nec_gc_subject_received(self, obj):
|
||||
contact = gajim.contacts.get_contact_with_highest_priority(
|
||||
obj.conn.name, obj.room_jid)
|
||||
if contact:
|
||||
contact.status = obj.subject
|
||||
self.draw_contact(obj.room_jid, obj.conn.name)
|
||||
|
||||
################################################################################
|
||||
### Menu and GUI callbacks
|
||||
### FIXME: order callbacks in itself...
|
||||
|
@ -6262,3 +6269,5 @@ class RosterWindow:
|
|||
self._nec_pep_received)
|
||||
gajim.ged.register_event_handler('vcard-received', ged.GUI1,
|
||||
self._nec_vcard_received)
|
||||
gajim.ged.register_event_handler('gc-subject-received', ged.GUI1,
|
||||
self._nec_gc_subject_received)
|
||||
|
|
Loading…
Reference in New Issue