Merge branch 'next'

This commit is contained in:
Manuel Cortez 2019-07-22 12:53:10 -05:00
commit 4caa5a6ab0
6 changed files with 75 additions and 32 deletions

View File

@ -4,6 +4,19 @@
### New additions ### New additions
### bugfixes
* Fixed an error that was making Socializer unable to attach audio files from the computer, if the file does not include correct ID3 TAGS.
* Fixed a traceback that was being logged when attempting to load an image but cancel the dialog for attaching it.
### Changes
* Less confidential user data will be send to the logs, so it will be much safer to pass logs publicly.
## changes in Versions 0.21 and 0.22 (14.07.2019)
### 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. * 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.
* In all audio buffers, it is possible to select individual tracks to be played together. In order to do so, you need to press space to start the selection of items. When selected, the item will emit a sound to indicate the change. Press space in all items you want to select/unselect. When you're focusing an already selected item it will play a sound to indicate that it is already selected. Once you're done with your selection, pressing enter in the list of tracks will start the playback of the list of items you have selected. This is a very experimental feature. More actions can be supported based in this selection method if it proves to be useful. * In all audio buffers, it is possible to select individual tracks to be played together. In order to do so, you need to press space to start the selection of items. When selected, the item will emit a sound to indicate the change. Press space in all items you want to select/unselect. When you're focusing an already selected item it will play a sound to indicate that it is already selected. Once you're done with your selection, pressing enter in the list of tracks will start the playback of the list of items you have selected. This is a very experimental feature. More actions can be supported based in this selection method if it proves to be useful.
* In conversation buffers, it is possible to display and open wall posts sent as attachments in messages. * In conversation buffers, it is possible to display and open wall posts sent as attachments in messages.

View File

@ -105,12 +105,12 @@ class baseBuffer(object):
if self.tab.list.get_count() > 0 and num > 0: if self.tab.list.get_count() > 0 and num > 0:
v = [i for i in self.session.db[self.name]["items"][:num]] v = [i for i in self.session.db[self.name]["items"][:num]]
v.reverse() v.reverse()
[self.insert(i, True) for i in v] [wx.CallAfter(self.insert, i, True) for i in v]
else: else:
[self.insert(i) for i in self.session.db[self.name]["items"][:num]] [wx.CallAfter(self.insert, i) for i in self.session.db[self.name]["items"][:num]]
else: else:
if num > 0: if num > 0:
[self.insert(i, False) for i in self.session.db[self.name]["items"][-num:]] [wx.CallAfter(self.insert, i, False) for i in self.session.db[self.name]["items"][-num:]]
return retrieved return retrieved
def get_more_items(self): def get_more_items(self):
@ -417,12 +417,12 @@ class feedBuffer(baseBuffer):
if self.tab.list.get_count() > 0 and num > 0: if self.tab.list.get_count() > 0 and num > 0:
v = [i for i in self.session.db[self.name]["items"][:num]] v = [i for i in self.session.db[self.name]["items"][:num]]
v.reverse() v.reverse()
[self.insert(i, True) for i in v] [wx.CallAfter(self.insert, i, True) for i in v]
else: else:
[self.insert(i) for i in self.session.db[self.name]["items"][:num]] [wx.CallAfter(self.insert, i) for i in self.session.db[self.name]["items"][:num]]
else: else:
if num > 0: if num > 0:
[self.insert(i, False) for i in self.session.db[self.name]["items"][-num:]] [wx.CallAfter(self.insert, i, False) for i in self.session.db[self.name]["items"][-num:]]
return retrieved return retrieved
def remove_buffer(self, mandatory=False): def remove_buffer(self, mandatory=False):
@ -1519,9 +1519,9 @@ class requestsBuffer(peopleBuffer):
if self.tab.list.get_count() > 0 and num > 0: if self.tab.list.get_count() > 0 and num > 0:
v = [i for i in self.session.db[self.name]["items"][:num]] v = [i for i in self.session.db[self.name]["items"][:num]]
v.reverse() v.reverse()
[self.insert(i, True) for i in v] [wx.CallAfter(self.insert, i, True) for i in v]
else: else:
[self.insert(i) for i in self.session.db[self.name]["items"][:num]] [wx.CallAfter(self.insert, i) for i in self.session.db[self.name]["items"][:num]]
return retrieved return retrieved
def accept_friendship(self, *args, **kwargs): def accept_friendship(self, *args, **kwargs):

