1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
#include "skype_proto.h"
int CSkypeProto::OnMessagePreCreate(WPARAM, LPARAM lParam)
{
MessageWindowEvent *evt = (MessageWindowEvent *)lParam;
if ( strcmp(GetContactProto(evt->hContact), this->m_szModuleName))
return 0;
MessageRef message(evt->seq);
SEBinary guid;
if (message->GetPropGuid(guid))
{
CMessage::TYPE messageType;
message->GetPropType(messageType);
if (messageType == CMessage::POSTED_TEXT)
{
evt->dbei->pBlob = (PBYTE)::mir_realloc(evt->dbei->pBlob, evt->dbei->cbBlob + guid.size());
::memcpy((char *)&evt->dbei->pBlob[evt->dbei->cbBlob], guid.data(), guid.size());
evt->dbei->cbBlob += (DWORD)guid.size();
}
else if (messageType == CMessage::POSTED_EMOTE)
{
evt->dbei->pBlob = (PBYTE)::mir_realloc(evt->dbei->pBlob, evt->dbei->cbBlob + guid.size() - 4);
::memcpy((char *)&evt->dbei->pBlob[0], (char *)&evt->dbei->pBlob[4], evt->dbei->cbBlob - 4);
::memcpy((char *)&evt->dbei->pBlob[evt->dbei->cbBlob - 4], guid.data(), guid.size());
evt->dbei->cbBlob += (DWORD)guid.size() - 4;
evt->dbei->eventType = SKYPE_DB_EVENT_TYPE_EMOTE;
}
}
return 1;
}
void CSkypeProto::OnMessageReceived(const ConversationRef &conversation, const MessageRef &message)
{
SEString data;
CMessage::TYPE messageType;
message->GetPropType(messageType);
uint timestamp;
message->GetPropTimestamp(timestamp);
CMessage::CONSUMPTION_STATUS status;
message->GetPropConsumptionStatus(status);
message->GetPropBodyXml(data);
char *text = CSkypeProto::RemoveHtml(data);
message->GetPropAuthor(data);
CContact::Ref author;
this->GetContact(data, author);
HANDLE hContact = this->AddContact(author);
this->UserIsTyping(hContact, PROTOTYPE_SELFTYPING_OFF);
SEBinary guid;
message->GetPropGuid(guid);
ReadMessageParam param = { guid, messageType };
if (status != CMessage::UNCONSUMED_NORMAL)
if (this->IsMessageInDB(hContact, timestamp, guid))
return;
DWORD flags = PREF_UTF;
if (status != CMessage::UNCONSUMED_NORMAL)
flags |= PREF_CREATEREAD;
PROTORECVEVENT recv;
recv.flags = flags;
recv.lParam = (LPARAM)¶m;
recv.timestamp = timestamp;
recv.szMessage = ::mir_strdup(text);
::ProtoChainRecvMsg(hContact, &recv);
}
/////////////////////////////////////////////////////////////////////////////////////////
void CSkypeProto::OnMessageSent(const ConversationRef &conversation, const MessageRef &message)
{
SEString data;
CMessage::TYPE messageType;
message->GetPropType(messageType);
uint timestamp;
message->GetPropTimestamp(timestamp);
CMessage::SENDING_STATUS sstatus;
message->GetPropSendingStatus(sstatus);
CMessage::CONSUMPTION_STATUS status;
message->GetPropConsumptionStatus(status);
message->GetPropBodyXml(data);
char *text = CSkypeProto::RemoveHtml(data);
CParticipant::Refs participants;
conversation->GetParticipants(participants, CConversation::OTHER_CONSUMERS);
participants[0]->GetPropIdentity(data);
CContact::Ref receiver;
this->GetContact(data, receiver);
HANDLE hContact = this->AddContact(receiver);
this->SendBroadcast(
hContact,
ACKTYPE_MESSAGE,
sstatus == CMessage::FAILED_TO_SEND ? ACKRESULT_FAILED : ACKRESULT_SUCCESS,
(HANDLE)message->getOID(), 0);
SEBinary guid;
message->GetPropGuid(guid);
this->RaiseMessageSentEvent(
hContact,
timestamp,
guid,
text,
status == CMessage::UNCONSUMED_NORMAL);
}
void CSkypeProto::OnMessageEvent(const ConversationRef &conversation, const MessageRef &message)
{
CMessage::TYPE messageType;
message->GetPropType(messageType);
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->OnMessageSent(conversation, message);
else
this->OnMessageReceived(conversation, message);
}
break;
case CMessage::STARTED_LIVESESSION:
{
uint timestamp;
message->GetPropTimestamp(timestamp);
SEString identity;
message->GetPropAuthor(identity);
CContact::Ref author;
this->GetContact(identity, author);
HANDLE hContact = this->AddContact(author);
char *message = ::mir_utf8encode(::Translate("Incoming call received"));
this->AddDBEvent(
hContact,
SKYPE_DB_EVENT_TYPE_CALL,
timestamp,
DBEF_UTF,
(DWORD)::strlen(message) + 1,
(PBYTE)message);
//temp popup
TCHAR popuptext[MAX_PATH];
mir_sntprintf(popuptext, SIZEOF(popuptext), TranslateT("Incoming call from %s. Use offical skype for calling."), mir_ptr<wchar_t>(::mir_utf8decodeW(identity)));
this->ShowNotification(popuptext);
}
break;
case CMessage::ENDED_LIVESESSION:
{
uint timestamp;
message->GetPropTimestamp(timestamp);
SEString identity;
message->GetPropAuthor(identity);
CContact::Ref author;
this->GetContact(identity, author);
HANDLE hContact = this->AddContact(author);
char *message = ::mir_utf8encode(::Translate("Incoming call finished"));
this->AddDBEvent(
hContact,
SKYPE_DB_EVENT_TYPE_CALL,
timestamp,
DBEF_UTF,
(DWORD)::strlen(message) + 1,
(PBYTE)message);
}
break;
}
}
|