summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraunsane <aunsane@gmail.com>2017-03-16 00:52:31 +0300
committeraunsane <aunsane@gmail.com>2017-03-16 00:52:31 +0300
commit69c00c5b8999f66f27475342c78cc4488959e8bb (patch)
tree89046c469bd8337e2c191d348d47bceb69a49ee0
parentc84b27ebb4eaa5327c601f0b504249bf061ef3b5 (diff)
Slack: some improvements
-rw-r--r--protocols/Slack/src/api/api_oauth.h35
-rw-r--r--protocols/Slack/src/http_request.h1
-rw-r--r--protocols/Slack/src/slack_accounts.cpp8
-rw-r--r--protocols/Slack/src/slack_connection.cpp11
-rw-r--r--protocols/Slack/src/slack_contacts.cpp3
-rw-r--r--protocols/Slack/src/slack_proto.cpp7
-rw-r--r--protocols/Slack/src/slack_proto.h3
-rw-r--r--protocols/Slack/src/slack_utils.cpp10
-rw-r--r--protocols/Slack/src/stdafx.h1
9 files changed, 67 insertions, 12 deletions
diff --git a/protocols/Slack/src/api/api_oauth.h b/protocols/Slack/src/api/api_oauth.h
new file mode 100644
index 0000000000..cc1c35ae3e
--- /dev/null
+++ b/protocols/Slack/src/api/api_oauth.h
@@ -0,0 +1,35 @@
+#ifndef _SLACK_API_OAUTH_H_
+#define _SLACK_API_OAUTH_H_
+
+class OAuhtAccessRequest : public HttpRequest
+{
+public:
+ OAuhtAccessRequest(const char *code, const char *state = NULL) :
+ HttpRequest(HttpMethod::HttpPost, SLACK_API_URL "/oauth.access")
+ {
+ Headers
+ << CHAR_VALUE("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
+ Content
+ << CHAR_VALUE("client_id", SLACK_CLIENT_ID)
+ << CHAR_VALUE("client_secret", SLACK_CLIENT_SECRET)
+ << ENCODED_VALUE("code", code)
+ << ENCODED_VALUE("state", state)
+ << ENCODED_VALUE("redirect_uri", SLACK_REDIRECT_URL);
+ }
+};
+
+class AuthRevokeRequest : public HttpRequest
+{
+public:
+ AuthRevokeRequest(const char *token) :
+ HttpRequest(HttpMethod::HttpPost, SLACK_API_URL "/auth.revoke")
+ {
+ timeout = 1; // in seconds?
+ Headers
+ << CHAR_VALUE("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
+ Content
+ << CHAR_VALUE("token", token);
+ }
+};
+
+#endif //_SLACK_API_OAUTH_H_ \ No newline at end of file
diff --git a/protocols/Slack/src/http_request.h b/protocols/Slack/src/http_request.h
index 03f5894c6f..9c0d52816f 100644
--- a/protocols/Slack/src/http_request.h
+++ b/protocols/Slack/src/http_request.h
@@ -332,6 +332,7 @@ public:
{
cbSize = sizeof(NETLIBHTTPREQUEST);
requestType = method;
+ flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMPHEADERS;
}
~HttpRequest()
diff --git a/protocols/Slack/src/slack_accounts.cpp b/protocols/Slack/src/slack_accounts.cpp
index 50640ae37a..47ebdecdc6 100644
--- a/protocols/Slack/src/slack_accounts.cpp
+++ b/protocols/Slack/src/slack_accounts.cpp
@@ -37,6 +37,14 @@ int CSlackProto::OnAccountLoaded(WPARAM, LPARAM)
return 0;
}
+int CSlackProto::OnAccountDeleted(WPARAM, LPARAM)
+{
+ ptrA token(getStringA("TokenSecret"));
+ SendRequest(new AuthRevokeRequest(token));
+
+ return 0;
+};
+
INT_PTR CSlackProto::OnAccountManagerInit(WPARAM, LPARAM)
{
return NULL;// (INT_PTR)(CSlackOptionsMain::CreateAccountManagerPage(this, (HWND)lParam))->GetHwnd();
diff --git a/protocols/Slack/src/slack_connection.cpp b/protocols/Slack/src/slack_connection.cpp
index 0cbb73992a..17f8eb5adf 100644
--- a/protocols/Slack/src/slack_connection.cpp
+++ b/protocols/Slack/src/slack_connection.cpp
@@ -22,16 +22,7 @@ void CSlackProto::Login()
return;
}
- HttpRequest *request = new HttpRequest(HttpMethod::HttpPost, SLACK_API_URL "/oauth.access");
- request->Headers
- << CHAR_VALUE("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
- request->Content
- << CHAR_VALUE("client_id", SLACK_CLIENT_ID)
- << CHAR_VALUE("client_secret", SLACK_CLIENT_SECRET)
- << ENCODED_VALUE("code", oauth.GetAuthCode())
- << ENCODED_VALUE("redirect_uri", SLACK_REDIRECT_URL);
-
- PushRequest(request, &CSlackProto::OnAuthorize);
+ PushRequest(new OAuhtAccessRequest(oauth.GetAuthCode()), &CSlackProto::OnAuthorize);
}
void CSlackProto::OnAuthorize(JSONNode &root, void*)
diff --git a/protocols/Slack/src/slack_contacts.cpp b/protocols/Slack/src/slack_contacts.cpp
index 5054e6003c..82798cb9ca 100644
--- a/protocols/Slack/src/slack_contacts.cpp
+++ b/protocols/Slack/src/slack_contacts.cpp
@@ -127,6 +127,9 @@ void CSlackProto::OnGotUserList(JSONNode &root, void*)
if (!status.IsEmpty())
setWString(hContact, "StatusMsg", status);
+ json_string presence = user["presence"].as_string();
+ SetContactStatus(hContact, SlackToMirandaStatus(presence.c_str()));
+
JSONNode profile = root["profile"].as_node();
OnGotUserProfile(hContact, profile);
}
diff --git a/protocols/Slack/src/slack_proto.cpp b/protocols/Slack/src/slack_proto.cpp
index e3731794d4..318e1366bc 100644
--- a/protocols/Slack/src/slack_proto.cpp
+++ b/protocols/Slack/src/slack_proto.cpp
@@ -23,9 +23,9 @@ DWORD_PTR CSlackProto::GetCaps(int type, MCONTACT)
case PFLAGNUM_1:
return PF1_IMSEND;
case PFLAGNUM_2:
- return PF2_ONLINE;
+ return PF2_ONLINE | PF2_SHORTAWAY;
case PFLAGNUM_3:
- return PF2_ONLINE;
+ return PF2_ONLINE | PF2_SHORTAWAY;
case PFLAG_UNIQUEIDTEXT:
return (INT_PTR)"User Id";
case PFLAG_UNIQUEIDSETTING:
@@ -154,6 +154,9 @@ int CSlackProto::OnEvent(PROTOEVENTTYPE iEventType, WPARAM wParam, LPARAM lParam
case EV_PROTO_ONLOAD:
return OnAccountLoaded(wParam, lParam);
+ case EV_PROTO_ONERASE:
+ return OnAccountDeleted(wParam, lParam);
+
case EV_PROTO_ONCONTACTDELETED:
return OnContactDeleted(wParam, lParam);
}
diff --git a/protocols/Slack/src/slack_proto.h b/protocols/Slack/src/slack_proto.h
index 25b667eea2..c7dd739f32 100644
--- a/protocols/Slack/src/slack_proto.h
+++ b/protocols/Slack/src/slack_proto.h
@@ -89,6 +89,7 @@ private:
static CSlackProto* GetContactAccount(MCONTACT hContact);
int __cdecl OnAccountLoaded(WPARAM, LPARAM);
+ int __cdecl OnAccountDeleted(WPARAM, LPARAM);
INT_PTR __cdecl OnAccountManagerInit(WPARAM, LPARAM);
@@ -143,6 +144,8 @@ private:
int __cdecl OnPreCreateMessage(WPARAM wParam, LPARAM lParam);
// utils
+ static int SlackToMirandaStatus(const char *presence);
+
static void ShowNotification(const TCHAR *message, int flags = 0, MCONTACT hContact = NULL);
static void ShowNotification(const TCHAR *caption, const TCHAR *message, int flags = 0, MCONTACT hContact = NULL);
diff --git a/protocols/Slack/src/slack_utils.cpp b/protocols/Slack/src/slack_utils.cpp
index 40a6680788..bcfe5916c2 100644
--- a/protocols/Slack/src/slack_utils.cpp
+++ b/protocols/Slack/src/slack_utils.cpp
@@ -1,5 +1,15 @@
#include "stdafx.h"
+int CSlackProto::SlackToMirandaStatus(const char *presence)
+{
+ if (!mir_strcmpi(presence, "active"))
+ return ID_STATUS_ONLINE;
+ else if (!mir_strcmpi(presence, "away"))
+ return ID_STATUS_AWAY;
+ else
+ return ID_STATUS_OFFLINE;
+}
+
void CSlackProto::ShowNotification(const TCHAR *caption, const TCHAR *message, int flags, MCONTACT hContact)
{
if (Miranda_IsTerminated())
diff --git a/protocols/Slack/src/stdafx.h b/protocols/Slack/src/stdafx.h
index 8a24cb29f7..82ee0ac61d 100644
--- a/protocols/Slack/src/stdafx.h
+++ b/protocols/Slack/src/stdafx.h
@@ -51,6 +51,7 @@ struct CSlackProto;
#include "slack_options.h"
#include "slack_proto.h"
+#include "api\api_oauth.h"
#include "api\api_users.h"
#include "api\api_chat.h"
#include "api\api_im.h"