From f796b157ac5cc978825d24fa7ccdae1a3501d782 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 22 Mar 2024 14:17:35 +0300 Subject: fix for #4289 for parsing smileys --- plugins/NewStory/src/templates.cpp | 34 +++++++++++++++++++++++++++++++--- plugins/NewStory/src/utils.cpp | 27 --------------------------- plugins/NewStory/src/utils.h | 1 - 3 files changed, 31 insertions(+), 31 deletions(-) (limited to 'plugins/NewStory/src') diff --git a/plugins/NewStory/src/templates.cpp b/plugins/NewStory/src/templates.cpp index 5581ec9d90..3c7b01eb4b 100644 --- a/plugins/NewStory/src/templates.cpp +++ b/plugins/NewStory/src/templates.cpp @@ -140,11 +140,39 @@ CMStringW ItemData::formatHtml(const wchar_t *pwszStr) str.Append(L"\n"); + CMStringW wszOrigText((pwszStr) ? pwszStr : formatString()); + + SMADD_BATCHPARSE sp = {}; + SMADD_BATCHPARSERES *spRes = nullptr; + if (g_plugin.bHasSmileys) { + sp.Protocolname = Proto_GetBaseAccountName(hContact); + sp.flag = SAFL_PATH | SAFL_UNICODE; + sp.str.w = wszOrigText; + sp.hContact = hContact; + spRes = (SMADD_BATCHPARSERES *)CallService(MS_SMILEYADD_BATCHPARSE, 0, (LPARAM)&sp); + } + CMStringW szBody; - AppendString(szBody, (pwszStr) ? pwszStr : formatString()); + AppendString(szBody, wszOrigText); UrlAutodetect(szBody); - if (g_plugin.bHasSmileys) - ReplaceSmileys(hContact, szBody); + if (spRes) { + for (int i = 0; i < (int)sp.numSmileys; i++) { + auto &smiley = spRes[i]; + if (!mir_wstrlen(smiley.filepath)) + continue; + + CMStringW wszFound(wszOrigText.Mid(smiley.startChar, smiley.size)); + int idx = szBody.Find(wszFound); + if (idx == -1) + continue; + + szBody.Delete(idx, smiley.size); + szBody.Insert(idx, CMStringW(FORMAT, L"\"%s\"", + smiley.filepath, wszFound.c_str(), wszFound.c_str())); + } + + CallService(MS_SMILEYADD_BATCHFREE, 0, (LPARAM)spRes); + } str += szBody; str.Append(L""); diff --git a/plugins/NewStory/src/utils.cpp b/plugins/NewStory/src/utils.cpp index a752b3688f..656abcfbea 100644 --- a/plugins/NewStory/src/utils.cpp +++ b/plugins/NewStory/src/utils.cpp @@ -156,30 +156,3 @@ void UrlAutodetect(CMStringW &str) p = str.c_str() + pos + newText.GetLength(); } } - -///////////////////////////////////////////////////////////////////////////////////////// - -void ReplaceSmileys(MCONTACT hContact, CMStringW &str) -{ - SMADD_BATCHPARSE sp; - sp.Protocolname = Proto_GetBaseAccountName(hContact); - sp.flag = SAFL_PATH | SAFL_UNICODE; - sp.str.w = str.c_str(); - sp.hContact = hContact; - - if (auto *spRes = (SMADD_BATCHPARSERES *)CallService(MS_SMILEYADD_BATCHPARSE, 0, (LPARAM)&sp)) { - for (int i = (int)sp.numSmileys-1; i >= 0; i--) { - auto &smiley = spRes[i]; - if (mir_wstrlen(smiley.filepath) > 0) { - CMStringW szText(str.Mid(smiley.startChar, smiley.size)); - str.Delete(smiley.startChar, smiley.size); - - CMStringW szNew; - szNew.Format(L"\"%s\"", smiley.filepath, szText.c_str(), szText.c_str()); - str.Insert(smiley.startChar, szNew); - } - } - - CallService(MS_SMILEYADD_BATCHFREE, 0, (LPARAM)spRes); - } -} diff --git a/plugins/NewStory/src/utils.h b/plugins/NewStory/src/utils.h index 1af7323338..d9fb352546 100644 --- a/plugins/NewStory/src/utils.h +++ b/plugins/NewStory/src/utils.h @@ -9,6 +9,5 @@ bool NSMenu_Process(int iCommand, NewstoryListData *data); int GetFontHeight(const LOGFONTA &lf); -void ReplaceSmileys(MCONTACT hContact, CMStringW &str); void UrlAutodetect(CMStringW &str); void RemoveBbcodes(CMStringW &pwszText); -- cgit v1.2.3