From 45bf5f51cc788cb8f19e1b8fcd5b8818dc7a2e00 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 25 Feb 2019 21:02:11 +0300 Subject: GCEVENT::GCEF_UTF8 - flag for direct communication with utf8-encoded chat events (UTF16LE by default) --- protocols/Twitter/src/chat.cpp | 45 +++++++++++++++++------------------------ protocols/Twitter/src/proto.cpp | 3 ++- protocols/Twitter/src/proto.h | 2 ++ 3 files changed, 23 insertions(+), 27 deletions(-) (limited to 'protocols/Twitter/src') diff --git a/protocols/Twitter/src/chat.cpp b/protocols/Twitter/src/chat.cpp index cbd2ee90aa..49601fc0ac 100644 --- a/protocols/Twitter/src/chat.cpp +++ b/protocols/Twitter/src/chat.cpp @@ -24,34 +24,31 @@ along with this program. If not, see . void TwitterProto::UpdateChat(const twitter_user &update) { - GCEVENT gce = { m_szModuleName, m_tszUserName, GC_EVENT_MESSAGE }; + GCEVENT gce = { m_szModuleName, m_szChatId, GC_EVENT_MESSAGE }; + gce.dwFlags = GCEF_UTF8 + GCEF_ADDTOLOG; gce.bIsMe = (update.username == twit_.get_username()); - gce.dwFlags = GCEF_ADDTOLOG; - gce.ptszUID = mir_a2u(update.username.c_str()); + gce.pszUID.a = update.username.c_str(); //TODO: write code here to replace % with %% in update.status.text (which is a std::string) std::string chatText = update.status.text; replaceAll(chatText, "%", "%%"); - gce.ptszText = mir_a2u_cp(chatText.c_str(), CP_UTF8); - //gce.ptszText = mir_a2u_cp(update.status.text.c_str(),CP_UTF8); + gce.pszText.a = chatText.c_str(); gce.time = static_cast(update.status.time); - DBVARIANT nick; MCONTACT hContact = UsernameToHContact(update.username.c_str()); - if (hContact && !db_get_s(hContact, "CList", "MyHandle", &nick)) { - gce.ptszNick = mir_a2u(nick.pszVal); - db_free(&nick); - } + CMStringA szNick = db_get_sm(hContact, "CList", "MyHandle"); + if (hContact && !szNick.IsEmpty()) + gce.pszNick.a = szNick; else - gce.ptszNick = mir_a2u(update.username.c_str()); + gce.pszNick.a = update.username.c_str(); Chat_Event(&gce); - mir_free(const_cast(gce.ptszNick)); - mir_free(const_cast(gce.ptszUID)); - mir_free(const_cast(gce.ptszText)); + mir_free(const_cast(gce.pszNick.w)); + mir_free(const_cast(gce.pszUID.w)); + mir_free(const_cast(gce.pszText.w)); } int TwitterProto::OnChatOutgoing(WPARAM, LPARAM lParam) @@ -88,25 +85,21 @@ int TwitterProto::OnChatOutgoing(WPARAM, LPARAM lParam) // TODO: remove nick? void TwitterProto::AddChatContact(const char *name, const char *nick) { - ptrW wszId(mir_a2u(name)); - ptrW wszNick(mir_a2u(nick ? nick : name)); - - GCEVENT gce = { m_szModuleName, m_tszUserName, GC_EVENT_JOIN }; + GCEVENT gce = { m_szModuleName, m_szChatId, GC_EVENT_JOIN }; + gce.dwFlags = GCEF_UTF8; gce.time = DWORD(time(0)); - gce.ptszNick = wszNick; - gce.ptszUID = wszId; - gce.ptszStatus = L"Normal"; + gce.pszNick.a = nick ? nick : name; + gce.pszUID.a = name; + gce.pszStatus.a = "Normal"; Chat_Event(&gce); } void TwitterProto::DeleteChatContact(const char *name) { - ptrW wszId(mir_a2u(name)); - - GCEVENT gce = { m_szModuleName, m_tszUserName, GC_EVENT_PART }; + GCEVENT gce = { m_szModuleName, m_szChatId, GC_EVENT_PART }; + gce.dwFlags = GCEF_UTF8; gce.time = DWORD(time(0)); - gce.ptszNick = wszId; - gce.ptszUID = gce.ptszNick; + gce.pszUID.a = gce.pszNick.a = name; Chat_Event(&gce); } diff --git a/protocols/Twitter/src/proto.cpp b/protocols/Twitter/src/proto.cpp index 8ef5a20493..7ad53590e0 100644 --- a/protocols/Twitter/src/proto.cpp +++ b/protocols/Twitter/src/proto.cpp @@ -27,7 +27,8 @@ along with this program. If not, see . static volatile LONG g_msgid = 1; TwitterProto::TwitterProto(const char *proto_name, const wchar_t *username) : - PROTO(proto_name, username) + PROTO(proto_name, username), + m_szChatId(mir_utf8encodeW(username)) { CreateProtoService(PS_CREATEACCMGRUI, &TwitterProto::SvcCreateAccMgrUI); diff --git a/protocols/Twitter/src/proto.h b/protocols/Twitter/src/proto.h index eb7eec67b2..b7d05b5686 100644 --- a/protocols/Twitter/src/proto.h +++ b/protocols/Twitter/src/proto.h @@ -22,6 +22,8 @@ along with this program. If not, see . class TwitterProto : public PROTO { + ptrA m_szChatId; + public: TwitterProto(const char*,const wchar_t*); ~TwitterProto(); -- cgit v1.2.3