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
|
#include "stdafx.h"
CMTProto::CMTProto(const char* protoName, const wchar_t* userName) :
PROTO<CMTProto>(protoName, userName),
m_pClientMmanager(std::make_unique<td::ClientManager>()),
m_arRequests(10, NumericKeySortT)
{
m_iClientId = m_pClientMmanager->create_client_id();
}
CMTProto::~CMTProto()
{
}
INT_PTR CMTProto::GetCaps(int type, MCONTACT)
{
switch (type) {
case PFLAGNUM_1:
return PF1_IM | PF1_FILE | PF1_CHAT | PF1_BASICSEARCH | PF1_ADDSEARCHRES | PF1_MODEMSGRECV;
case PFLAGNUM_2:
return PF2_ONLINE;
case PFLAGNUM_3:
return 0;
case PFLAGNUM_4:
return PF4_NOCUSTOMAUTH | PF4_NOAUTHDENYREASON | PF4_IMSENDOFFLINE | PF4_OFFLINEFILES | PF4_SUPPORTTYPING | PF4_AVATARS | PF4_SERVERMSGID;
case PFLAGNUM_5:
return 0;
case PFLAG_UNIQUEIDTEXT:
return (INT_PTR)L"Phone";
}
return 0;
}
int CMTProto::SetStatus(int iNewStatus)
{
if (m_iDesiredStatus == iNewStatus)
return 0;
int oldStatus = m_iStatus;
// Routing statuses not supported by Telegram
switch (iNewStatus) {
case ID_STATUS_OFFLINE:
m_iDesiredStatus = iNewStatus;
break;
case ID_STATUS_ONLINE:
case ID_STATUS_FREECHAT:
default:
m_iDesiredStatus = ID_STATUS_ONLINE;
break;
}
if (m_iDesiredStatus == ID_STATUS_OFFLINE) {
if (m_bRunning)
SendQuery(new td::td_api::close());
m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
}
else if (!m_bRunning && !IsStatusConnecting(m_iStatus)) {
m_iStatus = ID_STATUS_CONNECTING;
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
ForkThread(&CMTProto::ServerThread);
}
else if (m_bRunning) {
m_iStatus = m_iDesiredStatus;
ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
}
else ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldStatus, m_iStatus);
return 0;
}
|