2022-11-30 23:39:08 +00:00
|
|
|
# suggestions.py - follow suggestion endpoints
|
|
|
|
|
2023-06-19 21:35:03 +00:00
|
|
|
from mastodon.utility import api_version
|
2022-11-30 23:39:08 +00:00
|
|
|
|
2023-06-19 21:35:03 +00:00
|
|
|
from mastodon.internals import Mastodon as Internals
|
2025-02-13 23:14:07 +00:00
|
|
|
from mastodon.return_types import NonPaginatableList, Account, IdType, Suggestion
|
2023-06-19 21:35:03 +00:00
|
|
|
from typing import Union
|
2023-01-02 13:39:16 +00:00
|
|
|
|
2022-11-30 23:39:08 +00:00
|
|
|
class Mastodon(Internals):
|
|
|
|
###
|
|
|
|
# Reading data: Follow suggestions
|
|
|
|
###
|
2025-02-15 12:21:56 +00:00
|
|
|
@api_version("2.4.3", "2.4.3")
|
2025-02-13 21:35:34 +00:00
|
|
|
def suggestions_v1(self) -> NonPaginatableList[Account]:
|
2022-11-30 23:39:08 +00:00
|
|
|
"""
|
|
|
|
Fetch follow suggestions for the logged-in user.
|
|
|
|
"""
|
|
|
|
return self.__api_request('GET', '/api/v1/suggestions')
|
|
|
|
|
2025-02-15 12:21:56 +00:00
|
|
|
@api_version("3.4.0", "3.4.0")
|
2025-02-13 21:35:34 +00:00
|
|
|
def suggestions_v2(self) -> NonPaginatableList[Suggestion]:
|
|
|
|
"""
|
|
|
|
Fetch follow suggestions for the logged-in user.
|
|
|
|
"""
|
|
|
|
return self.__api_request('GET', '/api/v2/suggestions')
|
|
|
|
|
2025-02-14 19:01:56 +00:00
|
|
|
def suggestions(self) -> Union[NonPaginatableList[Suggestion], NonPaginatableList[Account]]:
|
2025-02-13 21:35:34 +00:00
|
|
|
"""
|
|
|
|
Fetch follow suggestions for the logged-in user.
|
|
|
|
|
|
|
|
Will use the v1 endpoint if the server is below 3.4.0, otherwise will use the v2 endpoint
|
|
|
|
and unpack the account dicts.
|
|
|
|
"""
|
|
|
|
if self.verify_minimum_version("3.4.0", cached=True):
|
|
|
|
suggestions = self.suggestions_v2()
|
|
|
|
return [s.account for s in suggestions]
|
|
|
|
else:
|
|
|
|
return self.suggestions_v1()
|
|
|
|
|
2022-11-30 23:39:08 +00:00
|
|
|
###
|
|
|
|
# Writing data: Follow suggestions
|
|
|
|
###
|
2025-02-15 12:21:56 +00:00
|
|
|
@api_version("2.4.3", "2.4.3")
|
2023-06-19 21:35:03 +00:00
|
|
|
def suggestion_delete(self, account_id: Union[Account, IdType]):
|
2022-11-30 23:39:08 +00:00
|
|
|
"""
|
|
|
|
Remove the user with the given `account_id` from the follow suggestions.
|
|
|
|
"""
|
|
|
|
account_id = self.__unpack_id(account_id)
|
2022-12-02 21:04:23 +00:00
|
|
|
self.__api_request('DELETE', f'/api/v1/suggestions/{account_id}')
|