From 906a9d5f75f282a1ddd683f29346041c8f73e511 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 22 Aug 2024 14:37:03 +0300 Subject: fixes #4592 (SkypeWeb: support status message) --- protocols/SkypeWeb/src/skype_contacts.cpp | 4 ++-- protocols/SkypeWeb/src/skype_utils.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/protocols/SkypeWeb/src/skype_contacts.cpp b/protocols/SkypeWeb/src/skype_contacts.cpp index 733bbc631a..0273ad0b23 100644 --- a/protocols/SkypeWeb/src/skype_contacts.cpp +++ b/protocols/SkypeWeb/src/skype_contacts.cpp @@ -196,8 +196,8 @@ void CSkypeProto::LoadContactList(MHttpResponse *response, AsyncHttpRequest*) SetString(hContact, "FirstName", name["first"]); SetString(hContact, "LastName", name["surname"]); - if (profile["mood"]) - db_set_ws(hContact, "CList", "StatusMsg", RemoveHtml(item["mood"].as_mstring())); + if (auto &pMood = profile["mood"]) + db_set_ws(hContact, "CList", "StatusMsg", RemoveHtml(pMood.as_mstring())); SetAvatarUrl(hContact, profile["avatar_url"].as_mstring()); ReloadAvatarInfo(hContact); diff --git a/protocols/SkypeWeb/src/skype_utils.cpp b/protocols/SkypeWeb/src/skype_utils.cpp index 78487e0850..2de2bc25d8 100644 --- a/protocols/SkypeWeb/src/skype_utils.cpp +++ b/protocols/SkypeWeb/src/skype_utils.cpp @@ -344,13 +344,30 @@ const HtmlEntity htmlEntities[] = { "zwnj", "\xE2\x80\x8C" } }; +static void Utf32toUtf16(uint32_t c, CMStringW &dest) +{ + if (c < 0x10000) + dest.AppendChar(c); + else { + unsigned int t = c - 0x10000; + dest.AppendChar((((t << 12) >> 22) + 0xD800)); + dest.AppendChar((((t << 22) >> 22) + 0xDC00)); + } +} + CMStringW RemoveHtml(const CMStringW &data) { + bool inSS = false; CMStringW new_string; for (int i = 0; i < data.GetLength(); i++) { wchar_t c = data[i]; if (c == '<') { + if (!wcsncmp(data.c_str() + i + 1, L"ss ", 3)) + inSS = true; + else if (!wcsncmp(data.c_str() + i + 1, L"/ss>", 4)) + inSS = false; + i = data.Find('>', i); if (i == -1) break; @@ -423,6 +440,18 @@ CMStringW RemoveHtml(const CMStringW &data) } } + if (c == '(' && inSS) { + uint32_t code = 0; + if (1 == swscanf(data.c_str() + i + 1, L"%x_", &code)) + Utf32toUtf16(code, new_string); + + int iEnd = data.Find(')', i); + if (iEnd != -1) { + i = iEnd; + continue; + } + } + new_string.AppendChar(c); } -- cgit v1.2.3