1
0
Fork 0

- decrease mentions count on the modeline when a status that contains a mention is opened.

This commit is contained in:
cage 2021-05-22 12:23:15 +02:00
parent c2e8e38249
commit deaf94299a
4 changed files with 37 additions and 24 deletions

View File

@ -728,7 +728,9 @@ node-status-id is not a leaf)."
(climb-fetch-statuses (reply-id status) (climb-fetch-statuses (reply-id status)
(push status branch))))))) (push status branch)))))))
(defun make-id= (&optional (test #'string=)) (defalias id= #'string=)
(defun make-id= (&optional (test #'id=))
"Returns a comparator function that checks for id equality" "Returns a comparator function that checks for id equality"
(lambda (a b) (funcall test (tooter:id a) (tooter:id b)))) (lambda (a b) (funcall test (tooter:id a) (tooter:id b))))

View File

@ -836,6 +836,7 @@
:message-id->tree :message-id->tree
:message-from-timeline-folder-message-index :message-from-timeline-folder-message-index
:message-index->tree :message-index->tree
:single-status-exists-p
:find-status-id :find-status-id
:find-message-id :find-message-id
:data-id :data-id
@ -1512,6 +1513,7 @@
:get-notifications :get-notifications
:delete-notification :delete-notification
:sort-id< :sort-id<
:id=
:all-mentions :all-mentions
:update-mentions-folder :update-mentions-folder
:expand-status-thread :expand-status-thread
@ -1931,8 +1933,8 @@
:search-next-message-meta :search-next-message-meta
:search-previous-message-meta :search-previous-message-meta
:search-next-unread :search-next-unread
:increase-mentions-count :add-mention
:decrease-mentions-count :remove-mention
:goto-message :goto-message
:goto-first-message :goto-first-message
:goto-last-message :goto-last-message

View File

@ -894,7 +894,8 @@
(mentions-count (length mentions)) (mentions-count (length mentions))
(thread-window specials:*thread-window*)) (thread-window specials:*thread-window*))
(when command-line:*notify-mentions* (when command-line:*notify-mentions*
(thread-window:increase-mentions-count thread-window mentions-count) (loop for mention in mentions do
(thread-window:add-mention thread-window mention))
(ui:notify (format nil (ui:notify (format nil
(n_ "Got ~a notification" (n_ "Got ~a notification"
"Got ~a notifications" "Got ~a notifications"

View File

@ -113,10 +113,10 @@
:initform db:+default-status-folder+ :initform db:+default-status-folder+
:initarg :timeline-folder :initarg :timeline-folder
:accessor timeline-folder) :accessor timeline-folder)
(mentions-count (mentions
:initform 0 :initform ()
:initarg :mentions-count :initarg :mentions
:accessor mentions-count))) :accessor mentions)))
(defmacro lambda-ignore-args (args &body body) (defmacro lambda-ignore-args (args &body body)
`(lambda (,@args) `(lambda (,@args)
@ -182,13 +182,13 @@
""))) "")))
(defun expand-mentions (window) (defun expand-mentions (window)
(with-accessors ((mentions-count mentions-count)) window (with-accessors ((mentions mentions)) window
(if (> mentions-count 0) (if mentions
(with-tuify-results (window) (with-tuify-results (window)
(format nil (format nil
"~a(~a)" "~a(~a)"
(swconf:config-notification-icon) (swconf:config-notification-icon)
mentions-count)) (length mentions)))
""))) "")))
(defun default-expander () (defun default-expander ()
@ -318,9 +318,9 @@
(defgeneric search-previous-message-meta (object text-looking-for)) (defgeneric search-previous-message-meta (object text-looking-for))
(defgeneric increase-mentions-count (object &optional amount)) (defgeneric add-mention (object mention))
(defgeneric decrease-mentions-count (object &optional amount)) (defgeneric remove-mention (object status-id))
(defun message-root (tree) (defun message-root (tree)
(mtree:root-node tree)) (mtree:root-node tree))
@ -808,6 +808,12 @@ db:renumber-timeline-message-index."
(attachments (status-attachments->text reblogged-id))) (attachments (status-attachments->text reblogged-id)))
(values body attachments)))) (values body attachments))))
(defun maybe-remove-mentions (window status-id)
(when-let ((exists-mention-p (db:single-status-exists-p status-id
db:+home-timeline+
db:+mentions-status-folder+)))
(remove-mention window status-id)))
(defmethod open-message ((object thread-window)) (defmethod open-message ((object thread-window))
(with-accessors ((row-selected-index row-selected-index) (with-accessors ((row-selected-index row-selected-index)
(rows rows) (rows rows)
@ -833,6 +839,7 @@ db:renumber-timeline-message-index."
(actual-attachments (if (string= attachments reblogged-status-attachments) (actual-attachments (if (string= attachments reblogged-status-attachments)
attachments attachments
(strcat reblogged-status-attachments attachments)))) (strcat reblogged-status-attachments attachments))))
(maybe-remove-mentions object status-id)
(message-window:prepare-for-rendering *message-window* (message-window:prepare-for-rendering *message-window*
(strcat header (strcat header
actual-body actual-body
@ -957,18 +964,19 @@ db:renumber-timeline-message-index."
(open-message object)) (open-message object))
(ui:info-message (_ "No others unread messages exist."))))))) (ui:info-message (_ "No others unread messages exist.")))))))
(defmethod increase-mentions-count ((object thread-window) &optional amount) (defmethod add-mention ((object thread-window) mention)
(with-accessors ((mentions-count mentions-count)) object (with-accessors ((mentions mentions)) object
(let ((old-count mentions-count)) (let ((reversed (reverse mentions)))
(incf mentions-count amount) (push mention reversed)
(setf mentions-count (max 0 mentions-count)) (setf mentions (reverse reversed)))))
(values object old-count))))
(defmethod decrease-mentions-count ((object thread-window) &optional amount) (defmethod remove-mention ((object thread-window) status-id)
(multiple-value-bind (x old-count) (with-accessors ((mentions mentions)) object
(increase-mentions-count object (- amount)) (setf mentions
(declare (ignore x)) (remove-if (lambda (mention) (api-client:id= (tooter:id (tooter:status mention))
(values object old-count))) status-id))
mentions))
object))
(defgeneric marked-to-delete-p (object)) (defgeneric marked-to-delete-p (object))