Commit e7bc06ca authored by Philipp Hörist's avatar Philipp Hörist

Receipts: Save/Load receipts to/from database

parent cd9885c0
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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,
......
......@@ -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
"""
......@@ -1053,6 +1053,9 @@ class ConversationTextview(GObject.GObject):
if error is not None:
message_line.show_error_icon(to_user_string(error))
if marker is not None:
message_line.show_receipt_icon()
if index is None:
# New Message
self._message_list.append(message_line)
......@@ -1307,9 +1310,15 @@ class MessageLine:
self.id = id_
self.timestamp = timestamp
self.start_mark = start_mark
self._has_receipt = False
self._message_icons = message_icons
@property
def has_receipt(self):
return self._has_receipt
def show_receipt_icon(self):
self._has_receipt = True
self._message_icons.set_receipt_icon_visible(True)
def show_correction_icon(self, tooltip):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment