From 319f0c53660aa80d357715881fd4b8068cdb73ca Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 15 Aug 2022 20:51:04 +0300 Subject: Jabber: ability to load group chat avatars (once in a day) --- protocols/JabberG/src/jabber_chat.cpp | 6 ++++++ protocols/JabberG/src/jabber_groupchat.cpp | 5 +++++ protocols/JabberG/src/jabber_iqid.cpp | 5 ++++- protocols/JabberG/src/jabber_util.cpp | 8 +++++--- protocols/JabberG/src/jabber_vcard.cpp | 2 +- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/protocols/JabberG/src/jabber_chat.cpp b/protocols/JabberG/src/jabber_chat.cpp index bd74e32719..a657f1af40 100644 --- a/protocols/JabberG/src/jabber_chat.cpp +++ b/protocols/JabberG/src/jabber_chat.cpp @@ -155,6 +155,12 @@ int CJabberProto::GcInit(JABBER_LIST_ITEM *item) Chat_Control(m_szModuleName, wszJid, (item->bAutoJoin && m_bAutoJoinHidden) ? WINDOW_HIDDEN : SESSION_INITDONE); Chat_Control(m_szModuleName, wszJid, SESSION_ONLINE); + + time_t lastDate = getDword(si->hContact, "LastGetVcard"), now = time(0); + if (now - lastDate > 24 * 60 * 60) { + SendGetVcard(si->hContact); + setDword(si->hContact, "LastGetVcard", now); + } return 0; } diff --git a/protocols/JabberG/src/jabber_groupchat.cpp b/protocols/JabberG/src/jabber_groupchat.cpp index 03d7d5c0a1..838c0f8d71 100644 --- a/protocols/JabberG/src/jabber_groupchat.cpp +++ b/protocols/JabberG/src/jabber_groupchat.cpp @@ -1008,6 +1008,11 @@ void CJabberProto::GroupchatProcessMessage(const TiXmlElement *node) if (resource != nullptr && *++resource == '\0') resource = nullptr; + for (auto *x : TiXmlFilter(node, "x")) + if (!mir_strcmp(XmlGetAttr(x, "xmlns"), JABBER_FEAT_MUC_USER)) + if (XmlGetChildByTag(x, "status", "code", "104")) + SendGetVcard(item->hContact); + if ((n = XmlFirstChild(node, "subject")) != nullptr) { msgText = n->GetText(); if (msgText == nullptr || msgText[0] == '\0') diff --git a/protocols/JabberG/src/jabber_iqid.cpp b/protocols/JabberG/src/jabber_iqid.cpp index db8652dfd4..e0daa61151 100644 --- a/protocols/JabberG/src/jabber_iqid.cpp +++ b/protocols/JabberG/src/jabber_iqid.cpp @@ -616,9 +616,12 @@ void CJabberProto::OnIqResultGetVcardPhoto(const TiXmlElement *n, MCONTACT hCont ReportSelfAvatarChanged(); } else { - ptrA jid(getUStringA(hContact, "jid")); + ptrA jid(ContactToJID(hContact)); if (jid != nullptr) { JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_ROSTER, jid); + if (item == nullptr) + item = ListGetItemPtr(LIST_CHATROOM, jid); + if (item == nullptr) { item = ListAdd(LIST_VCARD_TEMP, jid); // adding to the temp list to store information about photo if (item != nullptr) diff --git a/protocols/JabberG/src/jabber_util.cpp b/protocols/JabberG/src/jabber_util.cpp index 9da3058bf4..437b2b482d 100644 --- a/protocols/JabberG/src/jabber_util.cpp +++ b/protocols/JabberG/src/jabber_util.cpp @@ -55,12 +55,14 @@ MCONTACT CJabberProto::HContactFromJID(const char *jid, bool bStripResource) if (item != nullptr && item->hContact) return item->hContact; + item = ListGetItemPtr(LIST_CHATROOM, jid); + if (item != nullptr && item->hContact) + return item->hContact; + if (bStripResource) { char szJid[JABBER_MAX_JID_LEN]; JabberStripJid(jid, szJid, _countof(szJid)); - item = ListGetItemPtr(LIST_ROSTER, szJid); - if (item != nullptr && item->hContact) - return item->hContact; + return HContactFromJID(szJid, false); } return 0; diff --git a/protocols/JabberG/src/jabber_vcard.cpp b/protocols/JabberG/src/jabber_vcard.cpp index 97de0efe7a..d8ba73b3ca 100644 --- a/protocols/JabberG/src/jabber_vcard.cpp +++ b/protocols/JabberG/src/jabber_vcard.cpp @@ -43,7 +43,7 @@ int CJabberProto::SendGetVcard(MCONTACT hContact) pInfo = AddIQ(&CJabberProto::OnIqResultGetVcard, JABBER_IQ_TYPE_GET, m_szJabberJID); } else { - ptrA jid(getUStringA(hContact, "jid")); + ptrA jid(ContactToJID(hContact)); if (jid == nullptr) return -1; -- cgit v1.2.3