1
0
mirror of https://codeberg.org/cage/tinmop/ synced 2025-02-21 08:50:51 +01:00

- added '*skip-message-hook*' (with example).

This commit is contained in:
cage 2020-06-25 14:38:14 +02:00
parent b4f78df9b4
commit 15987cc5b2
5 changed files with 33 additions and 11 deletions

View File

@ -346,3 +346,16 @@
(define-key "q" #'close-open-message-link-window
*open-message-link-keymap*)
;;;; hooks
;;; this hooks will skips toots with contain less than 20 words
;;; (note: it is commented out)
;; (hooks:add-hook 'hooks:*skip-message-hook*
;; (lambda (toot)
;; (when-let* ((text (html-utils:html->text (tooter:content toot)
;; :add-link-footnotes nil))
;; (trimmed (text-utils:trim-blanks text))
;; (word-counts (length (text-utils:split-words trimmed))))
;; (< word-counts 10))))

View File

@ -81,3 +81,7 @@ non-nil.")
"Run this hooks before sending the message, note that the message
could be encrypted after this hooks runs, the function takes a
message-window as parameter")
(defparameter *skip-message-hook* '()
"Run this hooks to check if a message must be skipped,
all hooks must returns nil for this message to be not skipped")

View File

@ -64,11 +64,11 @@
(defun html->text (html &key (add-link-footnotes t))
"Transform html to text, note that if `add-link-footnotes` is non nil footnotes that marks html link in the text are added aftere the body of the message
This function uses a library that transhorm html5 text into s-expressions um the form
This function uses a library that transform html5 text into s-expressions um the form
'(name (attributes) children*)
Some convenience functions are provided to works with this structures.
Some convenience functions are provided to works with these structures.
"
(when html
(let ((root (append (list :root

View File

@ -1284,7 +1284,8 @@
:*before-main-loop*
:*before-quit*
:*before-prepare-for-rendering-message*
:*before-sending-message*))
:*before-sending-message*
:*skip-message-hook*))
(defpackage :keybindings
(:use

View File

@ -322,15 +322,19 @@
(dbg "statuses ~a" dump))
(loop for status in statuses do
(let ((account-id (tooter:id (tooter:account status)))
(status-id (tooter:id status)))
(when (and (db:user-ignored-p account-id)
(not (db:status-skipped-p status-id folder timeline-type)))
(status-id (tooter:id status))
(skip-this-status nil))
(when (or (and (db:user-ignored-p account-id)
(not (db:status-skipped-p status-id folder timeline-type)))
(hooks:run-hook-until-success 'hooks:*skip-message-hook* status))
(db:add-to-status-skipped status-id folder timeline-type)
(incf ignored-count)))
(db:update-db status
:timeline timeline-type
:folder folder
:skip-ignored-p t))
(setf skip-this-status t)
(incf ignored-count))
(when (not skip-this-status)
(db:update-db status
:timeline timeline-type
:folder folder
:skip-ignored-p t))))
(db:renumber-timeline-message-index timeline-type
folder
:account-id nil)