emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/ement 3f87a951fe 5/5: Merge: Fix retrieval of earlier e


From: ELPA Syncer
Subject: [elpa] externals/ement 3f87a951fe 5/5: Merge: Fix retrieval of earlier events in a just-joined room
Date: Tue, 10 Sep 2024 21:58:01 -0400 (EDT)

branch: externals/ement
commit 3f87a951fe0cb6791d3eadcb4189c9f099f146a5
Merge: 3552980d36 16d4878bb0
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>

    Merge: Fix retrieval of earlier events in a just-joined room
    
    Fixes #148.
---
 README.org    |  1 +
 ement-room.el | 35 +++++++++++++++++++++++++----------
 2 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/README.org b/README.org
index 3610a5ced2..88353eaa4d 100644
--- a/README.org
+++ b/README.org
@@ -315,6 +315,7 @@ Ement.el doesn't support encrypted rooms natively, but it 
can be used transparen
 + Replies to edited messages are correctly sent to the original event (whereas 
previously they were sent to the edit, which caused reactions to not be shown). 
 ([[https://github.com/alphapapa/ement.el/issues/230][#230]], 
[[https://github.com/alphapapa/ement.el/issues/277][#277]].  Thanks to 
[[https://github.com/phil-s][Phil Sainty]] for suggesting, and to 
[[https://github.com/dionisos2][dionisos]] for reporting.)
 + Set ~filter-buffer-substring-function~ in room buffers to prevent undesired 
text properties from being included in copied text.  
([[https://github.com/alphapapa/ement.el/pull/278][#278]].  Thanks to 
[[https://github.com/phil-s][Phil Sainty]].)
 + Command ~ement-disconnect~ no longer shows an error message.  
([[https://github.com/alphapapa/ement.el/issues/208][#208]].)
++ Retrieval of earlier events in a just-joined room.  
([[https://github.com/alphapapa/ement.el/issues/148][#148]].  Thanks to 
[[https://github.com/MagicRB][Richard Brežák]] for reporting, and to 
[[https://github.com/phil-s][Phil Sainty]] for testing.)
 
 ** 0.15.1
 
diff --git a/ement-room.el b/ement-room.el
index 12614fad8c..ed818bb4e2 100644
--- a/ement-room.el
+++ b/ement-room.el
@@ -1884,10 +1884,12 @@ see."
       ;; We use a timeout of 30, because sometimes the server can take a while 
to
       ;; respond, especially if loading, e.g. hundreds or thousands of events.
       (ement-api session endpoint :timeout 30
-        :params (list (list "from" prev-batch)
-                      (list "dir" "b")
-                      (list "limit" (number-to-string number))
-                      (list "filter" (json-encode ement-room-messages-filter)))
+        :params (remq nil
+                      (list (when prev-batch
+                              (list "from" prev-batch))
+                            (list "dir" "b")
+                            (list "limit" (number-to-string number))
+                            (list "filter" (json-encode 
ement-room-messages-filter))))
         :then then
         :else (lambda (plz-error)
                 (when buffer
@@ -2502,13 +2504,23 @@ before the earliest-seen message)."
                               (append (ement-room-state room) (append state 
nil))))
     (ement-with-progress-reporter (:reporter ("Ement: Processing earlier 
events..." 0 progress-max-value))
       ;; Append timeline events (in the "chunk").
+      ;; NOTE: It's regrettable that we have to turn the chunk vector into a 
list before
+      ;; appending it to the timeline, but we have to discard events that 
we've already
+      ;; seen.
+      ;; TODO: Consider looping over the vector and pushing one-by-one instead 
of using
+      ;; `seq-remove' and `append' (might be faster).
       (cl-loop for event across-ref chunk
-               do (setf event (ement--make-event event))
-               ;; HACK: Put events on events table.  See FIXME above about 
using the event hook.
-               (ement--put-event event nil session)
+               do (if (gethash (alist-get 'event_id event) 
(ement-session-events session))
+                      ;; Duplicate event: set to nil to be ignored.
+                      (setf event nil)
+                    ;; New event.
+                    (setf event (ement--make-event event))
+                    ;; HACK: Put events on events table.  See FIXME above 
about using the event hook.
+                    (ement--put-event event nil session))
                (ement-progress-update)
-               finally do (setf (ement-room-timeline room)
-                                (append (ement-room-timeline room) (append 
chunk nil))))
+               finally do
+               (setf chunk (seq-remove #'null chunk)
+                     (ement-room-timeline room) (append (ement-room-timeline 
room) chunk)))
       (when buffer
         ;; Insert events into the room's buffer.
         (with-current-buffer buffer
@@ -2518,7 +2530,10 @@ before the earliest-seen message)."
               (select-window buffer-window))
             ;; FIXME: Use retro-loading in event handlers, or in 
--handle-events, anyway.
             (ement-room--process-events chunk)
-            (when set-prev-batch
+            ;; Don't set the slot if the response doesn't include an "end" 
token (that
+            ;; would cause subsequent retro requests to fetch events from the 
end of the
+            ;; timeline, as if we had just joined).
+            (when (and set-prev-batch end)
               ;; This feels a little hacky, but maybe not too bad.
               (setf (ement-room-prev-batch room) end))
             (setf ement-room-retro-loading nil)))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]