forked from pinaraf/Slacken
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslackclient.h
112 lines (89 loc) · 2.27 KB
/
slackclient.h
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
#ifndef SLACKCLIENT_H
#define SLACKCLIENT_H
#include <QObject>
#include <QtNetworkAuth>
#include <QColor>
#include <QMap>
#include <vector>
class QWebSocket;
class SlackClient;
class SlackChannel
{
Q_GADGET
public:
SlackChannel(SlackClient *client, const QJsonValueRef &source);
QDateTime created;
QString id;
QString name;
QString topic;
bool is_group;
bool is_im;
bool is_channel;
bool is_mpim;
bool is_general;
bool is_archived;
bool is_member;
};
class SlackUser
{
Q_GADGET
public:
SlackUser(const QJsonValueRef &source);
QString id;
QString name;
bool is_deleted;
};
class SlackMessageAttachment
{
Q_GADGET
public:
SlackMessageAttachment(const QJsonObject &source);
QColor color;
QString text;
QString fallback;
QString title;
};
class SlackMessage
{
Q_GADGET
public:
SlackMessage(const QJsonObject &source);
SlackMessage(const QString &user, const QString &msg);
QString type;
QString user;
QString username; // Seriously slack ?
QString text;
QDateTime when;
std::vector<SlackMessageAttachment> attachments;
};
class SlackClient : public QObject
{
Q_OBJECT
public:
explicit SlackClient(QObject *parent = nullptr);
void fire();
const std::map<QString, SlackChannel> &channels() const;
const std::map<QString, SlackUser> &users() const;
const SlackUser &user(const QString &id) const;
QString userId(const QString &userName) const;
void requestHistory(const QString &id);
void sendMessage(const QString &channel, const QString &msg);
QString currentToken() const;
signals:
void authenticated();
void channelAdded(const SlackChannel &channel);
void userAdded(const SlackUser &user);
void channelHistory(const QList<SlackMessage> &history);
void newMessage(const QString &channel, const SlackMessage &msg);
void desktopNotification(const QString &title, const QString &subtitle, const QString &message);
public slots:
void login(const QString &existingToken);
private:
QString selfId;
QWebSocket *chaussette;
int socketMessageId;
QOAuth2AuthorizationCodeFlow oauth2;
std::map<QString, SlackChannel> m_channels;
std::map<QString, SlackUser> m_users;
};
#endif // SLACKCLIENT_H