blob: 9dc5a826c973b7ec19ccb6eca1366a051971afbf (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
;;; mastodon-profile.el --- Functions for inspecting Mastodon profiles -*- lexical-binding: t -*-
;; Copyright (C) 2017 Johnson Denen
;; Author: Johnson Denen <johnson.denen@gmail.com>
;; Version: 0.7.2
;; Package-Requires: ((emacs "24.4"))
;; Homepage: https://github.com/jdenen/mastodon.el
;; This file is not part of GNU Emacs.
;; This file is part of mastodon.el.
;; mastodon.el is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; mastodon.el is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with mastodon.el. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; mastodon-profile.el generates a stream of users toots.
;; To add
;; - Option to follow
;; - wheather they follow you or not
;; - Show only Media
;;; Code:
(defun mastodon-profile--toot-json ()
"Get the next toot-json."
(interactive)
(mastodon-tl--property 'toot-json))
(defun mastodon-profile--make-author-buffer (account)
"Take a ACCOUNT and inserts a user account into a new buffer."
(let* ((id (mastodon-profile--account-field account 'id))
(acct (mastodon-profile--account-field account 'acct))
(url (mastodon-http--api
(concat "accounts/"
(format "%s" id)
"/statuses" )))
(buffer (concat "*mastodon-" acct "*"))
(note (mastodon-profile--account-field account 'note))
(json (mastodon-http--get-json url)))
(with-output-to-temp-buffer buffer
(switch-to-buffer buffer)
(mastodon-mode)
(setq mastodon-tl--buffer-spec
`(buffer-name ,buffer
endpoint ,(format "accounts/%s/statuses" id)
update-function
,'mastodon-tl--timeline json))
(let ((inhibit-read-only t))
(insert
"\n"
(mastodon-profile--image-from-account account)
"\n"
(propertize (mastodon-profile--account-field
account 'display_name)
'face 'mastodon-display-name-face)
"\n"
(propertize acct
'face 'default)
"\n ------------\n"
(mastodon-tl--render-text note nil)
(mastodon-tl--set-face
(concat " ------------\n"
" TOOTS \n"
" ------------\n")
'success))
(setq mastodon-tl-update-point (point))
(mastodon-tl--timeline json)))
(mastodon-tl--goto-next-toot)))
(defun mastodon-profile--get-toot-author ()
"Opens authors profile of toot under point."
(interactive)
(mastodon-profile--make-author-buffer
(cdr (assoc 'account (mastodon-profile--toot-json)))))
(defun mastodon-profile--image-from-account (status)
"Generate an image from a STATUS."
(let ((url (cdr (assoc 'avatar_static status))))
(unless (equal url "/avatars/original/missing.png")
(mastodon-media--get-media-link-rendering url))))
(defun mastodon-profile--account-field (account field)
"Return FIELD from the ACCOUNT.
FIELD is used to identify regions under 'account"
(cdr (assoc field account)))
(defun mastodon-profile--get-next-authour-id ()
"Get the author id of the next toot."
(interactive)
(get-authour-id (toot-proporties)))
(defun mastodon-profile--add-author-bylines (tootv)
"Convert TOOTV into a author-bylines and insert."
(let ((inhibit-read-only t))
(mapc (lambda(toot)
(insert (propertize
(mastodon-tl--byline-author
(list (append (list 'account) toot)))
'byline 't
'toot-id (cdr (assoc 'id toot)) 'toot-json toot)
"\n"))
tootv))
(mastodon-media--inline-images))
(defun mastodon-profile--get-following ()
"Request a list of those who the user under point follows."
(interactive)
(mastodon-profile--make-follow-buffer "following"))
(defun mastodon-profile--followers ()
"Request a list of those following the user under point."
(interactive)
(mastodon-profile--make-follow-buffer "followers"))
(defun mastodon-profile--make-follow-buffer (string)
"Make a buffer contining followers or following of user under point.
STRING is an endpoint, either following or followers."
(let* ((account
(cdr (assoc 'account (mastodon-profile--toot-json))))
(id (mastodon-profile--account-field
account 'id))
(acct (mastodon-profile--account-field
account 'acct))
(buffer (format "*%s-%s*" string acct))
(tootv (mastodon-http--get-json
(mastodon-http--api (format "accounts/%s/%s"
id string)))))
(with-output-to-temp-buffer buffer
(switch-to-buffer buffer)
(mastodon-mode)
(setq mastodon-tl--buffer-spec
`(buffer-name ,buffer
endpoint ,(format "accounts/%s/%s" id string)
update-function
,'mastodon-profile--add-author-bylines))
(mastodon-profile--add-author-bylines tootv))))
(defun mastodon-profile--search-account-by-handle (handle)
"Return an account based on a users HANDLE.
If the handle does not match a search return then retun NIL."
(let* ((handle (if (string= "@" (substring handle 0 1))
(substring handle 1 (length handle))
handle))
(matching-account
(remove-if-not
(lambda(x) (string= (cdr (assoc 'acct x)) handle))
(mastodon-http--get-json
(mastodon-http--api (format "accounts/search?q=%s" handle))))))
(when (equal 1 (length matching-account))
(elt matching-account 0))))
(defun mastodon-profile--account-from-id (user-id)
"Request an account object relating to a USER-ID from Mastodon."
(mastodon-http--get-json
(mastodon-http--api (format "accounts/%s" user-id))))
(provide 'mastodon-profile)
;;; mastodon-profile.el ends here
|