diff options
author | George Hazan <george.hazan@gmail.com> | 2024-03-22 14:17:35 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2024-03-22 14:17:35 +0300 |
commit | f796b157ac5cc978825d24fa7ccdae1a3501d782 (patch) | |
tree | 96db99d3e8cb5091617a3cbbb7d61981d2d371e8 /plugins/NewStory/src | |
parent | 53b4e29739e1d67bb81c0428276ce89fbe9459b7 (diff) |
fix for #4289 for parsing smileys
Diffstat (limited to 'plugins/NewStory/src')
-rw-r--r-- | plugins/NewStory/src/templates.cpp | 34 | ||||
-rw-r--r-- | plugins/NewStory/src/utils.cpp | 27 | ||||
-rw-r--r-- | plugins/NewStory/src/utils.h | 1 |
3 files changed, 31 insertions, 31 deletions
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"</style></head><body class=\"body\">\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"<img class=\"img\" src=\"file://%s\" title=\"%s\" alt=\"%s\" />",
+ smiley.filepath, wszFound.c_str(), wszFound.c_str()));
+ }
+
+ CallService(MS_SMILEYADD_BATCHFREE, 0, (LPARAM)spRes);
+ }
str += szBody;
str.Append(L"</body></html>");
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"<img class=\"img\" src=\"file://%s\" title=\"%s\" alt=\"%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);
|