diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2013-05-13 18:30:05 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2013-05-13 18:30:05 +0000 |
commit | 2a1e6f05aa9fcc4dfe642bd42aeb175e3958d4b3 (patch) | |
tree | 1f0195caf23d086ecae10fc75b11fa61d85e9a66 /protocols/Skype/src/skype_chat.cpp | |
parent | 59651e97603936fc7179864506caa1818e260c76 (diff) |
Merged revision(s) from branches/unsane/skype_test:
- CSkypeProto is derived of Skype class now
- chat events moved to skype_chat.cpp
- fixed chat message timestamp
- fixed #331, #332
git-svn-id: http://svn.miranda-ng.org/main/trunk@4644 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Skype/src/skype_chat.cpp')
-rw-r--r-- | protocols/Skype/src/skype_chat.cpp | 244 |
1 files changed, 233 insertions, 11 deletions
diff --git a/protocols/Skype/src/skype_chat.cpp b/protocols/Skype/src/skype_chat.cpp index d5f0c9d787..51a51f132c 100644 --- a/protocols/Skype/src/skype_chat.cpp +++ b/protocols/Skype/src/skype_chat.cpp @@ -321,7 +321,7 @@ CConversation::Ref CSkypeProto::StartChat(StringList &invitedContacts) }
CConversation::Ref conversation;
- if (g_skype->CreateConferenceWithConsumers(conversation, needToAdd))
+ if (this->CreateConferenceWithConsumers(conversation, needToAdd))
{
delete param;
@@ -388,7 +388,7 @@ void CSkypeProto::JoinToChat(CConversation::Ref conversation, bool showWindow) participants[i]->GetPropRank(rank);
CContact::Ref contact;
- g_skype->GetContact(std::string(::mir_utf8encodeW(sid.c_str())).c_str(), contact);
+ this->GetContact(std::string(::mir_utf8encodeW(sid.c_str())).c_str(), contact);
auto status = Contact::OFFLINE;
contact->GetPropAvailability(status);
@@ -420,7 +420,7 @@ void CSkypeProto::AddConactsToChat(CConversation::Ref conversation, const String if (invitedContacts.contains(sid) && !alreadyInChat.contains(sid))
{
CContact::Ref contact;
- g_skype->GetContact((char *)mir_ptr<char>(::mir_utf8encodeW(sid)), contact);
+ this->GetContact((char *)mir_ptr<char>(::mir_utf8encodeW(sid)), contact);
CContact::AVAILABILITY status;
contact->GetPropAvailability(status);
@@ -452,7 +452,7 @@ void CSkypeProto::LeaveChat(const wchar_t *cid) ::CallServiceSync(MS_GC_EVENT, SESSION_TERMINATE, (LPARAM)&gce);
}
-void CSkypeProto::RaiseChatEvent(const wchar_t *cid, const wchar_t *sid, int evt, DWORD flags, DWORD itemData, const wchar_t *status, const wchar_t *message)
+void CSkypeProto::RaiseChatEvent(const wchar_t *cid, const wchar_t *sid, int evt, DWORD flags, DWORD itemData, const wchar_t *status, const wchar_t *message, DWORD timestamp)
{
HANDLE hContact = this->GetContactBySid(sid);
mir_ptr<wchar_t> nick(::db_get_wsa(hContact, this->m_szModuleName, "Nick"));
@@ -475,7 +475,7 @@ void CSkypeProto::RaiseChatEvent(const wchar_t *cid, const wchar_t *sid, int evt gce.dwItemData = itemData;
gce.ptszStatus = status;
gce.ptszText = message;
- gce.time = time(NULL);
+ gce.time = timestamp;
::CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce);
}
@@ -511,9 +511,9 @@ INT_PTR __cdecl CSkypeProto::OnJoinChat(WPARAM wParam, LPARAM) CConversation::Ref conversation;
//todo: fixme
- g_skype->GetConversationByIdentity(::mir_utf8encodeW(cid), conversation);
+ this->GetConversationByIdentity(::mir_utf8encodeW(cid), conversation);
conversation->GetJoinBlob(data);
- g_skype->GetConversationByBlob(data, conversation, false);
+ this->GetConversationByBlob(data, conversation, false);
conversation->Join();
this->JoinToChat(conversation);
@@ -545,7 +545,7 @@ int __cdecl CSkypeProto::OnGCEventHook(WPARAM, LPARAM lParam) CConversation::Ref conversation;
switch (gch->pDest->iType) {
case GC_SESSION_TERMINATE:
- if (g_skype->GetConversationByIdentity(::mir_utf8encodeW(cid), conversation, false))
+ if (this->GetConversationByIdentity(::mir_utf8encodeW(cid), conversation, false))
{
Participant::Refs participants;
conversation->GetParticipants(participants, CConversation::MYSELF);
@@ -556,7 +556,7 @@ int __cdecl CSkypeProto::OnGCEventHook(WPARAM, LPARAM lParam) case GC_USER_MESSAGE:
if (gch->ptszText && gch->ptszText[0])
{
- if (g_skype->GetConversationByIdentity(::mir_utf8encodeW(cid), conversation, false))
+ if (this->GetConversationByIdentity(::mir_utf8encodeW(cid), conversation, false))
{
CMessage::Ref message;
mir_ptr<char> text(::mir_utf8encodeW(gch->ptszText));
@@ -566,7 +566,7 @@ int __cdecl CSkypeProto::OnGCEventHook(WPARAM, LPARAM lParam) break;
/*case GC_USER_CHANMGR:
- if (g_skype->GetConversationByIdentity(::mir_utf8encodeW(cid), conversation, false))
+ if (this->GetConversationByIdentity(::mir_utf8encodeW(cid), conversation, false))
{
StringList invitedContacts(this->GetChatUsers(cid));
this->InviteConactsToChat(conversation, invitedContacts);
@@ -580,7 +580,7 @@ int __cdecl CSkypeProto::OnGCEventHook(WPARAM, LPARAM lParam) case GC_USER_LOGMENU:
switch(gch->dwData) {
case 10:
- if (g_skype->GetConversationByIdentity(::mir_utf8encodeW(cid), conversation, false))
+ if (this->GetConversationByIdentity(::mir_utf8encodeW(cid), conversation, false))
{
StringList invitedContacts(this->GetChatUsers(cid));
this->InviteConactsToChat(conversation, invitedContacts);
@@ -686,4 +686,226 @@ void CSkypeProto::UpdateChatUserStatus(CContact::Ref contact) 0,
CSkypeProto::SkypeToMirandaStatus(availability));
}
+}
+
+void CSkypeProto::OnChatMessageReceived(const ConversationRef &conversation, const MessageRef &message, uint messageType)
+{
+ SEString data;
+
+ uint timestamp;
+ message->GetPropTimestamp(timestamp);
+
+ message->GetPropBodyXml(data);
+ char *text = CSkypeProto::RemoveHtml(data);
+
+ message->GetPropAuthor(data);
+ mir_ptr<wchar_t> sid( ::mir_utf8decodeW(data));
+
+ conversation->GetPropIdentity(data);
+ mir_ptr<wchar_t> cid( ::mir_utf8decodeW(data));
+
+ //this->SendChatMessage(cid, sid, mir_ptr<wchar_t>(::mir_utf8decodeW(text)));
+ this->RaiseChatEvent(
+ cid,
+ sid,
+ messageType == CMessage::POSTED_TEXT ? GC_EVENT_MESSAGE : GC_EVENT_ACTION,
+ GCEF_ADDTOLOG,
+ 0,
+ NULL,
+ mir_ptr<wchar_t>(::mir_utf8decodeW(text)),
+ timestamp);
+}
+
+void CSkypeProto::OnChatMessageSent(const ConversationRef &conversation, const MessageRef &message, uint messageType)
+{
+ SEString data;
+
+ uint timestamp;
+ message->GetPropTimestamp(timestamp);
+
+ message->GetPropBodyXml(data);
+ char *text = CSkypeProto::RemoveHtml(data);
+
+ conversation->GetPropIdentity(data);
+ mir_ptr<wchar_t> cid( ::mir_utf8decodeW(data));
+
+ message->GetPropAuthor(data);
+ mir_ptr<wchar_t> sid( ::mir_utf8decodeW(data));
+
+ //this->SendChatMessage(cid, nick, mir_ptr<wchar_t>(::mir_utf8decodeW(text)));
+ this->RaiseChatEvent(
+ cid,
+ sid,
+ messageType == CMessage::POSTED_TEXT ? GC_EVENT_MESSAGE : GC_EVENT_ACTION,
+ GCEF_ADDTOLOG,
+ 0,
+ NULL,
+ mir_ptr<wchar_t>(::mir_utf8decodeW(text)),
+ timestamp);
+}
+
+void CSkypeProto::OnChatEvent(const ConversationRef &conversation, const MessageRef &message)
+{
+ uint messageType;
+ messageType = message->GetUintProp(Message::P_TYPE);
+
+ switch (messageType)
+ {
+ case CMessage::POSTED_EMOTE:
+ case CMessage::POSTED_TEXT:
+ {
+ SEString author;
+ message->GetPropAuthor(author);
+
+ if (::wcsicmp(mir_ptr<wchar_t>(::mir_utf8decodeW(author)), this->login) == 0)
+ this->OnChatMessageSent(conversation, message, messageType);
+ else
+ this->OnChatMessageReceived(conversation, message, messageType);
+ }
+ break;
+
+ case CMessage::ADDED_CONSUMERS:
+ {
+ SEString data;
+
+ conversation->GetPropIdentity(data);
+ wchar_t *cid = ::mir_utf8decodeW(data);
+
+ HANDLE hContact = this->AddChatRoom(conversation);
+ if ( !this->IsContactOnline(hContact))
+ {
+ this->JoinToChat(conversation);
+ }
+ else
+ {
+ StringList alreadyInChat(this->GetChatUsers(cid));
+
+ message->GetPropIdentities(data);
+ StringList needToAdd(::mir_utf8decodeW(data));
+
+ CParticipant::Refs participants;
+ conversation->GetParticipants(participants, CConversation::OTHER_CONSUMERS);
+ for (uint i = 0; i < participants.size(); i++)
+ {
+ participants[i]->GetPropIdentity(data);
+ std::wstring sid = ::mir_utf8decodeW(data);
+
+ if (needToAdd.contains(sid.c_str()) && !alreadyInChat.contains(sid.c_str()))
+ {
+ CContact::Ref contact;
+ this->GetContact(std::string(::mir_utf8encodeW(sid.c_str())).c_str(), contact);
+
+ CContact::AVAILABILITY status;
+ contact->GetPropAvailability(status);
+
+ CParticipant::RANK rank;
+ participants[i]->GetPropRank(rank);
+
+ this->AddChatContact(
+ cid,
+ sid.c_str(),
+ CSkypeProto::Roles[rank],
+ CSkypeProto::SkypeToMirandaStatus(status));
+ }
+ }
+ }
+ }
+ break;
+
+ case CMessage::RETIRED:
+ {
+ SEString data;
+
+ conversation->GetPropIdentity(data);
+ wchar_t *cid = ::mir_utf8decodeW(data);
+
+ StringList alreadyInChat(this->GetChatUsers(cid));
+
+ message->GetPropAuthor(data);
+ wchar_t *sid = ::mir_utf8decodeW(data);
+ if (::wcsicmp(sid, this->login) != 0)
+ if (alreadyInChat.contains(sid))
+ this->RemoveChatContact(cid, sid);
+ }
+ break;
+
+ case CMessage::RETIRED_OTHERS:
+ {
+ SEString data;
+
+ conversation->GetPropIdentity(data);
+ mir_ptr<wchar_t> cid( ::mir_utf8decodeW(data));
+
+ message->GetPropIdentities(data);
+
+ StringList alreadyInChat(this->GetChatUsers(cid));
+ StringList needToKick(::mir_utf8decodeW(data));
+
+ for (size_t i = 0; i < needToKick.size(); i++)
+ {
+ const wchar_t *sid = needToKick[i];
+ if (::wcsicmp(sid, this->login) == 0)
+ {
+ HANDLE hContact = this->GetChatRoomByCid(cid);
+ this->ShowNotification(::TranslateT("You have been kicked from the chat room"), 0, hContact);
+ this->LeaveChat(cid);
+ }
+ else if ( !alreadyInChat.contains(sid))
+ this->KickChatContact(cid, sid);
+ }
+ }
+ break;
+
+ case CMessage::SPAWNED_CONFERENCE:
+ {
+ SEString data;
+ conversation->GetPropIdentity(data);
+ char *cid = ::mir_strdup(data);
+
+ HANDLE hContact = this->AddChatRoom(conversation);
+ if ( !this->IsContactOnline(hContact))
+ {
+ this->JoinToChat(conversation);
+ }
+ }
+ break;
+
+ case CMessage::STARTED_LIVESESSION:
+ {
+ SEString data;
+
+ conversation->GetPropIdentity(data);
+ mir_ptr<wchar_t> cid( ::mir_utf8decodeW(data));
+ HANDLE hContact = this->GetChatRoomByCid(cid);
+
+ this->RaiseChatEvent(
+ cid,
+ this->login,
+ GC_EVENT_INFORMATION,
+ GCEF_ADDTOLOG,
+ 0,
+ NULL,
+ ::TranslateT("Incoming group call received"));
+ }
+ break;
+
+ case CMessage::ENDED_LIVESESSION:
+ {
+ SEString data;
+
+ conversation->GetPropIdentity(data);
+ mir_ptr<wchar_t> cid( ::mir_utf8decodeW(data));
+ HANDLE hContact = this->GetChatRoomByCid(cid);
+
+ this->RaiseChatEvent(
+ cid,
+ this->login,
+ GC_EVENT_INFORMATION,
+ GCEF_ADDTOLOG,
+ 0,
+ NULL,
+ ::TranslateT("Incoming group call finished"));
+ }
+ break;
+ }
}
\ No newline at end of file |