From f937a646677d1eb3e139aacccc8ecf4064d6b145 Mon Sep 17 00:00:00 2001 From: ElzorFox Date: Fri, 14 Aug 2020 19:23:57 +0500 Subject: =?UTF-8?q?VKontakte:=20rework=20=E2=80=98Process=20stickers=20as?= =?UTF-8?q?=20smileys=E2=80=99=20option=20for=20dynamic=20loading=20sticke?= =?UTF-8?q?r=20from=20vk=20(working)=20=20and=20showing=20as=20smiley=20(n?= =?UTF-8?q?ot=20working=20-=20issue=20#2527)=20version=20bump?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocols/VKontakte/src/misc.cpp | 92 ++++++++++++++++++++++++--------- protocols/VKontakte/src/stdafx.h | 1 + protocols/VKontakte/src/version.h | 2 +- protocols/VKontakte/src/vk_chats.cpp | 6 +-- protocols/VKontakte/src/vk_feed.cpp | 2 +- protocols/VKontakte/src/vk_history.cpp | 9 ++-- protocols/VKontakte/src/vk_messages.cpp | 6 +-- protocols/VKontakte/src/vk_proto.h | 6 +-- protocols/VKontakte/src/vk_struct.cpp | 9 +--- protocols/VKontakte/src/vk_struct.h | 1 + 10 files changed, 86 insertions(+), 48 deletions(-) (limited to 'protocols/VKontakte') diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp index c193c1d761..5839d90226 100644 --- a/protocols/VKontakte/src/misc.cpp +++ b/protocols/VKontakte/src/misc.cpp @@ -1086,7 +1086,7 @@ CMStringW& CVkProto::ClearFormatNick(CMStringW& wszText) ///////////////////////////////////////////////////////////////////////////////////////// -CMStringW CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, BBCSupport iBBC) +CMStringW CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, MCONTACT hContact, BBCSupport iBBC) { debugLogA("CVkProto::GetAttachmentDescr"); CMStringW res; @@ -1209,7 +1209,7 @@ CMStringW CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, BBCSupport const JSONNode& jnSubAttachments = jnCopyHystoryItem["attachments"]; if (jnSubAttachments) { debugLogA("CVkProto::GetAttachmentDescr SubAttachments"); - CMStringW wszAttachmentDescr = GetAttachmentDescr(jnSubAttachments, iBBC); + CMStringW wszAttachmentDescr = GetAttachmentDescr(jnSubAttachments, hContact, iBBC); wszAttachmentDescr.Replace(L"\n", L"\n\t\t"); wszAttachmentDescr.Replace(L"== FilterAudioMessages ==", L""); res += L"\n\t\t" + wszAttachmentDescr; @@ -1220,7 +1220,7 @@ CMStringW CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, BBCSupport const JSONNode& jnSubAttachments = jnWall["attachments"]; if (jnSubAttachments) { debugLogA("CVkProto::GetAttachmentDescr SubAttachments"); - CMStringW wszAttachmentDescr = GetAttachmentDescr(jnSubAttachments, iBBC); + CMStringW wszAttachmentDescr = GetAttachmentDescr(jnSubAttachments, hContact, iBBC); wszAttachmentDescr.Replace(L"\n", L"\n\t"); wszAttachmentDescr.Replace(L"== FilterAudioMessages ==", L""); res += L"\n\t" + wszAttachmentDescr; @@ -1270,27 +1270,71 @@ CMStringW CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, BBCSupport continue; res.Empty(); // sticker is not really an attachment, so we don't want all that heading info - if (m_vkOptions.bStikersAsSmyles) { - int id = jnSticker["sticker_id"].as_int(); - res.AppendFormat(L"[sticker:%d]", id); + CMStringW wszLink, wszLink128, wszLinkLast, wszUrl; + 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) { + wszLink = jnImage["url"].as_mstring(); + break; + } + + if (jnImage["width"].as_int() == 128) // default size + wszLink128 = jnImage["url"].as_mstring(); + + wszLinkLast = jnImage["url"].as_mstring(); } + + wszUrl = wszLink.IsEmpty() ? (wszLink128.IsEmpty() ? wszLinkLast : wszLink128) : wszLink; + + if (!m_vkOptions.bStikersAsSmyles) + res += SetBBCString(wszUrl, iBBC, vkbbcImg); + else if (m_vkOptions.bUseStikersAsStaticSmyles) + res.AppendFormat(L"[sticker:%d]", iStickerId); else { - CMStringW wszLink, wszLink128, wszLinkLast; - const JSONNode& jnImages = jnSticker[m_vkOptions.bStickerBackground ? "images_with_background" : "images"]; - for (auto& jnImage : jnImages) { - if (jnImage["width"].as_int() == (int)m_vkOptions.iStickerSize) { - wszLink = jnImage["url"].as_mstring(); - break; + if (ServiceExists(MS_SMILEYADD_LOADCONTACTSMILEYS)) { + CMStringW wszPath(FORMAT, L"%s\\%S\\Stickers", VARSW(L"%miranda_avatarcache%").get(), m_szModuleName); + CreateDirectoryTreeW(wszPath); + + bool bSuccess = false; + CMStringW wszFileName(FORMAT, L"%s\\{sticker-%d-%d}.png", wszPath.c_str(), iProductId, iStickerId); + + if (GetFileAttributesW(wszFileName) == INVALID_FILE_ATTRIBUTES) { + T2Utf szUrl(wszUrl); + NETLIBHTTPREQUEST req = {}; + req.cbSize = sizeof(req); + req.flags = NLHRF_NODUMP | NLHRF_SSL | NLHRF_HTTP11 | NLHRF_REDIRECT; + req.requestType = REQUEST_GET; + req.szUrl = szUrl; + + NETLIBHTTPREQUEST* pReply = Netlib_HttpTransaction(m_hNetlibUser, &req); + if (pReply != nullptr && pReply->resultCode == 200 && pReply->pData && pReply->dataLength) { + bSuccess = true; + FILE* out = _wfopen(wszFileName, L"wb"); + fwrite(pReply->pData, 1, pReply->dataLength, out); + fclose(out); + } } + else + bSuccess = true; - if (jnImage["width"].as_int() == 128) // default size - wszLink128 = jnImage["url"].as_mstring(); - wszLinkLast = jnImage["url"].as_mstring(); - } + if (bSuccess) { + res.AppendFormat(L"{sticker-%d-%d}", iProductId, iStickerId); - if (m_vkOptions.iIMGBBCSupport) - res += SetBBCString(wszLink.IsEmpty() ? (wszLink128.IsEmpty() ? wszLinkLast : wszLink128) : wszLink, iBBC, vkbbcImg); + SMADD_CONT cont; + cont.cbSize = sizeof(SMADD_CONT); + cont.hContact = hContact; + cont.type = 1; + cont.path = wszFileName.GetBuffer(); + CallService(MS_SMILEYADD_LOADCONTACTSMILEYS, 0, (LPARAM)&cont); + } + else + res += SetBBCString(TranslateT("Sticker"), iBBC, vkbbcUrl, wszUrl); + } } } @@ -1377,7 +1421,7 @@ CMStringW CVkProto::GetAttachmentDescr(const JSONNode &jnAttachments, BBCSupport return res; } -CMStringW CVkProto::GetFwdMessage(const JSONNode& jnMsg, const JSONNode& jnFUsers, OBJLIST& vkUsers, BBCSupport iBBC) +CMStringW CVkProto::GetFwdMessage(const JSONNode& jnMsg, const JSONNode& jnFUsers, OBJLIST& vkUsers, MCONTACT hConContact, BBCSupport iBBC) { UINT uid = jnMsg["from_id"].as_int(); CMStringW wszBody(jnMsg["text"].as_mstring()); @@ -1406,7 +1450,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, iBBC == bbcNo ? iBBC : m_vkOptions.BBCForAttachments()); + CMStringW wszFwdMessages = GetFwdMessages(jnFwdMessages, jnFUsers, hConContact, iBBC == bbcNo ? iBBC : m_vkOptions.BBCForAttachments()); if (!wszBody.IsEmpty()) wszFwdMessages = L"\n" + wszFwdMessages; wszBody += wszFwdMessages; @@ -1414,7 +1458,7 @@ CMStringW CVkProto::GetFwdMessage(const JSONNode& jnMsg, const JSONNode& jnFUser const JSONNode& jnAttachments = jnMsg["attachments"]; if (jnAttachments && !jnAttachments.empty()) { - CMStringW wszAttachmentDescr = GetAttachmentDescr(jnAttachments, iBBC == bbcNo ? iBBC : m_vkOptions.BBCForAttachments()); + CMStringW wszAttachmentDescr = GetAttachmentDescr(jnAttachments, hConContact, iBBC == bbcNo ? iBBC : m_vkOptions.BBCForAttachments()); if (wszAttachmentDescr != L"== FilterAudioMessages ==") { if (!wszBody.IsEmpty()) wszAttachmentDescr = L"\n" + wszAttachmentDescr; @@ -1437,7 +1481,7 @@ CMStringW CVkProto::GetFwdMessage(const JSONNode& jnMsg, const JSONNode& jnFUser } -CMStringW CVkProto::GetFwdMessages(const JSONNode &jnMessages, const JSONNode &jnFUsers, BBCSupport iBBC) +CMStringW CVkProto::GetFwdMessages(const JSONNode &jnMessages, const JSONNode &jnFUsers, MCONTACT hConContact, BBCSupport iBBC) { CMStringW res; debugLogA("CVkProto::GetFwdMessages"); @@ -1465,10 +1509,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, iBBC); + res += GetFwdMessage(jnMsg, jnFUsers, vkUsers, hConContact, iBBC); } else - res = GetFwdMessage(jnMessages, jnFUsers, vkUsers, iBBC); + res = GetFwdMessage(jnMessages, jnFUsers, vkUsers, hConContact, iBBC); res.AppendChar('\n'); vkUsers.destroy(); diff --git a/protocols/VKontakte/src/stdafx.h b/protocols/VKontakte/src/stdafx.h index b908201e91..73fd13633a 100644 --- a/protocols/VKontakte/src/stdafx.h +++ b/protocols/VKontakte/src/stdafx.h @@ -53,6 +53,7 @@ along with this program. If not, see . #include #include #include +#include #include "win2k.h" diff --git a/protocols/VKontakte/src/version.h b/protocols/VKontakte/src/version.h index 66d1d0f9ce..9f83b69a69 100644 --- a/protocols/VKontakte/src/version.h +++ b/protocols/VKontakte/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 1 #define __RELEASE_NUM 11 -#define __BUILD_NUM 3 +#define __BUILD_NUM 4 #include diff --git a/protocols/VKontakte/src/vk_chats.cpp b/protocols/VKontakte/src/vk_chats.cpp index f6dd409c78..becd62f285 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, bbcNo); + CMStringW wszFwdMessages = GetFwdMessages(jnFwdMessages, jnFUsers, cc->m_hContact, 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, bbcNo); + CMStringW wszReplyMessages = GetFwdMessages(jnReplyMessages, jnFUsers, cc->m_hContact, 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, bbcNo); + CMStringW wszAttachmentDescr = GetAttachmentDescr(jnAttachments, cc->m_hContact, bbcNo); if (wszAttachmentDescr == L"== FilterAudioMessages ==") return; diff --git a/protocols/VKontakte/src/vk_feed.cpp b/protocols/VKontakte/src/vk_feed.cpp index d2e92ec6f6..5f87ba23ff 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.h b/protocols/VKontakte/src/vk_proto.h index 613f778f30..c2d49e0e3b 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -358,9 +358,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, BBCSupport iBBC = bbcNo); - CMStringW GetFwdMessage(const JSONNode& jnMsg, const JSONNode& jnFUsers, OBJLIST& vkUsers, BBCSupport iBBC); - CMStringW GetFwdMessages(const JSONNode &jnMessages, const JSONNode &jnFUsers, BBCSupport iBBC = bbcNo); + 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); 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 ce8a288376..e493bcbe90 100644 --- a/protocols/VKontakte/src/vk_struct.cpp +++ b/protocols/VKontakte/src/vk_struct.cpp @@ -160,6 +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 bUserForceInvisibleOnActivity(proto, "UserForceOnlineOnActivity", false), bNewsEnabled(proto, "NewsEnabled", false), iMaxLoadNewsPhoto(proto, "MaxLoadNewsPhoto", 5), @@ -224,12 +225,4 @@ CVKOptions::CVKOptions(PROTO_INTERFACE* proto) : pwszVKLang(proto, "VKLang", nullptr) { - // Note: Delete this code after next stable build - int iAutoClean = db_get_b(0, proto->m_szModuleName, "AutoClean", -1); - if (iAutoClean != -1) { - bLoadOnlyFriends = (BYTE)iAutoClean; - db_set_b(0, proto->m_szModuleName, "LoadOnlyFriends", bLoadOnlyFriends); - db_unset(0, proto->m_szModuleName, "AutoClean"); - } - // Note } \ No newline at end of file diff --git a/protocols/VKontakte/src/vk_struct.h b/protocols/VKontakte/src/vk_struct.h index dfc718b9c0..67506acc62 100644 --- a/protocols/VKontakte/src/vk_struct.h +++ b/protocols/VKontakte/src/vk_struct.h @@ -257,6 +257,7 @@ struct CVKOptions { CMOption bPopUpSyncHistory; CMOption iMarkMessageReadOn; CMOption bStikersAsSmyles; + CMOption bUseStikersAsStaticSmyles; CMOption bUserForceInvisibleOnActivity; CMOption iMusicSendMetod; CMOption bPopupContactsMusic; -- cgit v1.2.3