summaryrefslogtreecommitdiff
path: root/protocols/JabberG/src/jabber_thread.cpp
diff options
context:
space:
mode:
authorVladimir <me@boku.ru>2018-01-29 17:56:07 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-01-30 18:51:41 +0300
commitac42d6d50636db69e56623b4b8093a5993c829d1 (patch)
tree71eeafa5e9b59d444a3073e3ac9d57845e5c285b /protocols/JabberG/src/jabber_thread.cpp
parent3d7ef20f11d1bfc7c75a16943a9c8cfcaef1408e (diff)
Carbons support attempt
Diffstat (limited to 'protocols/JabberG/src/jabber_thread.cpp')
-rwxr-xr-xprotocols/JabberG/src/jabber_thread.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp
index 60cf077661..1177020ab0 100755
--- a/protocols/JabberG/src/jabber_thread.cpp
+++ b/protocols/JabberG/src/jabber_thread.cpp
@@ -1051,6 +1051,43 @@ void CJabberProto::OnProcessMessage(HXML node, ThreadData *info)
if (m_messageManager.HandleMessagePermanent(node, info))
return;
+ //Handle carbons. The message MUST be coming from our bare JID.
+ HXML carbon = nullptr;
+ bool carbonSent = false; //2 cases: received or sent.
+ if (this->IsMyOwnJID(from)) {
+ carbon = XmlGetChildByTag(node, "received", "xmlns", JABBER_FEAT_CARBONS);
+ if (!carbon) {
+ carbon = XmlGetChildByTag(node, "sent", "xmlns", JABBER_FEAT_CARBONS);
+ if (carbon)
+ carbonSent = true;
+ }
+ if (carbon) {
+ HXML forwarded = NULL;
+ HXML message = NULL;
+ //Carbons MUST have forwarded/message content
+ if (!(forwarded = XmlGetChildByTag(carbon, "forwarded", "xmlns", JABBER_XMLNS_FORWARD))
+ || !(message = XmlGetChild(forwarded, "message")))
+ return;
+
+ //Unwrap the carbon in any case
+ node = message;
+ type = XmlGetAttrValue(node, L"type");
+
+ if (!carbonSent) {
+ //Received should just be treated like incoming messages, except maybe not flash the flasher. Simply unwrap.
+ from = XmlGetAttrValue(node, L"from");
+ if (from == nullptr)
+ return;
+ }
+ else {
+ //Sent should set SENT flag and invert from/to.
+ from = XmlGetAttrValue(node, L"to");
+ if (from == nullptr)
+ return;
+ }
+ }
+ }
+
MCONTACT hContact = HContactFromJID(from);
JABBER_LIST_ITEM *chatItem = ListGetItemPtr(LIST_CHATROOM, from);
if (chatItem) {
@@ -1416,6 +1453,11 @@ void CJabberProto::OnProcessMessage(HXML node, ThreadData *info)
msgTime = now;
PROTORECVEVENT recv = { 0 };
+ if (carbon) {
+ recv.flags |= PREF_CREATEREAD;
+ if (carbonSent)
+ recv.flags |= PREF_SENT;
+ }
recv.timestamp = (DWORD)msgTime;
recv.szMessage = buf;
recv.lParam = (LPARAM)((pFromResource != nullptr && m_options.EnableRemoteControl) ? pFromResource->m_tszResourceName : 0);
@@ -1941,6 +1983,17 @@ void CJabberProto::OnProcessRegIq(HXML node, ThreadData *info)
}
}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Carbons -- this might need to go into its own module
+
+void CJabberProto::EnableCarbons(bool bEnable)
+{
+ m_ThreadInfo->send(XmlNodeIq(L"set", SerialNext())
+ << XCHILDNS((bEnable) ? L"enable" : L"disable", JABBER_FEAT_CARBONS));
+}
+
+
/////////////////////////////////////////////////////////////////////////////////////////
// ThreadData constructor & destructor