| | 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 | |
| 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 |