From 4eb0b578b5e4ba920999427c137b98043b41c9d4 Mon Sep 17 00:00:00 2001 From: mousebot Date: Wed, 5 Jan 2022 14:14:36 +0100 Subject: add support for poll notifications finally we now display all types of notifications! it's about bloody time. --- lisp/mastodon-notifications.el | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 921fdc7..9444658 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -55,7 +55,8 @@ ("favourite" . mastodon-notifications--favourite) ("reblog" . mastodon-notifications--reblog) ("follow_request" . mastodon-notifications--follow-request) - ("status" . mastodon-notifications--status)) + ("status" . mastodon-notifications--status) + ("poll" . mastodon-notifications--poll)) "Alist of notification types and their corresponding function.") (defvar mastodon-notifications--response-alist @@ -64,7 +65,8 @@ ("Favourited" . "your status from") ("Boosted" . "your status from") ("Requested to follow" . "you") - ("Posted" . "a post")) + ("Posted" . "a post") + ("Posted a poll" . "that has now ended")) "Alist of subjects for notification types.") (defun mastodon-notifications--byline-concat (message) @@ -151,6 +153,10 @@ Status notifications are given when `mastodon-tl--enable-notify-user-posts' has been set." (mastodon-notifications--format-note note 'status)) +(defun mastodon-notifications--poll (note) + "Format for a `poll' NOTE." + (mastodon-notifications--format-note note 'poll)) + (defun mastodon-notifications--format-note (note type) "Format for a NOTE of TYPE." (let ((id (alist-get 'id note)) @@ -186,7 +192,7 @@ Status notifications are given when (cond ((equal type 'boost) "Boosted") ((equal type 'favorite) - "Favorited") + "Favourited") ((equal type 'follow-request) "Requested to follow") ((equal type 'follow) @@ -194,7 +200,9 @@ Status notifications are given when ((equal type 'mention) "Mentioned") ((equal type 'status) - "Posted")))) + "Posted") + ((equal type 'poll) + "Posted a poll")))) id))) (defun mastodon-notifications--insert-status (toot body author-byline action-byline id) -- cgit v1.2.3 From 5011f6634c66d0f803d60a13a471f17f0f307291 Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 11 Jan 2022 19:10:51 +0100 Subject: FIX fetching max toot length from server some servers have 'max_toot_chars, but others seem to have 'max_characters, under statuses, under configuation. we allow for both types, but also we check our var isn't nil before trying to check it's length, which broke toot--send in some cases. --- lisp/mastodon-toot.el | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index befffee..22699f1 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -162,11 +162,18 @@ Valid values are \"direct\", \"private\" (followers-only), (defun mastodon-toot--get-max-toot-chars-callback (json-response) "Set max_toot_chars returned in JSON-RESPONSE and display in new toot buffer." + (let ((max-chars + (or + (alist-get 'max_toot_chars json-response) + ;; some servers have this instead: + (alist-get 'max_characters + (alist-get 'statuses + (alist-get 'configuration + json-response)))))) (setq mastodon-toot--max-toot-chars - (number-to-string - (alist-get 'max_toot_chars json-response))) + (number-to-string max-chars)) (with-current-buffer "*new toot*" - (mastodon-toot--update-status-fields))) + (mastodon-toot--update-status-fields)))) (defun mastodon-toot--action-success (marker byline-region remove) "Insert/remove the text MARKER with 'success face in byline. @@ -493,7 +500,8 @@ If media items have been attached and uploaded with (not (= (length mastodon-toot--media-attachments) (length mastodon-toot--media-attachment-ids))))) (message "Something is wrong with your uploads. Wait for them to complete or try again.")) - ((> (length toot) (string-to-number mastodon-toot--max-toot-chars)) + ((and mastodon-toot--max-toot-chars + (> (length toot) (string-to-number 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.")) -- cgit v1.2.3 From 1ea5edbb7cb99ad4ab192169cbf649c6e179d0cc Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 11 Jan 2022 18:06:57 +0100 Subject: FIX local mentions/links checking we remove the hacky non-check for a user handle from mastodon-tl--process-link, so that it /always/ runs mastodon-tl--extract-userhandle-from-url. the in extract-userhandle-from-url, we test if the url host = local instance. if so, we just return buffer-text, which = "@user", with no suffix. else we return a full "@user@instance.url" handle. remove unused var after fix to userhandle parsing --- lisp/mastodon-tl.el | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 87b8dfc..cd27bd5 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -492,13 +492,8 @@ START and END are the boundaries of the link in the toot." mastodon-instance-url)) (maybe-hashtag (mastodon-tl--extract-hashtag-from-url url toot-instance-url)) - (url-instance (concat "https://" - (url-host (url-generic-parse-url url)))) - (maybe-userhandle (if (string= mastodon-instance-url url-instance) - ; if handle is local, then no instance suffix: - (buffer-substring-no-properties start end) - (mastodon-tl--extract-userhandle-from-url - url (buffer-substring-no-properties start end))))) + (maybe-userhandle (mastodon-tl--extract-userhandle-from-url + url (buffer-substring-no-properties start end)))) (cond (;; Hashtags: maybe-hashtag (setq mastodon-tab-stop-type 'hashtag @@ -550,11 +545,16 @@ START and END are the boundaries of the link in the toot." BUFFER-TEXT is the text covered by the link with URL, for a user profile this should be of the form , e.g. \"@Gargon\"." - (let ((parsed-url (url-generic-parse-url url))) + (let* ((parsed-url (url-generic-parse-url url)) + (local-p (string= + (url-host (url-generic-parse-url mastodon-instance-url)) + (url-host parsed-url)))) (when (and (string= "@" (substring buffer-text 0 1)) (string= (downcase buffer-text) (downcase (substring (url-filename parsed-url) 1)))) - (concat buffer-text "@" (url-host parsed-url))))) + (if local-p + buffer-text ; no instance suffic for local mention + (concat buffer-text "@" (url-host parsed-url)))))) (defun mastodon-tl--extract-hashtag-from-url (url instance-url) "Return the hashtag that URL points to or nil if URL is not a tag link. -- cgit v1.2.3 From c6b613a65bb796f89bf7b46f4dace53f97ce392f Mon Sep 17 00:00:00 2001 From: mousebot Date: Tue, 11 Jan 2022 21:18:23 +0100 Subject: byte compile warnings --- lisp/mastodon-notifications.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 9444658..1361099 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -48,6 +48,7 @@ (autoload 'mastodon-tl--spoiler "mastodon-tl.el") (autoload 'mastodon-tl--toot-id "mastodon-tl.el") (defvar mastodon-tl--display-media-p) +(defvar mastodon-tl--buffer-spec) (defvar mastodon-notifications--types-alist '(("mention" . mastodon-notifications--mention) @@ -174,8 +175,8 @@ Status notifications are given when (propertize (if (equal type 'follow) "Congratulations, you have a new follower!" (format "You have a follow request from... %s" - follower) - 'face 'default)) + follower)) + 'face 'default) (mastodon-tl--clean-tabs-and-nl (if (mastodon-tl--has-spoiler status) (mastodon-tl--spoiler status) -- cgit v1.2.3 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