Philipp Hörist pushed to branch master at gajim / gajim
Commits: e7bc06ca by Philipp Hörist at 2019-10-23T20:05:48Z Receipts: Save/Load receipts to/from database
- - - - - 23448095 by Philipp Hörist at 2019-10-23T20:05:48Z ConversationTextview: Rename methods
show_receipt_icon() -> set_receipt() show_error_icon() -> set_error() show_correction_icon() -> set_correction()
- - - - -
5 changed files:
- gajim/chat_control.py - gajim/chat_control_base.py - gajim/common/logger.py - gajim/common/modules/receipts.py - gajim/conversation_textview.py
Changes:
===================================== gajim/chat_control.py ===================================== @@ -1262,6 +1262,7 @@ class ChatControl(ChatControlBase): old_kind=local_old_kind, xhtml=xhtml, additional_data=additional_data, + marker=row.marker, error=row.error) if row.message.startswith('/me ') or row.message.startswith('/me\n'): local_old_kind = None
===================================== gajim/chat_control_base.py ===================================== @@ -991,7 +991,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): old_kind=None, xhtml=None, displaymarking=None, msg_log_id=None, message_id=None, correct_id=None, additional_data=None, - encrypted=None, error=None): + encrypted=None, marker=None, error=None): """ Print 'chat' type messages correct_id = (message_id, correct_id) @@ -1017,7 +1017,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): subject, old_kind, xhtml, displaymarking=displaymarking, message_id=message_id, correct_id=correct_id, additional_data=additional_data, - encrypted=encrypted, error=error) + encrypted=encrypted, marker=marker, error=error)
if restored: return
===================================== gajim/common/logger.py ===================================== @@ -195,12 +195,17 @@ def _convert_common_error(common_error): def _adapt_common_error(common_error): return common_error.serialize()
+def _convert_marker(marker): + return 'received' if marker == 0 else 'displayed' + sqlite.register_converter('disco_info', _convert_disco_info) sqlite.register_adapter(DiscoInfo, _adapt_disco_info)
sqlite.register_converter('common_error', _convert_common_error) sqlite.register_adapter(CommonError, _adapt_common_error)
+sqlite.register_converter('marker', _convert_marker) +
class Logger: def __init__(self): @@ -799,7 +804,7 @@ class Logger:
sql = ''' SELECT time, kind, message, error as "error [common_error]", - subject, additional_data + subject, additional_data, marker as "marker [marker]" FROM logs NATURAL JOIN jids WHERE jid IN ({jids}) AND kind IN ({kinds}) AND time > get_timeout() ORDER BY time DESC, log_line_id DESC LIMIT ? OFFSET ? @@ -1480,6 +1485,38 @@ class Logger: self._con.execute(sql, (error, account_id, jid_id, message_id)) self._timeout_commit()
+ def set_marker(self, account_jid, jid, message_id, state): + """ + Update the marker state of the corresponding message + + :param account_jid: The jid of the account + + :param jid: The jid that belongs to the avatar + + :param message_id: The id of the message + + :param state: The state, 'received' or 'displayed' + + """ + if state not in ('received', 'displayed'): + raise ValueError('Invalid marker state') + + account_id = self.get_jid_id(account_jid) + try: + jid_id = self.get_jid_id(str(jid)) + except ValueError: + # Unknown JID + return + + state = 0 if state == 'received' else 1 + + sql = ''' + UPDATE logs SET marker = ? + WHERE account_id = ? AND jid_id = ? AND message_id = ? + ''' + self._con.execute(sql, (state, account_id, jid_id, message_id)) + self._timeout_commit() + def set_avatar_sha(self, account_jid, jid, sha=None): """ Set the avatar sha of a jid on an account
===================================== gajim/common/modules/receipts.py ===================================== @@ -68,6 +68,11 @@ class Receipts(BaseModule): if not properties.is_muc_pm: jid.setBare()
+ app.logger.set_marker(app.get_jid_from_account(self._account), + jid, + properties.receipt.id, + 'received') + app.nec.push_incoming_event( NetworkEvent('receipt-received', account=self._account,
===================================== gajim/conversation_textview.py ===================================== @@ -405,13 +405,13 @@ class ConversationTextview(GObject.GObject): line = self._get_message_line(id_) if line is None: return - line.show_receipt_icon() + line.set_receipt()
def show_error(self, id_, error): line = self._get_message_line(id_) if line is None: return - line.show_error_icon(to_user_string(error)) + line.set_error(to_user_string(error))
def show_focus_out_line(self): if not self.allow_focus_out_line: @@ -915,7 +915,7 @@ class ConversationTextview(GObject.GObject): other_tags_for_name=None, other_tags_for_time=None, other_tags_for_text=None, subject=None, old_kind=None, xhtml=None, graphics=True, displaymarking=None, message_id=None, correct_id=None, additional_data=None, - encrypted=None, error=None): + encrypted=None, marker=None, error=None): """ Print 'chat' type messages """ @@ -1047,11 +1047,14 @@ class ConversationTextview(GObject.GObject): message_line = MessageLine(message_id, tim, message_icons, new_mark)
if corrected: - message_line.show_correction_icon( + message_line.set_correction( self.corrected_text_list[message_id])
if error is not None: - message_line.show_error_icon(to_user_string(error)) + message_line.set_error(to_user_string(error)) + + if marker is not None: + message_line.set_receipt()
if index is None: # New Message @@ -1307,16 +1310,22 @@ class MessageLine: self.id = id_ self.timestamp = timestamp self.start_mark = start_mark + self._has_receipt = False self._message_icons = message_icons
- def show_receipt_icon(self): + @property + def has_receipt(self): + return self._has_receipt + + def set_receipt(self): + self._has_receipt = True self._message_icons.set_receipt_icon_visible(True)
- def show_correction_icon(self, tooltip): + def set_correction(self, tooltip): self._message_icons.set_correction_icon_visible(True) self._message_icons.set_correction_tooltip(tooltip)
- def show_error_icon(self, tooltip): + def set_error(self, tooltip): self._message_icons.set_error_icon_visible(True) self._message_icons.set_error_tooltip(tooltip)
View it on GitLab: https://dev.gajim.org/gajim/gajim/compare/cd9885c0a1b2c55fd3ede70a20f3f2c4d2...