View File

@ -3,6 +3,7 @@ import time
import os import os
import webbrowser import webbrowser
import subprocess import subprocess
import functools
import logging import logging
import wx import wx
import widgetUtils import widgetUtils
@ -13,6 +14,7 @@ import views
import config import config
import paths import paths
import win32gui import win32gui
from concurrent import futures
from vk_api.exceptions import LoginRequired, VkApiError from vk_api.exceptions import LoginRequired, VkApiError
from requests.exceptions import ConnectionError from requests.exceptions import ConnectionError
from pubsub import pub from pubsub import pub
@ -33,6 +35,30 @@ from . import selector
log = logging.getLogger("controller.main") log = logging.getLogger("controller.main")
thread_pool_executor = futures.ThreadPoolExecutor(max_workers=1)
def wx_call_after(target):
@functools.wraps(target)
def wrapper(self, *args, **kwargs):
args = (self,) + args
wx.CallAfter(target, *args, **kwargs)
return wrapper
def submit_to_pool_executor(executor):
def decorator(target):
@functools.wraps(target)
def wrapper(*args, **kwargs):
result = executor.submit(target, *args, **kwargs)
result.add_done_callback(executor_done_call_back)
return result
return wrapper
return decorator
def executor_done_call_back(future):
exception = future.exception()
if exception:
raise exception
class Controller(object): class Controller(object):
### utils ### utils
@ -151,8 +177,7 @@ class Controller(object):
if ex.code == 6: if ex.code == 6:
log.exception("Something went wrong when getting messages. Waiting a second to retry") log.exception("Something went wrong when getting messages. Waiting a second to retry")
for i in msgs["items"]: for i in msgs["items"]:
call_threaded(self.chat_from_id, i["last_message"]["peer_id"], setfocus=False, unread=False) self.chat_from_id(i["last_message"]["peer_id"], setfocus=False, unread=False)
time.sleep(0.6)
def get_audio_albums(self, user_id=None, create_buffers=True, force_action=False): def get_audio_albums(self, user_id=None, create_buffers=True, force_action=False):
if self.session.settings["load_at_startup"]["audio_albums"] == False and force_action == False: if self.session.settings["load_at_startup"]["audio_albums"] == False and force_action == False:
@ -166,8 +191,7 @@ class Controller(object):
self.session.audio_albums = albums self.session.audio_albums = albums
if create_buffers: if create_buffers:
for i in albums: for i in albums:
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="audioAlbum", buffer_title=_("Album: {0}").format(i["title"],), parent_tab="audio_albums", loadable=True, kwargs=dict(parent=self.window.tb, name="{0}_audio_album".format(i["id"],), composefunc="render_audio", session=self.session, endpoint="get", parent_endpoint="audio", owner_id=user_id, album_id=i["id"])) pub.sendMessage("create_buffer", buffer_type="audioAlbum", buffer_title=_("Album: {0}").format(i["title"],), parent_tab="audio_albums", loadable=True, kwargs=dict(parent=self.window.tb, name="{0}_audio_album".format(i["id"],), composefunc="render_audio", session=self.session, endpoint="get", parent_endpoint="audio", owner_id=user_id, album_id=i["id"]))
time.sleep(0.6)
def get_video_albums(self, user_id=None, create_buffers=True, force_action=False): def get_video_albums(self, user_id=None, create_buffers=True, force_action=False):
if self.session.settings["load_at_startup"]["video_albums"] == False and force_action == False: if self.session.settings["load_at_startup"]["video_albums"] == False and force_action == False:
@ -177,8 +201,7 @@ class Controller(object):
self.session.video_albums = albums["items"] self.session.video_albums = albums["items"]
if create_buffers: if create_buffers:
for i in albums["items"]: for i in albums["items"]:
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="videoAlbum", buffer_title=_("Album: {0}").format(i["title"],), parent_tab="video_albums", loadable=True, kwargs=dict(parent=self.window.tb, name="{0}_video_album".format(i["id"],), composefunc="render_video", session=self.session, endpoint="get", parent_endpoint="video", count=self.session.settings["buffers"]["count_for_video_buffers"], user_id=user_id, album_id=i["id"])) pub.sendMessage("create_buffer", buffer_type="videoAlbum", buffer_title=_("Album: {0}").format(i["title"],), parent_tab="video_albums", loadable=True, kwargs=dict(parent=self.window.tb, name="{0}_video_album".format(i["id"],), composefunc="render_video", session=self.session, endpoint="get", parent_endpoint="video", count=self.session.settings["buffers"]["count_for_video_buffers"], user_id=user_id, album_id=i["id"]))
time.sleep(0.15)
def get_communities(self, user_id=None, create_buffers=True, force_action=False): def get_communities(self, user_id=None, create_buffers=True, force_action=False):
if self.session.settings["vk"]["invited_to_group"] == False: if self.session.settings["vk"]["invited_to_group"] == False:
@ -206,8 +229,8 @@ class Controller(object):
if create_buffers: if create_buffers:
for i in self.session.groups: for i in self.session.groups:
self.session.db["group_info"][i["id"]*-1] = i self.session.db["group_info"][i["id"]*-1] = i
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"])) 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"]))
time.sleep(0.15)
def login(self): def login(self):
self.window.change_status(_("Logging in VK")) self.window.change_status(_("Logging in VK"))
@ -219,7 +242,7 @@ class Controller(object):
self.window.change_status(_("Loading items for {0}").format(i.name,)) self.window.change_status(_("Loading items for {0}").format(i.name,))
i.get_items() i.get_items()
self.window.change_status(_("Ready")) self.window.change_status(_("Ready"))
self.create_unread_messages() call_threaded(self.create_unread_messages)
self.status_setter = RepeatingTimer(280, self.set_online) self.status_setter = RepeatingTimer(280, self.set_online)
self.status_setter.start() self.status_setter.start()
self.set_online(notify=True) self.set_online(notify=True)
@ -363,7 +386,7 @@ class Controller(object):
elif user_id > 2000000000: elif user_id > 2000000000:
chat = self.session.vk.client.messages.getChat(chat_id=user_id-2000000000) chat = self.session.vk.client.messages.getChat(chat_id=user_id-2000000000)
name = chat["title"] name = chat["title"]
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="chatBuffer", buffer_title=name, parent_tab="chats", get_items=True, kwargs=dict(parent=self.window.tb, name="{0}_messages".format(user_id,), composefunc="render_message", parent_endpoint="messages", endpoint="getHistory", session=self.session, unread=unread, count=200, peer_id=user_id, rev=0, extended=True, fields="id, user_id, date, read_state, out, body, attachments, deleted")) pub.sendMessage("create_buffer", buffer_type="chatBuffer", buffer_title=name, parent_tab="chats", get_items=True, kwargs=dict(parent=self.window.tb, name="{0}_messages".format(user_id,), composefunc="render_message", parent_endpoint="messages", endpoint="getHistory", session=self.session, unread=unread, count=200, peer_id=user_id, rev=0, extended=True, fields="id, user_id, date, read_state, out, body, attachments, deleted"))
# if setfocus: # if setfocus:
# pos = self.window.search(buffer.name) # pos = self.window.search(buffer.name)
# self.window.change_buffer(pos) # self.window.change_buffer(pos)
@ -449,7 +472,7 @@ class Controller(object):
if hasattr(self, "longpoll"): if hasattr(self, "longpoll"):
del self.longpoll del self.longpoll
self.create_longpoll_thread(notify=True) self.create_longpoll_thread(notify=True)
@wx_call_after
def create_buffer(self, buffer_type="baseBuffer", buffer_title="", parent_tab=None, loadable=False, get_items=False, kwargs={}): def create_buffer(self, buffer_type="baseBuffer", buffer_title="", parent_tab=None, loadable=False, get_items=False, kwargs={}):
""" Create and insert a buffer in the specified place. """ Create and insert a buffer in the specified place.
@buffer_type str: name of the buffer type to be created. This should be a class in the buffers.py module. @buffer_type str: name of the buffer type to be created. This should be a class in the buffers.py module.
@ -903,7 +926,7 @@ class Controller(object):
commonMessages.community_no_items() commonMessages.community_no_items()
return return
new_name = current_buffer.name+"_audios" new_name = current_buffer.name+"_audios"
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="audioBuffer", buffer_title=_("Audios"), parent_tab=current_buffer.tab.name, get_items=True, kwargs=dict(parent=self.window.tb, name=new_name, composefunc="render_audio", session=self.session, endpoint="get", parent_endpoint="audio", owner_id=current_buffer.kwargs["owner_id"])) pub.sendMessage("create_buffer", buffer_type="audioBuffer", buffer_title=_("Audios"), parent_tab=current_buffer.tab.name, get_items=True, kwargs=dict(parent=self.window.tb, name=new_name, composefunc="render_audio", session=self.session, endpoint="get", parent_endpoint="audio", owner_id=current_buffer.kwargs["owner_id"]))
def load_community_videos(self, *args, **kwargs): def load_community_videos(self, *args, **kwargs):
""" Load community videos if they are not loaded already.""" """ Load community videos if they are not loaded already."""
@ -916,7 +939,7 @@ class Controller(object):
commonMessages.community_no_items() commonMessages.community_no_items()
return return
new_name = current_buffer.name+"_videos" new_name = current_buffer.name+"_videos"
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="videoBuffer", buffer_title=_("Videos"), parent_tab=current_buffer.tab.name, get_items=True, kwargs=dict(parent=self.window.tb, name=new_name, composefunc="render_video", session=self.session, endpoint="get", parent_endpoint="video", count=self.session.settings["buffers"]["count_for_video_buffers"], owner_id=current_buffer.kwargs["owner_id"])) pub.sendMessage("create_buffer", buffer_type="videoBuffer", buffer_title=_("Videos"), parent_tab=current_buffer.tab.name, get_items=True, kwargs=dict(parent=self.window.tb, name=new_name, composefunc="render_video", session=self.session, endpoint="get", parent_endpoint="video", count=self.session.settings["buffers"]["count_for_video_buffers"], owner_id=current_buffer.kwargs["owner_id"]))
def load_community_topics(self, *args, **kwargs): def load_community_topics(self, *args, **kwargs):
""" Load community topics.""" """ Load community topics."""
@ -929,7 +952,7 @@ class Controller(object):
commonMessages.community_no_items() commonMessages.community_no_items()
return return
new_name = current_buffer.name+"_topics" new_name = current_buffer.name+"_topics"
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="topicBuffer", buffer_title=_("Topics"), parent_tab=current_buffer.tab.name, get_items=True, kwargs=dict(parent=self.window.tb, name=new_name, composefunc="render_topic", session=self.session, endpoint="getTopics", parent_endpoint="board", count=100, group_id=-1*current_buffer.kwargs["owner_id"], extended=1)) pub.sendMessage("create_buffer", buffer_type="topicBuffer", buffer_title=_("Topics"), parent_tab=current_buffer.tab.name, get_items=True, kwargs=dict(parent=self.window.tb, name=new_name, composefunc="render_topic", session=self.session, endpoint="getTopics", parent_endpoint="board", count=100, group_id=-1*current_buffer.kwargs["owner_id"], extended=1))
def load_community_documents(self, *args, **kwargs): def load_community_documents(self, *args, **kwargs):
current_buffer = self.get_current_buffer() current_buffer = self.get_current_buffer()
@ -941,7 +964,7 @@ class Controller(object):
commonMessages.community_no_items() commonMessages.community_no_items()
return return
new_name = current_buffer.name+"_documents" new_name = current_buffer.name+"_documents"
wx.CallAfter(pub.sendMessage, "create_buffer", buffer_type="documentCommunityBuffer", buffer_title=_("Documents"), parent_tab=current_buffer.tab.name, get_items=True, kwargs=dict(parent=self.window.tb, name=new_name, composefunc="render_document", session=self.session, endpoint="get", parent_endpoint="docs", owner_id=current_buffer.kwargs["owner_id"])) pub.sendMessage("create_buffer", buffer_type="documentCommunityBuffer", buffer_title=_("Documents"), parent_tab=current_buffer.tab.name, get_items=True, kwargs=dict(parent=self.window.tb, name=new_name, composefunc="render_document", session=self.session, endpoint="get", parent_endpoint="docs", owner_id=current_buffer.kwargs["owner_id"]))
def load_community_buffers(self, *args, **kwargs): def load_community_buffers(self, *args, **kwargs):
""" Load all community buffers regardless of the setting present in optional buffers tab of the preferences dialog.""" """ Load all community buffers regardless of the setting present in optional buffers tab of the preferences dialog."""

