branch: elpa/mastodon
commit ab16056a7608fc497003df5d5302c3de71b9baad
Merge: 3861f8c1a3 1af6f742ff
Author: marty hiatt <[email protected]>
Commit: marty hiatt <[email protected]>

    Merge branch 'develop'
---
 lisp/mastodon-tl.el         | 47 ++++++++++++++----------
 lisp/mastodon-toot.el       | 10 ++++--
 lisp/mastodon.el            | 34 ++++++++++--------
 test/mastodon-tests.el      | 88 +++++++++++++++++++++++++++++++++++++++++++++
 test/mastodon-toot-tests.el | 31 ++++++++++++++++
 5 files changed, 175 insertions(+), 35 deletions(-)

diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index 4d0facf105..a98e28caec 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -1794,19 +1794,21 @@ LENGTH is of the longest option, for formatting."
                          "\n")
               "\n"
               (propertize
-               (cond (.voters_count ; sometimes it is nil
-                      (format "%s %s | " .voters_count
-                              (if (= .voters_count 1) "person" "people")))
-                     (.vote_count
-                      (format "%s votes | " .vote_count))
-                     (t ""))
+               (concat
+                (cond (.voters_count ; sometimes it is nil
+                       (format "%s %s | " .voters_count
+                               (if (= .voters_count 1) "person" "people")))
+                      (.vote_count
+                       (format "%s votes | " .vote_count))
+                      (t ""))
+                (format "%s choice | "
+                        (if .multiple "multi" "single"))
+                (if (eq .expired :json-false)
+                    (if (eq .expires_at nil)
+                        ""
+                      (mastodon-tl--format-poll-expiry .expires_at))
+                  "Poll expired."))
                'face 'mastodon-toot-docs-face)
