Change: (ement-room-send-reaction) Take key as argument

This commit is contained in:
Adam Porter 2021-08-10 03:17:30 -05:00
parent 3a615a6182
commit 11a73eb60d

View file

@ -952,13 +952,14 @@ The message must be one sent by the local user."
(ement-room-read-string prompt nil nil nil 'inherit-input-method)))) (ement-room-read-string prompt nil nil nil 'inherit-input-method))))
(ement-room-send-message room session :body body :replying-to-event event)))) (ement-room-send-message room session :body body :replying-to-event event))))
(defun ement-room-send-reaction (position) (defun ement-room-send-reaction (key position)
"Send reaction to event at POSITION. "Send reaction of KEY to event at POSITION.
Interactively, send reaction to event at point." Interactively, send reaction to event at point. KEY should be a
reaction string, e.g. \"👍\"."
;; SPEC: MSC2677 <https://github.com/matrix-org/matrix-doc/pull/2677> ;; SPEC: MSC2677 <https://github.com/matrix-org/matrix-doc/pull/2677>
(interactive (list (point))) (interactive
;; HACK: We could simplify this by storing the key in a text property... (cl-labels
(cl-labels ((face-at-point-p ((face-at-point-p
(face) (let ((face-at-point (get-text-property (point) 'face))) (face) (let ((face-at-point (get-text-property (point) 'face)))
(or (eq face face-at-point) (or (eq face face-at-point)
(and (listp face-at-point) (and (listp face-at-point)
@ -978,13 +979,15 @@ Interactively, send reaction to event at point."
;; Point is in a reaction button but after the key. ;; Point is in a reaction button but after the key.
(buffer-substring-while (button-start (button-at pos)) (buffer-substring-while (button-start (button-at pos))
(apply-partially #'face-at-point-p 'ement-room-reactions-key)))))) (apply-partially #'face-at-point-p 'ement-room-reactions-key))))))
(ement-room-with-highlighted-event-at (point) (list (or (key-at (point))
(char-to-string (read-char-by-name "Reaction (prepend \"*\" for substring search): ")))
(point))))
;; HACK: We could simplify this by storing the key in a text property...
(ement-room-with-highlighted-event-at position
(pcase-let* ((event (or (ewoc-data (ewoc-locate ement-ewoc position)) (pcase-let* ((event (or (ewoc-data (ewoc-locate ement-ewoc position))
(user-error "No event at point"))) (user-error "No event at point")))
;; NOTE: Sadly, `face-at-point' doesn't work here because, e.g. if ;; NOTE: Sadly, `face-at-point' doesn't work here because, e.g. if
;; hl-line-mode is enabled, it only returns the hl-line face. ;; hl-line-mode is enabled, it only returns the hl-line face.
(key (or (key-at position)
(char-to-string (read-char-by-name "Reaction (prepend \"*\" for substring search): "))))
((cl-struct ement-event (id event-id)) event) ((cl-struct ement-event (id event-id)) event)
((cl-struct ement-room (id room-id)) ement-room) ((cl-struct ement-room (id room-id)) ement-room)
(endpoint (format "rooms/%s/send/%s/%s" (url-hexify-string room-id) (endpoint (format "rooms/%s/send/%s/%s" (url-hexify-string room-id)
@ -995,12 +998,14 @@ Interactively, send reaction to event at point."
"key" key)))) "key" key))))
(ement-api ement-session endpoint :method 'put :data (json-encode content) (ement-api ement-session endpoint :method 'put :data (json-encode content)
:then (apply-partially #'ement-room-send-event-callback :room ement-room :session ement-session :then (apply-partially #'ement-room-send-event-callback :room ement-room :session ement-session
:content content :data)))))) :content content :data)))))
(defun ement-room-reaction-button-action (button) (defun ement-room-reaction-button-action (button)
"Push reaction BUTTON at point." "Push reaction BUTTON at point."
;; TODO: Toggle reactions off with redactions (not in spec yet, but Element does it). ;; TODO: Toggle reactions off with redactions (not in spec yet, but Element does it).
(ement-room-send-reaction (button-start button))) (save-excursion
(goto-char (button-start button))
(call-interactively #'ement-room-send-reaction)))
;;;; Functions ;;;; Functions