Skip to content

Commit

Permalink
Merge pull request 'three fixes in total. view-post-at-point and rebl…
Browse files Browse the repository at this point in the history
…og-post-at-point are in my first pull request too. this pull request includes work on the json response as well' (gcr#2) from gargle/tumblesocks:fix3 into fix

Reviewed-on: https://codeberg.org/martianh/tumblesocks/pulls/2
  • Loading branch information
gargle committed Jul 17, 2023
2 parents 80ca574 + cf80d98 commit e65e3c8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
8 changes: 5 additions & 3 deletions tumblesocks-api.el
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ returning JSON or signaling an error for other requests."
(decode-coding-region (point-min) (point-max) 'utf-8-dos)
;; the following copied from url.el
(goto-char (point-min))
(skip-chars-forward " \t\n") ; Skip any blank crap
(skip-chars-forward "HTTP/") ; Skip HTTP Version
(skip-chars-forward " \t\n") ; Skip any blank crap
(skip-chars-forward "HTTP/") ; Skip HTTP Version
(skip-chars-forward "[0-9].")
(let ((pointpos (point))
(code (read (current-buffer))))
Expand All @@ -194,7 +194,9 @@ returning JSON or signaling an error for other requests."
(error (buffer-substring pointpos
(line-end-position))))
(t
(search-forward-regexp "^$" nil t)
;; brute force and ignorance
(search-forward-regexp "^{" nil t)
(previous-line)
;; body
(let* ((json-response (buffer-substring (1+ (point)) (point-max)))
(json-object-type 'plist)
Expand Down
46 changes: 25 additions & 21 deletions tumblesocks-view.el
Original file line number Diff line number Diff line change
Expand Up @@ -154,37 +154,41 @@ This causes Tumblesocks to ignore the setting of
(tumblesocks-view-refresh)
(goto-char pos))))

(defun tumblesocks-view-edit-post-at-point ()
(defun tumblesocks-view-post-at-point ()
"Open the post under point in a new buffer, showing notes, etc"
(interactive)
(when (yes-or-no-p "Really try to edit this post? ")
(tumblesocks-compose-edit-post
(format "%d"
(plist-get (get-text-property (point) 'tumblesocks-post-data) :id)))
'(lambda ()
(let ((pos (point)))
(tumblesocks-view-refresh)
(goto-char pos)))))
(when (get-text-property (point) 'tumblesocks-post-data)
(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-reblog-post-at-point ()
"Reblog the post at point, if there is one."
(interactive)
(when (get-text-property (point) 'tumblesocks-post-data)
(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)))
(when data
;; Get the reblog key.
(let* ((post_id
(format "%d"
(plist-get
(get-text-property (point) 'tumblesocks-post-data) :id)))
;; we need to do another API fetch because
;; tumblesocks-post-data doesn't have reblog keys, by design
(blog (tumblesocks-api-blog-posts
nil post_id nil "1" nil "true" nil "html"))
(post (car (plist-get blog :posts)))
(reblog_key (plist-get post :reblog_key)))
;; (let* ((tumblesocks-blog from-blog)
;; ;; we need to do another API fetch because
;; ;; tumblesocks-post-data doesn't have reblog keys, by design
;; (blog (tumblesocks-api-blog-posts
;; nil post_id nil "1" nil "true" nil "html"))
;; (post (car (plist-get blog :posts))))
;; (setq reblog_key (plist-get post :reblog_key)))

(tumblesocks-api-reblog-post
post_id reblog_key
(read-string "(Optional) comments to add: "))
(message "Reblogged.")
(tumblesocks-view-refresh))))
(let ((pos (point)))
(tumblesocks-view-refresh)
(goto-char pos))
)))



Expand Down

0 comments on commit e65e3c8

Please sign in to comment.