Added block in people buffers' menu and blacklist management in the application menu

This commit is contained in:
2019-10-10 10:43:29 -05:00
parent f274ba9caa
commit 19a5216373
12 changed files with 118 additions and 0 deletions

View File

@@ -1362,6 +1362,7 @@ class peopleBuffer(feedBuffer):
else:
m = menus.peopleMenu(is_request=False)
widgetUtils.connect_event(m, widgetUtils.MENU, self.decline_friendship, menuitem=m.decline)
widgetUtils.connect_event(m, widgetUtils.MENU, self.block_person, menuitem=m.block)
# It is not allowed to send messages to people who is not your friends, so let's disable it if we're in a pending or outgoing requests buffer.
if "friend_requests" in self.name:
m.message.Enable(False)
@@ -1395,6 +1396,21 @@ class peopleBuffer(feedBuffer):
self.session.db[self.name]["items"].pop(self.tab.list.get_selected())
self.tab.list.remove_item(self.tab.list.get_selected())
def block_person(self, *args, **kwargs):
person = self.get_post()
if person == None:
return
user = self.session.get_user(person["id"])
question = commonMessages.block_person(user)
if question == widgetUtils.NO:
return
result = self.session.vk.client.account.ban(owner_id=person["id"])
if result == 1:
msg = _("You've blocked {user1_nom} from your friends.").format(**user,)
pub.sendMessage("notify", message=msg)
self.session.db[self.name]["items"].pop(self.tab.list.get_selected())
self.tab.list.remove_item(self.tab.list.get_selected())
def keep_as_follower(self, *args, **kwargs):
pass

View File

@@ -624,6 +624,7 @@ class Controller(object):
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.changelog, menuitem=self.window.changelog)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.open_logs, menuitem=self.window.open_logs)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.open_config, menuitem=self.window.open_config)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.blacklist, menuitem=self.window.blacklist)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.configuration, menuitem=self.window.settings_dialog)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.new_timeline, menuitem=self.window.timeline)
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.create_audio_album, menuitem=self.window.audio_album)
@@ -723,10 +724,15 @@ class Controller(object):
os.chdir("documentation/%s" % (lang,))
webbrowser.open("changelog.html")
os.chdir("../../")
def configuration(self, *args, **kwargs):
""" Opens the global settings dialogue."""
presenter = presenters.configurationPresenter(session=self.session, view=views.configurationDialog(title=_("Preferences")), interactor=interactors.configurationInteractor())
def blacklist(self, *args, **kwargs):
""" Opens the blacklist presenter."""
presenter = presenters.blacklistPresenter(session=self.session, view=views.blacklistDialog(), interactor=interactors.blacklistInteractor())
def open_logs(self, *args, **kwargs):
subprocess.call(["explorer", paths.logs_path()])

View File

@@ -1,5 +1,6 @@
from .attach import *
from . audioRecorder import *
from . blacklist import *
from .configuration import *
from .postCreation import *
from .postDisplayer import *

View File

@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
import widgetUtils
from wxUI import commonMessages
from pubsub import pub
from . import base
class blacklistInteractor(base.baseInteractor):
def add_items(self, control, items):
if not hasattr(self.view, control):
raise AttributeError("The control is not present in the view.")
for i in items:
getattr(self.view, control).insert_item(False, *i)
def install(self, *args, **kwargs):
super(blacklistInteractor, self).install(*args, **kwargs)
widgetUtils.connect_event(self.view.unblock, widgetUtils.BUTTON_PRESSED, self.on_unblock)
pub.subscribe(self.add_items, self.modulename+"_add_items")
def uninstall(self):
super(blacklistInteractor, self).uninstall()
pub.unsubscribe(self.add_items, self.modulename+"_add_items")
def on_unblock(self, *args, **kwargs):
question = commonMessages.unblock_person()
if question == widgetUtils.NO:
return
item = self.view.persons.get_selected()
if self.presenter.unblock_person(item) == 1:
self.view.persons.remove_item(item)

View File

