summaryrefslogtreecommitdiff
path: root/protocols/VKontakte/src/vk_struct.h
blob: 89077432dd269c57b701aa338ae2ea26b3aa7b0c (plain)
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
/*
Copyright (c) 2013-19 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"
#pragma once

struct AsyncHttpRequest : public MTHttpRequest<CVkProto>
{
	enum RequestPriority { rpLow, rpMedium, rpHigh };

	AsyncHttpRequest();
	AsyncHttpRequest(CVkProto*, int iRequestType, LPCSTR szUrl, bool bSecure, MTHttpRequestHandler pFunc, RequestPriority rpPriority = rpMedium);

	void Redirect(NETLIBHTTPREQUEST*);

	int m_iRetry;
	int m_iErrorCode;
	RequestPriority m_priority;
	static ULONG m_reqCount;
	ULONG m_reqNum;
	bool m_bApiReq;
	bool bNeedsRestart, bIsMainConn;
};

struct CVkFileUploadParam : public MZeroedObject {
	enum VKFileType { typeInvalid, typeImg, typeAudio, typeDoc, typeNotSupported };
	wchar_t *FileName;
	wchar_t *Desc;
	char *atr;
	char *fname;
	MCONTACT hContact;
	VKFileType filetype;

	CVkFileUploadParam(MCONTACT _hContact, const wchar_t *_desc, wchar_t **_files);
	~CVkFileUploadParam();
	VKFileType GetType();
	__forceinline bool IsAccess() { return ::_waccess(FileName, 0) == 0; }
	__forceinline char* atrName() { GetType();  return atr; }
	__forceinline char* fileName() { GetType();  return fname; }
};

struct CVkSendMsgParam : public MZeroedObject
{
	CVkSendMsgParam(MCONTACT _hContact, int _iMsgID = 0, int _iCount = 0) :
		hContact(_hContact),
		iMsgID(_iMsgID),
		iCount(_iCount),
		pFUP(nullptr)
	{}

	CVkSendMsgParam(MCONTACT _hContact, CVkFileUploadParam *_pFUP) :
		hContact(_hContact),
		iMsgID(-1),
		iCount(0),
		pFUP(_pFUP)
	{}

	MCONTACT hContact;
	int iMsgID;
	int iCount;
	CVkFileUploadParam *pFUP;
};

struct CVkDBAddAuthRequestThreadParam : public MZeroedObject
{
	CVkDBAddAuthRequestThreadParam(MCONTACT _hContact, bool _bAdded) :
		hContact(_hContact),
		bAdded(_bAdded)
	{}

	MCONTACT hContact;
	bool bAdded;
};

struct CVkChatMessage : public MZeroedObject
{
	CVkChatMessage(int _id) :
		m_mid(_id),
		m_uid(0),
		m_date(0),
		m_bHistory(false),
		m_bIsAction(false)
	{}

	int m_mid, m_uid, m_date;
	bool m_bHistory, m_bIsAction;
	ptrW m_wszBody;
};

struct CVkChatUser : public MZeroedObject
{
	CVkChatUser(LONG _id) :
		m_uid(_id),
		m_bDel(false),
		m_bUnknown(false)
	{}

	LONG m_uid;
	bool m_bDel, m_bUnknown;
	ptrW m_wszNick;
};

struct CVkChatInfo : public MZeroedObject
{
	CVkChatInfo(int _id) :
		m_users(10, NumericKeySortT),
		m_msgs(10, NumericKeySortT),
		m_iChatId(_id),
		m_iAdminId(0),
		m_bHistoryRead(0),
		m_hContact(INVALID_CONTACT_ID)
	{}

	int m_iChatId, m_iAdminId;
	bool m_bHistoryRead;
	ptrW m_wszTopic, m_wszId;
	MCONTACT m_hContact;
	OBJLIST<CVkChatUser> m_users;
	OBJLIST<CVkChatMessage> m_msgs;

	CVkChatUser* GetUserById(LPCWSTR);
	CVkChatUser* GetUserById(int user_id);
};

struct CVkUserInfo : public MZeroedObject {
	CVkUserInfo(LONG _UserId) :
		m_UserId(_UserId),
		m_bIsGroup(false)
	{}

	CVkUserInfo(LONG _UserId, bool _bIsGroup, const CMStringW& _wszUserNick, const CMStringW& _wszLink, MCONTACT _hContact = 0) :
		m_UserId(_UserId),
		m_bIsGroup(_bIsGroup),
		m_wszUserNick(_wszUserNick),
		m_wszLink(_wszLink),
		m_hContact(_hContact)
	{}

	LONG m_UserId;
	MCONTACT m_hContact;
	CMStringW m_wszUserNick;
	CMStringW m_wszLink;
	bool m_bIsGroup;
};

enum VKObjType { vkNull, vkPost, vkPhoto, vkVideo, vkComment, vkTopic, vkUsers, vkCopy, vkInvite };

struct CVKNotification {
	wchar_t *pwszType;
	VKObjType vkParent, vkFeedback;
	wchar_t *pwszTranslate;
};

struct CVKNewsItem : public MZeroedObject {
	CVKNewsItem() :
		tDate(0),
		vkUser(nullptr),
		bIsGroup(false),
		bIsRepost(false),
		vkFeedbackType(vkNull),
		vkParentType(vkNull)
	{}

	CMStringW wszId;
	time_t tDate;
	CVkUserInfo *vkUser;
	CMStringW wszText;
	CMStringW wszLink;
	CMStringW wszType;
	CMStringW wszPopupTitle;
	CMStringW wszPopupText;
	VKObjType vkFeedbackType, vkParentType;
	bool bIsGroup;
	bool bIsRepost;
};

enum VKBBCType : BYTE { vkbbcB, vkbbcI, vkbbcS, vkbbcU, vkbbcCode, vkbbcImg, vkbbcUrl, vkbbcSize, vkbbcColor };
enum BBCSupport : BYTE { bbcNo, bbcBasic, bbcAdvanced };

struct CVKBBCItem {
	VKBBCType vkBBCType;
	BBCSupport vkBBCSettings;
	wchar_t *pwszTempate;
};

struct CVKChatContactTypingParam {
	CVKChatContactTypingParam(int pChatId, int pUserId) :
		m_ChatId(pChatId),
		m_UserId(pUserId)
	{}

	int m_ChatId;
	LONG m_UserId;
};

struct CVKInteres {
	const char *szField;
	wchar_t *pwszTranslate;
};

struct CVKLang {
	wchar_t *szCode;
	wchar_t *szDescription;
};

enum MarkMsgReadOn : BYTE { markOnRead, markOnReceive, markOnReply, markOnTyping };
enum SyncHistoryMetod : BYTE { syncOff, syncAuto, sync1Days, sync3Days };
enum MusicSendMetod : BYTE { sendNone, sendStatusOnly, sendBroadcastOnly, sendBroadcastAndStatus };
enum IMGBBCSypport : BYTE { imgNo, imgFullSize, imgPreview130, imgPreview604 };

struct CVKSync {
	const wchar_t *type;
	SyncHistoryMetod data;
};

struct CVKMarkMsgRead {
	const wchar_t *type;
	MarkMsgReadOn data;
};

struct CVkCookie
{
	CVkCookie(const CMStringA& name, const CMStringA& value, const CMStringA& domain) :
		m_name(name),
		m_value(value),
		m_domain(domain)
	{}

	CMStringA m_name, m_value, m_domain;
};

struct CVKOptions {
	CMOption<BYTE> bLoadLastMessageOnMsgWindowsOpen;
	CMOption<BYTE> bLoadOnlyFriends;
	CMOption<BYTE> bServerDelivery;
	CMOption<BYTE> bHideChats;
	CMOption<BYTE> bMesAsUnread;
	CMOption<BYTE> bUseLocalTime;
	CMOption<BYTE> bReportAbuse;
	CMOption<BYTE> bClearServerHistory;
	CMOption<BYTE> bRemoveFromFrendlist;
	CMOption<BYTE> bRemoveFromCList;
	CMOption<BYTE> bPopUpSyncHistory;
	CMOption<BYTE> iMarkMessageReadOn;
	CMOption<BYTE> bStikersAsSmyles;
	CMOption<BYTE> bUserForceInvisibleOnActivity;
	CMOption<BYTE> iMusicSendMetod;
	CMOption<BYTE> bPopupContactsMusic;
	CMOption<BYTE> iSyncHistoryMetod;
	CMOption<BYTE> bNewsEnabled;
	CMOption<BYTE> iMaxLoadNewsPhoto;
	CMOption<BYTE> bNotificationsEnabled;
	CMOption<BYTE> bNotificationsMarkAsViewed;
	CMOption<BYTE> bSpecialContactAlwaysEnabled;
	CMOption<BYTE> iIMGBBCSupport;
	CMOption<BYTE> iBBCForNews;
	CMOption<BYTE> iBBCForAttachments;
	CMOption<BYTE> bUseBBCOnAttacmentsAsNews;
	CMOption<BYTE> bNewsAutoClearHistory;
	CMOption<BYTE> bNewsFilterPosts;
	CMOption<BYTE> bNewsFilterPhotos;
	CMOption<BYTE> bNewsFilterTags;
	CMOption<BYTE> bNewsFilterWallPhotos;
	CMOption<BYTE> bNewsSourceFriends;
	CMOption<BYTE> bNewsSourceGroups;
	CMOption<BYTE> bNewsSourcePages;
	CMOption<BYTE> bNewsSourceFollowing;
	CMOption<BYTE> bNewsSourceIncludeBanned;
	CMOption<BYTE> bNewsSourceNoReposts;
	CMOption<BYTE> bNotificationFilterComments;
	CMOption<BYTE> bNotificationFilterLikes;
	CMOption<BYTE> bNotificationFilterReposts;
	CMOption<BYTE> bNotificationFilterMentions;
	CMOption<BYTE> bNotificationFilterInvites;
	CMOption<BYTE> bNotificationFilterAcceptedFriends;
	CMOption<BYTE> bUseNonStandardNotifications;
	CMOption<BYTE> bShortenLinksForAudio;
	CMOption<BYTE> bAddMessageLinkToMesWAtt;
	CMOption<BYTE> bSplitFormatFwdMsg;
	CMOption<BYTE> bSyncReadMessageStatusFromServer;
	CMOption<BYTE> bLoadFullCList;
	CMOption<BYTE> bSendVKLinksAsAttachments;
	CMOption<BYTE> bLoadSentAttachments;
	CMOption<BYTE> bShowVkDeactivateEvents;
	CMOption<BYTE> bStickerBackground;

	CMOption<BYTE> bShowProtoMenuItem0;
	CMOption<BYTE> bShowProtoMenuItem1;
	CMOption<BYTE> bShowProtoMenuItem2;
	CMOption<BYTE> bShowProtoMenuItem3;
	CMOption<BYTE> bShowProtoMenuItem4;
	CMOption<BYTE> bShowProtoMenuItem5;
	CMOption<BYTE> bShowProtoMenuItem6;

	CMOption<DWORD> iNewsInterval;
	CMOption<DWORD> iNotificationsInterval;
	CMOption<DWORD> iNewsAutoClearHistoryInterval;
	CMOption<DWORD> iInvisibleInterval;
	CMOption<DWORD> iMaxFriendsCount;
	CMOption<DWORD> iStickerSize;

	CMOption<wchar_t*> pwszDefaultGroup;
	CMOption<wchar_t*> pwszReturnChatMessage;
	CMOption<wchar_t*> pwszVKLang;

	CVKOptions(PROTO_INTERFACE *proto);

	__forceinline BBCSupport BBCForNews() { return (BBCSupport)(BYTE)iBBCForNews; };
	__forceinline BBCSupport BBCForAttachments() { return (BBCSupport)(BYTE)iBBCForAttachments; };

};

struct CVKDeactivateEvent {
	wchar_t *wszType;
	char *szDescription;
};

enum VKContactType : BYTE { vkContactNormal, vkContactSelf, vkContactMUCUser };
enum VKMesType : BYTE { vkALL, vkIN, vkOUT };

///////////////////////////////////////////////////////////////////////////////////////////////

enum vkJSONNodeType { vkJSONTypeProfile = 0, vkJSONTypeGroup, vkJSONTypeConversation };

class CVkUserItem : public MZeroedObject {
	CVkUserItem(CVkProto* vkProto, const JSONNode& jnNode, vkJSONNodeType vkJSONType = vkJSONTypeProfile);

	CVkUserItem(LONG _UserId) :
		m_iUserId(_UserId),
		m_bIsGroup(false)
	{}

	CVkUserItem(LONG _UserId, bool _bIsGroup, CMStringW& _wszUserNick, CMStringW& _wszLink, MCONTACT _hContact = 0) :
		m_iUserId(_UserId),
		m_bIsGroup(_bIsGroup),
		m_wszUserNick(_wszUserNick),
		m_wszLink(_wszLink),
		m_hContact(_hContact)
	{}

	/*
		"id, first_name, last_name, photo_100, bdate, sex, timezone, contacts, last_seen, online, status, country, city, relation, interests, activities, music, movies, tv, books, games, quotes, about,  domain, is_friend";
	*/
	LONG m_iKey;

	LONG m_iUserId;
	LONG m_iChatId;

	LONG m_iAdminId;


	LONG m_iStatus;
	LONG m_iLastSeen;
	LONG m_iLastMsgId;

	MCONTACT m_hContact;

	CMStringW m_wszFirstName;
	CMStringW m_wszLastName;
	CMStringW m_wszUserNick;
	CMStringW m_wszLink;
	CMStringW m_wszDeactivated;
	CMStringW m_wszCellular;
	CMStringW m_wszPhone;
	CMStringW m_wszCountry;
	CMStringW m_wszCity;
	CMStringW m_wszAbout;
	CMStringW m_wszDomain;
	CMStringW m_wszBDate;
	CMStringW m_wszAvatarUrl;

	BYTE m_btGender;
	BYTE m_btTimezone;
	BYTE m_btMaritalStatus;

	bool m_bIsGroup;
	bool m_bIsFriend;
	bool m_bIsUser;
	bool m_bIsEmail;
	bool m_bIsMUChat;
	bool m_bIsDeactivated;

	bool m_bIsHidden;
	bool m_bIsUpdated;

	CVkProto* m_VK;

	void LoadFromUserProfile(const JSONNode &jnNode);
	void LoadFromConversation(const JSONNode &jnNode);
	void LoadFromGroup(const JSONNode &jnNode);

	MCONTACT WriteToDB(bool bForce = false, VKContactType vkContactType = VKContactType::vkContactNormal);

	template <class T>
		T Set(T& PropertyName, T Value) {
			m_bIsUpdated = (PropertyName == Value);
			PropertyName = Value;
		}


};