message splitting and some bug fixes

This commit is contained in:
ingvar1995 2016-03-16 18:15:55 +03:00
parent 113176e37b
commit e28e625b42
3 changed files with 37 additions and 8 deletions

View File

@ -96,7 +96,6 @@ def friend_message(window, tray):
:return: function for tox.callback_friend_message. Adds new message to list :return: function for tox.callback_friend_message. Adds new message to list
""" """
def wrapped(tox, friend_number, message_type, message, size, user_data): def wrapped(tox, friend_number, message_type, message, size, user_data):
print 'Message: ', message.decode('utf8')
profile = Profile.get_instance() profile = Profile.get_instance()
settings = Settings.get_instance() settings = Settings.get_instance()
invoke_in_main_thread(profile.new_message, friend_number, message_type, message) invoke_in_main_thread(profile.new_message, friend_number, message_type, message)
@ -123,6 +122,7 @@ def init_callbacks(tox, window, tray):
Initialization of all callbacks. Initialization of all callbacks.
:param tox: tox instance :param tox: tox instance
:param window: main window :param window: main window
:param tray: tray (for notifications)
""" """
tox.callback_friend_status(friend_status, 0) tox.callback_friend_status(friend_status, 0)
tox.callback_friend_message(friend_message(window, tray), 0) tox.callback_friend_message(friend_message(window, tray), 0)

View File

@ -119,12 +119,19 @@ class Toxygen(object):
# initializing callbacks # initializing callbacks
init_callbacks(self.tox, self.ms, self.tray) init_callbacks(self.tox, self.ms, self.tray)
# bootstrap # bootstrap
try:
for data in node_generator(): for data in node_generator():
self.tox.bootstrap(*data) self.tox.bootstrap(*data)
except:
pass
self.msleep(10000) self.msleep(10000)
while not self.tox.self_get_connection_status() and not self.stop: while not self.tox.self_get_connection_status() and not self.stop:
try:
for data in node_generator(): for data in node_generator():
self.tox.bootstrap(*data) self.tox.bootstrap(*data)
except:
pass
finally:
self.msleep(5000) self.msleep(5000)
class ToxIterateThread(QtCore.QThread): class ToxIterateThread(QtCore.QThread):

View File

@ -447,6 +447,29 @@ class Profile(Contact, Singleton):
# Private messages # Private messages
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------
def split_and_send(self, number, message_type, message):
"""
Message splitting
:param number: friend's number
:param message_type: type of message
:param message: message text
"""
while len(message) > TOX_MAX_MESSAGE_LENGTH:
size = TOX_MAX_MESSAGE_LENGTH * 4 / 5
last_part = message[size:]
if ' ' in last_part:
index = last_part.index(' ')
elif ',' in last_part:
index = last_part.index(',')
elif '.' in last_part:
index = last_part.index('.')
else:
index = TOX_MAX_MESSAGE_LENGTH - size
index += size
self._tox.friend_send_message(number, message_type, message[:index])
message = message[index:]
self._tox.friend_send_message(number, message_type, message)
def new_message(self, friend_num, message_type, message): def new_message(self, friend_num, message_type, message):
""" """
Current user gets new message Current user gets new message
@ -482,8 +505,7 @@ class Profile(Contact, Singleton):
else: else:
message_type = TOX_MESSAGE_TYPE['NORMAL'] message_type = TOX_MESSAGE_TYPE['NORMAL']
friend = self._friends[self._active_friend] friend = self._friends[self._active_friend]
# TODO: add message splitting self.split_and_send(friend.number, message_type, text.encode('utf-8'))
self._tox.friend_send_message(friend.number, message_type, text.encode('utf-8'))
self.create_message_item(text, curr_time(), self._name, message_type) self.create_message_item(text, curr_time(), self._name, message_type)
self._screen.messageEdit.clear() self._screen.messageEdit.clear()
self._messages.scrollToBottom() self._messages.scrollToBottom()