Skip to content

Commit

Permalink
Fix: (ement-notify--log-to-buffer) Select log buffer's window
Browse files Browse the repository at this point in the history
Should work around EWOC bug similarly to how we do it elsewhere.

Fixes #191.  Thanks to Phil Sainty (@phil-s).
  • Loading branch information
alphapapa committed Aug 14, 2023
1 parent 1e348a7 commit 565b999
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
1 change: 1 addition & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ Note that, while ~matrix-client~ remains usable, and probably will for some time
+ Clean up SSO server process after two minutes in case SSO login fails.
+ Don't stop syncing if an error is signaled while sending a notification.
+ Command ~ement-room-list-next-unread~ could enter an infinite loop. (Thanks to [[https:/vizs][Visuwesh]] and ~@mrtnmrtn:matrix.org~.)
+ Events in notifications buffer could appear out-of-order. ([[https:/alphapapa/ement.el/issues/191][#191]]. Thanks to [[https:/phil-s][Phil Sainty]].)

** 0.10

Expand Down
64 changes: 34 additions & 30 deletions ement-notify.el
Original file line number Diff line number Diff line change
Expand Up @@ -281,36 +281,40 @@ If ROOM has no existing buffer, do nothing."
;; just to be safe...
(when (equal "m.room.message" (ement-event-type event))
(with-current-buffer (ement-notify--log-buffer buffer-name)
(let* ((ement-session session)
(ement-room room)
(ement-room-sender-in-left-margin nil)
(ement-room-message-format-spec "%o%O »%W %S> %B%R%t")
(new-node (ement-room--insert-event event))
(inhibit-read-only t)
start end)
(ewoc-goto-node ement-ewoc new-node)
(setf start (point))
(if-let (next-node (ewoc-next ement-ewoc new-node))
(ewoc-goto-node ement-ewoc next-node)
(goto-char (point-max)))
(setf end (- (point) 2))
(add-text-properties start end
(list 'button '(t)
'category 'default-button
'action #'ement-notify-button-action
'session session
'room room
'event event))
;; Remove button face property.
(alter-text-property start end 'face
(lambda (face)
(pcase face
('button nil)
((pred listp) (remq 'button face))
(_ face))))
(when ement-notify-prism-background
(add-face-text-property start end (list :background (ement-notify--room-background-color room)
:extend t))))))))
(save-window-excursion
(when-let ((buffer-window (get-buffer-window (current-buffer))))
;; Select the buffer's window to avoid EWOC bug. (See #191.)
(select-window buffer-window))
(let* ((ement-session session)
(ement-room room)
(ement-room-sender-in-left-margin nil)
(ement-room-message-format-spec "%o%O »%W %S> %B%R%t")
(new-node (ement-room--insert-event event))
(inhibit-read-only t)
start end)
(ewoc-goto-node ement-ewoc new-node)
(setf start (point))
(if-let (next-node (ewoc-next ement-ewoc new-node))
(ewoc-goto-node ement-ewoc next-node)
(goto-char (point-max)))
(setf end (- (point) 2))
(add-text-properties start end
(list 'button '(t)
'category 'default-button
'action #'ement-notify-button-action
'session session
'room room
'event event))
;; Remove button face property.
(alter-text-property start end 'face
(lambda (face)
(pcase face
('button nil)
((pred listp) (remq 'button face))
(_ face))))
(when ement-notify-prism-background
(add-face-text-property start end (list :background (ement-notify--room-background-color room)
:extend t)))))))))

(defun ement-notify--log-buffer (name)
"Return an Ement notifications buffer named NAME."
Expand Down

0 comments on commit 565b999

Please sign in to comment.