Added support for voice messages
This commit is contained in:
@@ -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.
|
||||
|
@@ -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=[]):
|
||||
|
Reference in New Issue
Block a user