Skip to content

Commit

Permalink
Merge pull request 'list out all notifications (it's called activity …
Browse files Browse the repository at this point in the history
…now in the new tumblr web interface)' (gcr#3) from gargle/tumblesocks:fix into fix

Reviewed-on: https://codeberg.org/martianh/tumblesocks/pulls/3
  • Loading branch information
gargle committed Aug 18, 2023
2 parents e65e3c8 + 3ce9841 commit 5c71752
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 17 deletions.
11 changes: 11 additions & 0 deletions tumblesocks-api.el
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,17 @@ returning JSON or signaling an error for other requests."
(tumblesocks-api-http-oauth-post (tumblesocks-api-url "/user/unlike")
`(:id ,id :reblog_key ,reblog_key)))

(defun tumblesocks-api-blog-notifications (&optional limit offset)
"Retrieve the activity items for a specific blog, in reverse chronological order, newest first"
(unless tumblesocks-blog (error "Which blog? Please set `tumblesocks-blog'"))
(let ((args (append
(and limit `(:limit ,limit))
(and offset `(:offset ,offset)))))
(tumblesocks-api-http-oauth-get
(tumblesocks-api-url "/blog/"
tumblesocks-blog
"/notifications") args)))

(defun tumblesocks-api-blog-info ()
"Gather information about the blog listed in
`tumblesocks-blog'."
Expand Down
58 changes: 41 additions & 17 deletions tumblesocks-view.el
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ This causes Tumblesocks to ignore the setting of
(define-key tumblesocks-view-mode-map "r" 'tumblesocks-view-reblog-post-at-point)
(define-key tumblesocks-view-mode-map (kbd "RET") 'tumblesocks-view-post-at-point)
(define-key tumblesocks-view-mode-map (kbd "SPC") 'forward-page)
(define-key tumblesocks-view-mode-map "a" 'tumblesocks-view-notifications)
(define-key tumblesocks-view-mode-map "b" 'tumblesocks-view-blog)
(define-key tumblesocks-view-mode-map "d" 'tumblesocks-view-delete-post-at-point)
(define-key tumblesocks-view-mode-map "e" 'tumblesocks-view-edit-post-at-point)
Expand Down Expand Up @@ -106,8 +107,11 @@ This causes Tumblesocks to ignore the setting of
"Open the post under point in a new buffer, showing notes, etc"
(interactive)
(when (get-text-property (point) 'tumblesocks-post-data)
(tumblesocks-view-post
(plist-get (get-text-property (point) 'tumblesocks-post-data) :id))))
(let ((id (plist-get (get-text-property (point) 'tumblesocks-post-data)
:id))
(tumblesocks-blog (plist-get (get-text-property (point) 'tumblesocks-post-data)
:blog_name)))
(tumblesocks-view-post id))))

(defun tumblesocks-view-post-url-at-point ()
"Open the post under point in your browser"
Expand Down Expand Up @@ -168,9 +172,9 @@ This causes Tumblesocks to ignore the setting of
"Reblog the post at point, if there is one."
(interactive)
(let* ((data (get-text-property (point) 'tumblesocks-post-data))
(from-blog (plist-get data :channel-name))
(post_id (format "%d" (plist-get data :id)))
(reblog_key (plist-get data :reblog_key)))
(from-blog (plist-get data :channel-name))
(post_id (format "%d" (plist-get data :id)))
(reblog_key (plist-get data :reblog_key)))
(when data
;; Get the reblog key.
;; (let* ((tumblesocks-blog from-blog)
Expand Down Expand Up @@ -351,7 +355,7 @@ better suited to inserting each post."
(cond
(title (tumblesocks-view-insert-html-fragment title t))
(caption (tumblesocks-view-insert-html-fragment caption t))
(question (tumblesocks-view-insert-html-fragment question t))
;;(question (tumblesocks-view-insert-html-fragment question t))
(t (insert " ")))
;; Notes
(when (and note_count (> note_count 0))
Expand All @@ -367,14 +371,7 @@ better suited to inserting each post."
"\nPermalink: ")
(tumblesocks-view-insert-parsed-html-fragment
`(a ((href . ,post_url)) ,post_url) t)
(insert "\n"))
(put-text-property begin end_bname 'face
(list '(:inverse-video t)
'(:weight bold)
font-lock-keyword-face))
(put-text-property end_bname (point) 'face
(list '(:weight bold)
'highlight))))
(insert "\n"))))

(defun tumblesocks-view-insert-text ()
(tumblesocks-view-insert-html-fragment body)
Expand Down Expand Up @@ -415,11 +412,13 @@ better suited to inserting each post."
(insert "\n"))

(defun tumblesocks-view-insert-answer ()
(insert asking_name " asks: \n ")
(insert asking_name " asks:")
(let ((start (point))
(shr-indentation 4))
(shr-indentation 32))
(tumblesocks-view-insert-html-fragment question t)
(put-text-property start (point) 'face font-lock-comment-face))
;;(put-text-property start (point) 'face font-lock-comment-face)
;;(set-face-attribute start (point) :background "grey")
)
(tumblesocks-view-insert-html-fragment answer))

(defun tumblesocks-view-insert-link ()
Expand Down Expand Up @@ -590,6 +589,31 @@ You can browse around, edit, and delete posts from here.
(insert "\n")
(comment-that))))))

(defun tumblesocks-view-notifications ()
"View all notfications, newest on top"
;; TODO paging!
(interactive)
(tumblesocks-api-blog-notifications)
(tumblesocks-view-prepare-buffer "notifications")
(let ((begin (point)))
(insert "Notifications")
(center-line)
(insert "\n\n")
(put-text-property begin (point) 'face font-lock-comment-face))
(dolist (notification (plist-get (tumblesocks-api-blog-notifications) :notifications))
;;(insert (format "%s\n" notification))
(insert (format "%s - " (format-time-string "%D %r" (plist-get notification :timestamp))))
(insert (format "%s - " (plist-get notification :type)))
(insert (format "%s - " (plist-get notification :from_tumblelog_name)))
(when (string= (plist-get notification :type) "reply")
(insert (format "%s - " (plist-get notification :reply_text))))
(tumblesocks-view-insert-parsed-html-fragment
`(img ((src . ,(plist-get notification :media_url)))) t)
(insert (format "\n%s\n\n\n" (plist-get notification :target_post_summary))))
(tumblesocks-view-finishrender)
(setq tumblesocks-view-refresh-action
`(lambda () (tumblesocks-view-notifications)))) ; <-- CLOSURE HACK :p

(defun tumblesocks-view-like-post-at-point (like-p)
"Like the post underneath point. With prefix arg (C-u), unlike it."
(interactive "P")
Expand Down

0 comments on commit 5c71752

Please sign in to comment.