From a6e43f8b4956e970b72f52e3a137e9a5cd43f2ed Mon Sep 17 00:00:00 2001 From: mousebot Date: Wed, 12 Jan 2022 15:11:44 +0100 Subject: keep mastodon-toot--max-toot-chars a number not a string. we use it as a number various times so let's leave it a number, then convert to string for display in toot info. --- lisp/mastodon-toot.el | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 22699f1..746b7d4 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -170,8 +170,7 @@ Valid values are \"direct\", \"private\" (followers-only), (alist-get 'statuses (alist-get 'configuration json-response)))))) - (setq mastodon-toot--max-toot-chars - (number-to-string max-chars)) + (setq mastodon-toot--max-toot-chars max-chars) (with-current-buffer "*new toot*" (mastodon-toot--update-status-fields)))) @@ -501,7 +500,7 @@ If media items have been attached and uploaded with (length mastodon-toot--media-attachment-ids))))) (message "Something is wrong with your uploads. Wait for them to complete or try again.")) ((and mastodon-toot--max-toot-chars - (> (length toot) (string-to-number mastodon-toot--max-toot-chars))) + (> (length toot) mastodon-toot--max-toot-chars)) (message "Looks like your toot is longer than that maximum allowed length.")) (empty-toot-p (message "Empty toot. Cowardly refusing to post this.")) @@ -857,7 +856,7 @@ REPLY-JSON is the full JSON of the toot being replied to." (list 'display (format "%s/%s characters" (- (point-max) (cdr header-region)) - mastodon-toot--max-toot-chars))) + (number-to-string mastodon-toot--max-toot-chars)))) (add-text-properties (car visibility-region) (cdr visibility-region) (list 'display (format "Visibility: %s" -- cgit v1.2.3 From 70546e4fd9951b31685a9063653b72b3ce6e44db Mon Sep 17 00:00:00 2001 From: mousebot Date: Sat, 15 Jan 2022 18:54:28 +0100 Subject: autoloads --- lisp/mastodon-notifications.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 1361099..c245edb 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -47,6 +47,8 @@ (autoload 'mastodon-tl--property "mastodon-tl.el") (autoload 'mastodon-tl--spoiler "mastodon-tl.el") (autoload 'mastodon-tl--toot-id "mastodon-tl.el") +(autoload 'mastodon-http--get-params-async-json "mastodon-http.el") +(defvar mastodon-tl--buffer-spec) (defvar mastodon-tl--display-media-p) (defvar mastodon-tl--buffer-spec) -- cgit v1.2.3 From 5994d01cf15800f274206819145cbf7ba176a007 Mon Sep 17 00:00:00 2001 From: mousebot Date: Sat, 15 Jan 2022 18:55:26 +0100 Subject: handle a buggy empty notification i received an notification (also in other clients/web interface) attached to no toot. these checks should allow notifications view to display without tripping up on any such vacant notifs from the server. --- lisp/mastodon-notifications.el | 3 ++- lisp/mastodon-tl.el | 35 ++++++++++++++++++----------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index c245edb..77d40a8 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -223,7 +223,8 @@ takes a single function. By default it is `mastodon-tl--byline-boosted'. ID is the notification's own id, which is attached as a property." - (mastodon-tl--insert-status toot body author-byline action-byline id)) + (when toot ; handle rare blank notif server bug + (mastodon-tl--insert-status toot body author-byline action-byline id))) (defun mastodon-notifications--by-type (note) "Filters NOTE for those listed in `mastodon-notifications--types-alist'." diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index cd27bd5..9b30a37 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -460,22 +460,23 @@ By default it is `mastodon-tl--byline-boosted'" The contents comes from the given TOOT which is used in parsing links in the text. If TOOT is nil no parsing occurs." - (with-temp-buffer - (insert string) - (let ((shr-use-fonts mastodon-tl--enable-proportional-fonts) - (shr-width (when mastodon-tl--enable-proportional-fonts - (- (window-width) 1)))) - (shr-render-region (point-min) (point-max))) - ;; Make all links a tab stop recognized by our own logic, make things point - ;; to our own logic (e.g. hashtags), and update keymaps where needed: - (when toot - (let (region) - (while (setq region (mastodon-tl--find-property-range - 'shr-url (or (cdr region) (point-min)))) - (mastodon-tl--process-link toot - (car region) (cdr region) - (get-text-property (car region) 'shr-url))))) - (buffer-string))) + (when string ; handle rare empty notif server bug + (with-temp-buffer + (insert string) + (let ((shr-use-fonts mastodon-tl--enable-proportional-fonts) + (shr-width (when mastodon-tl--enable-proportional-fonts + (- (window-width) 1)))) + (shr-render-region (point-min) (point-max))) + ;; Make all links a tab stop recognized by our own logic, make things point + ;; to our own logic (e.g. hashtags), and update keymaps where needed: + (when toot + (let (region) + (while (setq region (mastodon-tl--find-property-range + 'shr-url (or (cdr region) (point-min)))) + (mastodon-tl--process-link toot + (car region) (cdr region) + (get-text-property (car region) 'shr-url))))) + (buffer-string)))) (defun mastodon-tl--process-link (toot start end url) "Process link URL in TOOT as hashtag, userhandle, or normal link. @@ -1090,7 +1091,7 @@ NOTIFY is only non-nil when called by `mastodon-tl--follow-user'." ;; if unmuting/unblocking, we got handle from mute/block list (mastodon-profile--search-account-by-handle user-handle) - ;; if muting/blocking, we select from handles in current status + ;; if muting/blocking, we select from handles in current status (mastodon-profile--lookup-account-in-status user-handle (mastodon-profile--toot-json)))) (user-id (mastodon-profile--account-field account 'id)) -- cgit v1.2.3 From 54b7d1a60c590597355fb23cb2a660096640f1fd Mon Sep 17 00:00:00 2001 From: mousebot Date: Sun, 30 Jan 2022 10:19:50 +0100 Subject: autoload fix for mastodon-notifications--get; set interative to t to make `mastodon-notifications--get' available outside our keymap as it needs to be available to evil users and via M-x. otherwise there's no way to run it. --- lisp/mastodon-tl.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 9b30a37..8e2e027 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -56,7 +56,9 @@ (autoload 'mastodon-http--get-json-async "mastodon-http") (autoload 'mastodon-profile--lookup-account-in-status "mastodon-profile") (autoload 'mastodon-profile-mode "mastodon-profile") -(autoload 'mastodon-notifications--get "mastodon-notifications") +;; make notifications--get available via M-x and outside our keymap: +(autoload 'mastodon-notifications--get "mastodon-notifications" + "Display NOTIFICATIONS in buffer." t) ; interactive (defvar mastodon-instance-url) (defvar mastodon-toot-timestamp-format) (defvar shr-use-fonts) ;; declare it since Emacs24 didn't have this -- cgit v1.2.3 From 471d540c01ee45464bfc8a3d3cdcfaf91738ce99 Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 4 Feb 2022 13:00:02 +0100 Subject: update homepage and copyright boilerplate --- lisp/mastodon-async.el | 7 +++---- lisp/mastodon-auth.el | 2 +- lisp/mastodon-client.el | 2 +- lisp/mastodon-discover.el | 2 +- lisp/mastodon-http.el | 2 +- lisp/mastodon-inspect.el | 2 +- lisp/mastodon-media.el | 2 +- lisp/mastodon-notifications.el | 2 +- lisp/mastodon-profile.el | 2 +- lisp/mastodon-search.el | 7 +++---- lisp/mastodon-tl.el | 3 ++- lisp/mastodon-toot.el | 3 ++- lisp/mastodon.el | 2 +- 13 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lisp/mastodon-async.el b/lisp/mastodon-async.el index 6ff09e3..86547a1 100644 --- a/lisp/mastodon-async.el +++ b/lisp/mastodon-async.el @@ -1,12 +1,11 @@ ;;; mastodon-async.el --- Client for Mastodon -*- lexical-binding: t -*- -;; Copyright (C) 2017 Johnson Denen -;; Author: Johnson Denen -;; Alex J. Griffith +;; Copyright (C) 2017 Alex J. Griffith +;; Author: Alex J. Griffith ;; Maintainer: Marty Hiatt ;; Version: 0.10.0 ;; Package-Requires: ((emacs "27.1")) -;; Homepage: https://git.blast.noho.st/mouse/mastodon.el +;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 74d4404..e582e4f 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -5,7 +5,7 @@ ;; Maintainer: Marty Hiatt ;; Version: 0.10.0 ;; Package-Requires: ((emacs "27.1")) -;; Homepage: https://git.blast.noho.st/mouse/mastodon.el +;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el index b27d434..42e8b1f 100644 --- a/lisp/mastodon-client.el +++ b/lisp/mastodon-client.el @@ -5,7 +5,7 @@ ;; Maintainer: Marty Hiatt ;; Version: 0.10.0 ;; Package-Requires: ((emacs "27.1")) -;; Homepage: https://git.blast.noho.st/mouse/mastodon.el +;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-discover.el b/lisp/mastodon-discover.el index 10abc59..7046070 100644 --- a/lisp/mastodon-discover.el +++ b/lisp/mastodon-discover.el @@ -5,7 +5,7 @@ ;; Maintainer: Marty Hiatt ;; Version: 0.10.0 ;; Package-Requires: ((emacs "27.1")) -;; Homepage: https://git.blast.noho.st/mouse/mastodon.el +;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index f988e39..e288c18 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -5,7 +5,7 @@ ;; Maintainer: Marty Hiatt ;; Version: 0.10.0 ;; Package-Requires: ((emacs "27.1") (request "0.3.0")) -;; Homepage: https://git.blast.noho.st/mouse/mastodon.el +;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-inspect.el b/lisp/mastodon-inspect.el index b0270ee..15ee7ce 100644 --- a/lisp/mastodon-inspect.el +++ b/lisp/mastodon-inspect.el @@ -5,7 +5,7 @@ ;; Maintainer: Marty Hiatt ;; Version: 0.10.0 ;; Package-Requires: ((emacs "27.1")) -;; Homepage: https://git.blast.noho.st/mouse/mastodon.el +;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el index acce473..4e4a15d 100644 --- a/lisp/mastodon-media.el +++ b/lisp/mastodon-media.el @@ -5,7 +5,7 @@ ;; Maintainer: Marty Hiatt ;; Version: 0.10.0 ;; Package-Requires: ((emacs "27.1")) -;; Homepage: https://git.blast.noho.st/mouse/mastodon.el +;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 77d40a8..ce26924 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -5,7 +5,7 @@ ;; Maintainer: Marty Hiatt ;; Version: 0.10.0 ;; Package-Requires: ((emacs "27.1")) -;; Homepage: https://git.blast.noho.st/mouse/mastodon.el +;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 21b40b3..436ba87 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -5,7 +5,7 @@ ;; Maintainer: Marty Hiatt ;; Version: 0.10.0 ;; Package-Requires: ((emacs "27.1") (seq "1.0")) -;; Homepage: https://git.blast.noho.st/mouse/mastodon.el +;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 78c2ab4..5fee328 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -1,12 +1,11 @@ ;;; mastodon-search.el --- Search functions for mastodon.el -*- lexical-binding: t -*- -;; Copyright (C) 2017-2019 Johnson Denen -;; Author: Johnson Denen -;; Marty Hiatt +;; Copyright (C) 2017-2019 Marty Hiatt +;; Author: Marty Hiatt ;; Maintainer: Marty Hiatt ;; Version: 0.10.0 ;; Package-Requires: ((emacs "27.1")) -;; Homepage: https://git.blast.noho.st/mouse/mastodon.el +;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 8e2e027..639b497 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2,10 +2,11 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen +;; Marty Hiatt ;; Maintainer: Marty Hiatt ;; Version: 0.10.0 ;; Package-Requires: ((emacs "27.1")) -;; Homepage: https://git.blast.noho.st/mouse/mastodon.el +;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 746b7d4..3978e12 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -2,10 +2,11 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen +;; Marty Hiatt ;; Maintainer: Marty Hiatt ;; Version: 0.10.0 ;; Package-Requires: ((emacs "27.1")) -;; Homepage: https://git.blast.noho.st/mouse/mastodon.el +;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon.el b/lisp/mastodon.el index f65a86d..ab199f9 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -5,7 +5,7 @@ ;; Maintainer: Marty Hiatt ;; Version: 0.10.0 ;; Package-Requires: ((emacs "27.1") (request "0.3.2") (seq "1.0")) -;; Homepage: https://git.blast.noho.st/mouse/mastodon.el +;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. -- cgit v1.2.3 From 6a164669e0bffed67ad59c206f13651a67456127 Mon Sep 17 00:00:00 2001 From: mousebot Date: Sat, 5 Feb 2022 12:26:14 +0100 Subject: revert require of mastodon-toot to autoloads - use (autoload) call in mastodon.el for functions - use autoload cookie in mastodon-tool.el for customize options. --- lisp/mastodon-toot.el | 6 ++++++ lisp/mastodon.el | 22 +++++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 3978e12..b50cbf6 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -70,11 +70,13 @@ (autoload 'mastodon-tl--toot-id "mastodon-tl") (autoload 'mastodon-toot "mastodon") +;;;###autoload (defgroup mastodon-toot nil "Tooting in Mastodon." :prefix "mastodon-toot-" :group 'mastodon) +;;;###autoload (defcustom mastodon-toot--default-visibility "public" "The default visibility for new toots. @@ -87,16 +89,19 @@ followers-only), or \"direct\"." (const :tag "followers only" "private") (const :tag "direct" "direct"))) +;;;###autoload (defcustom mastodon-toot--default-media-directory "~/" "The default directory when prompting for a media file to upload." :group 'mastodon-toot :type 'string) +;;;###autoload (defcustom mastodon-toot--attachment-height 80 "Height of the attached images preview in the toot draft buffer." :group 'mastodon-toot :type 'integer) +;;;###autoload (defcustom mastodon-toot--enable-completion-for-mentions (if (require 'company nil :noerror) "following" "off") "Whether to enable company completion for mentions. @@ -110,6 +115,7 @@ This is only used if company mode is installed." (const :tag "following only" "following") (const :tag "all users" "all"))) +;;;###autoload (defcustom mastodon-toot--enable-custom-instance-emoji nil "Whether to enable your instance's custom emoji by default." :group 'mastodon-toot diff --git a/lisp/mastodon.el b/lisp/mastodon.el index ab199f9..bd0a557 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -32,8 +32,6 @@ ;;; Code: (require 'cl-lib) ; for `cl-some' call in mastodon -;; hack to make mastodon-toot customizes visible prior to running mastodon-toot: -(require 'mastodon-toot) (declare-function discover-add-context-menu "discover") (declare-function emojify-mode "emojify") @@ -54,10 +52,10 @@ (autoload 'mastodon-profile--get-toot-author "mastodon-profile") (autoload 'mastodon-profile--make-author-buffer "mastodon-profile") (autoload 'mastodon-profile--show-user "mastodon-profile") -;; (autoload 'mastodon-toot--compose-buffer "mastodon-toot") -;; (autoload 'mastodon-toot--reply "mastodon-toot") -;; (autoload 'mastodon-toot--toggle-boost "mastodon-toot") -;; (autoload 'mastodon-toot--toggle-favourite "mastodon-toot") +(autoload 'mastodon-toot--compose-buffer "mastodon-toot") +(autoload 'mastodon-toot--reply "mastodon-toot") +(autoload 'mastodon-toot--toggle-boost "mastodon-toot") +(autoload 'mastodon-toot--toggle-favourite "mastodon-toot") (autoload 'mastodon-discover "mastodon-discover") (autoload 'mastodon-tl--block-user "mastodon-tl") @@ -72,9 +70,9 @@ (autoload 'mastodon-notifications--follow-request-accept "mastodon-notifications") (autoload 'mastodon-notifications--follow-request-reject "mastodon-notifications") (autoload 'mastodon-search--search-query "mastodon-search") -;; (autoload 'mastodon-toot--delete-toot "mastodon-toot") -;; (autoload 'mastodon-toot--copy-toot-url "mastodon-toot") -;; (autoload 'mastodon-toot--pin-toot-toggle "mastodon-toot") +(autoload 'mastodon-toot--delete-toot "mastodon-toot") +(autoload 'mastodon-toot--copy-toot-url "mastodon-toot") +(autoload 'mastodon-toot--pin-toot-toggle "mastodon-toot") (autoload 'mastodon-auth--get-account-name "mastodon-auth") ;; (autoload 'mastodon-async--stream-federated "mastodon-async") ;; (autoload 'mastodon-async--stream-local "mastodon-async") @@ -84,9 +82,11 @@ (autoload 'mastodon-profile--update-user-profile-note "mastodon-profile") (autoload 'mastodon-auth--user-acct "mastodon-auth") (autoload 'mastodon-tl--poll-vote "mastodon-http") -;; (autoload 'mastodon-toot--delete-and-redraft-toot "mastodon-toot") +(autoload 'mastodon-toot--delete-and-redraft-toot "mastodon-toot") (autoload 'mastodon-profile--view-bookmarks "mastodon-profile") -;; (autoload 'mastodon-toot--bookmark-toot-toggle "mastodon-toot") +(autoload 'mastodon-toot--bookmark-toot-toggle "mastodon-toot") +(autoload 'mastodon-toot--enable-custom-emoji "mastodon-toot") +(defvar mastodon-toot--enable-custom-instance-emoji) (defgroup mastodon nil "Interface with Mastodon." -- cgit v1.2.3 From 2f58b4fd7de85367156caa9f39ac46e54f262fb9 Mon Sep 17 00:00:00 2001 From: mousebot Date: Sat, 5 Feb 2022 14:31:46 +0100 Subject: don't call mastodon-profile-mode in profile--view-follow-requests it's now called in tl-init* for follow requests inits. calling it here also enables profile mode in whatever bufer view-follow-reqs was called from, which is useless. --- lisp/mastodon-profile.el | 1 - 1 file changed, 1 deletion(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 436ba87..c04c40b 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -146,7 +146,6 @@ extra keybindings." (defun mastodon-profile--view-follow-requests () "Open a new buffer displaying the user's follow requests." (interactive) - (mastodon-profile-mode) (mastodon-tl--init "follow-requests" "follow_requests" 'mastodon-profile--add-author-bylines)) -- cgit v1.2.3 From 847b50f315ff96988927e8198eee2517a15cca7b Mon Sep 17 00:00:00 2001 From: mousebot Date: Sat, 5 Feb 2022 14:39:59 +0100 Subject: message for no follow reqs in add-author-bylines fun --- lisp/mastodon-profile.el | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index c04c40b..5811a4a 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -385,20 +385,22 @@ FIELD is used to identify regions under 'account" (defun mastodon-profile--add-author-bylines (tootv) "Convert TOOTV into a author-bylines and insert." (let ((inhibit-read-only t)) - (mapc (lambda (toot) - (let ((start-pos (point))) - (insert "\n" - (propertize - (mastodon-tl--byline-author `((account . ,toot))) - 'byline 't - 'toot-id (alist-get 'id toot) - 'base-toot-id (mastodon-tl--toot-id toot) - 'toot-json toot)) - (mastodon-media--inline-images start-pos (point)) - (insert "\n" - (mastodon-tl--render-text (alist-get 'note toot) nil) - "\n"))) - tootv))) + (if (equal tootv '[]) + (message "Looks like you have no follow requests for the moment.") + (mapc (lambda (toot) + (let ((start-pos (point))) + (insert "\n" + (propertize + (mastodon-tl--byline-author `((account . ,toot))) + 'byline 't + 'toot-id (alist-get 'id toot) + 'base-toot-id (mastodon-tl--toot-id toot) + 'toot-json toot)) + (mastodon-media--inline-images start-pos (point)) + (insert "\n" + (mastodon-tl--render-text (alist-get 'note toot) nil) + "\n"))) + tootv)))) (defun mastodon-profile--search-account-by-handle (handle) "Return an account based on a user's HANDLE. -- cgit v1.2.3 From ab14b07e054bb72b4780ae36a16257b9301629d0 Mon Sep 17 00:00:00 2001 From: mousebot Date: Sat, 5 Feb 2022 15:14:42 +0100 Subject: place point on byline of first toot on timeline load. --- lisp/mastodon-tl.el | 1 + 1 file changed, 1 insertion(+) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 639b497..d3ab56b 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1339,6 +1339,7 @@ JSON is the data returned from the server." mastodon-tl--timestamp-next-update (time-add (current-time) (seconds-to-time 300))) (funcall update-function json)) + (mastodon-tl--goto-next-toot) (mastodon-mode) (when (equal endpoint "follow_requests") (mastodon-profile-mode)) -- cgit v1.2.3 From 7e21eeabc68102e4bae6c5729a69daf5b9e2aca4 Mon Sep 17 00:00:00 2001 From: mousebot Date: Sat, 5 Feb 2022 15:15:05 +0100 Subject: message when notificiations--timeline returns nothing. --- lisp/mastodon-notifications.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index ce26924..5e3305a 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -238,8 +238,10 @@ ID is the notification's own id, which is attached as a property." (defun mastodon-notifications--timeline (json) "Format JSON in Emacs buffer." - (mapc #'mastodon-notifications--by-type json) - (goto-char (point-min))) + (if (equal json '[]) + (message "Looks like you have no notifications for the moment.") + (mapc #'mastodon-notifications--by-type json) + (goto-char (point-min)))) (defun mastodon-notifications--get () "Display NOTIFICATIONS in buffer." -- cgit v1.2.3 From 4bd42aa4c52d709a512be94524fe1182eac9c4f6 Mon Sep 17 00:00:00 2001 From: mousebot Date: Mon, 7 Feb 2022 16:54:54 +0100 Subject: implement follow suggestions. this factors out display of accounts from mastodon-search--search-query into mastodon-search--insert-users-propertized. mastodon-tl--get-follow-suggestions is the fun to view suggestions. seeing as this allows easy display of profile note under the account handle, i also added this display to --search-query, but it cd be easily disabled by calling --insert-users-propertized without its second arg. --- lisp/mastodon-search.el | 40 +++++++++++++++++++++++++--------------- lisp/mastodon-tl.el | 20 ++++++++++++++++++++ 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 5fee328..6c85965 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -97,19 +97,7 @@ Returns a nested list containing user handle, display name, and URL." " USERS\n" " ------------\n\n") 'success)) - (mapc (lambda (el) - (insert (propertize (car el) 'face 'mastodon-display-name-face) - " : \n : " - (propertize (concat "@" (car (cdr el))) - 'face 'mastodon-handle-face - 'mouse-face 'highlight - 'mastodon-tab-stop 'user-handle - 'keymap mastodon-tl--link-keymap - 'mastodon-handle (concat "@" (car (cdr el))) - 'help-echo (concat "Browse user profile of @" (car (cdr el)))) - " : \n" - "\n")) - user-ids) + (mastodon-search--insert-users-propertized user-ids :note) ;; hashtag results: (insert (mastodon-tl--set-face (concat "\n ------------\n" @@ -135,11 +123,33 @@ Returns a nested list containing user handle, display name, and URL." (mapc 'mastodon-tl--toot toots-list-json) (goto-char (point-min)))))) +(defun mastodon-search--insert-users-propertized (users &optional note) + "Insert USERS list into the buffer. +If NOTE is non-nil, include user's profile note. +This is also called by `mastodon-tl--get-follow-suggestions'." + (mapc (lambda (el) + (insert (propertize (car el) 'face 'mastodon-display-name-face) + " : \n : " + (propertize (concat "@" (car (cdr el))) + 'face 'mastodon-handle-face + 'mouse-face 'highlight + 'mastodon-tab-stop 'user-handle + 'keymap mastodon-tl--link-keymap + 'mastodon-handle (concat "@" (car (cdr el))) + 'help-echo (concat "Browse user profile of @" (car (cdr el)))) + " : \n" + (if note + (mastodon-tl--render-text (cadddr el) nil) + "") + "\n")) + users)) + (defun mastodon-search--get-user-info (account) - "Get user handle, display name and account URL from ACCOUNT." + "Get user handle, display name, account URL and profile note from ACCOUNT." (list (alist-get 'display_name account) (alist-get 'acct account) - (alist-get 'url account))) + (alist-get 'url account) + (alist-get 'note account))) (defun mastodon-search--get-hashtag-info (tag) "Get hashtag name and URL from TAG." diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index d3ab56b..13c6729 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -60,6 +60,7 @@ ;; make notifications--get available via M-x and outside our keymap: (autoload 'mastodon-notifications--get "mastodon-notifications" "Display NOTIFICATIONS in buffer." t) ; interactive +(autoload 'mastodon-search--insert-users-propertized "mastodon-search") (defvar mastodon-instance-url) (defvar mastodon-toot-timestamp-format) (defvar shr-use-fonts) ;; declare it since Emacs24 didn't have this @@ -991,6 +992,25 @@ webapp" (alist-get 'descendants context))))) (message "No Thread!")))) +(defun mastodon-tl--get-follow-suggestions () +"Display a buffer of suggested accounts to follow." + (interactive) + (let* ((buffer (format "*mastodon-follow-suggestions*")) + (response + (mastodon-http--get-json + (mastodon-http--api "suggestions"))) + (users (mapcar 'mastodon-search--get-user-info response))) + (with-output-to-temp-buffer buffer + (let ((inhibit-read-only t)) + (switch-to-buffer buffer) + (mastodon-mode) + (insert (mastodon-tl--set-face + (concat "\n ------------\n" + " SUGGESTED ACCOUNTS\n" + " ------------\n\n") + 'success)) + (mastodon-search--insert-users-propertized users :note))))) + (defun mastodon-tl--follow-user (user-handle &optional notify) "Query for USER-HANDLE from current status and follow that user. If NOTIFY is \"true\", enable notifications when that user posts. -- cgit v1.2.3 From 43d90313f2e879cd37b7123b87dcf53819605128 Mon Sep 17 00:00:00 2001 From: mousebot Date: Mon, 7 Feb 2022 19:52:35 +0100 Subject: add go to next toot to tl--thread fix go to first toot on thread load --- lisp/mastodon-tl.el | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 13c6729..8921259 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -977,19 +977,21 @@ webapp" (if (> (+ (length (alist-get 'ancestors context)) (length (alist-get 'descendants context))) 0) - (with-output-to-temp-buffer buffer - (switch-to-buffer buffer) - (mastodon-mode) - (setq mastodon-tl--buffer-spec - `(buffer-name ,buffer - endpoint ,(format "statuses/%s/context" id) - update-function - (lambda(toot) (message "END of thread.")))) - (let ((inhibit-read-only t)) - (mastodon-tl--timeline (vconcat - (alist-get 'ancestors context) - `(,toot) - (alist-get 'descendants context))))) + (progn + (with-output-to-temp-buffer buffer + (switch-to-buffer buffer) + (mastodon-mode) + (setq mastodon-tl--buffer-spec + `(buffer-name ,buffer + endpoint ,(format "statuses/%s/context" id) + update-function + (lambda (toot) (message "END of thread.")))) + (let ((inhibit-read-only t)) + (mastodon-tl--timeline (vconcat + (alist-get 'ancestors context) + `(,toot) + (alist-get 'descendants context))))) + (mastodon-tl--goto-next-toot)) (message "No Thread!")))) (defun mastodon-tl--get-follow-suggestions () -- cgit v1.2.3 From 16685d4e3fb7fce2011d751fc26661aa41ddd3aa Mon Sep 17 00:00:00 2001 From: mousebot Date: Mon, 7 Feb 2022 19:53:42 +0100 Subject: --search-accounts-query use http--api --- lisp/mastodon-search.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 6c85965..8c654cc 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -57,7 +57,7 @@ "Prompt for a search QUERY and return accounts synchronously. Returns a nested list containing user handle, display name, and URL." (interactive "sSearch mastodon for: ") - (let* ((url (format "%s/api/v1/accounts/search" mastodon-instance-url)) + (let* ((url (mastodon-http--api "accounts/search")) ;; (buffer (format "*mastodon-search-%s*" query)) (response (if (equal mastodon-toot--enable-completion-for-mentions "following") (mastodon-http--get-search-json url query "following=true") -- cgit v1.2.3 From a7aaba52da9730f29fe796e242c6ee5c75f5f48c Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 11 Feb 2022 18:29:14 +0100 Subject: revert to requiring mastodon toot we always need all the funs for operating on individual toots so this is best. Revert "revert require of mastodon-toot to autoloads" This reverts commit 6a164669e0bffed67ad59c206f13651a67456127. --- lisp/mastodon-toot.el | 6 ------ lisp/mastodon.el | 21 ++++++++++----------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index b50cbf6..3978e12 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -70,13 +70,11 @@ (autoload 'mastodon-tl--toot-id "mastodon-tl") (autoload 'mastodon-toot "mastodon") -;;;###autoload (defgroup mastodon-toot nil "Tooting in Mastodon." :prefix "mastodon-toot-" :group 'mastodon) -;;;###autoload (defcustom mastodon-toot--default-visibility "public" "The default visibility for new toots. @@ -89,19 +87,16 @@ followers-only), or \"direct\"." (const :tag "followers only" "private") (const :tag "direct" "direct"))) -;;;###autoload (defcustom mastodon-toot--default-media-directory "~/" "The default directory when prompting for a media file to upload." :group 'mastodon-toot :type 'string) -;;;###autoload (defcustom mastodon-toot--attachment-height 80 "Height of the attached images preview in the toot draft buffer." :group 'mastodon-toot :type 'integer) -;;;###autoload (defcustom mastodon-toot--enable-completion-for-mentions (if (require 'company nil :noerror) "following" "off") "Whether to enable company completion for mentions. @@ -115,7 +110,6 @@ This is only used if company mode is installed." (const :tag "following only" "following") (const :tag "all users" "all"))) -;;;###autoload (defcustom mastodon-toot--enable-custom-instance-emoji nil "Whether to enable your instance's custom emoji by default." :group 'mastodon-toot diff --git a/lisp/mastodon.el b/lisp/mastodon.el index bd0a557..a52bf41 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -32,6 +32,7 @@ ;;; Code: (require 'cl-lib) ; for `cl-some' call in mastodon +(require 'mastodon-toot) (declare-function discover-add-context-menu "discover") (declare-function emojify-mode "emojify") @@ -52,10 +53,10 @@ (autoload 'mastodon-profile--get-toot-author "mastodon-profile") (autoload 'mastodon-profile--make-author-buffer "mastodon-profile") (autoload 'mastodon-profile--show-user "mastodon-profile") -(autoload 'mastodon-toot--compose-buffer "mastodon-toot") -(autoload 'mastodon-toot--reply "mastodon-toot") -(autoload 'mastodon-toot--toggle-boost "mastodon-toot") -(autoload 'mastodon-toot--toggle-favourite "mastodon-toot") +;; (autoload 'mastodon-toot--compose-buffer "mastodon-toot") +;; (autoload 'mastodon-toot--reply "mastodon-toot") +;; (autoload 'mastodon-toot--toggle-boost "mastodon-toot") +;; (autoload 'mastodon-toot--toggle-favourite "mastodon-toot") (autoload 'mastodon-discover "mastodon-discover") (autoload 'mastodon-tl--block-user "mastodon-tl") @@ -70,9 +71,9 @@ (autoload 'mastodon-notifications--follow-request-accept "mastodon-notifications") (autoload 'mastodon-notifications--follow-request-reject "mastodon-notifications") (autoload 'mastodon-search--search-query "mastodon-search") -(autoload 'mastodon-toot--delete-toot "mastodon-toot") -(autoload 'mastodon-toot--copy-toot-url "mastodon-toot") -(autoload 'mastodon-toot--pin-toot-toggle "mastodon-toot") +;; (autoload 'mastodon-toot--delete-toot "mastodon-toot") +;; (autoload 'mastodon-toot--copy-toot-url "mastodon-toot") +;; (autoload 'mastodon-toot--pin-toot-toggle "mastodon-toot") (autoload 'mastodon-auth--get-account-name "mastodon-auth") ;; (autoload 'mastodon-async--stream-federated "mastodon-async") ;; (autoload 'mastodon-async--stream-local "mastodon-async") @@ -82,11 +83,9 @@ (autoload 'mastodon-profile--update-user-profile-note "mastodon-profile") (autoload 'mastodon-auth--user-acct "mastodon-auth") (autoload 'mastodon-tl--poll-vote "mastodon-http") -(autoload 'mastodon-toot--delete-and-redraft-toot "mastodon-toot") +;; (autoload 'mastodon-toot--delete-and-redraft-toot "mastodon-toot") (autoload 'mastodon-profile--view-bookmarks "mastodon-profile") -(autoload 'mastodon-toot--bookmark-toot-toggle "mastodon-toot") -(autoload 'mastodon-toot--enable-custom-emoji "mastodon-toot") -(defvar mastodon-toot--enable-custom-instance-emoji) +;; (autoload 'mastodon-toot--bookmark-toot-toggle "mastodon-toot") (defgroup mastodon nil "Interface with Mastodon." -- cgit v1.2.3 From 6621f981f318f9abdbf2182fa3385374fa23affc Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 11 Feb 2022 18:50:30 +0100 Subject: fix search-get-user-info test broken by follow suggestions --- test/mastodon-search-tests.el | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/mastodon-search-tests.el b/test/mastodon-search-tests.el index 996f786..e6d4cdb 100644 --- a/test/mastodon-search-tests.el +++ b/test/mastodon-search-tests.el @@ -126,7 +126,10 @@ (should (equal (mastodon-search--get-user-info mastodon-search--single-account-query) - '(": ( ) { : | : & } ; :" "mousebot" "https://todon.nl/@mousebot")))) + '(": ( ) { : | : & } ; :" + "mousebot" + "https://todon.nl/@mousebot" + "

poetry, writing, dmt, desertion, trash, black metal, translation, hegel, language, autonomia....

https://anarchive.mooo.com
https://pleasantlybabykid.tumblr.com/
IG: https://bibliogram.snopyta.org/u/martianhiatus
photos alt: @goosebot
git: https://git.blast.noho.st/mouse

want to trade chapbooks or zines? hmu!

he/him or they/them

")))) (ert-deftest mastodon-search--get-hashtag-info () "Should build a list of hashtag name and URL." -- cgit v1.2.3 From e5d73624023cb9bf0ec929985f35e935090b40f0 Mon Sep 17 00:00:00 2001 From: Holger Dürer Date: Sat, 12 Feb 2022 15:14:40 +0100 Subject: Fix the timers for auto-updating of relative timestamps. I have no idea how this ever worked, already the original commit (https://github.com/mooseyboots/mastodon.el/commit/746694f0ea75f5fa76739d49509836ccd67d7d65?utm_source=pocket_mylist) seems to have passed a time instead of seconds. The docs for `run-at-time` (https://www.gnu.org/software/emacs/manual/html_node/elisp/Timers.html) make it clear that this cannot work. Now we keep the absolute times but upon calling `run-at-time` we convert that to relative seconds from now. --- lisp/mastodon-tl.el | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 8921259..cdb4aa2 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1269,7 +1269,7 @@ is a no-op." ;; We need to re-schedule for an earlier time (cancel-timer mastodon-tl--timestamp-update-timer) (setq mastodon-tl--timestamp-update-timer - (run-at-time this-update + (run-at-time (time-to-seconds (time-subtract this-update (current-time))) nil ;; don't repeat #'mastodon-tl--update-timestamps-callback (current-buffer) nil))))))) @@ -1322,7 +1322,9 @@ from the start if it is nil." (copy-marker previous-timestamp)) ;; otherwise we are done for now; schedule a new run for when needed (setq mastodon-tl--timestamp-update-timer - (run-at-time mastodon-tl--timestamp-next-update + (run-at-time (time-to-seconds + (time-subtract mastodon-tl--timestamp-next-update + (current-time))) nil ;; don't repeat #'mastodon-tl--update-timestamps-callback buffer nil)))))))) @@ -1372,7 +1374,9 @@ JSON is the data returned from the server." update-function ,update-function) mastodon-tl--timestamp-update-timer (when mastodon-tl--enable-relative-timestamps - (run-at-time mastodon-tl--timestamp-next-update + (run-at-time (time-to-seconds + (time-subtract mastodon-tl--timestamp-next-update + (current-time))) nil ;; don't repeat #'mastodon-tl--update-timestamps-callback (current-buffer) @@ -1402,7 +1406,9 @@ Runs synchronously." ,update-function) mastodon-tl--timestamp-update-timer (when mastodon-tl--enable-relative-timestamps - (run-at-time mastodon-tl--timestamp-next-update + (run-at-time (time-to-seconds + (time-subtract mastodon-tl--timestamp-next-update + (current-time))) nil ;; don't repeat #'mastodon-tl--update-timestamps-callback (current-buffer) -- cgit v1.2.3 From d23331f89d2cae54636dc87a49a237d8587f1766 Mon Sep 17 00:00:00 2001 From: Holger Dürer Date: Sat, 12 Feb 2022 16:40:19 +0100 Subject: Fix the timer test that was broken with the recent timer fix. When we corrected the time arg for `run-at-time` we forgot to update the corresponding test which was strictly checking the time arg. --- test/mastodon-tl-tests.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mastodon-tl-tests.el b/test/mastodon-tl-tests.el index dd07416..a569c89 100644 --- a/test/mastodon-tl-tests.el +++ b/test/mastodon-tl-tests.el @@ -559,7 +559,7 @@ a string or a numeric." (mock (mastodon-tl--relative-time-details 'fake-timestamp) => (cons "xxx ago" soon-in-the-future)) (mock (cancel-timer 'initial-timer)) - (mock (run-at-time soon-in-the-future nil + (mock (run-at-time * nil #'mastodon-tl--update-timestamps-callback (current-buffer) nil) => 'new-timer) -- cgit v1.2.3 From 72eaa2e06086fa3c9a34b2e51a153b55b6e1a159 Mon Sep 17 00:00:00 2001 From: Holger Dürer Date: Sun, 14 Nov 2021 20:55:17 +0100 Subject: Add tests for mastodon-profile. These are completely missing so far so let's get some things added. --- test/mastodon-profile-tests.el | 288 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 288 insertions(+) create mode 100644 test/mastodon-profile-tests.el diff --git a/test/mastodon-profile-tests.el b/test/mastodon-profile-tests.el new file mode 100644 index 0000000..ca323ea --- /dev/null +++ b/test/mastodon-profile-tests.el @@ -0,0 +1,288 @@ +;;; mastodon-profile-test.el --- Tests for mastodon-profile.el -*- lexical-binding: nil -*- + +(require 'el-mock) + +(defconst gargron-profile-json + '((id . "1") + (username . "Gargron") + (acct . "Gargron") + (display_name . "Eugen") + (locked . :json-false) + (bot . :json-false) + (discoverable . t) + (group . :json-false) + (created_at . "2016-03-16T00:00:00.000Z") + (note . "

Developer of Mastodon and administrator of mastodon.social. I post service announcements, development updates, and personal stuff.

") + (url . "https://mastodon.social/@Gargron") + (avatar . "https://files.mastodon.social/accounts/avatars/000/000/001/original/d96d39a0abb45b92.jpg") + (avatar_static . "https://files.mastodon.social/accounts/avatars/000/000/001/original/d96d39a0abb45b92.jpg") + (header . "https://files.mastodon.social/accounts/headers/000/000/001/original/c91b871f294ea63e.png") + (header_static . "https://files.mastodon.social/accounts/headers/000/000/001/original/c91b871f294ea63e.png") + (followers_count . 470905) + (following_count . 451) + (statuses_count . 70741) + (last_status_at . "2021-11-14") + (emojis . []) + (fields . [((name . "Patreon") + (value . "https://www.patreon.com/mastodon") + (verified_at)) + ((name . "Homepage") + (value . "https://zeonfederated.com") + (verified_at . "2019-07-15T18:29:57.191+00:00"))]))) + +(defconst ccc-profile-json + '((id . "369027") + (username . "CCC") + (acct . "CCC@social.bau-ha.us") + (display_name . "") + (locked . :json-false) + (bot . :json-false) + (discoverable . :json-false) + (group . :json-false) + (created_at . "2018-06-03T00:00:00.000Z") + (note . "

https://www.ccc.de/

") + (url . "https://social.bau-ha.us/@CCC") + (avatar . "https://files.mastodon.social/cache/accounts/avatars/000/369/027/original/6cfeb310f40e041a.jpg") + (avatar_static . "https://files.mastodon.social/cache/accounts/avatars/000/369/027/original/6cfeb310f40e041a.jpg") + (header . "https://files.mastodon.social/cache/accounts/headers/000/369/027/original/0d20bef6131b8139.jpg") + (header_static . "https://files.mastodon.social/cache/accounts/headers/000/369/027/original/0d20bef6131b8139.jpg") + (followers_count . 2733) + (following_count . 120) + (statuses_count . 1357) + (last_status_at . "2021-11-02") + (emojis . []) + (fields . []))) + +(defconst gargon-statuses-json + `[((id . "123456789012345678") + (created_at . "2021-11-11T11:11:11.111Z") + (in_reply_to_id) + (in_reply_to_account_id) + (sensitive . :json-false) + (spoiler_text . "") + (visibility . "public") + (language) + (uri . "https://mastodon.social/users/Gargron/statuses/123456789012345678/activity") + (url . "https://mastodon.social/users/Gargron/statuses/123456789012345678/activity") + (replies_count . 0) + (reblogs_count . 0) + (favourites_count . 0) + (favourited . :json-false) + (reblogged . :json-false) + (muted . :json-false) + (bookmarked . :json-false) + (content . "

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.

") + (reblog) + (application) + (account ,@gargron-profile-json) + (media_attachments . []) + (mentions . []) + (tags . []) + (emojis . []) + (card) + (poll)) + ((id . "107279356043066700") + (created_at . "2021-11-11T00:00:00.000Z") + (in_reply_to_id) + (in_reply_to_account_id) + (sensitive . :json-false) + (spoiler_text . "") + (visibility . "public") + (language . "en") + (uri . "https://mastodon.social/users/Gargron/statuses/107279356043066700") + (url . "https://mastodon.social/@Gargron/107279356043066700") + (replies_count . 0) + (reblogs_count . 2) + (favourites_count . 0) + (favourited . :json-false) + (reblogged . :json-false) + (muted . :json-false) + (bookmarked . :json-false) + (content . "

@CCC At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

") + (reblog) + (application + (name . "Web") + (website)) + (account ,@gargron-profile-json) + (media_attachments . []) + (mentions . [((id . "369027") + (username . "CCC") + (url . "https://social.bau-ha.us/@CCC") + (acct . "CCC@social.bau-ha.us"))]) + (tags . []) + (emojis . []) + (card) + (poll))]) + +(ert-deftest mastodon-profile--add-author-bylines () + "Should correctly format short infos about one account. + +When formatting Gargon's state we want to see +- the short description of that profile, +- the url of the avatar (yet to be loaded) +- the info attached to the name" + (with-mock + ;; Don't start any image loading: + (mock (mastodon-media--inline-images * *) => nil) + ;; Let's not do formatting as that makes it hard to not rely on + ;; window width and reflowing the text. + (mock (shr-render-region * *) => nil) + (if (version< emacs-version "27.1") + (mock (image-type-available-p 'imagemagick) => t) + (mock (image-transforms-p) => t)) + + (with-temp-buffer + (let ((mastodon-tl--show-avatars t) + (mastodon-tl--display-media-p t)) + (mastodon-profile--add-author-bylines (list gargron-profile-json))) + + (should + (equal + (buffer-substring-no-properties (point-min) (point-max)) + "\n Eugen (@Gargron)\n

Developer of Mastodon and administrator of mastodon.social. I post service announcements, development updates, and personal stuff.

\n")) + + ;; Check the avatar at pos 2 + (should + (equal + (get-text-property 2 'media-url) + "https://files.mastodon.social/accounts/avatars/000/000/001/original/d96d39a0abb45b92.jpg")) + (should + (equal + (get-text-property 2 'media-state) + 'needs-loading)) + + ;; Check the byline state + (should + (equal + (get-text-property 4 'byline) + t)) + (should + (equal + (get-text-property 4 'toot-id) + (alist-get 'id gargron-profile-json))) + (should + (equal + (get-text-property 4 'toot-json) + gargron-profile-json))))) + +(ert-deftest mastodon-profile--search-account-by-handle--removes-at () + "Should ignore a leading at-sign in user handle. + +The search will happen as if called without the \"@\"." + (with-mock + + (mock (mastodon-http--get-json + "https://instance.url/api/v1/accounts/search?q=gargron")) + + (let ((mastodon-instance-url "https://instance.url")) + ;; We don't check anything from the return value. We only care + ;; that the mocked fetch was called with the expected URL. + (mastodon-profile--search-account-by-handle "@gargron")))) + +(ert-deftest mastodon-profile--search-account-by-handle--filters-out-false-results () + "Should ignore results that don't match the searched handle." + (with-mock + (mock (mastodon-http--get-json *) + => + (vector ccc-profile-json gargron-profile-json)) + + (let ((mastodon-instance-url "https://instance.url")) + (should + (equal + (mastodon-profile--search-account-by-handle "Gargron") + gargron-profile-json))))) + +(ert-deftest mastodon-profile--search-account-by-handle--filtering-is-case-sensitive () + "Should ignore results that don't match the searched handle with exact case. + +TODO: We need to decide if this is actually desired or not." + (with-mock + (mock (mastodon-http--get-json *) => (vector gargron-profile-json)) + + (let ((mastodon-instance-url "https://instance.url")) + (should + (null + (mastodon-profile--search-account-by-handle "gargron")))))) + +(ert-deftest mastodon-profile--account-from-id--correct-url () + "Should use the expected url for looking up by account id." + (with-mock + + (mock (mastodon-http--get-json + "https://instance.url/api/v1/accounts/1234567")) + + (let ((mastodon-instance-url "https://instance.url")) + ;; We don't check anything from the return value. We only care + ;; that the mocked fetch was called with the expected URL. + (mastodon-profile--account-from-id "1234567")))) + +(ert-deftest mastodon-profile--make-author-buffer () + "Should set up the buffer as expected for the given author. + +This is a far more complicated test as the +mastodon-profile--make-author-buffer function does so much. There +is a bit too much mocking and this may be brittle but it should +help identify when things change unexpectedly. + +TODO: Consider separating the data retrieval and the actual +content generation in the function under test." + (with-mock + ;; Don't start any image loading: + (mock (mastodon-media--inline-images * *) => nil) + (if (version< emacs-version "27.1") + (mock (image-type-available-p 'imagemagick) => t) + (mock (image-transforms-p) => t)) + (mock (mastodon-http--get-json "https://instance.url/api/v1/accounts/1/statuses") + => + gargon-statuses-json) + (mock (mastodon-profile--get-statuses-pinned *) + => + []) + (mock (mastodon-profile--relationships-get "1") + => + [((id . "1") (following . :json-false) (showing_reblogs . :json-false) (notifying . :json-false) (followed_by . :json-false) (blocking . :json-false) (blocked_by . :json-false) (muting . :json-false) (muting_notifications . :json-false) (requested . :json-false) (domain_blocking . :json-false) (endorsed . :json-false) (note . ""))]) + ;; Let's not do formatting as that makes it hard to not rely on + ;; window width and reflowing the text. + (mock (shr-render-region * *) => nil) + ;; Don't perform the actual update call at the end. + ;;(mock (mastodon-tl--timeline *)) + + (let ((mastodon-tl--show-avatars t) + (mastodon-tl--display-media-p t) + (mastodon-instance-url "https://instance.url")) + (mastodon-profile--make-author-buffer gargron-profile-json) + + (should + (equal + (buffer-substring-no-properties (point-min) (point-max)) + (concat + "\n" + "[img] \n" + "Eugen\n" + "@Gargron\n" + " ------------\n" + "

Developer of Mastodon and administrator of mastodon.social. I post service announcements, development updates, and personal stuff.

\n" + "_ Patreon __ :: https://www.patreon.com/mastodon_ Homepage _ :: https://zeonfederated.com\n" + " ------------\n" + " TOOTS: 70741 | FOLLOWERS: 470905 | FOLLOWING: 451\n" + " ------------\n" + "\n" + " ------------\n" + " TOOTS \n" + " ------------\n" + "\n" + "

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.

\n" + " Eugen (@Gargron) 2021-11-11 12:11:11\n" + " ------------\n" + "\n" + "\n" + "

@CCC At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

\n" + " Eugen (@Gargron) 2021-11-11 01:00:00\n" + " ------------\n" + "\n" + ))) + + ;; Until the function gets refactored this creates a non-temp + ;; buffer with Gargron's statuses which we want to delete (if + ;; the tests succeed). + (kill-buffer)))) -- cgit v1.2.3