message splitting and some bug fixes
This commit is contained in:
parent
113176e37b
commit
e28e625b42
3 changed files with 37 additions and 8 deletions
|
@ -96,7 +96,6 @@ def friend_message(window, tray):
|
|||
:return: function for tox.callback_friend_message. Adds new message to list
|
||||
"""
|
||||
def wrapped(tox, friend_number, message_type, message, size, user_data):
|
||||
print 'Message: ', message.decode('utf8')
|
||||
profile = Profile.get_instance()
|
||||
settings = Settings.get_instance()
|
||||
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.
|
||||
:param tox: tox instance
|
||||
:param window: main window
|
||||
:param tray: tray (for notifications)
|
||||
"""
|
||||
tox.callback_friend_status(friend_status, 0)
|
||||
tox.callback_friend_message(friend_message(window, tray), 0)
|
||||
|
|
17
src/main.py
17
src/main.py
|
@ -119,13 +119,20 @@ class Toxygen(object):
|
|||
# initializing callbacks
|
||||
init_callbacks(self.tox, self.ms, self.tray)
|
||||
# bootstrap
|
||||
for data in node_generator():
|
||||
self.tox.bootstrap(*data)
|
||||
self.msleep(10000)
|
||||
while not self.tox.self_get_connection_status() and not self.stop:
|
||||
try:
|
||||
for data in node_generator():
|
||||
self.tox.bootstrap(*data)
|
||||
self.msleep(5000)
|
||||
except:
|
||||
pass
|
||||
self.msleep(10000)
|
||||
while not self.tox.self_get_connection_status() and not self.stop:
|
||||
try:
|
||||
for data in node_generator():
|
||||
self.tox.bootstrap(*data)
|
||||
except:
|
||||
pass
|
||||
finally:
|
||||
self.msleep(5000)
|
||||
|
||||
class ToxIterateThread(QtCore.QThread):
|
||||
|
||||
|
|
|
@ -447,6 +447,29 @@ class Profile(Contact, Singleton):
|
|||
# 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):
|
||||
"""
|
||||
Current user gets new message
|
||||
|
@ -482,8 +505,7 @@ class Profile(Contact, Singleton):
|
|||
else:
|
||||
message_type = TOX_MESSAGE_TYPE['NORMAL']
|
||||
friend = self._friends[self._active_friend]
|
||||
# TODO: add message splitting
|
||||
self._tox.friend_send_message(friend.number, message_type, text.encode('utf-8'))
|
||||
self.split_and_send(friend.number, message_type, text.encode('utf-8'))
|
||||
self.create_message_item(text, curr_time(), self._name, message_type)
|
||||
self._screen.messageEdit.clear()
|
||||
self._messages.scrollToBottom()
|
||||
|
|
Loading…
Reference in a new issue