summaryrefslogtreecommitdiff
path: root/protocols/Twitter/src/chat.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Twitter/src/chat.cpp')
-rw-r--r--protocols/Twitter/src/chat.cpp78
1 files changed, 38 insertions, 40 deletions
diff --git a/protocols/Twitter/src/chat.cpp b/protocols/Twitter/src/chat.cpp
index e94bdc40e3..30e357a7bc 100644
--- a/protocols/Twitter/src/chat.cpp
+++ b/protocols/Twitter/src/chat.cpp
@@ -1,4 +1,5 @@
/*
+Copyright © 2012-15 Miranda NG team
Copyright © 2009 Jim Porter
This program is free software: you can redistribute it and/or modify
@@ -35,68 +36,67 @@ void TwitterProto::UpdateChat(const twitter_user &update)
replaceAll(chatText, "%", "%%");
- gce.ptszText = mir_a2t_cp(chatText.c_str(),CP_UTF8);
+ gce.ptszText = mir_a2t_cp(chatText.c_str(), CP_UTF8);
//gce.ptszText = mir_a2t_cp(update.status.text.c_str(),CP_UTF8);
- gce.time = static_cast<DWORD>(update.status.time);
+ 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))
- {
+ if (hContact && !db_get_s(hContact, "CList", "MyHandle", &nick)) {
gce.ptszNick = mir_a2t(nick.pszVal);
db_free(&nick);
}
else
gce.ptszNick = mir_a2t(update.username.c_str());
- CallServiceSync(MS_GC_EVENT,0,reinterpret_cast<LPARAM>(&gce));
+ CallServiceSync(MS_GC_EVENT, 0, reinterpret_cast<LPARAM>(&gce));
mir_free(const_cast<TCHAR*>(gce.ptszNick));
mir_free(const_cast<TCHAR*>(gce.ptszUID));
mir_free(const_cast<TCHAR*>(gce.ptszText));
}
-int TwitterProto::OnChatOutgoing(WPARAM wParam,LPARAM lParam)
+int TwitterProto::OnChatOutgoing(WPARAM wParam, LPARAM lParam)
{
GCHOOK *hook = reinterpret_cast<GCHOOK*>(lParam);
- if ( strcmp(hook->pDest->pszModule, m_szModuleName))
+ if (strcmp(hook->pDest->pszModule, m_szModuleName))
return 0;
- switch(hook->pDest->iType) {
+ switch (hook->pDest->iType) {
case GC_USER_MESSAGE:
- debugLog( _T("**Chat - Outgoing message: %s"), hook->ptszText);
+ debugLog(_T("**Chat - Outgoing message: %s"), hook->ptszText);
{
- ptrA text( mir_utf8encodeT(hook->ptszText));
+ ptrA text(mir_utf8encodeT(hook->ptszText));
std::string tweet(text);
replaceAll(tweet, "%%", "%"); // the chat plugin will turn "%" into "%%", so we have to change it back :/
- char *varTweet = mir_strdup( tweet.c_str());
+ char *varTweet = mir_strdup(tweet.c_str());
ForkThread(&TwitterProto::SendTweetWorker, varTweet);
}
break;
case GC_USER_PRIVMESS:
- {
- ptrA text( mir_t2a(hook->ptszUID));
- CallService(MS_MSG_SENDMESSAGE, WPARAM(UsernameToHContact(text)), 0);
- }
- break;
+ {
+ ptrA text(mir_t2a(hook->ptszUID));
+ CallService(MS_MSG_SENDMESSAGE, WPARAM(UsernameToHContact(text)), 0);
+ }
+ break;
}
return 0;
}
// TODO: remove nick?
-void TwitterProto::AddChatContact(const char *name,const char *nick)
+void TwitterProto::AddChatContact(const char *name, const char *nick)
{
GCDEST gcd = { m_szModuleName, m_tszUserName, GC_EVENT_JOIN };
GCEVENT gce = { sizeof(gce), &gcd };
gce.time = DWORD(time(0));
- gce.ptszNick = mir_a2t(nick ? nick:name);
+ gce.ptszNick = mir_a2t(nick ? nick : name);
gce.ptszUID = mir_a2t(name);
gce.ptszStatus = _T("Normal");
- CallServiceSync(MS_GC_EVENT,0,reinterpret_cast<LPARAM>(&gce));
+ CallServiceSync(MS_GC_EVENT, 0, reinterpret_cast<LPARAM>(&gce));
mir_free(const_cast<TCHAR*>(gce.ptszNick));
mir_free(const_cast<TCHAR*>(gce.ptszUID));
@@ -109,12 +109,12 @@ void TwitterProto::DeleteChatContact(const char *name)
gce.time = DWORD(time(0));
gce.ptszNick = mir_a2t(name);
gce.ptszUID = gce.ptszNick;
- CallServiceSync(MS_GC_EVENT,0,reinterpret_cast<LPARAM>(&gce));
+ CallServiceSync(MS_GC_EVENT, 0, reinterpret_cast<LPARAM>(&gce));
mir_free(const_cast<TCHAR*>(gce.ptszNick));
}
-INT_PTR TwitterProto::OnJoinChat(WPARAM,LPARAM suppress)
+INT_PTR TwitterProto::OnJoinChat(WPARAM, LPARAM suppress)
{
// ***** Create the group chat session
GCSESSION gcw = { sizeof(gcw) };
@@ -124,35 +124,35 @@ INT_PTR TwitterProto::OnJoinChat(WPARAM,LPARAM suppress)
gcw.ptszID = m_tszUserName;
CallServiceSync(MS_GC_NEWSESSION, 0, (LPARAM)&gcw);
- if(m_iStatus != ID_STATUS_ONLINE)
+ if (m_iStatus != ID_STATUS_ONLINE)
return 0;
// ***** Create a group
GCDEST gcd = { m_szModuleName, m_tszUserName, GC_EVENT_ADDGROUP };
GCEVENT gce = { sizeof(gce), &gcd };
gce.ptszStatus = _T("Normal");
- CallServiceSync(MS_GC_EVENT,0,reinterpret_cast<LPARAM>(&gce));
+ CallServiceSync(MS_GC_EVENT, 0, reinterpret_cast<LPARAM>(&gce));
// ***** Hook events
HookProtoEvent(ME_GC_EVENT, &TwitterProto::OnChatOutgoing);
// Note: Initialization will finish up in SetChatStatus, called separately
- if(!suppress)
+ if (!suppress)
SetChatStatus(m_iStatus);
in_chat_ = true;
return 0;
}
-INT_PTR TwitterProto::OnLeaveChat(WPARAM,LPARAM)
+INT_PTR TwitterProto::OnLeaveChat(WPARAM, LPARAM)
{
in_chat_ = false;
GCDEST gcd = { m_szModuleName, m_tszUserName, GC_EVENT_CONTROL };
GCEVENT gce = { sizeof(gce), &gcd };
- CallServiceSync(MS_GC_EVENT,SESSION_OFFLINE, reinterpret_cast<LPARAM>(&gce));
- CallServiceSync(MS_GC_EVENT,SESSION_TERMINATE,reinterpret_cast<LPARAM>(&gce));
+ CallServiceSync(MS_GC_EVENT, SESSION_OFFLINE, reinterpret_cast<LPARAM>(&gce));
+ CallServiceSync(MS_GC_EVENT, SESSION_TERMINATE, reinterpret_cast<LPARAM>(&gce));
return 0;
}
@@ -161,20 +161,18 @@ void TwitterProto::SetChatStatus(int status)
GCDEST gcd = { m_szModuleName, m_tszUserName, GC_EVENT_CONTROL };
GCEVENT gce = { sizeof(gce), &gcd };
- if(status == ID_STATUS_ONLINE)
- {
+ if (status == ID_STATUS_ONLINE) {
// Add all friends to contact list
- for(MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
- if( isChatRoom(hContact))
+ for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ if (isChatRoom(hContact))
continue;
- DBVARIANT uid,nick;
- if(db_get_s(hContact,m_szModuleName,TWITTER_KEY_UN,&uid))
+ DBVARIANT uid, nick;
+ if (db_get_s(hContact, m_szModuleName, TWITTER_KEY_UN, &uid))
continue;
- if(!db_get_s(hContact,"CList","MyHandle",&nick))
- {
- AddChatContact(uid.pszVal,nick.pszVal);
+ if (!db_get_s(hContact, "CList", "MyHandle", &nick)) {
+ AddChatContact(uid.pszVal, nick.pszVal);
db_free(&nick);
}
else
@@ -185,9 +183,9 @@ void TwitterProto::SetChatStatus(int status)
// For some reason, I have to send an INITDONE message, even if I'm not actually
// initializing the room...
- CallServiceSync(MS_GC_EVENT,SESSION_INITDONE,reinterpret_cast<LPARAM>(&gce));
- CallServiceSync(MS_GC_EVENT,SESSION_ONLINE, reinterpret_cast<LPARAM>(&gce));
+ CallServiceSync(MS_GC_EVENT, SESSION_INITDONE, reinterpret_cast<LPARAM>(&gce));
+ CallServiceSync(MS_GC_EVENT, SESSION_ONLINE, reinterpret_cast<LPARAM>(&gce));
}
else
- CallServiceSync(MS_GC_EVENT,SESSION_OFFLINE,reinterpret_cast<LPARAM>(&gce));
-} \ No newline at end of file
+ CallServiceSync(MS_GC_EVENT, SESSION_OFFLINE, reinterpret_cast<LPARAM>(&gce));
+}