blob: 8adfb0436545bd6ef5c69440f3b2fc32bc2d3f27 (
plain) (
blame)
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
;;; slack-file-info-buffer.el --- -*- lexical-binding: t; -*-
;; Copyright (C) 2017
;; 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 'eieio)
(require 'slack-util)
(require 'slack-buffer)
(require 'slack-message)
(define-derived-mode slack-file-info-buffer-mode slack-buffer-mode "Slack File Info"
(lui-set-prompt (format "Add Comment %s" lui-prompt-string))
(add-hook 'lui-post-output-hook 'slack-display-image t t)
(setq lui-input-function 'slack-file-comment--add))
(defclass slack-file-info-buffer (slack-buffer)
((file :initarg :file :type slack-file)))
(defmethod slack-buffer-name :static ((class slack-file-info-buffer) file team)
(format "*Slack - %s File: %s"
(oref team name)
(or (oref file title)
(oref file name)
(oref file id))))
(defun slack-create-file-info-buffer (team file)
(slack-if-let* ((buffer (slack-buffer-find 'slack-file-info-buffer
file
team)))
(progn
(oset buffer file file)
buffer)
(slack-file-info-buffer :team team :file file)))
(defmethod slack-buffer-init-buffer :after ((this slack-file-info-buffer))
(with-slots (file team) this
(let ((class (eieio-object-class-name this)))
(slack-buffer-push-new-3 class file team))))
(defmethod slack-buffer-name ((this slack-file-info-buffer))
(with-slots (file team) this
(slack-buffer-name (eieio-object-class-name this)
file
team)))
(defmethod slack-buffer-buffer ((this slack-file-info-buffer))
(slack-if-let* ((buf (get-buffer (slack-buffer-name this))))
(progn
(with-current-buffer buf
(slack-buffer-insert this))
buf)
(slack-buffer-init-buffer this)))
(defmethod slack-buffer-init-buffer ((this slack-file-info-buffer))
(let ((buf (call-next-method)))
(with-current-buffer buf
(slack-file-info-buffer-mode)
(slack-buffer-set-current-buffer this)
(slack-buffer-insert this))
buf))
(defmethod slack-buffer-file-to-string ((this slack-file-info-buffer))
(with-slots (file team) this
(let* ((header (slack-message-header-to-string file team))
(body (slack-message-body-to-string file team))
(thumb (or (and (slack-file-image-p file)
(slack-message-large-image-to-string file))
(slack-message-image-to-string file)))
(reactions (slack-message-reaction-to-string file team))
(comments-count
(slack-file-comments-count-to-string file)))
(propertize (slack-format-message header
body
thumb
reactions
comments-count)
'file-id (oref file id)))))
(defmethod slack-buffer-insert ((this slack-file-info-buffer))
(delete-region (point-min) lui-output-marker)
(with-slots (file team) this
(let ((lui-time-stamp-position nil))
(lui-insert "" t))
(lui-insert-with-text-properties
(slack-buffer-file-to-string this)
;; saved-text-properties not working??
'file-id (oref file id)
'ts (slack-ts file))
(lui-insert "" t)
(let ((comments (slack-file-comments-to-string file team)))
(mapc #'(lambda (comment)
(lui-insert-with-text-properties
(slack-message-to-string comment team)
'file-comment-id (oref comment id)
'ts (slack-ts comment))
(lui-insert "" t))
(oref file comments)))))
(defmethod slack-buffer-send-message ((this slack-file-info-buffer) message)
(with-slots (file team) this
(slack-file-comment-add-request (oref file id) message team)))
(defmethod slack-buffer-display-message-compose-buffer ((this slack-file-info-buffer))
(with-slots (file team) this
(let ((buffer (slack-create-file-comment-compose-buffer file team)))
(slack-buffer-display buffer))))
(defmethod slack-buffer-add-reaction-to-message
((this slack-file-info-buffer) reaction _ts)
(with-slots (file team) this
(slack-file-add-reaction (oref file id) reaction team)))
(defmethod slack-buffer-add-reaction-to-file-comment
((this slack-file-info-buffer) reaction id)
(with-slots (team) this
(slack-file-comment-add-reaction id reaction team)))
(defmethod slack-buffer-remove-reaction-from-message
((this slack-file-info-buffer) _ts &optional file-comment-id)
(with-slots (file team) this
(if file-comment-id
(slack-file-comment-remove-reaction file-comment-id
(oref file id)
team)
(slack-file-remove-reaction (oref file id) team))))
(defmethod slack-buffer-add-star ((this slack-file-info-buffer) _ts)
(let ((url slack-message-stars-add-url)
(file-comment-id (slack-get-file-comment-id)))
(with-slots (file team) this
(if file-comment-id
(slack-with-file-comment file-comment-id file
(slack-message-star-api-request
url
(list (slack-message-star-api-params file-comment))
team))
(slack-message-star-api-request url
(list (slack-message-star-api-params file))
team)))))
(defmethod slack-buffer-remove-star ((this slack-file-info-buffer) _ts)
(let ((url slack-message-stars-remove-url)
(file-comment-id (slack-get-file-comment-id)))
(with-slots (file team) this
(if file-comment-id
(slack-with-file-comment file-comment-id file
(slack-message-star-api-request url
(list (slack-message-star-api-params
file-comment))
team))
(slack-message-star-api-request url
(list (slack-message-star-api-params
file))
team)))))
(defmethod slack-buffer-display-edit-message-buffer ((this slack-file-info-buffer) _ts)
(with-slots (file team) this
(slack-if-let* ((file-comment-id (slack-get-file-comment-id)))
(let ((buf (slack-create-edit-file-comment-buffer
file
(slack-get-file-comment-id)
team)))
(slack-buffer-display buf)))))
(defmethod slack-buffer-delete-message ((this slack-file-info-buffer) _ts)
(with-slots (file team) this
(slack-if-let* ((file-comment-id (slack-get-file-comment-id)))
(if (yes-or-no-p "Are you sure want to delete this comment?")
(slack-with-file-comment file-comment-id file
(slack-file-comment-delete-request (oref file id)
file-comment-id
team))
(message "Canceled")))))
(defmethod slack-buffer--replace ((this slack-file-info-buffer) _ts)
(slack-if-let* ((buffer (get-buffer (slack-buffer-name this))))
(with-current-buffer buffer
(let ((inhibit-read-only t))
(slack-buffer-insert this)))))
(defmethod slack-buffer-update ((this slack-file-info-buffer)
&optional file-comment-id)
(with-slots (file team) this
(let ((buffer (get-buffer (slack-buffer-name this))))
(with-current-buffer buffer
(if file-comment-id
(let* ((comment (slack-find-file-comment file file-comment-id)))
(cl-labels
((pred () (let ((id (get-text-property (point) 'file-comment-id)))
(equal id file-comment-id))))
(if comment
(lui-replace (slack-message-to-string comment team) #'pred)
(lui-delete #'pred))))
(lui-replace
(slack-buffer-file-to-string this)
#'(lambda () (let ((id (get-text-property (point) 'file-id)))
(equal id (oref file id))))))))))
(defmethod slack-buffer-insert-file-comment ((this slack-file-info-buffer) comment-id)
(with-slots (file team) this
(let ((buffer (get-buffer (slack-buffer-name this)))
(comment (slack-find-file-comment file comment-id)))
(with-current-buffer buffer
(lui-insert-with-text-properties
(slack-message-to-string comment team)
'file-comment-id (oref comment id)
'ts (slack-ts comment))))))
(provide 'slack-file-info-buffer)
;;; slack-file-info-buffer.el ends here
|