forked from yuya373/emacs-slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slack-group.el
192 lines (163 loc) · 6.83 KB
/
slack-group.el
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
;;; slack-group.el --- slack private group interface -*- lexical-binding: t; -*-
;; Copyright (C) 2015 Yuya Minami
;; Author: Yuya Minami
;; Keywords:
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
(require 'eieio)
(require 'slack-room)
(require 'slack-util)
(require 'slack-buffer)
(defconst slack--group-open-url "https://slack.com/api/groups.open")
(defconst slack-group-history-url "https://slack.com/api/groups.history")
(defconst slack-group-buffer-name "*Slack - Private Group*")
(defconst slack-group-list-url "https://slack.com/api/groups.list")
(defconst slack-group-update-mark-url "https://slack.com/api/groups.mark")
(defconst slack-create-group-url "https://slack.com/api/groups.create")
(defconst slack-group-rename-url "https://slack.com/api/groups.rename")
(defconst slack-group-invite-url "https://slack.com/api/groups.invite")
(defconst slack-group-leave-url "https://slack.com/api/groups.leave")
(defconst slack-group-archive-url "https://slack.com/api/groups.archive")
(defconst slack-group-unarchive-url "https://slack.com/api/groups.unarchive")
(defvar slack-buffer-function)
(defclass slack-group (slack-room)
((name :initarg :name :type string)
(is-group :initarg :is_group)
(creator :initarg :creator)
(is-archived :initarg :is_archived)
(is-mpim :initarg :is_mpim)
(members :initarg :members :type list)
(topic :initarg :topic)
(unread-count-display :initarg :unread_count_display :initform 0 :type integer)
(purpose :initarg :purpose)))
(defun slack-group-names (team &optional filter)
(with-slots (groups) team
(slack-room-names groups filter)))
(defmethod slack-room-subscribedp ((room slack-group) team)
(with-slots (subscribed-channels) team
(let ((name (slack-room-name room)))
(and name
(memq (intern name) subscribed-channels)))))
(defmethod slack-room-buffer-name ((room slack-group))
(concat slack-group-buffer-name
" : "
(slack-room-name-with-team-name room)))
(defun slack-group-select ()
(interactive)
(let ((team (slack-team-select)))
(slack-room-select
(cl-loop for team in (list team)
for groups = (oref team groups)
nconc groups))))
(defun slack-group-list-update ()
(interactive)
(let ((team (slack-team-select)))
(cl-labels ((on-list-update
(&key data &allow-other-keys)
(slack-request-handle-error
(data "slack-group-list-update")
(with-slots (groups) team
(setq groups
(mapcar #'(lambda (g)
(slack-room-create g team 'slack-group))
(plist-get data :groups))))
(message "Slack Group List Updated"))))
(slack-room-list-update slack-group-list-url
#'on-list-update
:sync nil))))
(defmethod slack-room-update-mark-url ((_room slack-group))
slack-group-update-mark-url)
(defun slack-create-group ()
(interactive)
(let ((team (slack-team-select)))
(cl-labels
((on-create-group (&key data &allow-other-keys)
(slack-request-handle-error
(data "slack-create-group"))))
(slack-create-room slack-create-group-url
team
#'on-create-group))))
(defun slack-group-rename ()
(interactive)
(slack-room-rename slack-group-rename-url
#'slack-group-names))
(defun slack-group-invite ()
(interactive)
(slack-room-invite slack-group-invite-url
#'slack-group-names))
(defun slack-group-leave ()
(interactive)
(let* ((team (slack-team-select))
(group (slack-current-room-or-select
#'(lambda ()
(slack-group-names team)))))
(cl-labels
((on-group-leave
(&key data &allow-other-keys)
(slack-request-handle-error
(data "slack-group-leave")
(with-slots (groups) team
(setq groups
(cl-delete-if #'(lambda (g)
(slack-room-equal-p group g))
groups)))
(message "Left Group: %s"
(slack-room-name-with-team-name group)))))
(slack-room-request-with-id slack-group-leave-url
(oref group id)
team
#'on-group-leave))))
(defmethod slack-room-archived-p ((room slack-group))
(oref room is-archived))
(defun slack-group-archive ()
(interactive)
(let* ((team (slack-team-select))
(group (slack-current-room-or-select
#'(lambda ()
(slack-group-names
team
#'(lambda (groups)
(cl-remove-if #'slack-room-archived-p
groups)))))))
(cl-labels
((on-group-archive (&key data &allow-other-keys)
(slack-request-handle-error
(data "slack-group-archive"))))
(slack-room-request-with-id slack-group-archive-url
(oref group id)
team
#'on-group-archive))))
(defun slack-group-unarchive ()
(interactive)
(let* ((team (slack-team-select))
(group (slack-current-room-or-select
#'(lambda ()
(slack-group-names
team
#'(lambda (groups)
(cl-remove-if-not #'slack-room-archived-p
groups)))))))
(cl-labels
((on-group-unarchive (&key _data &allow-other-keys)
(data "slack-group-unarchive")))
(slack-room-request-with-id slack-group-unarchive-url
(oref group id)
team
#'on-group-unarchive))))
(defmethod slack-mpim-p ((room slack-group))
(oref room is-mpim))
(defmethod slack-room-history-url ((_room slack-group))
slack-group-history-url)
(provide 'slack-group)
;;; slack-group.el ends here