1
0
Fork 0

- improved following/unfollowing users

previously only user that had an entry in the program local database
  could be followed or unfollowed.

  With this changes  the software perform a name lookup  in the client
  and follow the first user found that match searched username.
This commit is contained in:
cage 2020-12-21 12:11:15 +01:00
parent ee5eb80d07
commit ba4577d223
3 changed files with 28 additions and 10 deletions

View File

@ -452,6 +452,11 @@ database."
:spoiler-text subject
:visibility visibility))
(defun-w-lock search-user (username &key (limit 1))
*client-lock*
"Find user identified by username"
(tooter:search-accounts *client* username :limit limit))
(defun-w-lock follow-user (user-id)
*client-lock*
"Follow user identified by user-id"

View File

@ -1390,6 +1390,7 @@
:get-remote-status
:send-status
:get-status-context
:search-user
:follow-user
:unfollow-user
:follow-requests

View File

@ -682,23 +682,35 @@
(ui:notify (_ "Message sent."))
(ui:close-send-message-window))))))))
(defun find-user-id-from-exact-acct (username)
(when-let ((remote-account-matching (api-client:search-user username :limit 1)))
(tooter:id (first-elt remote-account-matching))))
(defmacro with-process-follower ((username user-id
&optional (local-complete-username-fn #'db:all-unfollowed-usernames))
&body body)
`(tui:with-notify-errors
(let ((,user-id nil))
(if (find ,username (,local-complete-username-fn) :test #'string=)
(setf ,user-id (db:acct->id ,username))
(setf ,user-id (find-user-id-from-exact-acct ,username)))
(if ,user-id
(progn ,@body)
(error (format nil (_ "Unable to find user ~a") ,username))))))
(defclass follow-user-event (program-event) ())
(defmethod process-event ((object follow-user-event))
(when-let ((username (payload object)))
(when (find username (db:all-unfollowed-usernames) :test #'string=)
(let ((user-id (db:acct->id username)))
(client:follow-user user-id)
(db:add-to-followers user-id)))))
(with-process-follower ((payload object) user-id db:all-followed-usernames)
(client:unfollow-user user-id)
(db:remove-from-followers user-id)))
(defclass unfollow-user-event (program-event) ())
(defmethod process-event ((object unfollow-user-event))
(when-let ((username (payload object)))
(when (find username (db:all-followed-usernames) :test #'string=)
(let ((user-id (db:acct->id username)))
(client:unfollow-user user-id)
(db:remove-from-followers user-id)))))
(with-process-follower ((payload object) user-id db:all-followed-usernames)
(client:unfollow-user user-id)
(db:remove-from-followers user-id)))
(defclass open-follow-requests-window-event (program-event) ())