From 9548530c9e9c7bc1cbcf1c2c97008b217865fb4d Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 22 Oct 2019 19:50:54 +0300 Subject: fixes #2103 (Jabber: we should ignore AvatarHash if file does not exist) --- protocols/JabberG/src/jabber_misc.cpp | 12 +++++------- protocols/JabberG/src/jabber_thread.cpp | 9 +++++++-- 2 files changed, 12 insertions(+), 9 deletions(-) (limited to 'protocols/JabberG') diff --git a/protocols/JabberG/src/jabber_misc.cpp b/protocols/JabberG/src/jabber_misc.cpp index e4693220ae..74f6900762 100755 --- a/protocols/JabberG/src/jabber_misc.cpp +++ b/protocols/JabberG/src/jabber_misc.cpp @@ -148,13 +148,11 @@ void CJabberProto::GetAvatarFileName(MCONTACT hContact, wchar_t* pszDest, size_t if (hContact != 0) { char str[256]; JabberShaStrBuf buf; - DBVARIANT dbv; - if (!db_get_utf(hContact, m_szModuleName, "jid", &dbv)) { - strncpy_s(str, dbv.pszVal, _TRUNCATE); - str[sizeof(str) - 1] = 0; - db_free(&dbv); - } - else _i64toa((LONG_PTR)hContact, str, 10); + ptrA szJid(getUStringA(hContact, "jid")); + if (szJid) + strncpy_s(str, szJid, _TRUNCATE); + else + _i64toa((LONG_PTR)hContact, str, 10); mir_snwprintf(pszDest + tPathLen, MAX_PATH - tPathLen, L"%S%s", JabberSha1(str, buf), szFileType); } else if (m_ThreadInfo != nullptr) { diff --git a/protocols/JabberG/src/jabber_thread.cpp b/protocols/JabberG/src/jabber_thread.cpp index 29e11ee2cc..04c1aaad32 100755 --- a/protocols/JabberG/src/jabber_thread.cpp +++ b/protocols/JabberG/src/jabber_thread.cpp @@ -1643,12 +1643,17 @@ void CJabberProto::OnProcessPresence(const TiXmlElement *node, ThreadData *info) auto *szPhoto = XmlGetChildText(xNode, "photo"); if (szPhoto && !bHasAvatar) { if (mir_strlen(szPhoto)) { + // no file - no saved hash + wchar_t tszFileName[MAX_PATH]; + GetAvatarFileName(hContact, tszFileName, _countof(tszFileName)); + if (::_waccess(tszFileName, 0) != 0) + delSetting(hContact, "AvatarHash"); + bHasAvatar = true; ptrA saved(getStringA(hContact, "AvatarHash")); if (saved == nullptr || mir_strcmp(saved, szPhoto)) { debugLogA("Avatar was changed, reloading"); - setString(hContact, "AvatarHash", szPhoto); - ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_STATUS, nullptr, 0); + SendGetVcard(hContact); continue; } } -- cgit v1.2.3