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
|
#include "stdafx.h"
CSlackProto::CSlackProto(const char* protoName, const TCHAR* userName) :
PROTO<CSlackProto>(protoName, userName), requestQueue(1),
hMessageProcess(1)
{
InitNetlib();
//CreateProtoService(PS_CREATEACCMGRUI, &CSlackProto::OnAccountManagerInit);
SetAllContactsStatus(ID_STATUS_OFFLINE);
}
CSlackProto::~CSlackProto()
{
UninitNetlib();
}
DWORD_PTR CSlackProto::GetCaps(int type, MCONTACT)
{
switch (type)
{
case PFLAGNUM_1:
return PF1_IMSEND;
case PFLAGNUM_2:
return PF2_ONLINE;
case PFLAGNUM_3:
return PF2_ONLINE;
case PFLAG_UNIQUEIDTEXT:
return (INT_PTR)"User Id";
case PFLAG_UNIQUEIDSETTING:
return (DWORD_PTR)"UserId";
}
return 0;
}
MCONTACT CSlackProto::AddToList(int flags, PROTOSEARCHRESULT *psr)
{
return NULL;
}
int CSlackProto::AuthRecv(MCONTACT, PROTORECVEVENT* pre)
{
return Proto_AuthRecv(m_szModuleName, pre);
}
int CSlackProto::AuthRequest(MCONTACT hContact, const wchar_t *szMessage)
{
ptrA reason(mir_utf8encodeW(szMessage));
return OnRequestAuth(hContact, (LPARAM)reason);
}
int CSlackProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT *pre)
{
return OnReceiveMessage(hContact, pre);
}
int CSlackProto::SendMsg(MCONTACT hContact, int flags, const char *msg)
{
if (!IsOnline())
{
ForkThread(&CSlackProto::SendMessageAckThread, (void*)hContact);
return 1;
}
UINT hMessage = InterlockedIncrement(&hMessageProcess);
SendMessageParam *param = (SendMessageParam*)mir_calloc(sizeof(SendMessageParam));
param->hContact = hContact;
param->hMessage = hMessage;
param->message = mir_strdup(msg);
ForkThread(&CSlackProto::SendMessageThread, param);
return hMessage;
}
int CSlackProto::SetStatus(int iNewStatus)
{
if (iNewStatus == m_iDesiredStatus)
return 0;
switch (iNewStatus)
{
case ID_STATUS_FREECHAT:
case ID_STATUS_ONTHEPHONE:
iNewStatus = ID_STATUS_ONLINE;
break;
case ID_STATUS_NA:
case ID_STATUS_OUTTOLUNCH:
iNewStatus = ID_STATUS_AWAY;
break;
case ID_STATUS_DND:
case ID_STATUS_INVISIBLE:
iNewStatus = ID_STATUS_OCCUPIED;
break;
}
debugLogA(__FUNCTION__ ": changing status from %i to %i", m_iStatus, iNewStatus);
int old_status = m_iStatus;
m_iDesiredStatus = iNewStatus;
if (iNewStatus == ID_STATUS_OFFLINE)
{
// logout
LogOut();
if (!Miranda_IsTerminated())
{
SetAllContactsStatus(ID_STATUS_OFFLINE);
}
m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
}
else
{
if (old_status == ID_STATUS_CONNECTING)
{
return 0;
}
if (old_status == ID_STATUS_OFFLINE && !IsOnline())
{
// login
m_iStatus = ID_STATUS_CONNECTING;
isTerminated = false;
hRequestQueueThread = ForkThreadEx(&CSlackProto::RequestQueueThread, NULL, NULL);
}
else
{
// set tox status
m_iStatus = iNewStatus;
}
}
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);
return 0;
}
int CSlackProto::UserIsTyping(MCONTACT hContact, int type)
{
return OnUserIsTyping(hContact, type);
}
int CSlackProto::OnEvent(PROTOEVENTTYPE iEventType, WPARAM wParam, LPARAM lParam)
{
switch (iEventType)
{
case EV_PROTO_ONLOAD:
return OnAccountLoaded(wParam, lParam);
case EV_PROTO_ONCONTACTDELETED:
return OnContactDeleted(wParam, lParam);
}
return 1;
}
|