blob: 8873fd77160e043d0d081cad6dfb2ecb62803395 (
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
|
;;; slack-thread-message-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-room-buffer)
(define-derived-mode slack-thread-message-buffer-mode
slack-buffer-mode
"Slack Thread Message"
(lui-set-prompt lui-prompt-string)
(setq lui-input-function 'slack-thread-message--send))
(defclass slack-thread-message-buffer (slack-room-buffer)
((thread-ts :initarg :thread-ts :type string)))
(defmethod slack-buffer-find :static ((class slack-thread-message-buffer) room ts team)
(slack-buffer-find-4 class room ts team))
(defun slack-create-thread-message-buffer (room team thread-ts)
(slack-if-let* ((buf (slack-buffer-find 'slack-thread-message-buffer
room thread-ts team)))
buf
(slack-thread-message-buffer :room room
:team team
:thread-ts thread-ts)))
(defmethod slack-buffer-name :static ((class slack-thread-message-buffer) room ts team)
(format "*Slack - %s : %s Thread - %s"
(oref team name)
(slack-room-name room)
ts))
(defmethod slack-buffer-name ((this slack-thread-message-buffer))
(with-slots (room thread-ts team) this
(slack-buffer-name 'slack-thread-message-buffer
room thread-ts team)))
(defmethod slack-buffer-init-buffer ((this slack-thread-message-buffer))
(let* ((buf (generate-new-buffer (slack-buffer-name this))))
(with-current-buffer buf
(slack-thread-message-buffer-mode)
(slack-buffer-set-current-buffer this)
(goto-char lui-input-marker)
(with-slots (room thread-ts team) this
(slack-if-let* ((message (slack-room-find-message room thread-ts)))
(progn
(slack-buffer-insert this message t)
(let ((lui-time-stamp-position nil))
(lui-insert (format "%s\n" (make-string lui-fill-column ?=)) t))
(let ((thread (slack-message-thread message room)))
(and thread
(cl-loop for m in (oref thread messages)
do (slack-buffer-insert this m))))))))
(with-slots (room thread-ts team) this
(slack-buffer-push-new-4 (eieio-object-class-name this)
room
thread-ts
team))
buf))
(defmethod slack-buffer-display-message-compose-buffer
((this slack-thread-message-buffer))
(with-slots (room team thread-ts) this
(let ((buf (slack-create-thread-message-compose-buffer
room thread-ts team)))
(slack-buffer-display buf))))
(defmethod slack-buffer-send-message ((this slack-thread-message-buffer) message)
(with-slots (room team thread-ts) this
(slack-thread-send-message room team message thread-ts)))
(defmethod slack-buffer-add-reaction-to-message
((this slack-thread-message-buffer) reaction ts)
(with-slots (room team) this
(slack-message-reaction-add reaction ts room team)))
(defmethod slack-buffer-remove-reaction-from-message
((this slack-thread-message-buffer) ts &optional _file-comment-id)
(with-slots (room team) this
(let* ((message (slack-room-find-message room ts))
(reaction (slack-message-reaction-select
(slack-message-reactions message))))
(slack-message-reaction-remove reaction ts room team))))
(defmethod slack-buffer-add-star ((this slack-thread-message-buffer) ts)
(with-slots (room team) this
(slack-if-let* ((message (slack-room-find-message room ts)))
(slack-message-star-api-request slack-message-stars-add-url
(list (cons "channel" (oref room id))
(slack-message-star-api-params message))
team))))
(defmethod slack-buffer-remove-star ((this slack-thread-message-buffer) ts)
(with-slots (room team) this
(slack-if-let* ((message (slack-room-find-message room ts)))
(slack-message-star-api-request slack-message-stars-remove-url
(list (cons "channel" (oref room id))
(slack-message-star-api-params message))
team))))
(cl-defmethod slack-buffer-update ((this slack-thread-message-buffer) message &key replace)
(if replace (slack-buffer-replace this message)
(with-current-buffer (slack-buffer-buffer this)
(slack-buffer-insert this message))))
(defmethod slack-buffer-display-edit-message-buffer ((this slack-thread-message-buffer) ts)
(with-slots (room team) this
(let ((buf (slack-create-edit-message-buffer room team ts)))
(slack-buffer-display buf))))
(defmethod slack-buffer-share-message ((this slack-thread-message-buffer) ts)
(with-slots (room team) this
(let ((buf (slack-create-message-share-buffer room team ts)))
(slack-buffer-display buf))))
(provide 'slack-thread-message-buffer)
;;; slack-thread-message-buffer.el ends here
|