[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ement cc97d0eca7 1/2: Change/Fix: Room list avatars
From: |
ELPA Syncer |
Subject: |
[elpa] externals/ement cc97d0eca7 1/2: Change/Fix: Room list avatars |
Date: |
Thu, 27 Oct 2022 14:57:39 -0400 (EDT) |
branch: externals/ement
commit cc97d0eca7e9023631f37c0ae61de1fe628ac87b
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>
Change/Fix: Room list avatars
Since the cached avatar needs to be discarded when a room avatar event
is received, it's simpler to store the cached avatar in the room's
local alist rather than use a buffer-local hash table in the room list
buffer. It does mean that the avatars will remain in memory when the
room list buffer is killed, but that's unlikely to cause significant
memory usage, and the cached avatars could be cleared easily enough if
needed.
This also fixes a bug or race condition in that generated avatars
would not be replaced with downloaded ones.
---
ement-room-list.el | 12 +++++-------
ement.el | 9 ++++++---
2 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/ement-room-list.el b/ement-room-list.el
index 2363f70af4..bbd291d2d3 100644
--- a/ement-room-list.el
+++ b/ement-room-list.el
@@ -278,18 +278,16 @@ from recent to non-recent for rooms updated in the past
hour.")
;;;; Columns
-(defvar-local ement-room-list-room-avatar-cache (make-hash-table)
- ;; Use a buffer-local variable so that the cache is cleared when the buffer
is closed.
- "Hash table caching room avatars for the `ement-room-list' room list.")
-
(eval-and-compile
(taxy-magit-section-define-column-definer "ement-room-list"))
(ement-room-list-define-column #("🐱" 0 1 (help-echo "Avatar")) (:align 'right)
(pcase-let* ((`[,room ,_session] item)
- ((cl-struct ement-room avatar display-name) room))
+ ((cl-struct ement-room avatar display-name
+ (local (map room-list-avatar)))
+ room))
(if ement-room-list-avatars
- (or (gethash room ement-room-list-room-avatar-cache)
+ (or room-list-avatar
(let ((new-avatar
(if avatar
;; NOTE: We resize every avatar to be suitable for this
buffer, rather than using
@@ -308,7 +306,7 @@ from recent to non-recent for rooms updated in the past
hour.")
(propertize " " 'display (svg-lib-tag (substring string
0 1) nil
:background color
:foreground "white"
:stroke 0))))))
- (puthash room new-avatar ement-room-list-room-avatar-cache)))
+ (setf (alist-get 'room-list-avatar (ement-room-local room))
new-avatar)))
;; Avatars disabled: use a two-space string.
" ")))
diff --git a/ement.el b/ement.el
index e1dd71b1de..732e9ce2c4 100644
--- a/ement.el
+++ b/ement.el
@@ -862,9 +862,12 @@ and `session' to the session. Adds function to
;; Only do this when ImageMagick is supported.
;; FIXME: When requiring Emacs 27+, remove this (I
guess?).
(setf (image-property image :type) 'imagemagick))
- ;; We set the room-avatar slot to a propertized string
that displays
- ;; as the image. This seems the most convenient thing
to do.
- (setf (ement-room-avatar room) (propertize " " 'display
image)))))))
+ ;; We set the room-avatar slot to a propertized string
that
+ ;; displays as the image. This seems the most
convenient thing to
+ ;; do. We also unset the cached room-list-avatar so it
can be
+ ;; remade.
+ (setf (ement-room-avatar room) (propertize " " 'display
image)
+ (alist-get 'room-list-avatar (ement-room-local
room)) nil))))))
;; Unset avatar.
(setf (ement-room-avatar room) nil
(alist-get 'room-list-avatar (ement-room-local room)) nil))))