[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ement c6ba0ec273 2/2: Add: (ement-interrupted-sync-hook
From: |
ELPA Syncer |
Subject: |
[elpa] externals/ement c6ba0ec273 2/2: Add: (ement-interrupted-sync-hook) |
Date: |
Tue, 11 Oct 2022 19:57:35 -0400 (EDT) |
branch: externals/ement
commit c6ba0ec2738c2b0b4efd92895068505512fb22f8
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>
Add: (ement-interrupted-sync-hook)
---
README.org | 1 +
ement.el | 31 ++++++++++++++++++++++++++++---
2 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/README.org b/README.org
index 87503537b3..aea0d91dda 100644
--- a/README.org
+++ b/README.org
@@ -296,6 +296,7 @@ Note that, while ~matrix-client~ remains usable, and
probably will for some time
+ Command ~ement-set-display-name~ sets the user's global displayname.
+ Command ~ement-room-set-display-name~ sets the user's displayname in a room
(which is also now displayed in the room's Transient menu).
+ Column ~Notifications~ in the ~ement-taxy-room-list~ buffer shows rooms'
notification state.
++ Option ~ement-interrupted-sync-hook~ allows customization of how sync
interruptions are handled. (Now, by default, a warning is displayed instead of
merely a message.)
*Changes*
+ When a room's read receipt is updated, the room's buffer is also marked as
unmodified. (In concert with the new option, this makes rooms' unread status
more intuitive.)
diff --git a/ement.el b/ement.el
index 76bdf794ba..bd3cdb7aad 100644
--- a/ement.el
+++ b/ement.el
@@ -174,6 +174,16 @@ function `display-buffer' and info node `(elisp) Buffer
Display
Action Functions'."
:type 'function)
+(defcustom ement-interrupted-sync-hook '(ement-interrupted-sync-warning)
+ "Functions to call when syncing of a session is interrupted.
+Only called when `ement-auto-sync' is non-nil. Functions are
+called with one argument, the session whose sync was interrupted.
+
+This hook allows the user to customize how sync interruptions are
+handled (e.g. how to be notified)."
+ :type 'hook
+ :options '(ement-interrupted-sync-message ement-interrupted-sync-warning))
+
;;;; Commands
;;;###autoload
@@ -309,6 +319,23 @@ Useful in, e.g. `ement-disconnect-hook', which see."
;;;; Functions
+(defun ement-interrupted-sync-warning (session)
+ "Display a warning that syncing of SESSION was interrupted."
+ (display-warning
+ 'ement
+ (format
+ (substitute-command-keys
+ "\\<ement-room-mode-map>Syncing of session <%s> was interrupted. Use
command `ement-room-sync' in a room buffer to retry.")
+ (ement-user-id (ement-session-user session)))
+ :error))
+
+(defun ement-interrupted-sync-message (session)
+ "Display a message that syncing of SESSION was interrupted."
+ (message
+ (substitute-command-keys
+ "\\<ement-room-mode-map>Syncing of session <%s> was interrupted. Use
command `ement-room-sync' in a room buffer to retry.")
+ (ement-user-id (ement-session-user session))))
+
(defun ement--run-idle-timer (&rest _ignore)
"Run idle timer that updates read receipts.
To be called from `ement-after-initial-sync-hook'. Timer is
@@ -427,9 +454,7 @@ a filter ID). When unspecified, the value of
(`(,(or 28 429 502) . ,_)
;; Timeout (28), "Too Many Requests"
(429), or "Bad Gateway" (502): sync again if enabled.
(if (not ement-auto-sync)
- (error (substitute-command-keys
- "\\<ement-room-mode-map>Ement
sync timed out (%s). Press \\[ement-room-sync] in a room buffer to sync again")
- (ement-user-id
(ement-session-user session)))
+ (run-hook-with-args
'ement-interrupted-sync-hook session)
(let ((reason (pcase-exhaustive (car
(plz-error-curl-error plz-error))
(28 "timed out")
((or 429 502)
"failed"))))