summaryrefslogtreecommitdiff
path: root/protocols/Slack/src/slack_proto.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Slack/src/slack_proto.cpp')
-rw-r--r--protocols/Slack/src/slack_proto.cpp147
1 files changed, 147 insertions, 0 deletions
diff --git a/protocols/Slack/src/slack_proto.cpp b/protocols/Slack/src/slack_proto.cpp
new file mode 100644
index 0000000000..8a37838c28
--- /dev/null
+++ b/protocols/Slack/src/slack_proto.cpp
@@ -0,0 +1,147 @@
+#include "stdafx.h"
+
+CSlackProto::CSlackProto(const char* protoName, const TCHAR* userName) :
+ PROTO<CSlackProto>(protoName, userName), requestQueue(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_IM;
+ case PFLAGNUM_2:
+ return PF2_ONLINE | PF2_LONGAWAY;
+ case PFLAGNUM_3:
+ return PF2_ONLINE | PF2_LONGAWAY;
+ 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)
+{
+ return OnSendMessage(hContact, flags, msg);
+}
+
+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;
+}