mirror of
https://github.com/vale981/ement.el
synced 2025-03-05 09:21:37 -05:00
Change: Save room members in table and add in m.room.members events
Also, tidy some struct definitions, etc.
This commit is contained in:
parent
245d741e25
commit
cfb7a47237
2 changed files with 32 additions and 6 deletions
|
@ -43,10 +43,15 @@
|
|||
;;;; Structs
|
||||
|
||||
(cl-defstruct ement-user
|
||||
id displayname account-data room-display-names
|
||||
color message-color
|
||||
username ;; NOTE: Not exactly according to spec, I guess, but useful for now.
|
||||
)
|
||||
id displayname account-data
|
||||
(color nil :documentation "Color in which to display user's name.")
|
||||
(message-color nil :documentation "Color in which to display user's messages.")
|
||||
(username nil
|
||||
;; NOTE: Not exactly according to spec, I guess, but useful for now.
|
||||
:documentation "Username part of user's Matrix ID.")
|
||||
(avatar-url nil :documentation "MXC URL to user's avatar.")
|
||||
(avatar nil :documentation "One-space string with avatar image in display property.")
|
||||
(room-display-names (make-hash-table) :documentation "Hash table mapping rooms to the user's per-room display name."))
|
||||
|
||||
(cl-defstruct ement-event
|
||||
id sender content origin-server-ts type unsigned state-key
|
||||
|
@ -68,6 +73,7 @@
|
|||
id display-name prev-batch
|
||||
summary state timeline ephemeral account-data unread-notifications
|
||||
latest-ts topic canonical-alias avatar status type invite-state
|
||||
(members (make-hash-table :test #'equal) :documentation "Hash table mapping joined user IDs to user structs.")
|
||||
;; The local slot is an alist used by the local client only.
|
||||
local
|
||||
(receipts (make-hash-table :test #'equal)))
|
||||
|
|
24
ement.el
24
ement.el
|
@ -635,8 +635,7 @@ Adds sender to `ement-users' when necessary."
|
|||
('sender sender-id) ('state_key state-key))
|
||||
event)
|
||||
(sender (or (gethash sender-id ement-users)
|
||||
(puthash sender-id (make-ement-user
|
||||
:id sender-id :room-display-names (make-hash-table))
|
||||
(puthash sender-id (make-ement-user :id sender-id)
|
||||
ement-users))))
|
||||
;; MAYBE: Handle other keys in the event, such as "room_id" in "invite" events.
|
||||
(make-ement-event :id id :sender sender :type type :content content :state-key state-key
|
||||
|
@ -795,6 +794,27 @@ and `session' to the session. Adds function to
|
|||
(when type
|
||||
(setf (ement-room-type room) type))))
|
||||
|
||||
(ement-defevent "m.room.member"
|
||||
"Put/update member on `ement-users' and room's members table."
|
||||
(ignore session)
|
||||
(pcase-let* (((cl-struct ement-room members) room)
|
||||
((cl-struct ement-event state-key
|
||||
(content (map displayname
|
||||
('avatar_url avatar-url))))
|
||||
event)
|
||||
(user (or (gethash state-key ement-users)
|
||||
(puthash state-key
|
||||
(make-ement-user :id state-key :avatar-url avatar-url
|
||||
;; NOTE: The spec doesn't seem to say whether the
|
||||
;; displayname in the member event applies only to the
|
||||
;; room or is for the user generally, so we'll save it
|
||||
;; in the struct anyway.
|
||||
:displayname displayname)
|
||||
ement-users))))
|
||||
(puthash room displayname (ement-user-room-display-names user))
|
||||
(unless (gethash state-key members)
|
||||
(puthash state-key user members))))
|
||||
|
||||
(ement-defevent "m.room.name"
|
||||
(ignore session)
|
||||
(pcase-let* (((cl-struct ement-event (content (map name))) event))
|
||||
|
|
Loading…
Add table
Reference in a new issue