From ebbee28430b691dff1ef08618d042285e1544ddd Mon Sep 17 00:00:00 2001 From: cage Date: Thu, 27 Jun 2024 13:55:39 +0200 Subject: [PATCH] - [TUI][fediverse] ensured the printed status is updated after editing. --- src/api-client.lisp | 6 +++-- src/program-events.lisp | 50 ++++++++++++++++++++++++++--------------- src/ui-goodies.lisp | 3 ++- 3 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/api-client.lisp b/src/api-client.lisp index 8409459..cedae0d 100644 --- a/src/api-client.lisp +++ b/src/api-client.lisp @@ -501,13 +501,15 @@ become an emty string (\"\") :limit limit :min-id max-id)))) -(defun-api-call fetch-remote-status (status-id) +(defun-api-call fetch-remote-status (status-id &optional folder timeline) "Fetch a single status identified by status-id and generate an event `fetch-remote-status-event' that, in turn will save the status to the database." (when-let* ((status (tooter:find-status *client* status-id)) (event (make-instance 'program-events:fetch-remote-status-event - :payload status))) + :payload status + :folder folder + :timeline timeline))) (program-events:push-event event))) (defun-api-call get-remote-status (status-id) diff --git a/src/program-events.lisp b/src/program-events.lisp index 684c23d..6d1def0 100644 --- a/src/program-events.lisp +++ b/src/program-events.lisp @@ -556,15 +556,25 @@ (going-backward (ui:update-current-timeline-backwards (1+ recover-count))))))))) -(defclass fetch-remote-status-event (program-event) ()) +(defclass fetch-remote-status-event (program-event) + ((timeline + :initform nil + :initarg :timeline + :accessor timeline) + (folder + :initform nil + :initarg :folder + :accessor folder))) (defmethod process-event ((object fetch-remote-status-event)) (let ((status (payload object))) - #+debug-mode - (let ((dump (with-output-to-string (stream) - (tooter::present status stream)))) - (dbg "fetch single status ~a" dump)) - (db:update-db status))) + (with-accessors ((folder folder) + (timeline timeline)) object + #+debug-mode + (let ((dump (with-output-to-string (stream) + (tooter::present status stream)))) + (dbg "fetch single status ~a" dump)) + (db:update-db status :folder folder :timeline timeline)))) (defparameter *search-next-saved-event* nil) @@ -2068,9 +2078,12 @@ (defmethod process-event ((object edit-status-event)) (with-accessors ((status-id payload)) object - (when-let* ((status (db:find-status-id status-id)) - (text (db:row-message-rendered-text status)) - (status-id (db:row-message-status-id status))) + (when-let* ((status (db:find-status-id status-id)) + (text (db:row-message-rendered-text status)) + (status-id (db:row-message-status-id status)) + (folder (db:row-message-folder status)) + (timeline (db:row-message-timeline status)) + (message-index (db:row-message-index status))) (let ((temp-file (fs:temporary-file))) (with-open-file (stream temp-file :direction :output @@ -2080,15 +2093,16 @@ (croatoan:end-screen) (tui:with-notify-errors (os-utils:open-with-editor temp-file)) - (let* ((new-content (fs:slurp-file temp-file)) - (raw-rows (text-utils:split-lines new-content))) - (message-window:prepare-for-rendering specials:*message-window* raw-rows) - (windows:win-clear specials:*message-window*) - (windows:draw specials:*message-window*) - (ui:with-blocking-notify-procedure ((_ "Editing post…") - (_ "Post modified")) - (api-client:edit-status status-id new-content nil nil nil nil) - (client:fetch-remote-status status-id))))))) + (let ((new-content (fs:slurp-file temp-file))) + (ui:notify (_ "Editing post…")) + (client:edit-status status-id new-content nil nil nil nil) + (db:remove-from-status-ignored status-id folder timeline) + (db::delete-status timeline folder status-id) + (client:fetch-remote-status status-id folder timeline) + (ui:refresh-thread) + (with-enqueued-process (+minimum-event-priority+) + (ui:thread-open-selected-message) + (ui:notify (_ "Post modified")))))))) ;;;; end events diff --git a/src/ui-goodies.lisp b/src/ui-goodies.lisp index ab6dea6..588b4eb 100644 --- a/src/ui-goodies.lisp +++ b/src/ui-goodies.lisp @@ -955,7 +955,8 @@ Starting from the oldest toot and going back." :new-timeline timeline :status-id status-id)) (refresh-event (make-instance 'refresh-thread-windows-event - :priority +minimum-event-priority+ + :priority + (1+ +standard-event-priority+) :message-status-id status-id))) (push-event expand-event) (push-event refresh-event))))