Tag people in posts and comments. Closes #6
This commit is contained in:
parent
9fd845c424
commit
03f73564da
@ -8,6 +8,7 @@
|
||||
* Improved chats, now they should be more stable. Also you will be able to send the message by pressing enter in the text box. If you are trying to send the same message multiple times, you will be warned.
|
||||
* Added video management (my videos, video albums and video search). For playing videos, you will be redirected to a website in your browser.
|
||||
* Added a setting that allows you to specify if you want socializer to load images when you are opening posts. It could be useful for slow connection or those who don't want images to be loaded.
|
||||
* Added basic tagging for users in posts and comments. You can tag only people in your friend buffers.
|
||||
|
||||
## Changes in build 2016.07.08 (08/07/2016)
|
||||
|
||||
|
@ -86,7 +86,7 @@ class baseBuffer(object):
|
||||
self.get_items(show_nextpage=True)
|
||||
|
||||
def post(self, *args, **kwargs):
|
||||
p = messages.post(title=_(u"Write your post"), caption="", text="")
|
||||
p = messages.post(session=self.session, title=_(u"Write your post"), caption="", text="")
|
||||
if p.message.get_response() == widgetUtils.OK:
|
||||
call_threaded(self.do_last, p=p)
|
||||
|
||||
|
@ -1,19 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import time
|
||||
import widgetUtils
|
||||
import output
|
||||
from pubsub import pub
|
||||
import attach
|
||||
from wxUI.dialogs import message
|
||||
from wxUI.dialogs import message, selector
|
||||
from extra import SpellChecker, translator
|
||||
from logging import getLogger
|
||||
|
||||
log = getLogger("controller.message")
|
||||
|
||||
class post(object):
|
||||
def __init__(self, title, caption, text, post_type="post"):
|
||||
def __init__(self, session, title, caption, text, post_type="post"):
|
||||
super(post, self).__init__()
|
||||
self.session = session
|
||||
self.title = title
|
||||
self.message = getattr(message, post_type)(title, caption, text)
|
||||
self.message.set_title(title)
|
||||
widgetUtils.connect_event(self.message.spellcheck, widgetUtils.BUTTON_PRESSED, self.spellcheck)
|
||||
widgetUtils.connect_event(self.message.translateButton, widgetUtils.BUTTON_PRESSED, self.translate)
|
||||
widgetUtils.connect_event(self.message.mention, widgetUtils.BUTTON_PRESSED, self.mention)
|
||||
self.images = []
|
||||
if hasattr(self.message, "attach"):
|
||||
widgetUtils.connect_event(self.message.attach, widgetUtils.BUTTON_PRESSED, self.show_attach_dialog)
|
||||
@ -26,6 +32,26 @@ class post(object):
|
||||
privacy = 1
|
||||
return privacy
|
||||
|
||||
def mention(self, *args, **kwargs):
|
||||
try:
|
||||
fields = "id, first_name, last_name"
|
||||
friends = self.session.vk.client.friends.get(count=5000, fields=fields)
|
||||
except AttributeError:
|
||||
time.sleep(2)
|
||||
log.exception("Error retrieving friends...")
|
||||
return self.mention(*args, **kwargs)
|
||||
users = []
|
||||
for i in friends["items"]:
|
||||
users.append(u"{0} {1}".format(i["first_name"], i["last_name"]))
|
||||
select = selector.selectPeople(users)
|
||||
if select.get_response() == widgetUtils.OK and select.users.GetCount() > 0:
|
||||
self.tagged_people = []
|
||||
tagged_users = select.get_all_users()
|
||||
for i in friends["items"]:
|
||||
if u"{0} {1}".format(i["first_name"], i["last_name"]) in tagged_users:
|
||||
self.tagged_people.append(u"[id%s|%s]" % (str(i["id"]), i["first_name"]))
|
||||
self.message.text.SetValue(self.message.text.GetValue()+ u", ".join(self.tagged_people))
|
||||
|
||||
def translate(self, *args, **kwargs):
|
||||
dlg = translator.gui.translateDialog()
|
||||
if dlg.get_response() == widgetUtils.OK:
|
||||
@ -51,6 +77,6 @@ class post(object):
|
||||
self.attachments = a.attachments
|
||||
|
||||
class comment(post):
|
||||
def __init__(self, title, caption, text):
|
||||
super(comment, self).__init__(title, caption, text, "comment")
|
||||
def __init__(self, session, title, caption, text):
|
||||
super(comment, self).__init__(session, title, caption, text, "comment")
|
||||
self.message.set_title(_(u"New comment"))
|
@ -285,7 +285,7 @@ class postController(object):
|
||||
pass
|
||||
|
||||
def add_comment(self, *args, **kwargs):
|
||||
comment = messages.comment(title=_(u"Add a comment"), caption="", text="")
|
||||
comment = messages.comment(session=self.session, title=_(u"Add a comment"), caption="", text="")
|
||||
if comment.message.get_response() == widgetUtils.OK:
|
||||
msg = comment.message.get_text().encode("utf-8")
|
||||
try:
|
||||
|
@ -59,6 +59,7 @@ class post(textMessage):
|
||||
self.create_privacy_box()
|
||||
self.mainBox.Add(self.privacyBox, 0, wx.ALL, 5)
|
||||
self.attach = wx.Button(self.panel, -1, _(u"Attach"), size=wx.DefaultSize)
|
||||
self.mention = wx.Button(self.panel, wx.NewId(), _(u"Tag a friend"))
|
||||
self.spellcheck = wx.Button(self.panel, -1, _("Spelling &correction"), size=wx.DefaultSize)
|
||||
self.translateButton = wx.Button(self.panel, -1, _(u"&Translate message"), size=wx.DefaultSize)
|
||||
self.okButton = wx.Button(self.panel, wx.ID_OK, _(u"Send"), size=wx.DefaultSize)
|
||||
@ -66,6 +67,7 @@ class post(textMessage):
|
||||
cancelButton = wx.Button(self.panel, wx.ID_CANCEL, _(u"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)
|
||||
@ -92,12 +94,14 @@ class comment(textMessage):
|
||||
self.createTextArea(message, text)
|
||||
self.mainBox.Add(self.textBox, 0, wx.ALL, 5)
|
||||
self.spellcheck = wx.Button(self.panel, -1, _("Spelling correction"), size=wx.DefaultSize)
|
||||
self.mention = wx.Button(self.panel, wx.NewId(), _(u"Tag a friend"))
|
||||
self.translateButton = wx.Button(self.panel, -1, _(u"Translate message"), size=wx.DefaultSize)
|
||||
self.okButton = wx.Button(self.panel, wx.ID_OK, _(u"Send"), size=wx.DefaultSize)
|
||||
self.okButton.SetDefault()
|
||||
cancelButton = wx.Button(self.panel, wx.ID_CANCEL, _(u"Close"), size=wx.DefaultSize)
|
||||
self.buttonsBox1 = wx.BoxSizer(wx.HORIZONTAL)
|
||||
self.buttonsBox1.Add(self.spellcheck, 0, wx.ALL, 10)
|
||||
self.buttonsBox1.Add(self.mention, 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)
|
||||
|
@ -1,5 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import wx
|
||||
import widgetUtils
|
||||
|
||||
class selectAlbum(wx.Dialog):
|
||||
def __init__(self, title, albums):
|
||||
@ -28,4 +29,58 @@ class selectAlbum(wx.Dialog):
|
||||
return self.lista.GetSelection()
|
||||
|
||||
def get_response(self):
|
||||
return self.ShowModal()
|
||||
return self.ShowModal()
|
||||
|
||||
class selectPeople(widgetUtils.BaseDialog):
|
||||
|
||||
def __init__(self, users=[]):
|
||||
super(selectPeople, self).__init__(parent=None, title=_(u"Tag friends"))
|
||||
self.users_list = users
|
||||
panel = wx.Panel(self)
|
||||
sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
userLabel = wx.StaticText(panel, -1, _(u"All friends"))
|
||||
self.cb = wx.ComboBox(panel, -1, choices=users, value=users[0])
|
||||
self.cb.SetFocus()
|
||||
userSizer = wx.BoxSizer()
|
||||
userSizer.Add(userLabel, 0, wx.ALL, 5)
|
||||
userSizer.Add(self.cb, 0, wx.ALL, 5)
|
||||
self.add = wx.Button(panel, wx.NewId(), _(u"Select"))
|
||||
self.add.Bind(wx.EVT_BUTTON, self.add_user)
|
||||
userSizer.Add(self.add, 0, wx.ALL, 5)
|
||||
sizer.Add(userSizer, 0, wx.ALL, 5)
|
||||
lbl = wx.StaticText(panel, wx.NewId(), _(u"Tagged users"))
|
||||
self.users = wx.ListBox(panel, -1)
|
||||
self.remove = wx.Button(panel, wx.NewId(), _(u"Remove"))
|
||||
self.remove.Bind(wx.EVT_BUTTON, self.remove_user)
|
||||
selectionSizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
selectionSizer.Add(lbl, 0, wx.ALL, 5)
|
||||
selectionSizer.Add(self.users, 0, wx.ALL, 5)
|
||||
selectionSizer.Add(self.remove, 0, wx.ALL, 5)
|
||||
sizer.Add(selectionSizer, 0, wx.ALL, 5)
|
||||
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, 0, wx.ALL, 5)
|
||||
btnsizer.Add(cancel, 0, wx.ALL, 5)
|
||||
sizer.Add(btnsizer, 0, wx.ALL, 5)
|
||||
panel.SetSizer(sizer)
|
||||
self.SetClientSize(sizer.CalcMin())
|
||||
|
||||
def get_user(self):
|
||||
return self.cb.GetValue()
|
||||
|
||||
def add_user(self, *args, **kwargs):
|
||||
selection = self.get_user()
|
||||
if selection in self.users_list:
|
||||
self.users.Append(selection)
|
||||
|
||||
def remove_user(self, *args, **kwargs):
|
||||
self.users.Delete(self.users.GetSelection())
|
||||
|
||||
def get_all_users(self):
|
||||
users = []
|
||||
for i in xrange(0, self.users.GetCount()):
|
||||
self.users.Select(i)
|
||||
users.append(self.users.GetStringSelection())
|
||||
return users
|
Loading…
Reference in New Issue
Block a user