Skip to content

Commit

Permalink
add slack-message-update.el
Browse files Browse the repository at this point in the history
  • Loading branch information
yuya373 committed Feb 10, 2017
1 parent a286f22 commit eccf643
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 11 deletions.
80 changes: 80 additions & 0 deletions slack-message-update.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
;;; slack-message-update.el --- impl for message update -*- lexical-binding: t; -*-

;; Copyright (C) 2017 南優也

;; Author: 南優也 <[email protected]>
;; 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-message)

(defclass _slack-message-update ()
((message :initarg :message)
(room :initarg :room)
(team :initarg :team)
(replace :initarg :replace :initform nil)
(notify :initarg :notify :initform nil)))

(defclass _slack-thread-message-update (_slack-message-update) ())

(defmethod slack-message-update--buffer ((this _slack-message-update))
(with-slots (room message team replace) this
(slack-buffer-update room message team :replace replace)))

(defmethod slack-message-update--buffer ((this _slack-thread-message-update))
(with-slots (room team replace message) this
(let* ((parent (slack-room-find-thread-parent room message))
(thread (and parent (slack-message-get-thread parent team))))
(when parent
(slack-buffer-update room parent team :replace t)
(when thread
(slack-thread-add-message thread message)
(slack-thread-update-buffer thread message room team :replace replace))))))

(defmethod slack-message-update--notify ((this _slack-message-update))
(with-slots (notify message room team) this
(and notify (slack-message-notify message room team))))

(defmethod slack-message-update--notify ((this _slack-thread-message-update))
(with-slots (message room team) this
(slack-message-notify message room team)))

(defmethod slack-message-update--room ((this _slack-message-update))
(with-slots (message room) this
(when room
(slack-room-push-message room message)
(slack-room-update-latest room message))))

(defmethod slack-message-update ((m slack-message) team &optional replace no-notify)
(let ((class (or (and (slack-message-thread-messagep m) '_slack-thread-message-update)
'_slack-message-update)))
(let ((update (make-instance class
:message m
:room (slack-room-find (oref m channel) team)
:team team
:replace replace
:notify (not no-notify))))
(slack-message-update--room update)
(slack-message-update--buffer update)
(slack-message-update--notify update))))

(provide 'slack-message-update)
;;; slack-message-update.el ends here
11 changes: 0 additions & 11 deletions slack-message.el
Original file line number Diff line number Diff line change
Expand Up @@ -279,17 +279,6 @@
;; )
)))))))

(defmethod slack-message-update ((m slack-message) team &optional replace no-notify)
(if (and (oref m thread-ts) (not (slack-message-thread-parentp m)))
(slack-message-update-thread m team replace)
(with-slots (channel) m
(let ((room (slack-room-find channel team)))
(when room
(slack-room-push-message room m)
(slack-room-update-latest room m)
(slack-buffer-update room m team :replace replace)
(unless no-notify
(slack-message-notify m room team)))))))


(defun slack-message-edited (payload team)
Expand Down
3 changes: 3 additions & 0 deletions slack-room.el
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@
(oref room messages)
:from-end t))

(defun slack-room-find-thread-parent (room thread-message)
(slack-room-find-message room (oref thread-message thread-ts)))

(defun slack-room-find-thread (room ts)
(let ((message (slack-room-find-message room ts)))
(when message
Expand Down
3 changes: 3 additions & 0 deletions slack-thread.el
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@
(oref m thread-ts))))
(and thread-ts (string= (oref m ts) thread-ts))))

(defmethod slack-message-thread-messagep ((m slack-message))
(and (oref m thread-ts) (not (slack-message-thread-parentp m))))

(defun slack-thread-update-state (payload team)
(let* ((room (slack-room-find (plist-get payload :channel) team))
(state (plist-get payload :message))
Expand Down
1 change: 1 addition & 0 deletions slack.el
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
(require 'slack-search)
(require 'slack-reminder)
(require 'slack-thread)
(require 'slack-message-update)

(require 'slack-websocket)
(require 'slack-request)
Expand Down

0 comments on commit eccf643

Please sign in to comment.