@@ -13,6 +13,7 @@
"""
from .attach import *
from .audioRecorder import *
from .blacklist import *
from .createPosts import *
from .displayPosts import *
from .configuration import *

View File

@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
import threading
from pubsub import pub
from . import base
class blacklistPresenter(base.basePresenter):
def __init__(self, session, view, interactor):
self.session = session
super(blacklistPresenter, self).__init__(view=view, interactor=interactor, modulename="blacklist")
self.worker = threading.Thread(target=self.load_information)
self.worker.finished = threading.Event()
self.worker.start()
self.run()
def load_information(self):
banned_users = self.session.vk.client.account.getBanned(count=200)
self.users = banned_users["profiles"]
items = []
for i in self.users:
str_user = "{first_name} {last_name}".format(first_name=i["first_name"], last_name=i["last_name"])
items.append([str_user])
self.send_message("add_items", control="persons", items=items)
def unblock_person(self, item):
result = self.session.vk.client.account.unban(owner_id=self.users[item]["id"])
if result == 1:
msg = _("You've unblocked {user1_nom} from your friends.").format(**self.session.get_user(self.users[item]["id"]),)
pub.sendMessage("notify", message=msg)
return result

View File

@@ -5,6 +5,7 @@
"""
from .dialogs.attach import *
from .dialogs.audioRecorder import *
from .dialogs.blacklist import *
from .dialogs.postCreation import *
from .dialogs.postDisplay import *
from .dialogs.configuration import *

View File

@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import wx
import widgetUtils
class blacklistDialog(widgetUtils.BaseDialog):
def __init__(self):
super(blacklistDialog, self).__init__(parent=None, title=_("blacklist"))
panel = wx.Panel(self)
sizer = wx.BoxSizer(wx.VERTICAL)
box1 = wx.StaticBoxSizer(parent=panel, orient=wx.HORIZONTAL, label=_("blocked users"))
self.persons = widgetUtils.list(panel, _("User"), style=wx.LC_REPORT)
box1.Add(self.persons.list, 0, wx.ALL, 5)
sizer.Add(box1, 0, wx.ALL, 5)
self.unblock = wx.Button(panel, wx.NewId(), _("Unblock"))
sizer.Add(self.unblock, 0, wx.ALL, 5)
close = wx.Button(panel, wx.ID_CLOSE)
sizer.Add(close, 0, wx.ALL, 5)
panel.SetSizer(sizer)
self.SetClientSize(sizer.CalcMin())

View File

@@ -68,5 +68,11 @@ def community_no_items():
def delete_conversation():
return wx.MessageDialog(None, _("do you really want to delete all messages of this conversation in VK?"), _("Attention"), style=wx.ICON_QUESTION|wx.YES_NO).ShowModal()
def block_person(person):
return wx.MessageDialog(None, _("Are you really sure you want to block {user1_nom} from your VK account?").format(**person,), _("Attention"), style=wx.ICON_QUESTION|wx.YES_NO).ShowModal()
def unblock_person():
return wx.MessageDialog(None, _("Are you sure you want to unblock this user?"), _("Attention"), style=wx.ICON_QUESTION|wx.YES_NO).ShowModal()
def post_failed():
return wx.MessageDialog(None, _("Unfortunately, we could not send your last post or message to VK. Would you like to try again?"), _("Post failed"), style=wx.ICON_QUESTION|wx.YES_NO).ShowModal()

View File

@@ -15,6 +15,7 @@ class mainWindow(wx.Frame):
self.delete_audio_album = delete.Append(wx.NewId(), _("Audio album"))
self.delete_video_album = delete.Append(wx.NewId(), _("Video album"))
app_.Append(wx.NewId(), _("Delete"), delete)
self.blacklist = app_.Append(wx.NewId(), _("Blacklist"))
self.settings_dialog = app_.Append(wx.NewId(), _("Preferences"))
me = wx.Menu()
profile = wx.Menu()

View File

@@ -45,15 +45,18 @@ class peopleMenu(wx.Menu):
self.common_friends = self.Append(wx.NewId(), _("View friends in common"))
if is_request == False and is_subscriber == False and not_friend == False:
self.decline = self.Append(wx.NewId(), _("Remove from friends"))
self.block = self.Append(wx.NewId(), _("Block"))
self.open_in_browser = self.Append(wx.NewId(), _("Open in vk.com"))
def create_request_items(self):
self.accept = self.Append(wx.NewId(), _("Accept"))
self.decline = self.Append(wx.NewId(), _("Decline"))
self.keep_as_follower = self.Append(wx.NewId(), _("Keep as follower"))
self.block = self.Append(wx.NewId(), _("Block"))
def create_subscriber_items(self):
self.add = self.Append(wx.NewId(), _("Add to friends"))
self.block = self.Append(wx.NewId(), _("Block"))
class documentMenu(wx.Menu):
def __init__(self, added=False, *args, **kwargs):