diff --git a/tumblesocks-api.el b/tumblesocks-api.el index 0a848d2..c14ec5d 100644 --- a/tumblesocks-api.el +++ b/tumblesocks-api.el @@ -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'." diff --git a/tumblesocks-view.el b/tumblesocks-view.el index 746a223..c0acff1 100644 --- a/tumblesocks-view.el +++ b/tumblesocks-view.el @@ -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) @@ -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" @@ -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) @@ -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)) @@ -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) @@ -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 () @@ -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")