Added topic creation in groups (experimental)

This commit is contained in:
Manuel Cortez 2019-05-06 17:57:34 -05:00
parent 72cc04342f
commit 91eebfd895
3 changed files with 95 additions and 12 deletions

View File

@ -501,7 +501,6 @@ class communityBuffer(feedBuffer):
# Strangely, groups.get does not return counters so we need those to show options for loading specific posts for communities.
group_info = self.session.vk.client.groups.getById(group_ids=-1*self.kwargs["owner_id"], fields="counters")[0]
self.session.db["group_info"][self.group_info].update(group_info)
print(self.session.db["group_info"][self.group_info])
if "can_post" in self.session.db["group_info"][self.group_id] and self.session.db["group_info"][self.group_id]["can_post"] == True:
self.tab.post.Enable(True)
super(communityBuffer, self).get_items(*args, **kwargs)
@ -530,7 +529,7 @@ class topicBuffer(feedBuffer):
self.tab = home.topicTab(parent)
self.connect_events()
self.tab.name = self.name
if hasattr(self, "can_post") and self.can_post == False and hasattr(self.tab, "post"):
if "can_create_topic" not in self.session.db["group_info"][self.kwargs["group_id"]*-1] or ("can_create_topic" in self.session.db["group_info"][self.kwargs["group_id"]*-1] and self.session.db["group_info"][self.kwargs["group_id"]*-1]["can_create_topic"] != True):
self.tab.post.Enable(False)
def onFocus(self, event, *args, **kwargs):
@ -545,7 +544,6 @@ class topicBuffer(feedBuffer):
def open_in_browser(self, *args, **kwargs):
post = self.get_post()
print(post)
if post == None:
return
# In order to load the selected topic we firstly have to catch the group_id, which is present in self.kwargs
@ -554,6 +552,43 @@ class topicBuffer(feedBuffer):
url = "https://vk.com/topic{group_id}_{topic_id}".format(group_id=group_id, topic_id=post["id"])
webbrowser.open_new_tab(url)
def post(self, *args, **kwargs):
menu = wx.Menu()
user1 = self.session.get_user(self.session.user_id)
user2 = self.session.get_user(-1*self.kwargs["group_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["group_id"]
user = self.session.get_user(-1*owner_id, key="user1")
title = _("Create topic in {user1_nom}").format(**user)
p = presenters.createPostPresenter(session=self.session, interactor=interactors.createPostInteractor(), view=views.createTopicDialog(title=title, message="", text=""))
if hasattr(p, "text") or hasattr(p, "privacy"):
call_threaded(self.do_last, p=p, group_id=owner_id, from_group=from_group)
def do_last(self, p, *args, **kwargs):
title = p.view.title
msg = p.text
attachments = ""
if hasattr(p, "attachments"):
attachments = self.upload_attachments(p.attachments)
urls = utils.find_urls_in_text(msg)
if len(urls) != 0:
if len(attachments) == 0: attachments = urls[0]
else: attachments += urls[0]
msg = msg.replace(urls[0], "")
if msg != "":
kwargs.update(text=msg, title=title.GetValue())
if attachments != "":
kwargs.update(attachments=attachments)
# Determines the correct functions to call here.
post = self.session.vk.client.board.addTopic(**kwargs)
pub.sendMessage("posted", buffer=self.name)
class documentBuffer(feedBuffer):
can_get_items = False

View File

@ -200,7 +200,7 @@ class Controller(object):
if self.session.settings["load_at_startup"]["communities"] == False and force_action == False:
return
log.debug("Create community buffers...")
groups= self.session.vk.client.groups.get(user_id=user_id, extended=1, count=1000, fields="can_post, can_create_topic")
groups= self.session.vk.client.groups.get(user_id=user_id, extended=1, count=1000, fields="can_post,can_create_topic")
self.session.groups=groups["items"]
# Let's feed the local database cache with new groups coming from here.
data= dict(profiles=[], groups=self.session.groups)
@ -890,8 +890,8 @@ class Controller(object):
current_buffer = self.get_current_buffer()
# Get group_info if the community buffer does not have it already, so future menus will be able to use it.
if current_buffer.group_id not in self.session.db["group_info"] or "counters" not in self.session.db["group_info"][current_buffer.group_id]:
group_info = self.session.vk.client.groups.getById(group_ids=-1*current_buffer.kwargs["owner_id"], fields="counters")[0]
self.session.db["group_info"][current_buffer.kwargs["owner_id"]] = group_info
group_info = self.session.vk.client.groups.getById(group_ids=-1*current_buffer.kwargs["owner_id"], fields="counters,can_create_topics,can_post")[0]
self.session.db["group_info"][current_buffer.kwargs["owner_id"]].update(group_info)
if "audios" not in self.session.db["group_info"][current_buffer.group_id]["counters"]:
commonMessages.community_no_items()
return
@ -903,8 +903,8 @@ class Controller(object):
current_buffer = self.get_current_buffer()
# Get group_info if the community buffer does not have it already, so future menus will be able to use it.
if current_buffer.group_id not in self.session.db["group_info"] or "counters" not in self.session.db["group_info"][current_buffer.group_id]:
group_info = self.session.vk.client.groups.getById(group_ids=-1*current_buffer.kwargs["owner_id"], fields="counters")[0]
self.session.db["group_info"][current_buffer.kwargs["owner_id"]] = group_info
group_info = self.session.vk.client.groups.getById(group_ids=-1*current_buffer.kwargs["owner_id"], fields="counters,can_create_topics,can_post")[0]
self.session.db["group_info"][current_buffer.kwargs["owner_id"]].update(group_info)
if "videos" not in self.session.db["group_info"][current_buffer.group_id]["counters"]:
commonMessages.community_no_items()
return
@ -916,8 +916,8 @@ class Controller(object):
current_buffer = self.get_current_buffer()
# Get group_info if the community buffer does not have it already, so future menus will be able to use it.
if current_buffer.group_id not in self.session.db["group_info"] or "counters" not in self.session.db["group_info"][current_buffer.group_id]:
group_info = self.session.vk.client.groups.getById(group_ids=-1*current_buffer.kwargs["owner_id"], fields="counters")[0]
self.session.db["group_info"][current_buffer.kwargs["owner_id"]] = group_info
group_info = self.session.vk.client.groups.getById(group_ids=-1*current_buffer.kwargs["owner_id"], fields="counters,can_create_topic,can_post")[0]
self.session.db["group_info"][current_buffer.kwargs["owner_id"]].update(group_info)
if "topics" not in self.session.db["group_info"][current_buffer.group_id]["counters"]:
commonMessages.community_no_items()
return
@ -928,8 +928,8 @@ class Controller(object):
current_buffer = self.get_current_buffer()
# Get group_info if the community buffer does not have it already, so future menus will be able to use it.
if current_buffer.group_id not in self.session.db["group_info"] or "counters" not in self.session.db["group_info"][current_buffer.group_id]:
group_info = self.session.vk.client.groups.getById(group_ids=-1*current_buffer.kwargs["owner_id"], fields="counters")[0]
self.session.db["group_info"][current_buffer.kwargs["owner_id"]] = group_info
group_info = self.session.vk.client.groups.getById(group_ids=-1*current_buffer.kwargs["owner_id"], fields="counters,can_create_topics,can_post")[0]
self.session.db["group_info"][current_buffer.kwargs["owner_id"]].update(group_info)
if "docs" not in self.session.db["group_info"][current_buffer.group_id]["counters"]:
commonMessages.community_no_items()
return

View File

@ -121,3 +121,51 @@ class createCommentDialog(createTextMessage):
super(createCommentDialog, self).__init__()
self.createControls(message, title, text)
self.SetClientSize(self.mainBox.CalcMin())
self.SetTitle(title)
class createTopicDialog(createCommentDialog):
def createTextArea(self, message="", text=""):
self.panel = wx.Panel(self)
label = wx.StaticText(self.panel, -1, _("Title"))
self.title = wx.TextCtrl(self.panel, wx.NewId())
label2 = wx.StaticText(self.panel, -1, _("Message"))
self.text = wx.TextCtrl(self.panel, -1, text, size=(439, -1), style=wx.TE_MULTILINE)
self.title.SetFocus()
self.textBox = wx.BoxSizer(wx.VERTICAL)
titleb = wx.BoxSizer(wx.HORIZONTAL)
titleb.Add(label, 0, wx.ALL, 5)
titleb.Add(self.title, 0, wx.ALL, 5)
self.textBox.Add(titleb, 0, wx.ALL, 5)
textb = wx.BoxSizer(wx.HORIZONTAL)
textb.Add(label2, 0, wx.ALL, 5)
textb.Add(self.text, 0, wx.ALL, 5)
self.textBox.Add(textb, 0, wx.ALL, 5)
def createControls(self, title, message, text):
self.mainBox = wx.BoxSizer(wx.VERTICAL)
self.createTextArea(message, text)
self.mainBox.Add(self.textBox, 0, wx.ALL, 5)
self.attach = wx.Button(self.panel, -1, _("Attach"), size=wx.DefaultSize)
self.mention = wx.Button(self.panel, wx.NewId(), _("Tag a friend"))
self.spellcheck = wx.Button(self.panel, -1, _("Spelling &correction"), size=wx.DefaultSize)
self.translateButton = wx.Button(self.panel, -1, _("&Translate message"), size=wx.DefaultSize)
self.okButton = wx.Button(self.panel, wx.ID_OK, _("Send"), size=wx.DefaultSize)
self.okButton.SetDefault()
cancelButton = wx.Button(self.panel, wx.ID_CANCEL, _("Close"), size=wx.DefaultSize)
self.buttonsBox1 = wx.BoxSizer(wx.HORIZONTAL)
self.buttonsBox1.Add(self.attach, 0, wx.ALL, 10)
self.buttonsBox1.Add(self.mention, 0, wx.ALL, 10)
self.buttonsBox1.Add(self.spellcheck, 0, wx.ALL, 10)
self.buttonsBox1.Add(self.translateButton, 0, wx.ALL, 10)
self.mainBox.Add(self.buttonsBox1, 0, wx.ALL, 10)
self.ok_cancelSizer = wx.BoxSizer(wx.HORIZONTAL)
self.ok_cancelSizer.Add(self.okButton, 0, wx.ALL, 10)
self.ok_cancelSizer.Add(cancelButton, 0, wx.ALL, 10)
self.mainBox.Add(self.ok_cancelSizer)
selectId = wx.NewId()
self.Bind(wx.EVT_MENU, self.onSelect, id=selectId)
self.accel_tbl = wx.AcceleratorTable([
(wx.ACCEL_CTRL, ord('A'), selectId),])
self.SetAcceleratorTable(self.accel_tbl)
self.panel.SetSizer(self.mainBox)