[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ement 7c12e04d76 2/4: Add: (ement-room-override-name)
From: |
ELPA Syncer |
Subject: |
[elpa] externals/ement 7c12e04d76 2/4: Add: (ement-room-override-name) |
Date: |
Sun, 5 Mar 2023 23:57:51 -0500 (EST) |
branch: externals/ement
commit 7c12e04d769bc8696bec89730729ac12083aeee3
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>
Add: (ement-room-override-name)
Closes #129.
---
README.org | 4 ++++
ement-lib.el | 8 +++++++-
ement-room.el | 34 ++++++++++++++++++++++++++++++++++
3 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/README.org b/README.org
index 467615bea3..08ac0f12cc 100644
--- a/README.org
+++ b/README.org
@@ -289,6 +289,10 @@ Note that, while ~matrix-client~ remains usable, and
probably will for some time
** 0.7-pre
+*Additions*
+
++ Command ~ement-room-override-name~ sets a local override for a room's
display name. (Especially helpful for 1:1 rooms and bridged rooms. See
[[https://github.com/matrix-org/matrix-spec-proposals/pull/3015#issuecomment-1451017296][MSC3015]].)
+
*Changes*
+ Improve display of room tombstones (displayed at top and bottom of buffer,
and new room ID is linked to join).
diff --git a/ement-lib.el b/ement-lib.el
index bb21fdf83f..7b77a317b8 100644
--- a/ement-lib.el
+++ b/ement-lib.el
@@ -1347,6 +1347,11 @@ Works in major-modes `ement-room-mode',
(heroes joined)
(format "%s, and %s others" (hero-names heroes)
(- joined (length heroes))))
+ (local-alias
+ () (when-let ((event (alist-get
"org.matrix.msc3015.m.room.name.override"
+ (ement-room-account-data room)
+ nil nil #'equal)))
+ (map-nested-elt event '(content name))))
(empty-room
(heroes joined) (cl-etypecase (length heroes)
((satisfies zerop) "Empty room")
@@ -1354,7 +1359,8 @@ Works in major-modes `ement-room-mode',
(hero-names heroes)))
(t (format "Empty room (was %s)"
(heroes-and-others heroes
joined))))))
- (or (latest-event "m.room.name" 'name)
+ (or (local-alias)
+ (latest-event "m.room.name" 'name)
(latest-event "m.room.canonical_alias" 'alias)
(heroes-name)
(member-events-name)
diff --git a/ement-room.el b/ement-room.el
index 895ae3bb57..6e56fa7d7e 100644
--- a/ement-room.el
+++ b/ement-room.el
@@ -157,6 +157,7 @@ Used to, e.g. call `ement-room-compose-org'.")
(define-key map (kbd "r t") #'ement-room-set-topic)
(define-key map (kbd "r f") #'ement-room-set-message-format)
(define-key map (kbd "r n") #'ement-room-set-notification-state)
+ (define-key map (kbd "r N") #'ement-room-override-name)
(define-key map (kbd "r T") #'ement-tag-room)
;; Room membership
@@ -1013,6 +1014,26 @@ Note that, if ROOM has no buffer, STRING is returned
unchanged."
;;;; Commands
+(defun ement-room-override-name (name room session)
+ "Set NAME override for ROOM on SESSION.
+If NAME is the empty string, remove the override.
+
+Sets account-data event of type
+\"org.matrix.msc3015.m.room.name.override\". This name is only
+used by clients that respect this proposed override. See
+<https://github.com/matrix-org/matrix-spec-proposals/pull/3015#issuecomment-1451017296>."
+ (interactive (pcase-let* ((`(,room ,session) (ement-complete-room :suggest
t))
+ (name (read-string "Set name override: ")))
+ (list name room session)))
+ (ement-put-account-data session "org.matrix.msc3015.m.room.name.override"
+ (if (string-empty-p name)
+ ;; `json-encode' wants an empty hash table to represent an empty map.
And
+ ;; apparently there's no way to DELETE account-data events, so we have
to re-PUT
+ ;; it with empty content.
+ (make-hash-table)
+ (ement-alist "name" name))
+ :room room))
+
(defun ement-room-flush-colors ()
"Flush generated username/message colors.
Also, redisplay events in all open buffers. The colors will be
@@ -2399,6 +2420,11 @@ function to `ement-room-event-fns', which see."
(ement-room-defevent "m.room.avatar"
(ement-room--insert-event event))
+(ement-room-defevent "org.matrix.msc3015.m.room.name.override"
+ (ignore event)
+ (setf (ement-room-display-name ement-room) (ement--room-display-name
ement-room))
+ (rename-buffer (ement-room--buffer-name ement-room)))
+
(ement-room-defevent "m.room.member"
(with-silent-modifications
(ement-room--insert-event event)))
@@ -4245,6 +4271,14 @@ For use in `completion-at-point-functions'."
("r m" "List members" ement-list-members)
("r t" "Set topic" ement-room-set-topic)
("r f" "Set message format" ement-room-set-message-format)
+ ("r N" "Override name" ement-room-override-name
+ :description (lambda ()
+ (format "Name override: %s"
+ (if-let* ((event (alist-get
"org.matrix.msc3015.m.room.name.override"
+
(ement-room-account-data ement-room) nil nil #'equal))
+ (name (map-nested-elt event
'(content name))))
+ (propertize name 'face
'transient-value)
+ (propertize "none" 'face
'transient-inactive-value)))))
("r n" "Set notification state" ement-room-set-notification-state
:description (lambda ()
(let ((state (ement-room-notification-state
ement-room ement-session)))