summaryrefslogtreecommitdiff
path: root/protocols/Twitter/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-02-25 21:02:11 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-02-25 21:02:11 +0300
commit45bf5f51cc788cb8f19e1b8fcd5b8818dc7a2e00 (patch)
tree40a087f36b75b4c1fb7218bd06052df2968bf2d2 /protocols/Twitter/src
parent8ba9e423e683d570702476dd93571cea26a27c1a (diff)
GCEVENT::GCEF_UTF8 - flag for direct communication with utf8-encoded chat events (UTF16LE by default)
Diffstat (limited to 'protocols/Twitter/src')
-rw-r--r--protocols/Twitter/src/chat.cpp45
-rw-r--r--protocols/Twitter/src/proto.cpp3
-rw-r--r--protocols/Twitter/src/proto.h2
3 files changed, 23 insertions, 27 deletions
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 <http://www.gnu.org/licenses/>.
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<DWORD>(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<wchar_t*>(gce.ptszNick));
- mir_free(const_cast<wchar_t*>(gce.ptszUID));
- mir_free(const_cast<wchar_t*>(gce.ptszText));
+ mir_free(const_cast<wchar_t*>(gce.pszNick.w));
+ mir_free(const_cast<wchar_t*>(gce.pszUID.w));
+ mir_free(const_cast<wchar_t*>(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 <http://www.gnu.org/licenses/>.
static volatile LONG g_msgid = 1;
TwitterProto::TwitterProto(const char *proto_name, const wchar_t *username) :
- PROTO<TwitterProto>(proto_name, username)
+ PROTO<TwitterProto>(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 <http://www.gnu.org/licenses/>.
class TwitterProto : public PROTO<TwitterProto>
{
+ ptrA m_szChatId;
+
public:
TwitterProto(const char*,const wchar_t*);
~TwitterProto();