Show
Ignore:
Timestamp:
04/15/08 07:32:45 (7 months ago)
Author:
bct
Message:

check tic-tac-toe win conditions, slimmed down _messageCB some more

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/session_centric/src/session.py

    r9459 r9465  
    11from common import helpers 
    22 
     3from common import exceptions 
    34from common import gajim 
    45from common import stanza_session 
    56from common import contacts 
    67 
     8import common.xmpp 
     9 
    710import dialogs 
    811 
     
    1720                self.control = None 
    1821 
     22        # extracts chatstate from a <message/> stanza 
     23        def get_chatstate(self, msg, msgtxt): 
     24                composing_xep = None 
     25                chatstate = None 
     26 
     27                # chatstates - look for chatstate tags in a message if not delayed 
     28                delayed = msg.getTag('x', namespace=common.xmpp.NS_DELAY) != None 
     29                if not delayed: 
     30                        composing_xep = False 
     31                        children = msg.getChildren() 
     32                        for child in children: 
     33                                if child.getNamespace() == 'http://jabber.org/protocol/chatstates': 
     34                                        chatstate = child.getName() 
     35                                        composing_xep = 'XEP-0085' 
     36                                        break 
     37                        # No XEP-0085 support, fallback to XEP-0022 
     38                        if not chatstate: 
     39                                chatstate_child = msg.getTag('x', namespace = common.xmpp.NS_EVENT) 
     40                                if chatstate_child: 
     41                                        chatstate = 'active' 
     42                                        composing_xep = 'XEP-0022' 
     43                                        if not msgtxt and chatstate_child.getTag('composing'): 
     44                                                chatstate = 'composing' 
     45 
     46                return (composing_xep, chatstate) 
     47 
    1948        # dispatch a received <message> stanza 
    20         def received(self, full_jid_with_resource, message, tim, encrypted, msg_type, subject, chatstate, msg_id, composing_xep, user_nick, xhtml, form_node): 
     49        def received(self, full_jid_with_resource, msgtxt, tim, encrypted, subject, msg): 
     50                msg_type = msg.getType() 
     51                msg_id = None 
     52 
     53                # XEP-0172 User Nickname 
     54                user_nick = msg.getTagData('nick') 
     55                if not user_nick: 
     56                        user_nick ='' 
     57 
     58                form_node = None 
     59                for xtag in msg.getTags('x'): 
     60                        if xtag.getNamespace() == common.xmpp.NS_DATA: 
     61                                form_node = xtag 
     62                                break 
     63 
     64                composing_xep, chatstate = self.get_chatstate(msg, msgtxt) 
     65 
     66                xhtml = msg.getXHTML() 
     67 
     68                if msg_type == 'chat': 
     69                        if not msg.getTag('body') and chatstate is None: 
     70                                return 
     71 
     72                        log_type = 'chat_msg_recv' 
     73                else: 
     74                        log_type = 'single_msg_recv' 
     75 
     76                if self.is_loggable() and msgtxt: 
     77                        try: 
     78                                msg_id = gajim.logger.write(log_type, full_jid_with_resource, msgtxt, 
     79                                                tim=tim, subject=subject) 
     80                        except exceptions.PysqliteOperationalError, e: 
     81                                gajim.dispatch('ERROR', (_('Disk WriteError'), str(e))) 
     82 
     83                treat_as = gajim.config.get('treat_incoming_messages') 
     84                if treat_as: 
     85                        msg_type = treat_as 
    2186 
    2287                jid = gajim.get_jid_without_resource(full_jid_with_resource) 
     
    66131                # THIS MUST BE AFTER chatstates handling 
    67132                # AND BEFORE playsound (else we ear sounding on chatstates!) 
    68                 if not message: # empty message text 
     133                if not msgtxt: # empty message text 
    69134                        return 
    70135 
     
    87152                if pm: 
    88153                        nickname = resource 
    89                         groupchat_control.on_private_message(nickname, message, array[2], 
     154                        groupchat_control.on_private_message(nickname, msgtxt, array[2], 
    90155                                xhtml, session, msg_id) 
    91156                else: 
    92                         self.roster_message(jid, message, tim, encrypted, msg_type, 
     157                        self.roster_message(jid, msgtxt, tim, encrypted, msg_type, 
    93158                                subject, resource, msg_id, user_nick, advanced_notif_num, 
    94159                                xhtml=xhtml, form_node=form_node) 
     
    96161                        nickname = gajim.get_name_from_jid(self.conn.name, jid) 
    97162                # Check and do wanted notifications 
    98                 msg = message 
     163                msg = msgtxt 
    99164                if subject: 
    100165                        msg = _('Subject: %s') % subject + '\n' + msg 
     
    112177                if gajim.interface.remote_ctrl: 
    113178                        gajim.interface.remote_ctrl.raise_signal('NewMessage', 
    114                                         (self.conn.name, [full_jid_with_resource, message, tim, 
     179                                        (self.conn.name, [full_jid_with_resource, msgtxt, tim, 
    115180                                                encrypted, msg_type, subject, chatstate, msg_id, 
    116181                                                composing_xep, user_nick, xhtml, form_node]))