diff options
-rw-r--r-- | lisp/mastodon-tl.el | 56 | ||||
-rw-r--r-- | test/mastodon-tl-tests.el | 43 |
2 files changed, 69 insertions, 30 deletions
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index b066608..d86135d 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -328,8 +328,14 @@ E.g. this could return something like \"1 min ago\", \"yesterday\", etc. TIME-STAMP is assumed to be in the past." (car (mastodon-tl--relative-time-details timestamp current-time))) -(defun mastodon-tl--byline (toot) - "Generate byline for TOOT." +(defun mastodon-tl--byline (toot author-byline action-byline) + "Generate byline for TOOT. + +AUTHOR-BYLINE is function for adding the author portion of +the byline that takes one variable. +ACTION-BYLINE is a function for adding an action, such as boosting +favouriting and following to the byline. It also takes a single function. By default +it is `mastodon-tl--byline-boosted'" (let ((id (cdr (assoc 'id toot))) (parsed-time (date-to-time (mastodon-tl--field 'created_at toot))) (faved (equal 't (mastodon-tl--field 'favourited toot))) @@ -343,8 +349,8 @@ TIME-STAMP is assumed to be in the past." (when faved (format "(%s) " (propertize "F" 'face 'mastodon-boost-fave-face))) - (mastodon-tl--byline-author toot) - (mastodon-tl--byline-boosted toot) + (funcall author-byline toot) + (funcall action-byline toot) " " ;; TODO: Once we have a view for toot (responses etc.) make ;; this a tab stop and attach an action. @@ -535,26 +541,36 @@ message is a link which unhides/hides the main body." (mastodon-tl--render-text content toot) (mastodon-tl--media toot)))) -(defun mastodon-tl--toot (toot) - "Display TOOT content and byline." - (insert - (concat - ;; remove trailing whitespace +(defun mastodon-tl--insert-status (toot body author-byline action-byline) + "Display the content and byline of a timeline element. - (replace-regexp-in-string - "[\t\n ]*\\'" "" - (if (mastodon-tl--has-spoiler toot) - (mastodon-tl--spoiler toot) - (mastodon-tl--content toot))) - (mastodon-tl--byline toot) - "\n\n"))) +BODY will form the section of the toot above the byline. +AUTHOR-BYLINE is an optional function for adding the author portion of +the byline that takes one variable. By default it is `mastodon-tl--byline-author' +ACTION-BYLINE is also an optional function for adding an action, such as boosting +favouriting and following to the byline. It also takes a single function. By default +it is `mastodon-tl--byline-boosted'" + (insert + body + (mastodon-tl--byline toot author-byline action-byline) + "\n\n")) + +(defun mastodon-tl--toot(toot) + "Formats TOOT and insertes it into the buffer." + (mastodon-tl--insert-status + toot + (replace-regexp-in-string + "[\t\n ]*\\'" "" + (if (mastodon-tl--has-spoiler toot) + (mastodon-tl--spoiler toot) + (mastodon-tl--content toot))) + 'mastodon-tl--byline-author + 'mastodon-tl--byline-boosted)) (defun mastodon-tl--timeline (toots) "Display each toot in TOOTS." (mapc 'mastodon-tl--toot toots) (goto-char (point-min)) - (while (search-forward "\n\n\n | " nil t) - (replace-match "\n | ")) (when mastodon-tl--display-media-p (mastodon-media--inline-images))) @@ -653,10 +669,10 @@ webapp" (toot (mastodon-tl--property 'toot-json)) (context (mastodon-http--get-json url))) (when (member (cdr (assoc 'type toot)) '("reblog" "favourite")) - (setq toot (cdr(assoc 'status toot)))) + (setq toot (cdr (assoc 'status toot)))) (if (> (+ (length (cdr (assoc 'ancestors context))) (length (cdr (assoc 'descendants context)))) - 0) + 0) (with-output-to-temp-buffer buffer (switch-to-buffer buffer) (mastodon-mode) diff --git a/test/mastodon-tl-tests.el b/test/mastodon-tl-tests.el index 6e75d26..04f00e5 100644 --- a/test/mastodon-tl-tests.el +++ b/test/mastodon-tl-tests.el @@ -257,7 +257,9 @@ a string or a numeric." (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22") (should (string= (substring-no-properties - (mastodon-tl--byline mastodon-tl-test-base-toot)) + (mastodon-tl--byline mastodon-tl-test-base-toot + 'mastodon-tl--byline-author + 'mastodon-tl--byline-boosted)) " | Account 42 (@acct42@example.space) 2999-99-99 00:11:22 ------------"))))) @@ -272,7 +274,9 @@ a string or a numeric." (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22") (should (string= (substring-no-properties - (mastodon-tl--byline mastodon-tl-test-base-toot)) + (mastodon-tl--byline mastodon-tl-test-base-toot + 'mastodon-tl--byline-author + 'mastodon-tl--byline-boosted)) " | Account 42 (@acct42@example.space) 2999-99-99 00:11:22 ------------"))))) @@ -286,7 +290,10 @@ a string or a numeric." (mock (date-to-time timestamp) => '(22782 21551)) (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22") - (should (string= (substring-no-properties (mastodon-tl--byline toot)) + (should (string= (substring-no-properties + (mastodon-tl--byline toot + 'mastodon-tl--byline-author + 'mastodon-tl--byline-boosted)) " | (B) Account 42 (@acct42@example.space) 2999-99-99 00:11:22 ------------"))))) @@ -300,7 +307,10 @@ a string or a numeric." (mock (date-to-time timestamp) => '(22782 21551)) (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22") - (should (string= (substring-no-properties (mastodon-tl--byline toot)) + (should (string= (substring-no-properties + (mastodon-tl--byline toot + 'mastodon-tl--byline-author + 'mastodon-tl--byline-boosted)) " | (F) Account 42 (@acct42@example.space) 2999-99-99 00:11:22 ------------"))))) @@ -315,7 +325,10 @@ a string or a numeric." (mock (date-to-time timestamp) => '(22782 21551)) (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22") - (should (string= (substring-no-properties (mastodon-tl--byline toot)) + (should (string= (substring-no-properties + (mastodon-tl--byline toot + 'mastodon-tl--byline-author + 'mastodon-tl--byline-boosted)) " | (B) (F) Account 42 (@acct42@example.space) 2999-99-99 00:11:22 ------------"))))) @@ -335,7 +348,10 @@ a string or a numeric." (mock (date-to-time original-timestamp) => '(3 4)) (mock (format-time-string mastodon-toot-timestamp-format '(3 4)) => "original time") - (should (string= (substring-no-properties (mastodon-tl--byline toot)) + (should (string= (substring-no-properties + (mastodon-tl--byline toot + 'mastodon-tl--byline-author + 'mastodon-tl--byline-boosted)) " | Account 42 (@acct42@example.space) Boosted Account 43 (@acct43@example.space) original time ------------"))))) @@ -356,8 +372,10 @@ a string or a numeric." (mock (date-to-time original-timestamp) => '(3 4)) (mock (format-time-string mastodon-toot-timestamp-format '(3 4)) => "original time") - (should (string= (substring-no-properties (mastodon-tl--byline toot)) - " + (should (string= (substring-no-properties + (mastodon-tl--byline toot + 'mastodon-tl--byline-author + 'mastodon-tl--byline-boosted))" | Account 42 (@acct42@example.space) Boosted Account 43 (@acct43@example.space) original time ------------"))))) @@ -376,7 +394,10 @@ a string or a numeric." (mock (date-to-time original-timestamp) => '(3 4)) (mock (format-time-string mastodon-toot-timestamp-format '(3 4)) => "original time") - (should (string= (substring-no-properties (mastodon-tl--byline toot)) + (should (string= (substring-no-properties + (mastodon-tl--byline toot + 'mastodon-tl--byline-author + 'mastodon-tl--byline-boosted)) " | (B) (F) Account 42 (@acct42@example.space) Boosted Account 43 (@acct43@example.space) original time ------------"))))) @@ -390,7 +411,9 @@ a string or a numeric." (mock (current-time) => '(22782 22000)) (mock (format-time-string mastodon-toot-timestamp-format '(22782 21551)) => "2999-99-99 00:11:22") - (let* ((formatted-string (mastodon-tl--byline mastodon-tl-test-base-toot)) + (let* ((formatted-string (mastodon-tl--byline mastodon-tl-test-base-toot + 'mastodon-tl--byline-author + 'mastodon-tl--byline-boosted)) (timestamp-start (string-match "2999-99-99" formatted-string)) (properties (text-properties-at timestamp-start formatted-string))) (should (equal '(22782 21551) (plist-get properties 'timestamp))) |