Now it is possible to post as group or username in group walls

This commit is contained in:
Manuel Cortez 2019-05-06 14:58:45 -05:00
parent f81d302c9a
commit 75267294f9
3 changed files with 31 additions and 5 deletions

View File

@ -4,6 +4,8 @@
### New additions ### New additions
* Added "post in groups" feature. In order to do so, you need to load the posts for the group where you want to send something. Once loaded, go to the post button in the group's wall and select whether you want to post in the group's behalf or as yourself.
### bugfixes ### bugfixes
* Fixed an error with two factor authentication in the recent socializer version. Now it works reliably again. * Fixed an error with two factor authentication in the recent socializer version. Now it works reliably again.

View File

@ -475,11 +475,14 @@ class feedBuffer(baseBuffer):
class communityBuffer(feedBuffer): class communityBuffer(feedBuffer):
def __init__(self, group_info, *args, **kwargs):
super(communityBuffer, self).__init__(*args, **kwargs)
self.group_data = group_info
def create_tab(self, parent): def create_tab(self, parent):
self.tab = home.communityTab(parent) self.tab = home.communityTab(parent)
self.connect_events() self.connect_events()
self.tab.name = self.name self.tab.name = self.name
if hasattr(self, "can_post") and self.can_post == False and hasattr(self.tab, "post"):
self.tab.post.Enable(False) self.tab.post.Enable(False)
def connect_events(self): def connect_events(self):
@ -497,9 +500,30 @@ class communityBuffer(feedBuffer):
if self.can_get_items: if self.can_get_items:
# Strangely, groups.get does not return counters so we need those to show options for loading specific posts for communities. # Strangely, groups.get does not return counters so we need those to show options for loading specific posts for communities.
self.group_info = self.session.vk.client.groups.getById(group_ids=-1*self.kwargs["owner_id"], fields="counters")[0] self.group_info = self.session.vk.client.groups.getById(group_ids=-1*self.kwargs["owner_id"], fields="counters")[0]
# print(self.group_info["counters"]) self.group_info.update(self.group_data)
print(self.group_info)
if "can_post" in self.group_info and self.group_info["can_post"] == True:
self.tab.post.Enable(True)
super(communityBuffer, self).get_items(*args, **kwargs) super(communityBuffer, self).get_items(*args, **kwargs)
def post(self, *args, **kwargs):
menu = wx.Menu()
user1 = self.session.get_user(self.session.user_id)
user2 = self.session.get_user(self.kwargs["owner_id"])
user = menu.Append(wx.NewId(), _("Post as {user1_nom}").format(**user1))
group = menu.Append(wx.NewId(), _("Post as {user1_nom}").format(**user2))
menu.Bind(widgetUtils.MENU, lambda evt: self._post(evt, 1), group)
menu.Bind(widgetUtils.MENU, lambda evt: self._post(evt, 0), user)
self.tab.post.PopupMenu(menu, self.tab.post.GetPosition())
def _post(self, event, from_group):
owner_id = self.kwargs["owner_id"]
user = self.session.get_user(owner_id, key="user1")
title = _("Post to {user1_nom}'s wall").format(**user)
p = presenters.createPostPresenter(session=self.session, interactor=interactors.createPostInteractor(), view=views.createPostDialog(title=title, message="", text=""))
if hasattr(p, "text") or hasattr(p, "privacy"):
call_threaded(self.do_last, p=p, owner_id=owner_id, from_group=from_group)
class topicBuffer(feedBuffer): class topicBuffer(feedBuffer):
def create_tab(self, parent): def create_tab(self, parent):

View File

@ -200,14 +200,14 @@ class Controller(object):
if self.session.settings["load_at_startup"]["communities"] == False and force_action == False: if self.session.settings["load_at_startup"]["communities"] == False and force_action == False:
return return
log.debug("Create community buffers...") log.debug("Create community buffers...")
groups= self.session.vk.client.groups.get(user_id=user_id, extended=1, count=1000) groups= self.session.vk.client.groups.get(user_id=user_id, extended=1, count=1000, fields="can_post")
self.session.groups=groups["items"] self.session.groups=groups["items"]
# Let's feed the local database cache with new groups coming from here. # Let's feed the local database cache with new groups coming from here.
data= dict(profiles=[], groups=self.session.groups) data= dict(profiles=[], groups=self.session.groups)
self.session.process_usernames(data) self.session.process_usernames(data)
if create_buffers: if create_buffers:
for i in self.session.groups: for i in self.session.groups:
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="communityBuffer", buffer_title=i["name"], parent_tab="communities", loadable=True, get_items=True, kwargs=dict(parent=self.window.tb, name="{0}_community".format(i["id"],), composefunc="render_status", session=self.session, endpoint="get", parent_endpoint="wall", extended=1, count=self.session.settings["buffers"]["count_for_wall_buffers"], owner_id=-1*i["id"])) wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="communityBuffer", buffer_title=i["name"], parent_tab="communities", loadable=True, get_items=True, kwargs=dict(parent=self.window.tb, name="{0}_community".format(i["id"],), composefunc="render_status", session=self.session, group_info=i, endpoint="get", parent_endpoint="wall", extended=1, count=self.session.settings["buffers"]["count_for_wall_buffers"], owner_id=-1*i["id"]))
time.sleep(0.15) time.sleep(0.15)
def login(self): def login(self):