mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-26 12:53:12 -06:00
Implemented userActions for mastodon sessions
This commit is contained in:
parent
035de92496
commit
120da217f5
@ -2,6 +2,7 @@
|
|||||||
import logging
|
import logging
|
||||||
from pubsub import pub
|
from pubsub import pub
|
||||||
from sessions.twitter import utils
|
from sessions.twitter import utils
|
||||||
|
from . import userActions
|
||||||
|
|
||||||
log = logging.getLogger("controller.mastodon.handler")
|
log = logging.getLogger("controller.mastodon.handler")
|
||||||
|
|
||||||
@ -79,3 +80,20 @@ class Handler(object):
|
|||||||
toot = toot.reblog
|
toot = toot.reblog
|
||||||
conversations_position =controller.view.search("direct_messages", buffer.session.db["user_name"])
|
conversations_position =controller.view.search("direct_messages", buffer.session.db["user_name"])
|
||||||
pub.sendMessage("createBuffer", buffer_type="ConversationBuffer", session_type=buffer.session.type, buffer_title=_("Conversation with {0}").format(toot.account.acct), parent_tab=conversations_position, start=True, kwargs=dict(parent=controller.view.nb, function="status_context", name="%s-conversation" % (toot.id,), sessionObject=buffer.session, account=buffer.session.db["user_name"], sound="search_updated.ogg", toot=toot, id=toot.id))
|
pub.sendMessage("createBuffer", buffer_type="ConversationBuffer", session_type=buffer.session.type, buffer_title=_("Conversation with {0}").format(toot.account.acct), parent_tab=conversations_position, start=True, kwargs=dict(parent=controller.view.nb, function="status_context", name="%s-conversation" % (toot.id,), sessionObject=buffer.session, account=buffer.session.db["user_name"], sound="search_updated.ogg", toot=toot, id=toot.id))
|
||||||
|
|
||||||
|
def follow(self, buffer):
|
||||||
|
if not hasattr(buffer, "get_item"):
|
||||||
|
return
|
||||||
|
item = buffer.get_item()
|
||||||
|
if buffer.type == "user":
|
||||||
|
users = [item.acct]
|
||||||
|
elif buffer.type == "baseBuffer":
|
||||||
|
if item.reblog != None:
|
||||||
|
users = [user.acct for user in item.reblog.mentions if user.id != buffer.session.db["user_id"]]
|
||||||
|
if item.reblog.account.acct not in users and item.account.id != buffer.session.db["user_id"]:
|
||||||
|
users.insert(0, item.reblog.account.acct)
|
||||||
|
else:
|
||||||
|
users = [user.acct for user in item.mentions if user.id != buffer.session.db["user_id"]]
|
||||||
|
if item.account.acct not in users and item.account.id != buffer.session.db["user_id"]:
|
||||||
|
users.insert(0, item.account.acct)
|
||||||
|
u = userActions.userActionsController(buffer.session, users)
|
||||||
|
80
src/controller/mastodon/userActions.py
Normal file
80
src/controller/mastodon/userActions.py
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
import logging
|
||||||
|
import widgetUtils
|
||||||
|
import output
|
||||||
|
from wxUI.dialogs.mastodon import userActions
|
||||||
|
from pubsub import pub
|
||||||
|
from mastodon import MastodonError, MastodonNotFoundError
|
||||||
|
from extra.autocompletionUsers import completion
|
||||||
|
|
||||||
|
log = logging.getLogger("controller.mastodon.userActions")
|
||||||
|
|
||||||
|
class userActionsController(object):
|
||||||
|
def __init__(self, session, users=[], default="follow"):
|
||||||
|
super(userActionsController, self).__init__()
|
||||||
|
self.session = session
|
||||||
|
self.dialog = userActions.UserActionsDialog(users, default)
|
||||||
|
widgetUtils.connect_event(self.dialog.autocompletion, widgetUtils.BUTTON_PRESSED, self.autocomplete_users)
|
||||||
|
if self.dialog.get_response() == widgetUtils.OK:
|
||||||
|
self.process_action()
|
||||||
|
|
||||||
|
def autocomplete_users(self, *args, **kwargs):
|
||||||
|
c = completion.autocompletionUsers(self.dialog, self.session.session_id)
|
||||||
|
c.show_menu("dm")
|
||||||
|
|
||||||
|
def process_action(self):
|
||||||
|
action = self.dialog.get_action()
|
||||||
|
user = self.dialog.get_user()
|
||||||
|
user = self.search_user(user)
|
||||||
|
if user == None:
|
||||||
|
return
|
||||||
|
getattr(self, action)(user)
|
||||||
|
|
||||||
|
def search_user(self, user):
|
||||||
|
try:
|
||||||
|
users = self.session.api.account_search(user)
|
||||||
|
if len(users) > 0:
|
||||||
|
return users[0]
|
||||||
|
except MastodonError:
|
||||||
|
log.exception("Error searching for user %s.".format(user))
|
||||||
|
|
||||||
|
def follow(self, user):
|
||||||
|
try:
|
||||||
|
self.session.api.account_follow(user.id)
|
||||||
|
pub.sendMessage("restartStreaming", session=self.session.session_id)
|
||||||
|
except MastodonError as err:
|
||||||
|
output.speak("Error %s" % (str(err)), True)
|
||||||
|
|
||||||
|
def unfollow(self, user):
|
||||||
|
try:
|
||||||
|
result = self.session.api.account_unfollow(user.id)
|
||||||
|
pub.sendMessage("restartStreaming", session=self.session.session_id)
|
||||||
|
except MastodonError as err:
|
||||||
|
output.speak("Error %s" % (str(err)), True)
|
||||||
|
|
||||||
|
def mute(self, user):
|
||||||
|
try:
|
||||||
|
id = self.session.api.account_mute(user.id)
|
||||||
|
pub.sendMessage("restartStreaming", session=self.session.session_id)
|
||||||
|
except MastodonError as err:
|
||||||
|
output.speak("Error %s" % (str(err)), True)
|
||||||
|
|
||||||
|
def unmute(self, user):
|
||||||
|
try:
|
||||||
|
id = self.session.api.account_unmute(user.id)
|
||||||
|
pub.sendMessage("restartStreaming", session=self.session.session_id)
|
||||||
|
except MastodonError as err:
|
||||||
|
output.speak("Error %s" % (str(err)), True)
|
||||||
|
|
||||||
|
def block(self, user):
|
||||||
|
try:
|
||||||
|
id = self.session.api.account_block(user.id)
|
||||||
|
pub.sendMessage("restartStreaming", session=self.session.session_id)
|
||||||
|
except MastodonError as err:
|
||||||
|
output.speak("Error %s" % (str(err)), True)
|
||||||
|
|
||||||
|
def unblock(self, user):
|
||||||
|
try:
|
||||||
|
id = self.session.api.account_unblock(user.id)
|
||||||
|
except MastodonError as err:
|
||||||
|
output.speak("Error %s" % (str(err)), True)
|
@ -12,7 +12,7 @@ class userPanel(wx.Panel):
|
|||||||
def __init__(self, parent, name):
|
def __init__(self, parent, name):
|
||||||
super(userPanel, self).__init__(parent)
|
super(userPanel, self).__init__(parent)
|
||||||
self.name = name
|
self.name = name
|
||||||
self.type = "baseBuffer"
|
self.type = "user"
|
||||||
self.sizer = wx.BoxSizer(wx.VERTICAL)
|
self.sizer = wx.BoxSizer(wx.VERTICAL)
|
||||||
self.create_list()
|
self.create_list()
|
||||||
self.toot = wx.Button(self, -1, _("Toot"))
|
self.toot = wx.Button(self, -1, _("Toot"))
|
||||||
|
79
src/wxUI/dialogs/mastodon/userActions.py
Normal file
79
src/wxUI/dialogs/mastodon/userActions.py
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
import wx
|
||||||
|
|
||||||
|
class UserActionsDialog(wx.Dialog):
|
||||||
|
def __init__(self, users=[], default="follow", *args, **kwargs):
|
||||||
|
super(UserActionsDialog, self).__init__(parent=None, *args, **kwargs)
|
||||||
|
panel = wx.Panel(self)
|
||||||
|
userSizer = wx.BoxSizer()
|
||||||
|
self.SetTitle(_(u"Action"))
|
||||||
|
userLabel = wx.StaticText(panel, -1, _(u"&User"))
|
||||||
|
self.cb = wx.ComboBox(panel, -1, choices=users, value=users[0])
|
||||||
|
self.cb.SetFocus()
|
||||||
|
self.autocompletion = wx.Button(panel, -1, _(u"&Autocomplete users"))
|
||||||
|
userSizer.Add(userLabel, 0, wx.ALL, 5)
|
||||||
|
userSizer.Add(self.cb, 0, wx.ALL, 5)
|
||||||
|
userSizer.Add(self.autocompletion, 0, wx.ALL, 5)
|
||||||
|
actionSizer = wx.BoxSizer(wx.VERTICAL)
|
||||||
|
label2 = wx.StaticText(panel, -1, _(u"Action"))
|
||||||
|
self.follow = wx.RadioButton(panel, -1, _(u"&Follow"), name=_(u"Action"), style=wx.RB_GROUP)
|
||||||
|
self.unfollow = wx.RadioButton(panel, -1, _(u"U&nfollow"))
|
||||||
|
self.mute = wx.RadioButton(panel, -1, _(u"&Mute"))
|
||||||
|
self.unmute = wx.RadioButton(panel, -1, _(u"Unmu&te"))
|
||||||
|
self.block = wx.RadioButton(panel, -1, _(u"&Block"))
|
||||||
|
self.unblock = wx.RadioButton(panel, -1, _(u"Unbl&ock"))
|
||||||
|
self.setup_default(default)
|
||||||
|
hSizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||||
|
hSizer.Add(label2, 0, wx.ALL, 5)
|
||||||
|
actionSizer.Add(self.follow, 0, wx.ALL, 5)
|
||||||
|
actionSizer.Add(self.unfollow, 0, wx.ALL, 5)
|
||||||
|
actionSizer.Add(self.mute, 0, wx.ALL, 5)
|
||||||
|
actionSizer.Add(self.unmute, 0, wx.ALL, 5)
|
||||||
|
actionSizer.Add(self.block, 0, wx.ALL, 5)
|
||||||
|
actionSizer.Add(self.unblock, 0, wx.ALL, 5)
|
||||||
|
hSizer.Add(actionSizer, 0, wx.ALL, 5)
|
||||||
|
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||||
|
ok = wx.Button(panel, wx.ID_OK, _(u"&OK"))
|
||||||
|
ok.SetDefault()
|
||||||
|
cancel = wx.Button(panel, wx.ID_CANCEL, _(u"&Close"))
|
||||||
|
btnsizer = wx.BoxSizer()
|
||||||
|
btnsizer.Add(ok)
|
||||||
|
btnsizer.Add(cancel)
|
||||||
|
sizer.Add(userSizer)
|
||||||
|
sizer.Add(hSizer, 0, wx.ALL, 5)
|
||||||
|
sizer.Add(btnsizer)
|
||||||
|
panel.SetSizer(sizer)
|
||||||
|
|
||||||
|
def get_action(self):
|
||||||
|
if self.follow.GetValue() == True: return "follow"
|
||||||
|
elif self.unfollow.GetValue() == True: return "unfollow"
|
||||||
|
elif self.mute.GetValue() == True: return "mute"
|
||||||
|
elif self.unmute.GetValue() == True: return "unmute"
|
||||||
|
elif self.block.GetValue() == True: return "block"
|
||||||
|
elif self.unblock.GetValue() == True: return "unblock"
|
||||||
|
|
||||||
|
def setup_default(self, default):
|
||||||
|
if default == "follow":
|
||||||
|
self.follow.SetValue(True)
|
||||||
|
elif default == "unfollow":
|
||||||
|
self.unfollow.SetValue(True)
|
||||||
|
elif default == "mute":
|
||||||
|
self.mute.SetValue(True)
|
||||||
|
elif default == "unmute":
|
||||||
|
self.unmute.SetValue(True)
|
||||||
|
elif default == "block":
|
||||||
|
self.block.SetValue(True)
|
||||||
|
elif default == "unblock":
|
||||||
|
self.unblock.SetValue(True)
|
||||||
|
|
||||||
|
def get_response(self):
|
||||||
|
return self.ShowModal()
|
||||||
|
|
||||||
|
def get_user(self):
|
||||||
|
return self.cb.GetValue()
|
||||||
|
|
||||||
|
def get_position(self):
|
||||||
|
return self.cb.GetPosition()
|
||||||
|
|
||||||
|
def popup_menu(self, menu):
|
||||||
|
self.PopupMenu(menu, self.cb.GetPosition())
|
Loading…
Reference in New Issue
Block a user