diff options
Diffstat (limited to 'protocols/JabberG/src/jabber_thread.cpp')
-rwxr-xr-x | protocols/JabberG/src/jabber_thread.cpp | 61 |
1 files changed, 35 insertions, 26 deletions
diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp index f295adbfc7..a9b3a6c78d 100755 --- a/protocols/JabberG/src/jabber_thread.cpp +++ b/protocols/JabberG/src/jabber_thread.cpp @@ -1005,18 +1005,49 @@ void CJabberProto::OnProcessMessage(const TiXmlElement *node, ThreadData *info) if (!node->Name() || mir_strcmp(node->Name(), "message"))
return;
- const char *from, *type = XmlGetAttr(node, "type");
- if ((from = XmlGetAttr(node, "from")) == nullptr) {
+ bool bEnableDelivery = true;
+ time_t msgTime = 0;
+ auto *from = XmlGetAttr(node, "from"), *type = XmlGetAttr(node, "type"), *idStr = XmlGetAttr(node, "id");
+ const char *szMsgId = nullptr; // MAM support
+
+ // check for MAM response
+ if (auto *mamResult = XmlGetChildByTag(node, "result", "xmlns", JABBER_FEAT_MAM)) {
+ szMsgId = XmlGetAttr(mamResult, "id");
+ if (szMsgId)
+ setString("LastMamId", szMsgId);
+
+ // we only collect ids, no need to store messages
+ if (m_bMamDisableMessages)
+ return;
+
+ auto *xmlForwarded = XmlGetChildByTag(mamResult, "forwarded", "xmlns", JABBER_XMLNS_FORWARD);
+ if (auto *xmlMessage = XmlFirstChild(xmlForwarded, "message")) {
+ node = xmlMessage;
+ type = XmlGetAttr(node, "type");
+ from = XmlGetAttr(node, "from");
+ if (!mir_strcmpi(from, info->fullJID)) {
+ debugLogA("MAM: outgoing message from this machine (%s), ignored", from);
+ return;
+ }
+ }
+
+ if (auto *xmlDelay = XmlGetChildByTag(xmlForwarded, "delay", "xmlns", JABBER_FEAT_DELAY))
+ if (auto *ptszTimeStamp = XmlGetAttr(xmlDelay, "stamp"))
+ msgTime = JabberIsoToUnixTime(ptszTimeStamp);
+
+ bEnableDelivery = false;
+ }
+
+ if (from == nullptr) {
debugLogA("no 'from' attribute, returning");
return;
}
- const char *idStr = XmlGetAttr(node, "id");
pResourceStatus pFromResource(ResourceInfoFromJID(from));
// Message receipts delivery request. Reply here, before a call to HandleMessagePermanent() to make sure message receipts are handled for external plugins too.
bool bSendMark = false;
- if ((!type || mir_strcmpi(type, "error"))) {
+ if (bEnableDelivery && (!type || mir_strcmpi(type, "error"))) {
bool bSendReceipt = XmlGetChildByTag(node, "request", "xmlns", JABBER_FEAT_MESSAGE_RECEIPTS) != 0;
bSendMark = XmlGetChildByTag(node, "markable", "xmlns", JABBER_FEAT_CHAT_MARKERS) != 0;
if (bSendReceipt || bSendMark) {
@@ -1040,8 +1071,6 @@ void CJabberProto::OnProcessMessage(const TiXmlElement *node, ThreadData *info) return;
}
- time_t msgTime = 0;
-
// Handle carbons. The message MUST be coming from our bare JID.
const TiXmlElement *carbon = nullptr;
bool carbonSent = false; //2 cases: received or sent.
@@ -1087,24 +1116,6 @@ void CJabberProto::OnProcessMessage(const TiXmlElement *node, ThreadData *info) }
}
}
- else { // check for MAM response
- if (auto *mamResult = XmlGetChildByTag(node, "result", "xmlns", JABBER_FEAT_MAM)) {
- auto *xmlForwarded = XmlGetChildByTag(mamResult, "forwarded", "xmlns", JABBER_XMLNS_FORWARD);
- if (auto *xmlMessage = XmlFirstChild(xmlForwarded, "message")) {
- node = xmlMessage;
- type = XmlGetAttr(node, "type");
- from = XmlGetAttr(node, "from");
- if (!mir_strcmpi(from, info->fullJID)) {
- debugLogA("MAM: outgoing message from this machine (%s), ignored", from);
- return;
- }
- }
- if (auto *xmlDelay = XmlGetChildByTag(xmlForwarded, "delay", "xmlns", JABBER_FEAT_DELAY)) {
- if (auto *ptszTimeStamp = XmlGetAttr(xmlDelay, "stamp"))
- msgTime = JabberIsoToUnixTime(ptszTimeStamp);
- }
- }
- }
}
MCONTACT hContact = HContactFromJID(from);
@@ -1146,8 +1157,6 @@ void CJabberProto::OnProcessMessage(const TiXmlElement *node, ThreadData *info) if (bodyNode != nullptr)
szMessage.Append(bodyNode->GetText());
- // check MAM support
- const char *szMsgId = nullptr;
if (auto *n = XmlGetChildByTag(node, "stanza-id", "xmlns", JABBER_FEAT_SID))
if (szMsgId = n->Attribute("id"))
setString("LastMamId", szMsgId);
|