read receipts - spinner

This commit is contained in:
ingvar1995 2016-06-15 23:27:57 +03:00
parent fe4af18196
commit 85061454a6
4 changed files with 20 additions and 12 deletions

View File

@ -148,7 +148,10 @@ def friend_typing(tox, friend_number, typing, user_data):
def friend_read_receipt(tox, friend_number, message_id, user_data): def friend_read_receipt(tox, friend_number, message_id, user_data):
Profile.get_instance().get_friend_by_number(friend_number).dec_receipt() profile = Profile.get_instance()
profile.get_friend_by_number(friend_number).dec_receipt()
if friend_number == profile.get_active_number():
invoke_in_main_thread(profile.update) # TODO: improve
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------
# Callbacks - file transfers # Callbacks - file transfers

BIN
src/images/spinner.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -98,7 +98,7 @@ class MessageItem(QtGui.QWidget):
""" """
Message in messages list Message in messages list
""" """
def __init__(self, text, time, user='', message_type=TOX_MESSAGE_TYPE['NORMAL'], parent=None): def __init__(self, text, time, user='', sent=True, message_type=TOX_MESSAGE_TYPE['NORMAL'], parent=None):
QtGui.QWidget.__init__(self, parent) QtGui.QWidget.__init__(self, parent)
self.name = DataLabel(self) self.name = DataLabel(self)
self.name.setGeometry(QtCore.QRect(0, 2, 95, 20)) self.name.setGeometry(QtCore.QRect(0, 2, 95, 20))
@ -118,8 +118,13 @@ class MessageItem(QtGui.QWidget):
font.setPointSize(10) font.setPointSize(10)
font.setBold(False) font.setBold(False)
self.time.setFont(font) self.time.setFont(font)
self.time.setObjectName("time")
self.time.setText(time) if not sent:
movie = QtGui.QMovie(curr_directory() + '/images/spinner.gif')
self.time.setMovie(movie)
movie.start()
else:
self.time.setText(time)
self.message = MessageEdit(text, parent.width() - 150, self) self.message = MessageEdit(text, parent.width() - 150, self)
self.message.setGeometry(QtCore.QRect(100, 0, parent.width() - 150, self.message.height())) self.message.setGeometry(QtCore.QRect(100, 0, parent.width() - 150, self.message.height()))

View File

@ -166,7 +166,7 @@ class Profile(contact.Contact, Singleton):
data = message.get_data() data = message.get_data()
self.create_message_item(data[0], self.create_message_item(data[0],
convert_time(data[2]), convert_time(data[2]),
friend.name if data[1] == MESSAGE_OWNER['FRIEND'] else self._name, data[1],
data[3]) data[3])
elif message.get_type() == MESSAGE_TYPE['FILE_TRANSFER']: elif message.get_type() == MESSAGE_TYPE['FILE_TRANSFER']:
if message.get_status() is None: if message.get_status() is None:
@ -350,8 +350,7 @@ class Profile(contact.Contact, Singleton):
:param message: text of message :param message: text of message
""" """
if friend_num == self.get_active_number(): # add message to list if friend_num == self.get_active_number(): # add message to list
user_name = Profile.get_instance().get_active_name() self.create_message_item(message.decode('utf-8'), curr_time(), MESSAGE_OWNER['FRIEND'], message_type)
self.create_message_item(message.decode('utf-8'), curr_time(), user_name, message_type)
self._messages.scrollToBottom() self._messages.scrollToBottom()
self._friends[self._active_friend].append_message( self._friends[self._active_friend].append_message(
TextMessage(message.decode('utf-8'), MESSAGE_OWNER['FRIEND'], time.time(), message_type)) TextMessage(message.decode('utf-8'), MESSAGE_OWNER['FRIEND'], time.time(), message_type))
@ -378,13 +377,13 @@ class Profile(contact.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]
friend.inc_receipts()
if friend.status is not None: if friend.status is not None:
self.split_and_send(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.create_message_item(text, curr_time(), MESSAGE_OWNER['NOT_SENT'], message_type)
self._screen.messageEdit.clear() self._screen.messageEdit.clear()
self._messages.scrollToBottom() self._messages.scrollToBottom()
friend.append_message(TextMessage(text, MESSAGE_OWNER['NOT_SENT'], time.time(), message_type)) friend.append_message(TextMessage(text, MESSAGE_OWNER['NOT_SENT'], time.time(), message_type))
friend.inc_receipts()
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------
# History support # History support
@ -440,7 +439,7 @@ class Profile(contact.Contact, Singleton):
data = message.get_data() data = message.get_data()
self.create_message_item(data[0], self.create_message_item(data[0],
convert_time(data[2]), convert_time(data[2]),
friend.name if data[1] == MESSAGE_OWNER['FRIEND'] else self._name, data[1],
data[3], data[3],
False) False)
elif message.get_type() == MESSAGE_TYPE['FILE_TRANSFER']: elif message.get_type() == MESSAGE_TYPE['FILE_TRANSFER']:
@ -479,8 +478,9 @@ class Profile(contact.Contact, Singleton):
self._screen.friends_list.setItemWidget(elem, item) self._screen.friends_list.setItemWidget(elem, item)
return item return item
def create_message_item(self, text, time, name, message_type, append=True): def create_message_item(self, text, time, owner, message_type, append=True):
item = MessageItem(text, time, name, message_type, self._messages) name = self.get_active_name() if owner == MESSAGE_OWNER['FRIEND'] else self.name
item = MessageItem(text, time, name, owner != MESSAGE_OWNER['NOT_SENT'], message_type, self._messages)
elem = QtGui.QListWidgetItem() elem = QtGui.QListWidgetItem()
elem.setSizeHint(QtCore.QSize(self._messages.width(), item.height())) elem.setSizeHint(QtCore.QSize(self._messages.width(), item.height()))
if append: if append: