mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-22 11:18:08 -06:00
Change: on SessionManager, identify via nodeinfo which kind of platform we are talking with and create gts or mastodon sessions accordingly.
This commit is contained in:
parent
c05dc4b211
commit
74360ac50f
@ -14,6 +14,7 @@ import application
|
|||||||
from pubsub import pub
|
from pubsub import pub
|
||||||
from controller import settings
|
from controller import settings
|
||||||
from sessions.mastodon import session as MastodonSession
|
from sessions.mastodon import session as MastodonSession
|
||||||
|
from sessions.gotosocial import session as GotosocialSession
|
||||||
from . import manager
|
from . import manager
|
||||||
from . import wxUI as view
|
from . import wxUI as view
|
||||||
|
|
||||||
@ -68,7 +69,7 @@ class sessionManagerController(object):
|
|||||||
name = _("{account_name}@{instance} (Mastodon)").format(account_name=config_test["mastodon"]["user_name"], instance=config_test["mastodon"]["instance"].replace("https://", ""))
|
name = _("{account_name}@{instance} (Mastodon)").format(account_name=config_test["mastodon"]["user_name"], instance=config_test["mastodon"]["instance"].replace("https://", ""))
|
||||||
if config_test["mastodon"]["instance"] != "" and config_test["mastodon"]["access_token"] != "":
|
if config_test["mastodon"]["instance"] != "" and config_test["mastodon"]["access_token"] != "":
|
||||||
sessionsList.append(name)
|
sessionsList.append(name)
|
||||||
self.sessions.append(dict(type="mastodon", id=i))
|
self.sessions.append(dict(type=config_test["mastodon"].get("type", "mastodon"), id=i))
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
log.debug("Deleting session %s" % (i,))
|
log.debug("Deleting session %s" % (i,))
|
||||||
@ -94,6 +95,8 @@ class sessionManagerController(object):
|
|||||||
# Create the session object based in session type.
|
# Create the session object based in session type.
|
||||||
if i.get("type") == "mastodon":
|
if i.get("type") == "mastodon":
|
||||||
s = MastodonSession.Session(i.get("id"))
|
s = MastodonSession.Session(i.get("id"))
|
||||||
|
elif i.get("type") == "gotosocial":
|
||||||
|
s = GotosocialSession.Session(i.get("id"))
|
||||||
s.get_configuration()
|
s.get_configuration()
|
||||||
if i.get("id") not in config.app["sessions"]["ignored_sessions"]:
|
if i.get("id") not in config.app["sessions"]["ignored_sessions"]:
|
||||||
try:
|
try:
|
||||||
@ -116,7 +119,7 @@ class sessionManagerController(object):
|
|||||||
s = MastodonSession.Session(location)
|
s = MastodonSession.Session(location)
|
||||||
result = s.authorise()
|
result = s.authorise()
|
||||||
if result == True:
|
if result == True:
|
||||||
self.sessions.append(dict(id=location, type=type))
|
self.sessions.append(dict(id=location, type=s.settings["mastodon"].get("type")))
|
||||||
self.view.add_new_session_to_list()
|
self.view.add_new_session_to_list()
|
||||||
|
|
||||||
def remove_account(self, index):
|
def remove_account(self, index):
|
||||||
|
@ -22,6 +22,7 @@ log = logging.getLogger("sessions.mastodonSession")
|
|||||||
MASTODON_VERSION = "4.0.1"
|
MASTODON_VERSION = "4.0.1"
|
||||||
|
|
||||||
class Session(base.baseSession):
|
class Session(base.baseSession):
|
||||||
|
version_check_mode = "created"
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(Session, self).__init__(*args, **kwargs)
|
super(Session, self).__init__(*args, **kwargs)
|
||||||
@ -32,6 +33,7 @@ class Session(base.baseSession):
|
|||||||
self.char_limit = 500
|
self.char_limit = 500
|
||||||
self.post_visibility = "public"
|
self.post_visibility = "public"
|
||||||
self.expand_spoilers = False
|
self.expand_spoilers = False
|
||||||
|
self.software = "mastodon"
|
||||||
pub.subscribe(self.on_status, "mastodon.status_received")
|
pub.subscribe(self.on_status, "mastodon.status_received")
|
||||||
pub.subscribe(self.on_status_updated, "mastodon.status_updated")
|
pub.subscribe(self.on_status_updated, "mastodon.status_updated")
|
||||||
pub.subscribe(self.on_notification, "mastodon.notification_received")
|
pub.subscribe(self.on_notification, "mastodon.notification_received")
|
||||||
@ -40,7 +42,7 @@ class Session(base.baseSession):
|
|||||||
if self.settings["mastodon"]["access_token"] != None and self.settings["mastodon"]["instance"] != None:
|
if self.settings["mastodon"]["access_token"] != None and self.settings["mastodon"]["instance"] != None:
|
||||||
try:
|
try:
|
||||||
log.debug("Logging in to Mastodon instance {}...".format(self.settings["mastodon"]["instance"]))
|
log.debug("Logging in to Mastodon instance {}...".format(self.settings["mastodon"]["instance"]))
|
||||||
self.api = mastodon.Mastodon(access_token=self.settings["mastodon"]["access_token"], api_base_url=self.settings["mastodon"]["instance"], mastodon_version=MASTODON_VERSION, user_agent="TWBlue/{}".format(application.version))
|
self.api = mastodon.Mastodon(access_token=self.settings["mastodon"]["access_token"], api_base_url=self.settings["mastodon"]["instance"], mastodon_version=MASTODON_VERSION, user_agent="TWBlue/{}".format(application.version), version_check_mode=self.version_check_mode)
|
||||||
if verify_credentials == True:
|
if verify_credentials == True:
|
||||||
credentials = self.api.account_verify_credentials()
|
credentials = self.api.account_verify_credentials()
|
||||||
self.db["user_name"] = credentials["username"]
|
self.db["user_name"] = credentials["username"]
|
||||||
@ -67,7 +69,7 @@ class Session(base.baseSession):
|
|||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
client_id, client_secret = mastodon.Mastodon.create_app("TWBlue", api_base_url=authorisation_dialog.GetValue(), website="https://twblue.es")
|
client_id, client_secret = mastodon.Mastodon.create_app("TWBlue", api_base_url=authorisation_dialog.GetValue(), website="https://twblue.es")
|
||||||
temporary_api = mastodon.Mastodon(client_id=client_id, client_secret=client_secret, api_base_url=instance, mastodon_version=MASTODON_VERSION, user_agent="TWBlue/{}".format(application.version))
|
temporary_api = mastodon.Mastodon(client_id=client_id, client_secret=client_secret, api_base_url=instance, mastodon_version=MASTODON_VERSION, user_agent="TWBlue/{}".format(application.version), version_check_mode="none") # disable version check so we can handle more platforms than Mastodon.
|
||||||
auth_url = temporary_api.auth_request_url()
|
auth_url = temporary_api.auth_request_url()
|
||||||
except MastodonError:
|
except MastodonError:
|
||||||
dlg = wx.MessageDialog(None, _("We could not connect to your mastodon instance. Please verify that the domain exists and the instance is accessible via a web browser."), _("Instance error"), wx.ICON_ERROR)
|
dlg = wx.MessageDialog(None, _("We could not connect to your mastodon instance. Please verify that the domain exists and the instance is accessible via a web browser."), _("Instance error"), wx.ICON_ERROR)
|
||||||
@ -90,6 +92,13 @@ class Session(base.baseSession):
|
|||||||
return
|
return
|
||||||
self.create_session_folder()
|
self.create_session_folder()
|
||||||
self.get_configuration()
|
self.get_configuration()
|
||||||
|
# handle when the instance is GoTosocial.
|
||||||
|
# this might be extended for other activity pub software later on.
|
||||||
|
nodeinfo = temporary_api.instance_nodeinfo()
|
||||||
|
if nodeinfo.software.get("name") == "gotosocial":
|
||||||
|
self.settings["mastodon"]["type"] = nodeinfo.software.get("name")
|
||||||
|
# GoToSocial doesn't support certain buffers so we redefine all of them here.
|
||||||
|
self.settings["general"]["buffer_order"] = ['home', 'local', 'mentions', 'sent', 'favorites', 'bookmarks', 'followers', 'following', 'blocked', 'notifications']
|
||||||
self.settings["mastodon"]["access_token"] = access_token
|
self.settings["mastodon"]["access_token"] = access_token
|
||||||
self.settings["mastodon"]["instance"] = instance
|
self.settings["mastodon"]["instance"] = instance
|
||||||
self.settings.write()
|
self.settings.write()
|
||||||
@ -117,11 +126,20 @@ class Session(base.baseSession):
|
|||||||
|
|
||||||
def get_lists(self):
|
def get_lists(self):
|
||||||
""" Gets the lists that the user is subscribed to and stores them in the database. Returns None."""
|
""" Gets the lists that the user is subscribed to and stores them in the database. Returns None."""
|
||||||
|
if self.software == "gotosocial":
|
||||||
|
self.db["lists"] = []
|
||||||
|
return
|
||||||
self.db["lists"] = self.api.lists()
|
self.db["lists"] = self.api.lists()
|
||||||
|
|
||||||
def get_muted_users(self):
|
def get_muted_users(self):
|
||||||
### ToDo: Use a function to retrieve all muted users.
|
### ToDo: Use a function to retrieve all muted users.
|
||||||
self.db["muted_users"] = self.api.mutes()
|
if self.software == "gotosocial":
|
||||||
|
self.db["muted_users"] = []
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
self.db["muted_users"] = self.api.mutes()
|
||||||
|
except MastodonNotFoundError:
|
||||||
|
self.db["muted_users"] = []
|
||||||
|
|
||||||
def order_buffer(self, name, data, ignore_older=False):
|
def order_buffer(self, name, data, ignore_older=False):
|
||||||
num = 0
|
num = 0
|
||||||
@ -229,6 +247,8 @@ class Session(base.baseSession):
|
|||||||
if self.settings["general"]["disable_streaming"]:
|
if self.settings["general"]["disable_streaming"]:
|
||||||
log.info("Streaming is disabled for session {}. Skipping...".format(self.get_name()))
|
log.info("Streaming is disabled for session {}. Skipping...".format(self.get_name()))
|
||||||
return
|
return
|
||||||
|
if self.software == "gotosocial":
|
||||||
|
return
|
||||||
listener = streaming.StreamListener(session_name=self.get_name(), user_id=self.db["user_id"])
|
listener = streaming.StreamListener(session_name=self.get_name(), user_id=self.db["user_id"])
|
||||||
try:
|
try:
|
||||||
stream_healthy = self.api.stream_healthy()
|
stream_healthy = self.api.stream_healthy()
|
||||||
|
Loading…
Reference in New Issue
Block a user