Beispiel #1
0
    def setData(self, remote_jid, from_me, data, image=None):
        localKey = Key(
            remote_jid, from_me,
            FMessage.generating_header + str(FMessage.generating_id))

        while WAXMPP.message_store.get(localKey) is not None:
            FMessage.generating_id += 1
            localKey = Key(
                remote_jid, from_me,
                FMessage.generating_header + str(FMessage.generating_id))

        WAXMPP.message_store.put(localKey, self)
        self.key = localKey
        if data is not None:
            self.data = data
            self.thumb_image = image
            self.timestamp = int(time.time()) * 1000
Beispiel #2
0
    def parseMessage(self, messageNode):

        #throw media in the garbage

        if messageNode.getChild("media") is not None:
            return

        fmsg = WAXMPP.message_store.store.Message.create()

        fmsg.wantsReceipt = False

        msg_id = messageNode.getAttributeValue("id")
        attribute_t = messageNode.getAttributeValue("t")
        fromAttribute = messageNode.getAttributeValue("from")
        author = messageNode.getAttributeValue("author")

        typeAttribute = messageNode.getAttributeValue("type")

        if typeAttribute == "error":
            errorCode = 0
            errorNodes = messageNode.getAllChildren("error")
            for errorNode in errorNodes:
                codeString = errorNode.getAttributeValue("code")
                try:
                    errorCode = int(codeString)
                except ValueError:
                    '''catch value error'''
            message = None
            if fromAttribute is not None and msg_id is not None:
                key = Key(fromAttribute, True, msg_id)
                message = message_store.get(key.toString())

            if message is not None:
                message.status = 7
                self.eventHandler.message_error(message, errorCode)

        elif typeAttribute == "subject":
            receiptRequested = False
            requestNodes = messageNode.getAllChildren("request")
            for requestNode in requestNodes:
                if requestNode.getAttributeValue(
                        "xmlns") == "urn:xmpp:receipts":
                    receiptRequested = True

            bodyNode = messageNode.getChild("body")
            newSubject = None if bodyNode is None else bodyNode.data

            if newSubject is not None and self.groupEventHandler is not None:
                self.groupEventHandler.group_new_subject(
                    fromAttribute, author, newSubject, int(attribute_t))

            if receiptRequested and self.eventHandler is not None:
                self.eventHandler.subjectReceiptRequested(
                    fromAttribute, msg_id)

        elif typeAttribute == "chat":
            duplicate = False
            wantsReceipt = False
            messageChildren = [] if messageNode.children is None else messageNode.children

            for childNode in messageChildren:
                if ProtocolTreeNode.tagEquals(childNode, "composing"):
                    if self.eventHandler is not None:
                        self.eventHandler.typing_received(fromAttribute)
                elif ProtocolTreeNode.tagEquals(childNode, "paused"):
                    if self.eventHandler is not None:
                        self.eventHandler.paused_received(fromAttribute)

                elif ProtocolTreeNode.tagEquals(childNode,
                                                "body") and msg_id is not None:
                    msgdata = childNode.data
                    key = Key(fromAttribute, False, msg_id)
                    ret = WAXMPP.message_store.get(key.toString())

                    if ret is None:
                        conversation = WAXMPP.message_store.getOrCreateConversationByJid(
                            fromAttribute)
                        fmsg.setData({
                            "status":
                            0,
                            "key":
                            key.toString(),
                            "content":
                            msgdata,
                            "conversation_id":
                            conversation.id,
                            "type":
                            WAXMPP.message_store.store.Message.TYPE_RECEIVED
                        })

                        WAXMPP.message_store.pushMessage(fmsg)
                        fmsg.key = key

                        #if self.eventHandler is not None:
                        #self.eventHandler.message_received(fmsg);
                    else:
                        fmsg.key = eval(ret.key)
                        duplicate = True
                elif not (ProtocolTreeNode.tagEquals(childNode, "active")):
                    if ProtocolTreeNode.tagEquals(childNode, "request"):
                        fmsg.wantsReceipt = True

                    elif ProtocolTreeNode.tagEquals(childNode, "notify"):
                        fmsg.notify_name = childNode.getAttributeValue("name")
                    elif ProtocolTreeNode.tagEquals(childNode, "x"):
                        xmlns = childNode.getAttributeValue("xmlns")
                        if "jabber:x:event" == xmlns and msg_id is not None:

                            key = Key(fromAttribute, True, msg_id)
                            message = WAXMPP.message_store.get(key.toString())
                            if message is not None:
                                WAXMPP.message_store.updateStatus(
                                    message, WAXMPP.message_store.store.
                                    Message.STATUS_SENT)

                                if self.eventHandler is not None:
                                    self.eventHandler.message_status_update(
                                        message)
                        elif "jabber:x:delay" == xmlns:
                            continue
                            #TODO FORCED CONTINUE, WHAT SHOULD I DO HERE? #wtf?
                            stamp_str = childNode.getAttributeValue("stamp")
                            if stamp_str is not None:
                                stamp = stamp_str
                                fmsg.timestamp = stamp
                                fmsg.offline = True
                    else:
                        if ProtocolTreeNode.tagEquals(
                                childNode,
                                "delay") or not ProtocolTreeNode.tagEquals(
                                    childNode, "received") or msg_id is None:
                            continue
                        key = Key(fromAttribute, True, msg_id)
                        message = WAXMPP.message_store.get(key.toString())
                        if message is not None:
                            WAXMPP.message_store.updateStatus(
                                message, WAXMPP.message_store.store.Message.
                                STATUS_DELIVERED)
                            if self.eventHandler is not None:
                                self.eventHandler.message_status_update(
                                    message)
                            print self.connection.supports_receipt_acks
                            if self.connection.supports_receipt_acks:

                                receipt_type = childNode.getAttributeValue(
                                    "type")
                                if receipt_type is None or receipt_type == "delivered":
                                    self.connection.sendDeliveredReceiptAck(
                                        fromAttribute, msg_id)
                                elif receipt_type == "visible":
                                    self.connection.sendVisibleReceiptAck(
                                        fromAttribute, msg_id)

            if fmsg.timestamp is None:
                fmsg.timestamp = time.time() * 1000
                fmsg.offline = False

            if self.eventHandler is not None:
                self.eventHandler.message_received(fmsg, duplicate)