From 3d754a28afdcac002ef1d958c4d2ad3793bddb5a Mon Sep 17 00:00:00 2001 From: ElzorFox Date: Sat, 15 Aug 2020 20:08:40 +0500 Subject: =?UTF-8?q?VKontakte:=20fix=20=E2=80=98Process=20stickers=20as=20s?= =?UTF-8?q?mileys=E2=80=99=20option=20add=20template=20[sticker-%d]=20for?= =?UTF-8?q?=20sending=20stickers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocols/VKontakte/src/misc.cpp | 31 +++++++++++++++---------------- protocols/VKontakte/src/vk_chats.cpp | 6 +++--- protocols/VKontakte/src/vk_feed.cpp | 2 +- protocols/VKontakte/src/vk_history.cpp | 6 +++--- protocols/VKontakte/src/vk_messages.cpp | 6 +++--- protocols/VKontakte/src/vk_proto.cpp | 29 +++++++++++++++++++++++++++++ protocols/VKontakte/src/vk_proto.h | 9 ++++++--- protocols/VKontakte/src/vk_struct.cpp | 2 +- 8 files changed, 61 insertions(+), 30 deletions(-) (limited to 'protocols/VKontakte/src') diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp index 5839d90226..018c0da7fe 100644 --- a/protocols/VKontakte/src/misc.cpp +++ b/protocols/VKontakte/src/misc.cpp @@ -800,9 +800,10 @@ char* CVkProto::GetStickerId(const char *Msg, int &stickerid) char *retMsg = nullptr; int iRes = 0; - const char *tmpMsg = strstr(Msg, "[sticker:"); + const char *tmpMsg = strstr(Msg, "[sticker"); if (tmpMsg) - iRes = sscanf(tmpMsg, "[sticker:%d]", &stickerid); + iRes = sscanf(tmpMsg, "[sticker:%d]", &stickerid) == 1 ? 1 : sscanf(tmpMsg, "[sticker-%d]", &stickerid); + if (iRes == 1) { char HeadMsg[32] = { 0 }; mir_snprintf(HeadMsg, "[sticker:%d]", stickerid); @@ -1086,7 +1087,7 @@ CMStringW& CVkProto::ClearFormatNick(CMStringW& wszText) ///////////////////////////////////////////////////////////////////////////////////////// -CMStringW CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, MCONTACT hContact, BBCSupport iBBC) +CMStringW CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, BBCSupport iBBC) { debugLogA("CVkProto::GetAttachmentDescr"); CMStringW res; @@ -1209,7 +1210,7 @@ CMStringW CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, MCONTACT h const JSONNode& jnSubAttachments = jnCopyHystoryItem["attachments"]; if (jnSubAttachments) { debugLogA("CVkProto::GetAttachmentDescr SubAttachments"); - CMStringW wszAttachmentDescr = GetAttachmentDescr(jnSubAttachments, hContact, iBBC); + CMStringW wszAttachmentDescr = GetAttachmentDescr(jnSubAttachments, iBBC); wszAttachmentDescr.Replace(L"\n", L"\n\t\t"); wszAttachmentDescr.Replace(L"== FilterAudioMessages ==", L""); res += L"\n\t\t" + wszAttachmentDescr; @@ -1220,7 +1221,7 @@ CMStringW CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, MCONTACT h const JSONNode& jnSubAttachments = jnWall["attachments"]; if (jnSubAttachments) { debugLogA("CVkProto::GetAttachmentDescr SubAttachments"); - CMStringW wszAttachmentDescr = GetAttachmentDescr(jnSubAttachments, hContact, iBBC); + CMStringW wszAttachmentDescr = GetAttachmentDescr(jnSubAttachments, iBBC); wszAttachmentDescr.Replace(L"\n", L"\n\t"); wszAttachmentDescr.Replace(L"== FilterAudioMessages ==", L""); res += L"\n\t" + wszAttachmentDescr; @@ -1274,7 +1275,6 @@ CMStringW CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, MCONTACT h const JSONNode& jnImages = jnSticker[m_vkOptions.bStickerBackground ? "images_with_background" : "images"]; int iStickerId = jnSticker["sticker_id"].as_int(); - int iProductId = jnSticker["product_id"].as_int(); for (auto& jnImage : jnImages) { if (jnImage["width"].as_int() == (int)m_vkOptions.iStickerSize) { @@ -1300,7 +1300,7 @@ CMStringW CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, MCONTACT h CreateDirectoryTreeW(wszPath); bool bSuccess = false; - CMStringW wszFileName(FORMAT, L"%s\\{sticker-%d-%d}.png", wszPath.c_str(), iProductId, iStickerId); + CMStringW wszFileName(FORMAT, L"%s\\[sticker-%d].png", wszPath.c_str(), iStickerId); if (GetFileAttributesW(wszFileName) == INVALID_FILE_ATTRIBUTES) { T2Utf szUrl(wszUrl); @@ -1321,13 +1321,12 @@ CMStringW CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, MCONTACT h else bSuccess = true; - if (bSuccess) { - res.AppendFormat(L"{sticker-%d-%d}", iProductId, iStickerId); + res.AppendFormat(L"[sticker-%d]", iStickerId); SMADD_CONT cont; cont.cbSize = sizeof(SMADD_CONT); - cont.hContact = hContact; + cont.hContact = 0; cont.type = 1; cont.path = wszFileName.GetBuffer(); CallService(MS_SMILEYADD_LOADCONTACTSMILEYS, 0, (LPARAM)&cont); @@ -1421,7 +1420,7 @@ CMStringW CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, MCONTACT h return res; } -CMStringW CVkProto::GetFwdMessage(const JSONNode& jnMsg, const JSONNode& jnFUsers, OBJLIST& vkUsers, MCONTACT hConContact, BBCSupport iBBC) +CMStringW CVkProto::GetFwdMessage(const JSONNode& jnMsg, const JSONNode& jnFUsers, OBJLIST& vkUsers, BBCSupport iBBC) { UINT uid = jnMsg["from_id"].as_int(); CMStringW wszBody(jnMsg["text"].as_mstring()); @@ -1450,7 +1449,7 @@ CMStringW CVkProto::GetFwdMessage(const JSONNode& jnMsg, const JSONNode& jnFUser const JSONNode& jnFwdMessages = jnMsg["fwd_messages"]; if (jnFwdMessages && !jnFwdMessages.empty()) { - CMStringW wszFwdMessages = GetFwdMessages(jnFwdMessages, jnFUsers, hConContact, iBBC == bbcNo ? iBBC : m_vkOptions.BBCForAttachments()); + CMStringW wszFwdMessages = GetFwdMessages(jnFwdMessages, jnFUsers, iBBC == bbcNo ? iBBC : m_vkOptions.BBCForAttachments()); if (!wszBody.IsEmpty()) wszFwdMessages = L"\n" + wszFwdMessages; wszBody += wszFwdMessages; @@ -1458,7 +1457,7 @@ CMStringW CVkProto::GetFwdMessage(const JSONNode& jnMsg, const JSONNode& jnFUser const JSONNode& jnAttachments = jnMsg["attachments"]; if (jnAttachments && !jnAttachments.empty()) { - CMStringW wszAttachmentDescr = GetAttachmentDescr(jnAttachments, hConContact, iBBC == bbcNo ? iBBC : m_vkOptions.BBCForAttachments()); + CMStringW wszAttachmentDescr = GetAttachmentDescr(jnAttachments, iBBC == bbcNo ? iBBC : m_vkOptions.BBCForAttachments()); if (wszAttachmentDescr != L"== FilterAudioMessages ==") { if (!wszBody.IsEmpty()) wszAttachmentDescr = L"\n" + wszAttachmentDescr; @@ -1481,7 +1480,7 @@ CMStringW CVkProto::GetFwdMessage(const JSONNode& jnMsg, const JSONNode& jnFUser } -CMStringW CVkProto::GetFwdMessages(const JSONNode &jnMessages, const JSONNode &jnFUsers, MCONTACT hConContact, BBCSupport iBBC) +CMStringW CVkProto::GetFwdMessages(const JSONNode &jnMessages, const JSONNode &jnFUsers, BBCSupport iBBC) { CMStringW res; debugLogA("CVkProto::GetFwdMessages"); @@ -1509,10 +1508,10 @@ CMStringW CVkProto::GetFwdMessages(const JSONNode &jnMessages, const JSONNode &j for (auto& jnMsg : jnMessages.as_array()) { if (!res.IsEmpty()) res.AppendChar('\n'); - res += GetFwdMessage(jnMsg, jnFUsers, vkUsers, hConContact, iBBC); + res += GetFwdMessage(jnMsg, jnFUsers, vkUsers, iBBC); } else - res = GetFwdMessage(jnMessages, jnFUsers, vkUsers, hConContact, iBBC); + res = GetFwdMessage(jnMessages, jnFUsers, vkUsers, iBBC); res.AppendChar('\n'); vkUsers.destroy(); diff --git a/protocols/VKontakte/src/vk_chats.cpp b/protocols/VKontakte/src/vk_chats.cpp index becd62f285..f6dd409c78 100644 --- a/protocols/VKontakte/src/vk_chats.cpp +++ b/protocols/VKontakte/src/vk_chats.cpp @@ -294,7 +294,7 @@ void CVkProto::AppendChatConversationMessage(int id, const JSONNode& jnMsg, cons const JSONNode& jnFwdMessages = jnMsg["fwd_messages"]; if (jnFwdMessages && !jnFwdMessages.empty()) { - CMStringW wszFwdMessages = GetFwdMessages(jnFwdMessages, jnFUsers, cc->m_hContact, bbcNo); + CMStringW wszFwdMessages = GetFwdMessages(jnFwdMessages, jnFUsers, bbcNo); if (!wszBody.IsEmpty()) wszFwdMessages = L"\n" + wszFwdMessages; wszBody += wszFwdMessages; @@ -302,7 +302,7 @@ void CVkProto::AppendChatConversationMessage(int id, const JSONNode& jnMsg, cons const JSONNode& jnReplyMessages = jnMsg["reply_message"]; if (jnReplyMessages && !jnReplyMessages.empty()) { - CMStringW wszReplyMessages = GetFwdMessages(jnReplyMessages, jnFUsers, cc->m_hContact, bbcNo); + CMStringW wszReplyMessages = GetFwdMessages(jnReplyMessages, jnFUsers, bbcNo); if (!wszBody.IsEmpty()) wszReplyMessages = L"\n" + wszReplyMessages; wszBody += wszReplyMessages; @@ -310,7 +310,7 @@ void CVkProto::AppendChatConversationMessage(int id, const JSONNode& jnMsg, cons const JSONNode& jnAttachments = jnMsg["attachments"]; if (jnAttachments && !jnAttachments.empty()) { - CMStringW wszAttachmentDescr = GetAttachmentDescr(jnAttachments, cc->m_hContact, bbcNo); + CMStringW wszAttachmentDescr = GetAttachmentDescr(jnAttachments, bbcNo); if (wszAttachmentDescr == L"== FilterAudioMessages ==") return; diff --git a/protocols/VKontakte/src/vk_feed.cpp b/protocols/VKontakte/src/vk_feed.cpp index 5f87ba23ff..d2e92ec6f6 100644 --- a/protocols/VKontakte/src/vk_feed.cpp +++ b/protocols/VKontakte/src/vk_feed.cpp @@ -237,7 +237,7 @@ CVKNewsItem* CVkProto::GetVkNewsItem(const JSONNode &jnItem, OBJLIST getDword(hContact, "lastmsgid", -1))) diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp index 2ba0ebfc25..9fb235deeb 100644 --- a/protocols/VKontakte/src/vk_proto.cpp +++ b/protocols/VKontakte/src/vk_proto.cpp @@ -112,9 +112,38 @@ void CVkProto::OnModulesLoaded() InitPopups(); InitMenus(); InitDBCustomEvents(); + InitSmileys(); } ///////////////////////////////////////////////////////////////////////////////////////// + +void CVkProto::InitSmileys() +{ + if (!m_vkOptions.bStikersAsSmyles) + return; + + if (m_vkOptions.bUseStikersAsStaticSmyles) + return; + + CMStringW wszPath(FORMAT, L"%s\\%S\\Stickers\\*.png", VARSW(L"%miranda_avatarcache%").get(), m_szModuleName); + + WIN32_FIND_DATAW findData; + HANDLE hFind = FindFirstFileW(wszPath, &findData); + if (hFind != INVALID_HANDLE_VALUE) { + wszPath.Truncate(wszPath.GetLength() - 5); + do { + CMStringW wszFileName = wszPath + findData.cFileName; + + SMADD_CONT cont; + cont.cbSize = sizeof(SMADD_CONT); + cont.hContact = 0; + cont.type = 1; + cont.path = wszFileName.GetBuffer(); + CallService(MS_SMILEYADD_LOADCONTACTSMILEYS, 0, (LPARAM)&cont); + } while (FindNextFileW(hFind, &findData)); + } +} + // Menu support void CVkProto::OnBuildProtoMenu() diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index c2d49e0e3b..dcc60f9c7f 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -230,6 +230,9 @@ private: m_hContactHistoryMenuItems[CHMI_COUNT], m_hProtoMenuItems[PMI_COUNT]; + + void InitSmileys(); + //==== Menus ========================================================================= void InitMenus(); @@ -358,9 +361,9 @@ private: CMStringW GetVkPhotoItem(const JSONNode &jnPhoto, BBCSupport iBBC); CMStringW SetBBCString(LPCWSTR wszString, BBCSupport iBBC, VKBBCType bbcType, LPCWSTR wszAddString = nullptr); CMStringW& ClearFormatNick(CMStringW& wszText); - CMStringW GetAttachmentDescr(const JSONNode &jnAttachments, MCONTACT hContact, BBCSupport iBBC); - CMStringW GetFwdMessage(const JSONNode& jnMsg, const JSONNode& jnFUsers, OBJLIST& vkUsers, MCONTACT hConContact, BBCSupport iBBC); - CMStringW GetFwdMessages(const JSONNode &jnMessages, const JSONNode &jnFUsers, MCONTACT hConContact, BBCSupport iBBC); + CMStringW GetAttachmentDescr(const JSONNode &jnAttachments, BBCSupport iBBC); + CMStringW GetFwdMessage(const JSONNode& jnMsg, const JSONNode& jnFUsers, OBJLIST& vkUsers, BBCSupport iBBC); + CMStringW GetFwdMessages(const JSONNode &jnMessages, const JSONNode &jnFUsers, BBCSupport iBBC); void SetInvisible(MCONTACT hContact); CMStringW RemoveBBC(CMStringW& wszSrc); void AddVkDeactivateEvent(MCONTACT hContact, CMStringW & wszType); diff --git a/protocols/VKontakte/src/vk_struct.cpp b/protocols/VKontakte/src/vk_struct.cpp index e493bcbe90..7afe14c6e7 100644 --- a/protocols/VKontakte/src/vk_struct.cpp +++ b/protocols/VKontakte/src/vk_struct.cpp @@ -160,7 +160,7 @@ CVKOptions::CVKOptions(PROTO_INTERFACE* proto) : bPopUpSyncHistory(proto, "PopUpSyncHistory", false), iMarkMessageReadOn(proto, "MarkMessageReadOn", MarkMsgReadOn::markOnRead), bStikersAsSmyles(proto, "StikersAsSmyles", false), - bUseStikersAsStaticSmyles(proto, "UseStikersAsStaticSmyles", true), //true - while issue #2527 not fixed + bUseStikersAsStaticSmyles(proto, "UseStikersAsStaticSmyles", false), bUserForceInvisibleOnActivity(proto, "UserForceOnlineOnActivity", false), bNewsEnabled(proto, "NewsEnabled", false), iMaxLoadNewsPhoto(proto, "MaxLoadNewsPhoto", 5), -- cgit v1.2.3