mirror of
https://github.com/vale981/ement.el
synced 2025-03-05 09:21:37 -05:00
Change: Move room-display-name function to ement-room
Seems to make sense.
This commit is contained in:
parent
2d525429b2
commit
41140995b7
3 changed files with 55 additions and 54 deletions
|
@ -185,7 +185,7 @@ call `pop-to-buffer'."
|
||||||
;; (e-avatar (if avatar (ement-resize-avatar avatar) ""))
|
;; (e-avatar (if avatar (ement-resize-avatar avatar) ""))
|
||||||
(e-name (list (propertize (or display-name
|
(e-name (list (propertize (or display-name
|
||||||
(setf (ement-room-display-name room)
|
(setf (ement-room-display-name room)
|
||||||
(ement--room-display-name room)))
|
(ement-room--room-display-name room)))
|
||||||
'help-echo e-alias)
|
'help-echo e-alias)
|
||||||
'action #'ement-room-list-action))
|
'action #'ement-room-list-action))
|
||||||
(e-topic (if topic
|
(e-topic (if topic
|
||||||
|
|
|
@ -99,6 +99,7 @@ In that case, sender names are aligned to the margin edge.")
|
||||||
|
|
||||||
;; Variables from other files.
|
;; Variables from other files.
|
||||||
(defvar ement-sessions)
|
(defvar ement-sessions)
|
||||||
|
(defvar ement-users)
|
||||||
|
|
||||||
;;;; Customization
|
;;;; Customization
|
||||||
|
|
||||||
|
@ -780,6 +781,57 @@ data slot."
|
||||||
;; Return the buffer!
|
;; Return the buffer!
|
||||||
new-buffer)))
|
new-buffer)))
|
||||||
|
|
||||||
|
(defun ement-room--room-display-name (room)
|
||||||
|
"Return the displayname for ROOM."
|
||||||
|
;; SPEC: <https://matrix.org/docs/spec/client_server/r0.6.1#calculating-the-display-name-for-a-room>.
|
||||||
|
(cl-labels ((latest-event (type content-field)
|
||||||
|
(or (cl-loop for event in (ement-room-timeline room)
|
||||||
|
when (and (equal type (ement-event-type event))
|
||||||
|
(not (string-empty-p (alist-get content-field (ement-event-content event)))))
|
||||||
|
return (alist-get content-field (ement-event-content event)))
|
||||||
|
(cl-loop for event in (ement-room-state room)
|
||||||
|
when (and (equal type (ement-event-type event))
|
||||||
|
(not (string-empty-p (alist-get content-field (ement-event-content event)))))
|
||||||
|
return (alist-get content-field (ement-event-content event)))))
|
||||||
|
(heroes-name
|
||||||
|
() (pcase-let* (((cl-struct ement-room summary) room)
|
||||||
|
((map ('m.heroes hero-ids) ('m.joined_member_count joined-count)
|
||||||
|
('m.invited_member_count invited-count))
|
||||||
|
summary))
|
||||||
|
;; TODO: Disambiguate hero display names.
|
||||||
|
(when hero-ids
|
||||||
|
(cond ((>= (length hero-ids) (1- (+ joined-count invited-count)))
|
||||||
|
;; Members == heroes.
|
||||||
|
(hero-names hero-ids))
|
||||||
|
((and (< (length hero-ids) (1- (+ joined-count invited-count)))
|
||||||
|
(> (+ joined-count invited-count) 1))
|
||||||
|
;; More members than heroes.
|
||||||
|
(heroes-and-others hero-ids joined-count))
|
||||||
|
((<= (+ joined-count invited-count) 1)
|
||||||
|
;; Empty room.
|
||||||
|
(empty-room hero-ids joined-count))))))
|
||||||
|
(hero-names
|
||||||
|
(heroes) (string-join (mapcar #'hero-name heroes) ", "))
|
||||||
|
(hero-name
|
||||||
|
(id) (if-let ((user (gethash id ement-users)))
|
||||||
|
(ement-room--user-display-name user room)
|
||||||
|
id))
|
||||||
|
(heroes-and-others
|
||||||
|
(heroes joined)
|
||||||
|
(format "%s, and %s others" (hero-names heroes)
|
||||||
|
(- joined (length heroes))))
|
||||||
|
(empty-room
|
||||||
|
(heroes joined) (cl-etypecase (length heroes)
|
||||||
|
((satisfies zerop) "Empty room")
|
||||||
|
((number 1 5) (format "Empty room (was %s)"
|
||||||
|
(hero-names heroes)))
|
||||||
|
(t (format "Empty room (was %s)"
|
||||||
|
(heroes-and-others heroes joined))))))
|
||||||
|
(or (latest-event "m.room.name" 'name)
|
||||||
|
(latest-event "m.room.canonical_alias" 'alias)
|
||||||
|
(heroes-name)
|
||||||
|
(ement-room-id room))))
|
||||||
|
|
||||||
(defun ement-room--user-display-name (user room)
|
(defun ement-room--user-display-name (user room)
|
||||||
"Return the displayname for USER in ROOM."
|
"Return the displayname for USER in ROOM."
|
||||||
;; SPEC: <https://matrix.org/docs/spec/client_server/r0.6.1#calculating-the-display-name-for-a-user>.
|
;; SPEC: <https://matrix.org/docs/spec/client_server/r0.6.1#calculating-the-display-name-for-a-user>.
|
||||||
|
|
55
ement.el
55
ement.el
|
@ -265,7 +265,7 @@ If no URI is found, prompt the user for the hostname."
|
||||||
(concat ement-room-buffer-name-prefix
|
(concat ement-room-buffer-name-prefix
|
||||||
(or (ement-room-display-name room)
|
(or (ement-room-display-name room)
|
||||||
(setf (ement-room-display-name room)
|
(setf (ement-room-display-name room)
|
||||||
(ement--room-display-name room)))
|
(ement-room--room-display-name room)))
|
||||||
ement-room-buffer-name-suffix))
|
ement-room-buffer-name-suffix))
|
||||||
|
|
||||||
(defun ement-complete-session ()
|
(defun ement-complete-session ()
|
||||||
|
@ -285,7 +285,7 @@ If no URI is found, prompt the user for the hostname."
|
||||||
collect (cons (format "%s (%s)"
|
collect (cons (format "%s (%s)"
|
||||||
(or (ement-room-display-name room)
|
(or (ement-room-display-name room)
|
||||||
(setf (ement-room-display-name room)
|
(setf (ement-room-display-name room)
|
||||||
(ement--room-display-name room)))
|
(ement-room--room-display-name room)))
|
||||||
(ement--room-alias room))
|
(ement--room-alias room))
|
||||||
room)))
|
room)))
|
||||||
(names (mapcar #'car name-to-room))
|
(names (mapcar #'car name-to-room))
|
||||||
|
@ -487,57 +487,6 @@ Adds sender to `ement-users' when necessary."
|
||||||
(make-ement-event :id id :sender sender :type type :content content
|
(make-ement-event :id id :sender sender :type type :content content
|
||||||
:origin-server-ts ts :unsigned unsigned)))
|
:origin-server-ts ts :unsigned unsigned)))
|
||||||
|
|
||||||
(defun ement--room-display-name (room)
|
|
||||||
"Return the displayname for ROOM."
|
|
||||||
;; SPEC: <https://matrix.org/docs/spec/client_server/r0.6.1#calculating-the-display-name-for-a-room>.
|
|
||||||
(cl-labels ((latest-event (type content-field)
|
|
||||||
(or (cl-loop for event in (ement-room-timeline room)
|
|
||||||
when (and (equal type (ement-event-type event))
|
|
||||||
(not (string-empty-p (alist-get content-field (ement-event-content event)))))
|
|
||||||
return (alist-get content-field (ement-event-content event)))
|
|
||||||
(cl-loop for event in (ement-room-state room)
|
|
||||||
when (and (equal type (ement-event-type event))
|
|
||||||
(not (string-empty-p (alist-get content-field (ement-event-content event)))))
|
|
||||||
return (alist-get content-field (ement-event-content event)))))
|
|
||||||
(heroes-name
|
|
||||||
() (pcase-let* (((cl-struct ement-room summary) room)
|
|
||||||
((map ('m.heroes hero-ids) ('m.joined_member_count joined-count)
|
|
||||||
('m.invited_member_count invited-count))
|
|
||||||
summary))
|
|
||||||
;; TODO: Disambiguate hero display names.
|
|
||||||
(when hero-ids
|
|
||||||
(cond ((>= (length hero-ids) (1- (+ joined-count invited-count)))
|
|
||||||
;; Members == heroes.
|
|
||||||
(hero-names hero-ids))
|
|
||||||
((and (< (length hero-ids) (1- (+ joined-count invited-count)))
|
|
||||||
(> (+ joined-count invited-count) 1))
|
|
||||||
;; More members than heroes.
|
|
||||||
(heroes-and-others hero-ids joined-count))
|
|
||||||
((<= (+ joined-count invited-count) 1)
|
|
||||||
;; Empty room.
|
|
||||||
(empty-room hero-ids joined-count))))))
|
|
||||||
(hero-names
|
|
||||||
(heroes) (string-join (mapcar #'hero-name heroes) ", "))
|
|
||||||
(hero-name
|
|
||||||
(id) (if-let ((user (gethash id ement-users)))
|
|
||||||
(ement-room--user-display-name user room)
|
|
||||||
id))
|
|
||||||
(heroes-and-others
|
|
||||||
(heroes joined)
|
|
||||||
(format "%s, and %s others" (hero-names heroes)
|
|
||||||
(- joined (length heroes))))
|
|
||||||
(empty-room
|
|
||||||
(heroes joined) (cl-etypecase (length heroes)
|
|
||||||
((satisfies zerop) "Empty room")
|
|
||||||
((number 1 5) (format "Empty room (was %s)"
|
|
||||||
(hero-names heroes)))
|
|
||||||
(t (format "Empty room (was %s)"
|
|
||||||
(heroes-and-others heroes joined))))))
|
|
||||||
(or (latest-event "m.room.name" 'name)
|
|
||||||
(latest-event "m.room.canonical_alias" 'alias)
|
|
||||||
(heroes-name)
|
|
||||||
(ement-room-id room))))
|
|
||||||
|
|
||||||
;; FIXME: These functions probably need to compare timestamps to
|
;; FIXME: These functions probably need to compare timestamps to
|
||||||
;; ensure that older events that are inserted at the head of the
|
;; ensure that older events that are inserted at the head of the
|
||||||
;; events lists aren't used instead of newer ones.
|
;; events lists aren't used instead of newer ones.
|
||||||
|
|
Loading…
Add table
Reference in a new issue