-              (let ((str (if (eq .expired :json-false)
-                             (if (eq .expires_at nil)
-                                 ""
-                               (mastodon-tl--format-poll-expiry .expires_at))
-                           "Poll expired.")))
-                (propertize str 'face 'mastodon-toot-docs-face))
               "\n"))))
 
 (defconst mastodon-tl--time-units
@@ -2141,7 +2143,8 @@ TOOT is the data for the quoting toot."
            (mastodon-tl--format-quote-non-display
             (format "Quote hidden, %s" state) nil :noprop))
           ((string= state "pending")
-           (mastodon-tl--format-quote-non-display "quote pending" .url))
+           ;; pending quotes have no data, so no URL:
+           (mastodon-tl--format-quote-non-display "quote pending" nil :noprop))
           (t
            (let ((quote-rendered (mastodon-tl-prop-quote rendered .uri))
                  (nested-quote (alist-get 'quote quoted)))
@@ -2157,7 +2160,9 @@ TOOT is the data for the quoting toot."
               ;; quoted text:
               (if foldable
                   (mastodon-tl--fold-body quote-rendered
-                               (mastodon-search--format-heading "click for 
full toot"))
+                               (mastodon-tl-prop-quote 
(mastodon-search--format-heading
+                                             "click for full toot")
+                                            .uri))
                 quote-rendered)
               (when nested-quote
                 (propertize
@@ -2305,10 +2310,16 @@ CW-EXPANDED means treat content warnings as unfolded."
            ""))
         'toot-body t) ;; includes newlines etc. for folding
        ;; post tags:
-       (let ((tags (alist-get 'tags toot)))
-         ;; FIXME: we also need to test here for normal body tags, and if
-         ;; so, don't go ahead:
-         (if tags (concat (mastodon-tl--base-tags tags body-tags)) ""))
+       (if-let* ((tags (alist-get 'tags toot))
+                 (rendered (mastodon-tl--base-tags tags body-tags)))
+           ;; FIXME: we also need to test here for normal body tags, and if
+           ;; so, don't go ahead:
+           (if (mastodon-tl--has-spoiler toot)
+               (propertize rendered
+                           'invisible t
+                           'mastodon-content-warning-body t)
+             rendered)
+         "")
        ;; byline:
        "\n"
        (if no-byline
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el
index f96a6a8566..279b7b8858 100644
--- a/lisp/mastodon-toot.el
+++ b/lisp/mastodon-toot.el
@@ -934,8 +934,12 @@ to `emojify-user-emojis', and the emoji data is updated."
       "poll[options][]"
       (plist-get mastodon-toot-poll :options))
      `(("poll[expires_in]" .  ,(plist-get mastodon-toot-poll :expiry)))
-     `(("poll[multiple]" . ,(symbol-name (plist-get mastodon-toot-poll 
:multi))))
-     `(("poll[hide_totals]" . ,(symbol-name (plist-get mastodon-toot-poll 
:hide)))))))
+     `(("poll[multiple]" . ,(if (plist-get mastodon-toot-poll :multi)
+                                "true"
+                              "false")))
+     `(("poll[hide_totals]" . ,(if (plist-get mastodon-toot-poll :hide)
+                                   "true"
+                                 "false"))))))
 
 
 ;;; SEND TOOT FUNCTION
@@ -962,7 +966,7 @@ instance to edit a toot."
              ("sensitive" . ,(when mastodon-toot--content-nsfw
                                (symbol-name t)))
              ("spoiler_text" . ,mastodon-toot--content-warning)
-             ("quote_approval_policy" . ,mastodon-toot-quote-policy)
+             ("quote_approval_policy" . ,(symbol-name 
mastodon-toot-quote-policy))
              ("language" . ,mastodon-toot--language)
              ("quoted_status_id" . ,mastodon-toot-quote-id))
            ;; Pleroma instances can't handle null-valued
diff --git a/lisp/mastodon.el b/lisp/mastodon.el
index bc6a64b21d..25461ed794 100644
--- a/lisp/mastodon.el
+++ b/lisp/mastodon.el
@@ -6,7 +6,7 @@
 ;; Author: Johnson Denen <[email protected]>
 ;;         Marty Hiatt <[email protected]>
 ;; Maintainer: Marty Hiatt <[email protected]>
-;; Version: 2.1.7
+;; Version: 2.1.8
 ;; Package-Requires: ((emacs "29.1") (compat "31") (persist "0.8") (tp "0.8"))
 ;; Homepage: https://codeberg.org/martianh/mastodon.el
 
@@ -631,37 +631,43 @@ If FORCE, do a lookup regardless of the result of 
`mastodon--fedi-url-p'."
                     (string-trim-right url-filename "/")
                   url-filename)))
     (save-match-data
-      (or (string-match "^/@[^/]+$" query)
-          (string-match "^/@[^/]+/[[:digit:]]+$" query)
-          (string-match "^/user[s]?/@?[[:alnum:]_]+$" query) ; @: pleroma or 
soapbox
+      (or (string-match "^/@[^/]+$" query) ;; user handle
+          (string-match "^/@[^/]+/[[:digit:]]+$" query) ;; user item
+          (string-match "^/user[s]?/@?[[:alnum:]_]+$" query) ;; @: pleroma or 
soapbox user
+          (string-match "^/tags/[[:alnum:]_-]+$" query) ;; tag
           ;; URI is used for quote posts, due to flipboard formats, so we
           ;; need to match some ap/ URIs?
           ;; e.g. "/ap/users/116739186617842944/statuses/117224123424001867"
           ;; maybe in the long run we would just rather regex the flipboard 
format though?
           (string-match "^/ap/user[s]?/@?[[:alnum:]_]+$" query)
           (string-match 
"^/ap/user[s]?/@?[[:alnum:]_]+/statuses/[[:alnum:]_]+$" query)
-          (string-match "^/notice/[[:alnum:]]+$" query)
-          (string-match "^/objects/[-a-f0-9]+$" query)
-          (string-match "^/notes/[a-z0-9]+$" query)
-          (string-match "^/display/[-a-f0-9]+$" query)
+          (string-match "^/notice/[[:alnum:]]+$" query) ;; pleroma post
+          (string-match "^/objects/[-a-f0-9]+$" query) ;; ?
+          ;; (string-match "^/notes/[a-z0-9]+$" query) ;; duplicated below:
+          (string-match "^/display/[-a-f0-9]+$" query) ;; ?
           (string-match "^/profile/[[:alpha:]_]+$" query)
           (string-match "^/p/[[:alpha:]_]+/[[:digit:]]+$" query)
-          (string-match "^/[[:alpha:]_]+$" query)
-          (string-match "^/u/[[:alpha:]_]+$" query)
-          (string-match "^/c/[[:alnum:]_]+$" query)
+          (string-match "^/[[:alpha:]_]+$" query) ;; ?
+          (string-match "^/u/[[:alnum:]_]+$" query)
           ;; a lemmy post must NOT open in mastodon.el lest we get stuck in
           ;; a self-loading circle and can't load the URL in the lemmy
           ;; post itself:
           ;; (string-match "^/post/[[:digit:]]+$" query)
-          (string-match "^/comment/[[:digit:]]+$" query) ; lemmy
-          (string-match "^/@[^/]+/statuses/[[:alnum:]]" query) ; GTS
+          ;; FIXME: or perhaps we need to load lemmy posts in mastodon.el,
+          ;; but then force the self-link that they contain to load
+          ;; externally?
+          (string-match "^/comment/[[:digit:]]+$" query) ; lemmy comment
+          (string-match "^/@[^/]+/posts/[[:alnum:]]+$" query) ;; akkoma post
+          (string-match "^/@[^/]+/statuses/[[:alnum:]]" query) ; GTS status
           ;; (string-match "^/@[[:alpha:]-_]/" query) ;; flipboard post
           ;; fliboard post (works with modified hometown below):
           ;; either uri: 
https://flipboard.com/users/Gizmodo/statuses/UQ_TmLCbShiYB55LrrrzWQ:a:1876139665
           ;; or url: 
https://flipboard.com/@gizmodo/tech-fknh6odjz/-/a-UQ_TmLCbShiYB55LrrrzWQ%3Aa%3A1876139665-%2F0
-          (string-match "^/user[s]?/[[:alnum:]_]+/statuses/[[:alnum:]-_:]+$" 
query) ; hometown
+          ;; hometown (obsolete? checking https://rage.love/@puf, seems same 
as mastodon):
+          (string-match "^/user[s]?/[[:alnum:]_]+/statuses/[[:alnum:]-_:]+$" 
query)
           (string-match "^/notes/[[:alnum:]]+$" query) ; misskey post
           (string-match "^/w/[[:alnum:]_]+$" query) ; peertube post
+          (string-match "^/c/[[:alnum:]_]+$" query) ;; peertube channel
           ;; bsky via fed.brid.gy (unsure if this needs narrowing down?):
           (string-prefix-p "https://fed.brid.gy/r/"; url)
           (string-match "^/collections/[[:digit:]_]+$" query) ;; collection
diff --git a/test/mastodon-tests.el b/test/mastodon-tests.el
new file mode 100644
index 0000000000..8791e863d7
--- /dev/null
+++ b/test/mastodon-tests.el
@@ -0,0 +1,88 @@
+;;; mastodon-test.el --- Tests for mastodon.el  -*- lexical-binding: nil -*-
+
+(ert-deftest mastodon-fedi-url-p ()
+  ;; TODO: /objects, /display, /profile, /p, /u, /comment
+  (should
+   ;; User handle:
+   (mastodon--fedi-url-p
+    "https://misskey.noellabo.jp/@shigeru";))
+  (should
+   ;; User post:
+   (mastodon--fedi-url-p
+    "https://todon.nl/@admin/117134394057436440";))
+  (should
+   ;; tag:
+   (mastodon--fedi-url-p
+    "https://todon.nl/tags/nobot";))
+  (should
+   ;; we match such handles, but not with crazy codes and multi slashes
+   ;; after them, so we went with URI, below (poss stupid):
+   ;; Flipboard URL:
+   (not
+    (mastodon--fedi-url-p
+     
"https://flipboard.com/@gizmodo/tech-fknh6odjz/-/a-UQ_TmLCbShiYB55LrrrzWQ%3Aa%3A1876139665-%2F0";)))
+  (should
+   ;; Flipboard URI:
+   (mastodon--fedi-url-p
+    
"https://flipboard.com/users/Gizmodo/statuses/UQ_TmLCbShiYB55LrrrzWQ:a:1876139665";))
+  (should
+   ;; pleroma user
+   (mastodon--fedi-url-p
+    "https://udongein.xyz/users/duponin";))
+  (should
+   ;; pleroma post
+   (mastodon--fedi-url-p
+    "https://udongein.xyz/notice/AcsRkbQxDJbO6T8hbE";))
+  (should
+   ;; Akkoma post:
+   (mastodon--fedi-url-p
+    "https://fe.disroot.org/@muppeth/posts/BBD5a3BRt4d2RTDQdU";))
+  (should
+   ;; Lemmy post:
+   (not (mastodon--fedi-url-p
+         "https://lemmy.ml/post/53786458";)))
+  (should
+   ;; Lemmy comment:
+   (not (mastodon--fedi-url-p
+         "https://lemmy.ml/post/53786458/28261605";)))
+  (should
+   ;; lemmy comment 2:
+   (mastodon--fedi-url-p
+    "https://lemmy.ml/comment/28252098";))
+  (should
+   ;; Lemmy user:
+   (mastodon--fedi-url-p
+    "https://lemmy.ml/u/Trying2KnowMyself";))
+  (should
+   ;; Misskey post:
+   (mastodon--fedi-url-p
+    "https://misskey.noellabo.jp/notes/as5y0n7y98";))
+  (should
+   ;; gts post
+   (mastodon--fedi-url-p
+    "https://aseachange.com/@elena/statuses/01KXDSRTC2KYZ9VSGB219EXPKP";))
+  (should
+   ;; peertube post (should this not be external?)
+   (mastodon--fedi-url-p
+    "https://peertube.tv/w/ej3Ye8C4ZQcFyPZLev4x93";))
+  (should
+   ;; peertube channel (should this not be external?)
+   (mastodon--fedi-url-p
+    "https://peertube.tv/c/transport_evolved";))
+  (should
+   ;; collection
+   (mastodon--fedi-url-p
+    "https://todon.nl/collections/116879312823651190";))
+  (should
+   (mastodon--fedi-url-p
+    "https://fed.brid.gy/r/https://user.name/about";))
+  ;; Non-fedi links
+  (should
+   (not (mastodon--fedi-url-p
+         "https://x.com/asdf/status/3412352456345";)))
+  (should
+   (not (mastodon--fedi-url-p
+         "https://example.com";)))
+  (should
+   (not (mastodon--fedi-url-p
+         "https://www.theguardian.com/profile/kitty-sayers";))))
diff --git a/test/mastodon-toot-tests.el b/test/mastodon-toot-tests.el
index 2330d80a2a..cd66d62042 100644
--- a/test/mastodon-toot-tests.el
+++ b/test/mastodon-toot-tests.el
@@ -233,3 +233,34 @@ mention string."
 ;;        (mock (mastodon-auth--user-acct) => "[email protected]")
 ;;        (should (equal (mastodon-toot-pin-toot-toggle)
 ;;                       "You can only pin your own toots"))))))
+
+(ert-deftest mastodon-toot-poll-params ()
+  "Test that we prepare poll related parameters correctly.
+Whether using transient or not."
+  (let ((mastodon-toot-poll-use-transient nil)
+        (mastodon-toot-poll '( :options ("asdf" "qwer")
+                  :length 75 :expiry-readable "1 day" :expiry
+                  "86400" :multi t :hide nil)))
+    (should
+     (equal
+      (mastodon-toot--build-poll-params)
+      '(("poll[options][]" . "asdf")
+        ("poll[options][]" . "qwer")
+        ("poll[expires_in]" . "86400")
+        ("poll[multiple]" . "true")
+        ("poll[hide_totals]" . "false"))
+      )))
+  (let ((mastodon-toot-poll-use-transient t)
+        (mastodon-toot-poll '((four) (three) (two . "zxcv") (one . "asdf")
+                 (expiry . "259200") (hide . "true") (multi . "false"))))
+    (should
+     (equal
+      (mastodon-toot--build-poll-params)
+
+      '(("poll[options][]" . "asdf")
+        ("poll[options][]" . "zxcv")
+        ("poll[options][]")
+        ("poll[options][]")
+        ("poll[expires_in]" . "259200")
+        ("poll[multiple]" . "false")
+        ("poll[hide_totals]" . "true"))))))

Reply via email to