Added support for voice messages

This commit is contained in:
Manuel Cortez 2018-12-24 17:54:18 -06:00
parent dd07501c5c
commit 46ba62d346
3 changed files with 21 additions and 1 deletions

View File

@ -3,6 +3,7 @@
## changes in this version
* Added support for Two factor authentication (2FA). When detecting 2FA in an user account, Socializer will switch automatically to alternative tokens. There is some work to authorize kate's tokens with 2FA, but currently it doesn't work fully. ([#13,](https://code.manuelcortez.net/manuelcortez/socializer/issues/13))
* Now it is possible to send voice messages from socializer. Voice messages are available from the "add" button in any conversation buffer.
* tokens generated by socializer will never expire. ([#3,](https://code.manuelcortez.net/manuelcortez/socializer/issues/3))
* In order to use all methods available in VK, socializer will use tokens of kate mobile for Android. It means you may receive an email by saying that you've authorised Kate for accessing your account from an Android device.
* Audio albums are loaded correctly.

View File

@ -5,7 +5,9 @@ this controller will take care of preparing data structures to be uploaded later
import os
import logging
import widgetUtils
import audioRecorder
from mutagen.id3 import ID3
from sessionmanager.utils import seconds_to_string
from wxUI.dialogs import attach as gui
from wxUI.dialogs import selector
from wxUI.menus import attachMenu
@ -31,6 +33,8 @@ class attach(object):
self.dialog = gui.attachDialog(voice_messages)
widgetUtils.connect_event(self.dialog.photo, widgetUtils.BUTTON_PRESSED, self.on_image)
widgetUtils.connect_event(self.dialog.audio, widgetUtils.BUTTON_PRESSED, self.on_audio)
if voice_messages:
widgetUtils.connect_event(self.dialog.voice_message, widgetUtils.BUTTON_PRESSED, self.upload_voice_message)
widgetUtils.connect_event(self.dialog.remove, widgetUtils.BUTTON_PRESSED, self.remove_attachment)
log.debug("Attachments controller started.")
self.dialog.get_response()
@ -85,6 +89,16 @@ class attach(object):
self.dialog.attachments.insert_item(False, *info)
self.dialog.remove.Enable(True)
def upload_voice_message(self, *args, **kwargs):
a = audioRecorder.audioRecorder()
if a.file != None and a.duration != 0:
audioInfo = {"type": "voice_message", "file": a.file, "from": "local"}
self.attachments.append(audioInfo)
# Translators: This is the text displayed in the attachments dialog, when the user adds an audio file.
info = [_(u"Voice message"), seconds_to_string(a.duration,)]
self.dialog.attachments.insert_item(False, *info)
self.dialog.remove.Enable(True)
def add_audio(self, *args, **kwargs):
""" Allow adding an audio directly from the user's audio library."""
# Let's reuse the already downloaded audios.

View File

@ -776,7 +776,7 @@ class chatBuffer(baseBuffer):
return retrieved
def add_attachment(self, *args, **kwargs):
a = attach.attach(self.session)
a = attach.attach(self.session, True)
if len(a.attachments) != 0:
self.attachments_to_be_sent = a.attachments
@ -816,6 +816,11 @@ class chatBuffer(baseBuffer):
id = r["id"]
owner_id = r["owner_id"]
local_attachments += "audio{0}_{1},".format(owner_id, id)
elif i["from"] == "local" and i["type"] == "voice_message":
r = uploader.audio_message(i["file"], peer_id=self.kwargs["user_id"])
id = r["audio_message"]["id"]
owner_id = r["audio_message"]["owner_id"]
local_attachments += "audio_message{0}_{1},".format(owner_id, id)
return local_attachments
def _send_message(self, text, attachments=[]):