Added accepting/declining friend requests from friendship request folder by using the menu key or right mouse click
This commit is contained in:
parent
15e4c19f04
commit
52f892f35f
@ -809,7 +809,19 @@ class peopleBuffer(feedBuffer):
|
||||
pass
|
||||
|
||||
def get_menu(self, *args, **kwargs):
|
||||
m = menus.peopleMenu()
|
||||
""" display menu for people buffers (friends and requests)"""
|
||||
# If this is an incoming requests buffer, there is a flag in the peopleMenu that shows a few new options.
|
||||
# So let's make sure we call it accordingly.
|
||||
if self.name == "friend_requests":
|
||||
m = menus.peopleMenu(is_request=True)
|
||||
# Connect the accept and decline methods from here.
|
||||
widgetUtils.connect_event(m, widgetUtils.MENU, self.accept_friendship, menuitem=m.accept)
|
||||
widgetUtils.connect_event(m, widgetUtils.MENU, self.decline_friendship, menuitem=m.decline)
|
||||
else:
|
||||
m = menus.peopleMenu(is_request=False)
|
||||
# It is not allowed to send messages to people who is not your friends, so let's disble it if we're in a pending or outgoing requests folder.
|
||||
if "friend_requests" in self.name:
|
||||
m.message.Enable(False)
|
||||
widgetUtils.connect_event(m, widgetUtils.MENU, self.new_chat, menuitem=m.message)
|
||||
widgetUtils.connect_event(m, widgetUtils.MENU, self.open_timeline, menuitem=m.timeline)
|
||||
widgetUtils.connect_event(m, widgetUtils.MENU, self.open_person_profile, menuitem=m.view_profile)
|
||||
@ -821,6 +833,12 @@ class peopleBuffer(feedBuffer):
|
||||
|
||||
def pause_audio(self, *args, **kwargs): pass
|
||||
|
||||
def accept_friendship(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def decline_friendship(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
class requestsBuffer(peopleBuffer):
|
||||
|
||||
def get_items(self, show_nextpage=False):
|
||||
@ -841,3 +859,25 @@ class requestsBuffer(peopleBuffer):
|
||||
else:
|
||||
[self.insert(i) for i in self.session.db[self.name]["items"][:num]]
|
||||
return retrieved
|
||||
|
||||
def accept_friendship(self, *args, **kwargs):
|
||||
""" Adds a person to a list of friends. This method is done for accepting someone else's friend requet."""
|
||||
person = self.get_post()
|
||||
result = self.session.vk.client.friends.add(user_id=person["id"])
|
||||
if result == 2:
|
||||
msg = _(u"{0} {1} now is your friend.").format(person["first_name"], person["last_name"])
|
||||
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 decline_friendship(self, *args, **kwargs):
|
||||
""" Declines a freind request."""
|
||||
person = self.get_post()
|
||||
result = self.session.vk.client.friends.delete(user_id=person["id"])
|
||||
if "out_request_deleted" in result:
|
||||
msg = _(u"You've deleted the friends request to {0} {1}.").format(person["first_name"], person["last_name"])
|
||||
elif "in_request_deleted" in result:
|
||||
msg = _(u"You've declined the friend request of {0} {1}.").format(person["first_name"], person["last_name"])
|
||||
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())
|
@ -137,6 +137,7 @@ class Controller(object):
|
||||
pub.subscribe(self.user_profile, "user-profile")
|
||||
pub.subscribe(self.user_online, "user-online")
|
||||
pub.subscribe(self.user_offline, "user-offline")
|
||||
pub.subscribe(self.notify, "notify")
|
||||
widgetUtils.connect_event(self.window, widgetUtils.CLOSE_EVENT, self.exit)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.update_buffer, menuitem=self.window.update_buffer)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.check_for_updates, menuitem=self.window.check_for_updates)
|
||||
@ -176,6 +177,7 @@ class Controller(object):
|
||||
pub.unsubscribe(self.update_status_bar, "update-status-bar")
|
||||
pub.unsubscribe(self.user_online, "user-online")
|
||||
pub.unsubscribe(self.user_offline, "user-offline")
|
||||
pub.unsubscribe(self.notify, "notify")
|
||||
|
||||
def authorisation_failed(self):
|
||||
commonMessages.bad_authorisation()
|
||||
@ -610,3 +612,6 @@ class Controller(object):
|
||||
|
||||
def view_my_profile_in_browser(self, *args, **kwargs):
|
||||
webbrowser.open_new_tab("https://vk.com/id{id}".format(id=self.session.user_id,))
|
||||
|
||||
def notify(self, message=""):
|
||||
self.window.notify(_("Socializer"), message)
|
@ -39,14 +39,24 @@ class audioMenu(wx.Menu):
|
||||
self.Append(self.move)
|
||||
|
||||
class peopleMenu(wx.Menu):
|
||||
def __init__(self, *args, **kwargs):
|
||||
def __init__(self, is_request=False, *args, **kwargs):
|
||||
super(peopleMenu, self).__init__(*args, **kwargs)
|
||||
if is_request:
|
||||
self.create_extra_items()
|
||||
self.view_profile = wx.MenuItem(self, wx.NewId(), _(u"View profile"))
|
||||
self.Append(self.view_profile)
|
||||
self.message = wx.MenuItem(self, wx.NewId(), _(u"Send a message"))
|
||||
self.Append(self.message)
|
||||
self.timeline = wx.MenuItem(self, wx.NewId(), _(u"Open timeline"))
|
||||
self.Append(self.timeline)
|
||||
self.common_friends = wx.MenuItem(self, wx.NewId(), _(u"View friends in common"))
|
||||
self.Append(self.common_friends)
|
||||
|
||||
def create_extra_items(self):
|
||||
self.accept = wx.MenuItem(self, wx.NewId(), _(u"Accept"))
|
||||
self.Append(self.accept)
|
||||
self.decline = wx.MenuItem(self, wx.NewId(), _(u"Decline"))
|
||||
self.Append(self.decline)
|
||||
|
||||
class commentMenu(wx.Menu):
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
Loading…
Reference in New Issue
Block a user