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
193
194
195
196
197
198
199
200
201
|
;;; helm-slack.el --- -*- lexical-binding: t; -*-
;; Copyright (C) 2018
;; Author: <yuya373@yuya373>
;; 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 <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
(require 'helm)
(require 'slack-team)
(require 'slack-room-info-buffer)
(require 'slack-conversations)
(require 'slack-user-profile-buffer)
(defvar helm-slack-actions
(helm-make-actions
"Display channel" #'helm-slack-display-room
"Archive channel" #'helm-slack-archive-room
"Invite user to channel" #'helm-slack-invite-to-room
"Kick user from channel" #'helm-slack-kick-from-room
"List user in channel" #'helm-slack-list-member-in-room
"Join channel" #'helm-slack-join-room
"Leave channel" #'helm-slack-leave-room
"Rename channel" #'helm-slack-rename-room
"Set purpose for channel" #'helm-slack-set-purpose-for-room
"Set topic of channel" #'helm-slack-set-topic-of-room
))
(defvar helm-slack-members-actions
(helm-make-actions "Display User" #'helm-slack-display-user))
(defvar helm-slack-channels-source (helm-build-sync-source "Channels (Slack)"
:persistent-action #'helm-slack-persistent-action
:action helm-slack-actions
:candidates #'helm-slack-build-channels-candidates))
(defvar helm-slack-groups-source (helm-build-sync-source "Private Channels (Slack)"
:persistent-action #'helm-slack-persistent-action
:action helm-slack-actions
:candidates #'helm-slack-build-groups-candidates))
(defvar helm-slack-ims-source (helm-build-sync-source "Direct Messages (Slack)"
:persistent-action #'helm-slack-persistent-action
:action helm-slack-actions
:candidates #'helm-slack-build-ims-candidates))
(defvar helm-slack-source (helm-build-sync-source "Slack"
:persistent-action #'helm-slack-persistent-action
:action helm-slack-actions
:candidates #'helm-slack-build-candidates))
(defcustom helm-slack-sources
'(helm-slack-source)
"Default helm sources.
pre defined sources are `helm-slack-channels-source', `helm-slack-groups-source', `helm-slack-ims-source', `helm-slack-source'"
:type 'list
:group 'slack)
(defun helm-slack-build-channels-candidates ()
(helm-slack-build--candidates #'(lambda (team) (oref team channels))))
(defun helm-slack-build-groups-candidates ()
(helm-slack-build--candidates #'(lambda (team) (oref team groups))))
(defun helm-slack-build-ims-candidates ()
(helm-slack-build--candidates #'(lambda (team) (oref team ims))))
(defun helm-slack-build-candidates ()
(helm-slack-build--candidates #'(lambda (team) (with-slots (channels groups ims) team
(append channels groups ims)))))
(defun helm-slack-build--candidates (rooms-selector)
(cl-loop for team in slack-teams
as rooms = (funcall rooms-selector team)
nconc (cl-labels
((filter (rooms) (cl-remove-if #'slack-room-hidden-p
rooms))
(collector (label room) (list label room team)))
(let ((slack-display-team-name
(< 1 (length slack-teams))))
(slack-room-names (append rooms nil) team
#'filter #'collector)))))
(defmacro helm-slack-bind-room-and-team (candidate &rest body)
(declare (indent 2) (debug t))
`(let ((room (car ,candidate))
(team (cadr ,candidate)))
,@body))
(defmacro helm-slack-bind-user-and-team (candidate &rest body)
(declare (indent 2) (debug t))
`(let ((user (car ,candidate))
(team (cadr ,candidate)))
,@body))
(defun helm-slack-persistent-action (candidate)
(helm-slack-bind-room-and-team candidate
(let* ((buffer (slack-create-room-info-buffer room team)))
(switch-to-buffer (slack-buffer-buffer buffer)))))
(defun helm-slack-display-room (candidate)
(helm-slack-bind-room-and-team candidate
(slack-room-display room team)))
(defun helm-slack-archive-room (candidate)
(helm-slack-bind-room-and-team candidate
(slack-conversations-archive room team)))
(defun helm-slack-invite-to-room (candidate)
(helm-slack-bind-room-and-team candidate
(slack-conversations-invite room team)))
(defun helm-slack-join-room (candidate)
(helm-slack-bind-room-and-team candidate
(slack-conversations-join room team)))
(defun helm-slack-leave-room (candidate)
(helm-slack-bind-room-and-team candidate
(slack-conversations-leave room team)))
(defun helm-slack-rename-room (candidate)
(helm-slack-bind-room-and-team candidate
(slack-conversations-rename room team)))
(defun helm-slack-set-purpose-for-room (candidate)
(helm-slack-bind-room-and-team candidate
(slack-conversations-set-purpose room team)))
(defun helm-slack-set-topic-of-room (candidate)
(helm-slack-bind-room-and-team candidate
(slack-conversations-set-topic room team)))
(defun helm-slack-kick-from-room (candidate)
(helm-slack-bind-room-and-team candidate
(slack-conversations-kick room team)))
(defun helm-slack-list-member-in-room (candidate)
(helm-slack-bind-room-and-team candidate
(helm-slack-members-in-room room team)))
(defun helm-slack-members-in-room (room team)
(let ((candidates nil)
(cursor nil))
(cl-labels
((inject-team (candidates)
(mapcar #'(lambda (candidate)
(list (car candidate)
(cdr candidate)
team))
candidates))
(on-members-success (members next-cursor)
(setq candidates (append candidates
members))
(setq cursor next-cursor)))
(while (or (null cursor)
(< 0 (length cursor)))
(slack-conversations-members room
team
cursor
#'on-members-success))
(helm
:prompt "Select Member : "
:sources (helm-build-sync-source "Members"
:candidates (inject-team candidates)
:action helm-slack-members-actions)))))
(defun helm-slack-display-user (candidate)
(helm-slack-bind-user-and-team candidate
(let* ((user-id (plist-get user :id))
(buffer (slack-create-user-profile-buffer team
user-id)))
(slack-buffer-display buffer))))
(defun helm-slack ()
"Helm Slack"
(interactive)
(helm
:prompt "Select Channel : "
:sources helm-slack-sources))
(provide 'helm-slack)
;;; helm-slack.el ends here
|