def sendMediaMessage(self,jid,messageId,data): try: jid.index('-') message = WAXMPP.message_store.store.Groupmessage.create() except ValueError: message = WAXMPP.message_store.store.Message.create() message = message.findFirst({'id':messageId}); media = message.getMedia() url = data.split(',')[0] name = data.split(',')[1] size = data.split(',')[2] self._d("sending media message to " + jid + " - file: " + url) if media.mediatype_id == WAConstants.MEDIA_TYPE_IMAGE: returnedId = self.interfaceHandler.call("message_imageSend", (jid, url, name, size, media.preview)) elif media.mediatype_id == WAConstants.MEDIA_TYPE_AUDIO: returnedId = self.interfaceHandler.call("message_audioSend", (jid, url, name, size)) elif media.mediatype_id == WAConstants.MEDIA_TYPE_VIDEO: returnedId = self.interfaceHandler.call("message_videoSend", (jid, url, name, size, media.preview)) key = Key(jid, True, returnedId) message.key = key.toString() message.save()
def onGroupPictureUpdatedNotification(self, jid, author, timestamp, messageId, wantsReceipt = True): if wantsReceipt: self.onNotificationReceiptRequested(jid, messageId) if WAXMPP.message_store.messageExists(jid, messageId): return key = Key(jid, False, messageId) msg = WAXMPP.message_store.createMessage(jid) msg.setData({"timestamp": timestamp,"status":0,"key":key.toString(),"content":jid,"type":23}) contact = WAXMPP.message_store.store.Contact.getOrCreateContactByJid(author) msg.contact_id = contact.id msg.Conversation = WAXMPP.message_store.getOrCreateConversationByJid(jid) msg.content = author#QtCore.QCoreApplication.translate("WAEventHandler", "%1 changed the group picture") selfChange = contact.number == self.account msg.content = msg.content.replace("%1", (contact.name or contact.number) if not selfChange else "You") WAXMPP.message_store.pushMessage(jid, msg) if not selfChange: self.interfaceHandler.call("contact_getProfilePicture", (jid,)) #@@TODO CHECK NAMING FOR GROUPS
def sendLocation(self, jid, latitude, longitude, rotate): latitude = latitude[:10] longitude = longitude[:10] self._d("Capturing preview...") QPixmap.grabWindow(QApplication.desktop().winId()).save(WAConstants.CACHE_PATH+"/tempimg.png", "PNG") img = QImage(WAConstants.CACHE_PATH+"/tempimg.png") if rotate == "true": rot = QTransform() rot = rot.rotate(90) img = img.transformed(rot) if img.height() > img.width(): result = img.scaledToWidth(320,Qt.SmoothTransformation); result = result.copy(result.width()/2-50,result.height()/2-50,100,100); elif img.height() < img.width(): result = img.scaledToHeight(320,Qt.SmoothTransformation); result = result.copy(result.width()/2-50,result.height()/2-50,100,100); #result = img.scaled(96, 96, Qt.KeepAspectRatioByExpanding, Qt.SmoothTransformation); result.save( WAConstants.CACHE_PATH+"/tempimg2.jpg", "JPG" ); f = open(WAConstants.CACHE_PATH+"/tempimg2.jpg", 'r') stream = base64.b64encode(f.read()) f.close() os.remove(WAConstants.CACHE_PATH+"/tempimg.png") os.remove(WAConstants.CACHE_PATH+"/tempimg2.jpg") fmsg = WAXMPP.message_store.createMessage(jid); mediaItem = WAXMPP.message_store.store.Media.create() mediaItem.mediatype_id = WAConstants.MEDIA_TYPE_LOCATION mediaItem.remote_url = None mediaItem.preview = stream mediaItem.local_path ="%s,%s"%(latitude,longitude) mediaItem.transfer_status = 2 fmsg.content = QtCore.QCoreApplication.translate("WAEventHandler", "Location") fmsg.Media = mediaItem if fmsg.Conversation.type == "group": contact = WAXMPP.message_store.store.Contact.getOrCreateContactByJid(self.conn.jid) fmsg.setContact(contact); fmsg.setData({"status":0,"content":fmsg.content,"type":1}) WAXMPP.message_store.pushMessage(jid,fmsg) resultId = self.interfaceHandler.call("message_locationSend", (jid, latitude, longitude, stream)) k = Key(jid, True, resultId) fmsg.key = k.toString() fmsg.save()
def sendVCard(self,jid,contactName): contactName = contactName.encode('utf-8') self._d("Sending vcard: " + WAConstants.VCARD_PATH + "/" + contactName + ".vcf") stream = self.readVCard(contactName) if not stream: return #print "DATA: " + stream fmsg = WAXMPP.message_store.createMessage(jid); mediaItem = WAXMPP.message_store.store.Media.create() mediaItem.mediatype_id = 6 mediaItem.remote_url = None mediaItem.local_path = WAConstants.VCARD_PATH + "/"+contactName+".vcf" mediaItem.transfer_status = 2 vcardImage = "" if "PHOTO;BASE64" in stream: n = stream.find("PHOTO;BASE64") +13 vcardImage = stream[n:] vcardImage = vcardImage.replace("END:VCARD","") #mediaItem.preview = vcardImage if "PHOTO;TYPE=JPEG" in stream: n = stream.find("PHOTO;TYPE=JPEG") +27 vcardImage = stream[n:] vcardImage = vcardImage.replace("END:VCARD","") #mediaItem.preview = vcardImage if "PHOTO;TYPE=PNG" in stream: n = stream.find("PHOTO;TYPE=PNG") +26 vcardImage = stream[n:] vcardImage = vcardImage.replace("END:VCARD","") #mediaItem.preview = vcardImage mediaItem.preview = vcardImage fmsg.content = contactName fmsg.Media = mediaItem if fmsg.Conversation.type == "group": contact = WAXMPP.message_store.store.Contact.getOrCreateContactByJid(self.conn.jid) fmsg.setContact(contact); fmsg.setData({"status":0,"content":fmsg.content,"type":1}) WAXMPP.message_store.pushMessage(jid,fmsg) resultId = self.interfaceHandler.call("message_vcardSend", (jid, stream, contactName)) k = Key(jid, True, resultId) fmsg.key = k.toString() fmsg.save()
def onMessageSent(self, jid, msgId): self._d("IN MESSAGE SENT") k = Key(jid, True, msgId) self._d("KEY: %s"%k.toString()) waMessage = WAXMPP.message_store.get(k); self._d(waMessage) if waMessage: WAXMPP.message_store.updateStatus(waMessage,WAXMPP.message_store.store.Message.STATUS_SENT) self.messageSent.emit(waMessage.id, jid)
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
def resendUnsent(self): ''' Resends all unsent messages, should invoke on connect ''' messages = WAXMPP.message_store.getUnsent(); self._d("Resending %i old messages"%(len(messages))) for m in messages: media = m.getMedia() jid = m.getConversation().getJid() if media is not None: if media.transfer_status == 2: if media.mediatype_id == 6: vcard = self.readVCard(m.content) if vcard: resultId = self.interfaceHandler.call("message_vcardSend", (jid, vcard, m.content)) k = Key(jid, True, resultId) m.key = k.toString() m.save() elif media.mediatype_id == 5: latitude,longitude = media.local_path.split(',') resultId = self.interfaceHandler.call("message_locationSend", (jid, latitude, longitude, media.preview)) k = Key(jid, True, resultId) m.key = k.toString() m.save() else: media.transfer_status = 1 media.save() else: try: msgId = self.interfaceHandler.call("message_send", (jid, m.content.encode('utf-8'))) m.key = Key(jid, True, msgId).toString() m.save() except UnicodeDecodeError: self._d("skipped sending an old message because UnicodeDecodeError") self._d("Resending old messages done")
def onGroupParticipantAddedNotification(self, gJid, jid, author, timestamp, messageId, wantsReceipt = True): if wantsReceipt: self.onNotificationReceiptRequested(gJid, messageId) if WAXMPP.message_store.messageExists(jid, messageId): return key = Key(gJid, False, messageId) if jid == self.account: print "THIS IS ME! GETTING OWNER..." jid = gJid.split('-')[0]+"@s.whatsapp.net" self._d("Contact added: " + jid) msg = WAXMPP.message_store.createMessage(gJid) msg.setData({"timestamp": timestamp,"status":0,"key":key.toString(),"content":jid,"type":20}) contact = WAXMPP.message_store.store.Contact.getOrCreateContactByJid(jid) msg.contact_id = contact.id msg.content = jid msg.Conversation = WAXMPP.message_store.getOrCreateConversationByJid(gJid) msg.Conversation.subject = "" if msg.Conversation.subject is None else msg.Conversation.subject if author == jid: notifyContent = QtCore.QCoreApplication.translate("WAEventHandler", "%1 joined the group") notifyContent = msg.content.replace("%1", contact.name or contact.number) else: authorContact = WAXMPP.message_store.store.Contact.getOrCreateContactByJid(author) notifyContent = QtCore.QCoreApplication.translate("WAEventHandler", "%1 added %2 to the group") notifyContent.replace("%1", authorContact.name or authorContact.number) notifyContent = msg.content.replace("%2", contact.name or contact.number) msg.contact_id = authorContact.id WAXMPP.message_store.pushMessage(gJid,msg) self.notifier.newGroupMessage(gJid, "%s - %s"%(contact.name or contact.number, msg.Conversation.subject.decode("utf8")), notifyContent, self.getDisplayPicture(gJid).encode('utf-8'),callback = self.notificationClicked);
def wrapped(self, *args): messageId = args[0] jid = args[1] if WAXMPP.message_store.messageExists(jid, messageId): self.interfaceHandler.call("message_ack", (jid, messageId)) return key = Key(jid,False,messageId); msg = WAXMPP.message_store.createMessage(jid) author = jid isGroup = WAXMPP.message_store.isGroupJid(jid) if isGroup: author = args[2] msgContact = WAXMPP.message_store.store.Contact.getOrCreateContactByJid(author) msg.Contact = msgContact msg.setData({"status":0,"key":key.toString(),"type":WAXMPP.message_store.store.Message.TYPE_RECEIVED}); msg.contact_id = msgContact.id return fn(self,msg, *args[2:]) if author == jid else fn(self,msg, *args[3:]) #omits author as well if group
def parseMessage(self,messageNode): #if messageNode.getChild("media") is not None: # return fromAttribute = messageNode.getAttributeValue("from"); author = messageNode.getAttributeValue("author"); fmsg = WAXMPP.message_store.createMessage(fromAttribute) fmsg.wantsReceipt = False conversation = WAXMPP.message_store.getOrCreateConversationByJid(fromAttribute); fmsg.conversation_id = conversation fmsg.Conversation = conversation msg_id = messageNode.getAttributeValue("id"); attribute_t = messageNode.getAttributeValue("t"); 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); 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,"media") and msg_id is not None: self._d("MULTIMEDIA MESSAGE!"); mediaItem = WAXMPP.message_store.store.Media.create() mediaItem.remote_url = messageNode.getChild("media").getAttributeValue("url"); mediaType = messageNode.getChild("media").getAttributeValue("type") msgdata = mediaType preview = None try: index = fromAttribute.index('-') #group conv contact = WAXMPP.message_store.store.Contact.getOrCreateContactByJid(author) fmsg.contact_id = contact.id fmsg.contact = contact except ValueError: #single conv pass if mediaType == "image": mediaItem.mediatype_id = WAConstants.MEDIA_TYPE_IMAGE mediaItem.preview = messageNode.getChild("media").data elif mediaType == "audio": mediaItem.mediatype_id = WAConstants.MEDIA_TYPE_AUDIO elif mediaType == "video": mediaItem.mediatype_id = WAConstants.MEDIA_TYPE_VIDEO elif mediaType == "location": mlatitude = messageNode.getChild("media").getAttributeValue("latitude") mlongitude = messageNode.getChild("media").getAttributeValue("longitude") mediaItem.mediatype_id = WAConstants.MEDIA_TYPE_LOCATION mediaItem.remote_url = None mediaItem.preview = messageNode.getChild("media").data mediaItem.local_path ="%s,%s"%(mlatitude,mlongitude) mediaItem.transfer_status = 2 elif mediaType =="vcard": return mediaItem.preview = messageNode.getChild("media").data else: self._d("Unknown media type") return fmsg.Media = mediaItem #if ProtocolTreeNode.tagEquals(childNode,"body"): This suposses handle MEDIA + TEXT # msgdata = msgdata + " " + childNode.data; But it's not supported in whatsapp? key = Key(fromAttribute,False,msg_id); fmsg.setData({"status":0,"key":key.toString(),"content":msgdata,"type":WAXMPP.message_store.store.Message.TYPE_RECEIVED}); elif ProtocolTreeNode.tagEquals(childNode,"body") and msg_id is not None: msgdata = childNode.data; #mediaItem = WAXMPP.message_store.store.Media.create() #mediaItem.mediatype_id = WAConstants.MEDIA_TYPE_TEXT #fmsg.Media = mediaItem fmsg.Media = None key = Key(fromAttribute,False,msg_id); fmsg.setData({"status":0,"key":key.toString(),"content":msgdata,"type":WAXMPP.message_store.store.Message.TYPE_RECEIVED}); 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,"delay"): xmlns = childNode.getAttributeValue("xmlns"); if "urn:xmpp:delay" == xmlns: stamp_str = childNode.getAttributeValue("stamp"); if stamp_str is not None: stamp = stamp_str fmsg.timestamp = self.parseOfflineMessageStamp(stamp)*1000; fmsg.offline = True; 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) 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); 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); self._d(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; print fmsg.getModelData(); if self.eventHandler is not None: signal = True if fmsg.content: try: index = fromAttribute.index('-') #group conv contact = WAXMPP.message_store.store.Contact.getOrCreateContactByJid(author) fmsg.contact_id = contact.id fmsg.contact = contact except ValueError: #single conv pass if conversation.type == "group": if conversation.subject is None: signal = False self._d("GETTING GROUP INFO") self.connection.sendGetGroupInfo(fromAttribute) ret = WAXMPP.message_store.get(key); if ret is None: conversation.incrementNew(); WAXMPP.message_store.pushMessage(fromAttribute,fmsg) fmsg.key = key else: fmsg.key = eval(ret.key) duplicate = True; if signal: self.eventHandler.message_received(fmsg,duplicate);
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)
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);