View File

@ -14,6 +14,8 @@ formatter = logging.Formatter(MESSAGE_FORMAT, datefmt=DATE_FORMAT)
requests_log = logging.getLogger("requests") requests_log = logging.getLogger("requests")
requests_log.setLevel(logging.WARNING) requests_log.setLevel(logging.WARNING)
urllib3 = logging.getLogger("urllib3")
urllib3.setLevel(logging.WARNING)
logger = logging.getLogger() logger = logging.getLogger()
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)

View File

@ -8,6 +8,7 @@ import logging
import interactors import interactors
import views import views
from mutagen.id3 import ID3 from mutagen.id3 import ID3
from mutagen.id3._util import ID3NoHeaderError
from sessionmanager.utils import seconds_to_string from sessionmanager.utils import seconds_to_string
from . import audioRecorder, base from . import audioRecorder, base
@ -47,6 +48,7 @@ class attachPresenter(base.basePresenter):
if audio != None: if audio != None:
# Define data structure for this attachment, as will be required by VK API later. # Define data structure for this attachment, as will be required by VK API later.
# Let's extract the ID3 tags to show them in the list and send them to VK, too. # Let's extract the ID3 tags to show them in the list and send them to VK, too.
try:
audio_tags = ID3(audio) audio_tags = ID3(audio)
if "TIT2" in audio_tags: if "TIT2" in audio_tags:
title = audio_tags["TIT2"].text[0] title = audio_tags["TIT2"].text[0]
@ -56,6 +58,9 @@ class attachPresenter(base.basePresenter):
artist = audio_tags["TPE1"].text[0] artist = audio_tags["TPE1"].text[0]
else: else:
artist = _("Unknown artist") artist = _("Unknown artist")
except ID3NoHeaderError: # File doesn't include ID3 tags so let's assume unknown artist.
artist = _("Unknown artist")
title = os.path.basename(audio).replace(".mp3", "")
audioInfo = {"type": "audio", "file": audio, "from": "local", "title": title, "artist": artist} audioInfo = {"type": "audio", "file": audio, "from": "local", "title": title, "artist": artist}
self.attachments.append(audioInfo) self.attachments.append(audioInfo)
# Translators: This is the text displayed in the attachments dialog, when the user adds an audio file. # Translators: This is the text displayed in the attachments dialog, when the user adds an audio file.

View File

@ -41,7 +41,7 @@ class attachDialog(widgetUtils.BaseDialog):
def get_image(self): def get_image(self):
openFileDialog = wx.FileDialog(self, _("Select the picture to be uploaded"), "", "", _("Image files (*.png, *.jpg, *.gif)|*.png; *.jpg; *.gif"), wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) openFileDialog = wx.FileDialog(self, _("Select the picture to be uploaded"), "", "", _("Image files (*.png, *.jpg, *.gif)|*.png; *.jpg; *.gif"), wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
if openFileDialog.ShowModal() == wx.ID_CANCEL: if openFileDialog.ShowModal() == wx.ID_CANCEL:
return None return (None, None)
dsc = self.ask_description() dsc = self.ask_description()
return (openFileDialog.GetPath(), dsc) return (openFileDialog.GetPath(), dsc)