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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
/*
Copyright (c) 2015-21 Miranda NG team (https://miranda-ng.org)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation version 2
of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
uint16_t CSkypeProto::GetContactStatus(MCONTACT hContact)
{
return getWord(hContact, "Status", ID_STATUS_OFFLINE);
}
void CSkypeProto::SetContactStatus(MCONTACT hContact, uint16_t status)
{
uint16_t oldStatus = GetContactStatus(hContact);
if (oldStatus != status) {
setWord(hContact, "Status", status);
if (status == ID_STATUS_OFFLINE)
delSetting(hContact, "MirVer");
}
}
void CSkypeProto::SetChatStatus(MCONTACT hContact, int iStatus)
{
ptrW tszChatID(getWStringA(hContact, "ChatRoomID"));
if (tszChatID != NULL)
Chat_Control(m_szModuleName, tszChatID, (iStatus == ID_STATUS_OFFLINE) ? SESSION_OFFLINE : SESSION_ONLINE);
}
MCONTACT CSkypeProto::GetContactFromAuthEvent(MEVENT hEvent)
{
uint32_t body[3];
DBEVENTINFO dbei = {};
dbei.cbBlob = sizeof(uint32_t) * 2;
dbei.pBlob = (uint8_t*)&body;
if (db_event_get(hEvent, &dbei))
return INVALID_CONTACT_ID;
if (dbei.eventType != EVENTTYPE_AUTHREQUEST)
return INVALID_CONTACT_ID;
if (mir_strcmp(dbei.szModule, m_szModuleName) != 0)
return INVALID_CONTACT_ID;
return DbGetAuthEventContact(&dbei);
}
MCONTACT CSkypeProto::FindContact(const char *skypeId)
{
for (auto &hContact : AccContacts())
if (!mir_strcmpi(skypeId, ptrA(getUStringA(hContact, SKYPE_SETTINGS_ID))))
return hContact;
return 0;
}
MCONTACT CSkypeProto::FindContact(const wchar_t *skypeId)
{
for (auto &hContact : AccContacts())
if (!mir_wstrcmpi(skypeId, getMStringW(hContact, SKYPE_SETTINGS_ID)))
return hContact;
return 0;
}
MCONTACT CSkypeProto::AddContact(const char *skypeId, const char *nick, bool isTemporary)
{
MCONTACT hContact = FindContact(skypeId);
if (hContact)
return hContact;
hContact = db_add_contact();
Proto_AddToContact(hContact, m_szModuleName);
setString(hContact, SKYPE_SETTINGS_ID, skypeId);
setUString(hContact, "Nick", (nick) ? nick : GetSkypeNick(skypeId));
if (wstrCListGroup) {
Clist_GroupCreate(0, wstrCListGroup);
Clist_SetGroup(hContact, wstrCListGroup);
}
setByte(hContact, "Auth", 1);
setByte(hContact, "Grant", 1);
if (isTemporary)
Contact_RemoveFromList(hContact);
return hContact;
}
void CSkypeProto::LoadContactsAuth(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
{
JsonReply reply(response);
if (reply.error())
return;
auto &root = reply.data();
for (auto &item : root["invite_list"]) {
std::string skypeId = item["mri"].as_string().erase(0, 2);
std::string reason = item["greeting"].as_string();
time_t eventTime = 0;
for (auto &it : item["invites"])
eventTime = IsoToUnixTime(it["time"].as_string());
std::string displayName = item["displayname"].as_string();
const char *szNick = (displayName.empty()) ? nullptr : displayName.c_str();
MCONTACT hContact = AddContact(skypeId.c_str(), szNick);
time_t lastEventTime = getDword(hContact, "LastAuthRequestTime");
if (lastEventTime && lastEventTime >= eventTime)
continue;
setUString(hContact, "Nick", displayName.c_str());
setDword(hContact, "LastAuthRequestTime", eventTime);
delSetting(hContact, "Auth");
DB::AUTH_BLOB blob(hContact, displayName.c_str(), nullptr, nullptr, skypeId.c_str(), reason.c_str());
PROTORECVEVENT pre = { 0 };
pre.timestamp = time(0);
pre.lParam = blob.size();
pre.szMessage = blob;
ProtoChainRecv(hContact, PSR_AUTH, 0, (LPARAM)&pre);
}
}
//[{"skypeId":"echo123", "authorized" : true, "blocked" : false, ...},...]
// other properties is exists but empty
void CSkypeProto::LoadContactList(NETLIBHTTPREQUEST *response, AsyncHttpRequest*)
{
JsonReply reply(response);
if (reply.error())
return;
bool loadAll = getBool("LoadAllContacts", false);
auto &root = reply.data();
for (auto &item : root["contacts"]) {
const JSONNode &name = item["name"];
std::string skypeId = item["person_id"].as_string();
CMStringW first_name = name["first"].as_mstring();
CMStringW last_name = name["surname"].as_mstring();
CMStringW avatar_url = item["avatar_url"].as_mstring();
std::string type = item["type"].as_string();
if (type == "skype" || loadAll) {
MCONTACT hContact = AddContact(skypeId.c_str(), nullptr);
std::string displayName = item["display_name"].as_string();
if (!displayName.empty())
setUString(hContact, "Nick", displayName.c_str());
if (item["authorized"].as_bool()) {
delSetting(hContact, "Auth");
delSetting(hContact, "Grant");
}
else setByte(hContact, "Grant", 1);
if (item["blocked"].as_bool())
setByte(hContact, "IsBlocked", 1);
else
delSetting(hContact, "IsBlocked");
ptrW wszGroup(Clist_GetGroup(hContact));
if (wszGroup == nullptr) {
if (wstrCListGroup) {
Clist_GroupCreate(0, wstrCListGroup);
Clist_SetGroup(hContact, wstrCListGroup);
}
}
setString(hContact, "Type", type.c_str());
if (first_name)
setWString(hContact, "FirstName", first_name);
if (last_name)
setWString(hContact, "LastName", last_name);
if (item["mood"])
db_set_ws(hContact, "CList", "StatusMsg", RemoveHtml(item["mood"].as_mstring()));
SetAvatarUrl(hContact, avatar_url);
ReloadAvatarInfo(hContact);
for (auto &phone : item["phones"]) {
CMStringW number = phone["number"].as_mstring();
switch (phone["type"].as_int()) {
case 0:
setWString(hContact, "Phone", number);
break;
case 2:
setWString(hContact, "Cellular", number);
break;
}
}
}
}
PushRequest(new GetContactsAuthRequest());
}
INT_PTR CSkypeProto::OnRequestAuth(WPARAM hContact, LPARAM)
{
if (hContact == INVALID_CONTACT_ID)
return 1;
PushRequest(new AddContactRequest(getId(hContact)));
return 0;
}
INT_PTR CSkypeProto::OnGrantAuth(WPARAM hContact, LPARAM)
{
if (hContact == INVALID_CONTACT_ID)
return 1;
PushRequest(new AuthAcceptRequest(getId(hContact)));
return 0;
}
void CSkypeProto::OnContactDeleted(MCONTACT hContact)
{
if (IsOnline() && hContact) {
if (isChatRoom(hContact))
PushRequest(new DestroyChatroomRequest(getMStringA(hContact, "ChatRoomID")));
else
PushRequest(new DeleteContactRequest(getId(hContact)));
}
}
INT_PTR CSkypeProto::BlockContact(WPARAM hContact, LPARAM)
{
if (!IsOnline()) return 1;
if (IDYES == MessageBox(NULL, TranslateT("Are you sure?"), TranslateT("Warning"), MB_YESNO | MB_ICONQUESTION))
PushRequest(new BlockContactRequest(this, hContact));
return 0;
}
void CSkypeProto::OnBlockContact(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest)
{
MCONTACT hContact = (DWORD_PTR)pRequest->pUserInfo;
if (response != nullptr)
Contact_Hide(hContact);
}
INT_PTR CSkypeProto::UnblockContact(WPARAM hContact, LPARAM)
{
PushRequest(new UnblockContactRequest(this, hContact));
return 0;
}
void CSkypeProto::OnUnblockContact(NETLIBHTTPREQUEST *response, AsyncHttpRequest *pRequest)
{
if (response == nullptr)
return;
MCONTACT hContact = (DWORD_PTR)pRequest->pUserInfo;
Contact_Hide(hContact, false);
delSetting(hContact, "IsBlocked");
}
|