changeset 90040f3e931c in /home/hg/repos/gajim

details:http://hg.gajim.org/gajim?cmd=changeset;node=90040f3e931c
description: use NEC to handle message (not) sent events

diffstat:

 src/common/connection.py                   |   9 ++++++---
 src/common/connection_handlers_events.py   |   4 ++++
 src/common/zeroconf/connection_zeroconf.py |   3 ++-
 src/gui_interface.py                       |  19 +++++++++----------
 4 files changed, 21 insertions(+), 14 deletions(-)

diffs (114 lines):

diff -r e694ca90429e -r 90040f3e931c src/common/connection.py
--- a/src/common/connection.py  Sun Nov 07 22:45:01 2010 +0100
+++ b/src/common/connection.py  Mon Nov 08 21:23:08 2010 +0100
@@ -340,7 +340,8 @@
             return
         # Encryption failed, do not send message
         tim = localtime()
-        self.dispatch('MSGNOTSENT', (jid, error, msgtxt, tim, session))
+        gajim.nec.push_incoming_event(MessageNotSentEvent(None, conn=self,
+            jid=jid, message=msgtxt, error=error, time_=tim, session=session))
 
     def _on_continue_message(self, type_, msg, msgtxt, original_message, fjid,
     resource, jid, xhtml, subject, msgenc, keyID, chatstate, msg_id,
@@ -1646,7 +1647,8 @@
         subject, type_, msg_iq):
             msg_id = self.connection.send(msg_iq, now=now)
             jid = helpers.parse_jid(jid)
-            self.dispatch('MSGSENT', (jid, msg, keyID))
+            gajim.nec.push_incoming_event(MessageSentEvent(None, conn=self,
+                jid=jid, message=msg, keyID=keyID))
             if callback:
                 callback(msg_id, *callback_args)
 
@@ -2100,7 +2102,8 @@
         if label is not None:
             msg_iq.addChild(node = label)
         self.connection.send(msg_iq)
-        self.dispatch('MSGSENT', (jid, msg))
+        gajim.nec.push_incoming_event(MessageSentEvent(None, conn=self,
+            jid=jid, message=msg, keyID=None))
 
     def send_gc_subject(self, jid, subject):
         if not gajim.account_is_connected(self.name):
diff -r e694ca90429e -r 90040f3e931c src/common/connection_handlers_events.py
--- a/src/common/connection_handlers_events.py  Sun Nov 07 22:45:01 2010 +0100
+++ b/src/common/connection_handlers_events.py  Mon Nov 08 21:23:08 2010 +0100
@@ -1115,6 +1115,10 @@
 
         return True
 
+class MessageSentEvent(nec.NetworkIncomingEvent):
+    name = 'message-sent'
+    base_network_events = []
+
 class AnonymousAuthEvent(nec.NetworkIncomingEvent):
     name = 'anonymous-auth'
     base_network_events = []
diff -r e694ca90429e -r 90040f3e931c src/common/zeroconf/connection_zeroconf.py
--- a/src/common/zeroconf/connection_zeroconf.py        Sun Nov 07 22:45:01 
2010 +0100
+++ b/src/common/zeroconf/connection_zeroconf.py        Mon Nov 08 21:23:08 
2010 +0100
@@ -329,7 +329,8 @@
     callback_args=[], now=True):
 
         def on_send_ok(msg_id):
-            self.dispatch('MSGSENT', (jid, msg, keyID))
+            gajim.nec.push_incoming_event(MessageSentEvent(None, conn=self,
+                jid=jid, message=msg, keyID=keyID))
             if callback:
                 callback(msg_id, *callback_args)
 
diff -r e694ca90429e -r 90040f3e931c src/gui_interface.py
--- a/src/gui_interface.py      Sun Nov 07 22:45:01 2010 +0100
+++ b/src/gui_interface.py      Mon Nov 08 21:23:08 2010 +0100
@@ -452,25 +452,24 @@
         if session:
             session.roster_message(jid, msg, array[4], msg_type='error')
 
-    def handle_event_msgsent(self, account, array):
+    def handle_event_msgsent(self, obj):
         #('MSGSENT', account, (jid, msg, keyID))
-        msg = array[1]
         # do not play sound when standalone chatstate message (eg no msg)
-        if msg and gajim.config.get_per('soundevents', 'message_sent',
+        if obj.message and gajim.config.get_per('soundevents', 'message_sent',
         'enabled'):
             helpers.play_sound('message_sent')
 
-    def handle_event_msgnotsent(self, account, array):
+    def handle_event_msgnotsent(self, obj):
         #('MSGNOTSENT', account, (jid, ierror_msg, msg, time, session))
         msg = _('error while sending %(message)s ( %(error)s )') % {
-                'message': array[2], 'error': array[1]}
-        if not array[4]:
+                'message': obj.message, 'error': obj.error}
+        if not obj.session:
             # No session. This can happen when sending a message from
             # gajim-remote
             log.warn(msg)
             return
-        array[4].roster_message(array[0], msg, array[3], account,
-                msg_type='error')
+        obj.session.roster_message(obj.jid, msg, obj.time_, obj.conn.name,
+            msg_type='error')
 
     def handle_event_subscribe_presence(self, obj):
         #('SUBSCRIBE', account, (jid, text, user_nick)) user_nick is JEP-0172
@@ -1796,8 +1795,6 @@
             'DB_ERROR': [self.handle_event_db_error],
             'INFORMATION': [self.handle_event_information],
             'MSGERROR': [self.handle_event_msgerror],
-            'MSGSENT': [self.handle_event_msgsent],
-            'MSGNOTSENT': [self.handle_event_msgnotsent],
             'AGENT_REMOVED': [self.handle_event_agent_removed],
             'REGISTER_AGENT_INFO': [self.handle_event_register_agent_info],
             'AGENT_INFO_ITEMS': [self.handle_event_agent_info_items],
@@ -1857,6 +1854,8 @@
             'jingle-error-received': [self.handle_event_jingle_error],
             'jingle-request-received': [self.handle_event_jingle_incoming],
             'last-result-received': [self.handle_event_last_status_time],
+            'message-not-sent': [self.handle_event_msgnotsent],
+            'message-sent': [self.handle_event_msgsent],
             'muc-admin-received': [self.handle_event_gc_affiliation],
             'muc-owner-received': [self.handle_event_gc_config],
             'our-show': [self.handle_event_status],
_______________________________________________
Commits mailing list
[email protected]
http://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to