[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ement 1450e0329a 6/8: Add: (ement-forget-room) Add FORC
From: |
ELPA Syncer |
Subject: |
[elpa] externals/ement 1450e0329a 6/8: Add: (ement-forget-room) Add FORCE-P argument to also leave room |
Date: |
Fri, 23 Sep 2022 14:57:38 -0400 (EDT) |
branch: externals/ement
commit 1450e0329ad3971019c0411cbecb60b5802f8e07
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>
Add: (ement-forget-room) Add FORCE-P argument to also leave room
---
README.org | 1 +
ement-lib.el | 48 ++++++++++++++++++++++++++++++++++--------------
2 files changed, 35 insertions(+), 14 deletions(-)
diff --git a/README.org b/README.org
index 9d3a0b991e..36f9a137a3 100644
--- a/README.org
+++ b/README.org
@@ -287,6 +287,7 @@ Note that, while ~matrix-client~ remains usable, and
probably will for some time
+ Command ~ement-directory~ shows a server's room directory.
+ Command ~ement-directory-search~ searches a server's room directory.
+ Command ~ement-leave-room~ accepts a ~FORCE-P~ argument (interactively, with
prefix) to leave a room without prompting.
++ Command ~ement-forget-room~ accepts a ~FORCE-P~ argument (interactively,
with prefix) to also leave the room, and to forget it without prompting.
*Fixes*
+ Command ~ement-describe-room~ for rooms without topics.
diff --git a/ement-lib.el b/ement-lib.el
index 78b2f93f62..fea6c91ef5 100644
--- a/ement-lib.el
+++ b/ement-lib.el
@@ -100,21 +100,41 @@ the request."
(ement-api session endpoint :method 'post :data (json-encode data)
:then then))))
-(defun ement-forget-room (room session)
- "Forget ROOM on SESSION."
- (interactive (ement-complete-room))
- (pcase-let* (((cl-struct ement-room id display-name) room)
+(defun ement-forget-room (room session &optional force-p)
+ "Forget ROOM on SESSION.
+If FORCE-P (interactively, with prefix), prompt to leave the room
+when necessary, and forget the room without prompting."
+ (interactive (pcase-let ((`(,room ,session) (ement-complete-room)))
+ (list room session current-prefix-arg)))
+ (pcase-let* (((cl-struct ement-room id display-name status) room)
(endpoint (format "rooms/%s/forget" (url-hexify-string id))))
- (when (yes-or-no-p (format "Forget room \"%s\" (%s)? " display-name id))
- (ement-api session endpoint :method 'post :data ""
- :then (lambda (_data)
- ;; NOTE: The spec does not seem to indicate that the action of
forgetting
- ;; a room is synced to other clients, so it seems that we need
to remove
- ;; the room from the session here.
- (setf (ement-session-rooms session)
- (cl-remove room (ement-session-rooms session)))
- ;; TODO: Indicate forgotten in footer in room buffer.
- (message "Room \"%s\" (%s) forgotten." display-name id))))))
+ (pcase status
+ ('join (if (and force-p
+ (yes-or-no-p (format "Leave and forget room %s?
(WARNING: You will not be able to rejoin the room to access its content.) "
+ (ement--format-room room))))
+ (progn
+ ;; TODO: Use `letrec'.
+ (let* ((forget-fn-symbol (gensym (format "ement-forget-%s"
room)))
+ (forget-fn (lambda (_session)
+ (when (equal 'leave (ement-room-status
room))
+ (remove-hook
'ement-sync-callback-hook forget-fn-symbol)
+ ;; FIXME: Probably need to unintern
the symbol.
+ (ement-forget-room room session
'force)))))
+ (setf (symbol-function forget-fn-symbol) forget-fn)
+ (add-hook 'ement-sync-callback-hook forget-fn-symbol))
+ (ement-leave-room room session 'force))
+ (user-error "Room %s is joined (must be left before forgetting)"
+ (ement--format-room room))))
+ ('leave (when (or force-p (yes-or-no-p (format "Forget room \"%s\" (%s)?
" display-name id)))
+ (ement-api session endpoint :method 'post :data ""
+ :then (lambda (_data)
+ ;; NOTE: The spec does not seem to indicate that the
action of forgetting
+ ;; a room is synced to other clients, so it seems
that we need to remove
+ ;; the room from the session here.
+ (setf (ement-session-rooms session)
+ (cl-remove room (ement-session-rooms session)))
+ ;; TODO: Indicate forgotten in footer in room buffer.
+ (message "Room \"%s\" (%s) forgotten." display-name
id))))))))
(defun ement-ignore-user (user-id session &optional unignore-p)
"Ignore USER-ID on SESSION.
- [elpa] externals/ement updated (a48e55d655 -> 9344939e15), ELPA Syncer, 2022/09/23
- [elpa] externals/ement 63aab1943f 2/8: Fix: (ement-describe-room) Nil topics, ELPA Syncer, 2022/09/23
- [elpa] externals/ement 4188168568 4/8: Comment: Add TODO, ELPA Syncer, 2022/09/23
- [elpa] externals/ement 9344939e15 8/8: Tidy: (ement-room-leave) Move to ement-lib, ELPA Syncer, 2022/09/23
- [elpa] externals/ement 8bbdcc3aac 1/8: Fix: (ement-directory) Interactive arguments, ELPA Syncer, 2022/09/23
- [elpa] externals/ement 910ae0020e 3/8: Docs: Tidy, ELPA Syncer, 2022/09/23
- [elpa] externals/ement 96bc0f638e 5/8: Add: (ement-room-leave) FORCE-P argument, ELPA Syncer, 2022/09/23
- [elpa] externals/ement 467f7d9353 7/8: Change: (ement--format-room) Quote room name, ELPA Syncer, 2022/09/23
- [elpa] externals/ement 1450e0329a 6/8: Add: (ement-forget-room) Add FORCE-P argument to also leave room,
ELPA Syncer <=