blob: faeba0cdcdd730ed13bf6cb21029b258fc30f88f (
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
|
;;; slack-file-comment.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 'slack-util)
(require 'slack-message)
(require 'slack-file)
(define-derived-mode slack-edit-file-comment-mode
fundamental-mode
"Slack Edit File Comment"
""
(slack-buffer-enable-emojify))
(defvar slack-edit-file-comment-mode-map
(let ((keymap (make-sparse-keymap)))
(define-key keymap (kbd "C-c C-c") #'slack-file-comment-edit-commit)
keymap))
(defclass slack-file-comment (slack-user-message)
((id :initarg :id)
(file-id :initarg :file_id :type string)
(created :initarg :created)
(timestamp :initarg :timestamp)
(user :initarg :user)
(is-intro :initarg :is_intro)
(comment :initarg :comment)
(channel :initarg :channel)
(reactions :initarg :reactions type list)
(is-starred :initarg :is_starred :type boolean :initform nil)))
(defclass slack-file-comment-message (slack-file-message)
((comment :initarg :comment :initform nil)))
(defclass slack-file-mention-message (slack-file-message)
((user :initarg :user :initform nil)))
(defmethod slack-reaction-delete ((this slack-file-comment) reaction)
(with-slots (reactions) this
(setq reactions
(slack-reaction--delete reactions reaction))))
(defmethod slack-reaction-push ((this slack-file-comment) reaction)
(push reaction (oref this reactions)))
(defmethod slack-reaction-find ((this slack-file-comment) reaction)
(slack-reaction--find (oref this reactions) reaction))
(defmethod slack-message-reactions ((this slack-file-comment))
(oref this reactions))
(defmethod slack-message-reaction-to-string ((m slack-file-comment) team)
(let ((reactions (oref m reactions)))
(when reactions
(slack-format-reactions reactions team))))
(defmethod slack-equalp ((c slack-file-comment) other)
(string= (oref c id) (oref other id)))
(defmethod slack-merge ((old slack-file-comment) new)
(slack-merge-list (oref old reactions) (oref new reactions))
(oset old comment (oref new comment)))
(defmethod slack-message-body ((comment slack-file-comment) team)
(slack-message-unescape-string (oref comment comment) team))
(defmethod slack-message-to-string ((comment slack-file-comment) team)
(let ((header (slack-message-header-to-string comment team))
(body (slack-message-body-to-string comment team))
(reactions (slack-message-reaction-to-string comment team)))
(propertize (slack-format-message header body reactions)
'file-comment-id (oref comment id))))
(defmethod slack-file-id ((file-comment slack-file-comment))
(oref file-comment file-id))
(defmethod slack-message-star-added ((this slack-file-comment))
(oset this is-starred t))
(defmethod slack-message-star-removed ((this slack-file-comment))
(oset this is-starred nil))
(defmethod slack-message-star-api-params ((this slack-file-comment))
(cons "file_comment" (oref this id)))
(defun slack-file-comment-edit-commit ()
(interactive)
(slack-if-let* ((buf slack-current-buffer)
(message (buffer-substring-no-properties (point-min) (point-max))))
(slack-buffer-send-message buf message)))
(defun slack-file-comment-process-star-api (url team)
(slack-if-let* ((file-id slack-current-file-id)
(file-comment-id (slack-get-file-comment-id)))
(slack-with-file file-id team
(slack-with-file-comment file-comment-id file
(slack-message-star-api-request url
(list (slack-message-star-api-params file-comment))
team)))))
(defmethod slack-message-set-file-comment ((m slack-file-comment-message) payload)
(let* ((file-id (plist-get (plist-get payload :file) :id))
(comment (plist-get payload :comment))
(file-comment (slack-file-comment-create comment file-id)))
(oset m comment file-comment)
m))
(defmethod slack-message-sender-name ((m slack-file-comment-message) team)
(slack-user-name (oref (oref m comment) user) team))
(defmethod slack-message-sender-id ((m slack-file-comment-message))
(oref (oref m comment) user))
(defmethod slack-message-star-added ((m slack-file-comment-message))
(slack-message-star-added (oref m comment)))
(defmethod slack-message-star-removed ((m slack-file-comment-message))
(slack-message-star-removed (oref m comment)))
(defmethod slack-message-star-api-params ((m slack-file-comment-message))
(slack-message-star-api-params (oref m comment)))
(defmethod slack-reaction-delete ((this slack-file-comment-message) reaction)
(slack-reaction-delete (oref this comment) reaction))
(defmethod slack-reaction-push ((this slack-file-comment-message) reaction)
(slack-reaction-push (oref this comment) reaction))
(defmethod slack-reaction-find ((this slack-file-comment-message) reaction)
(slack-reaction-find (oref this comment) reaction))
(defmethod slack-message-reactions ((this slack-file-comment-message))
(slack-message-reactions (oref this comment)))
(defmethod slack-message-get-param-for-reaction ((m slack-file-comment-message))
(cons "file_comment" (oref (oref m comment) id)))
(defmethod slack-file-id ((m slack-file-comment-message))
(slack-file-id (oref m comment)))
(defmethod slack-message-starred-p ((m slack-file-comment-message))
(oref (oref m comment) is-starred))
(defmethod slack-message-to-string ((this slack-file-comment-message) team)
(with-slots (permalink name id page) (oref this file)
(with-slots (comment) (oref this comment)
(let* ((face '(:underline t))
(text (format "commented on %s <%s|open in browser>\n%s"
(slack-file-link-info (oref (oref this file) id) name)
permalink
(format "“ %s" (slack-message-unescape-string comment
team))))
(header (slack-message-header-to-string this team))
(reactions (slack-message-reaction-to-string this team)))
(slack-format-message header text reactions)))))
(defmethod slack-message-get-user-id ((m slack-file-comment-message))
(oref (oref m comment) user))
(defmethod slack-message-edit-type ((_m slack-file-comment-message))
'edit-file-comment)
(defmethod slack-message-get-text ((m slack-file-comment-message))
(oref (oref m comment) comment))
(defmethod slack-message-changed--copy ((this slack-file-comment-message) other)
(when (slack-file-comment-message-p other)
(let ((changed (call-next-method)))
(with-slots ((old-comment comment) text) this
(let ((new-comment (oref other comment)))
(oset old-comment reactions (oref new-comment reactions))
(unless (string= (oref old-comment comment) (oref new-comment comment))
(oset old-comment comment (oref new-comment comment))
(setq changed t))))
changed)))
(defmethod slack-ts ((this slack-file-comment))
(number-to-string (oref this timestamp)))
(defmethod slack-message-update ((this slack-file-comment) file team)
(slack-if-let* ((buffer (slack-buffer-find 'slack-file-info-buffer
file
team)))
(progn
(oset buffer file file)
(slack-buffer-update buffer (oref this id)))))
(provide 'slack-file-comment)
;;; slack-file-comment.el ends here
|