Skip to content
Snippets Groups Projects
Commit f48ed5e1 authored by Nico's avatar Nico
Browse files

Indicate delivery state of messages

Briar Headless still lacks web events of delivery state changes, therefore this commit doesn't update delivery states automatically.
There's #69 to do that.

Fixes #52.
parent 3567c100
No related branches found
No related tags found
1 merge request!68Indicate delivery state of messages
Pipeline #4970 passed
......@@ -40,6 +40,12 @@ class PrivateChatContainer(Container):
{
"text": message,
"local": True,
"sent": False,
"seen": False,
# TODO: Remove once web events updating is implemented
"no_stored_indicator": True,
"timestamp": int(round(time.time() * 1000))
})
widget.set_text("")
......
......@@ -33,9 +33,15 @@ class PrivateMessageWidget(Gtk.ListBoxRow):
username_info = PrivateMessageWidget._create_username_info(
username, username_style_class)
delivery_state_info = PrivateMessageWidget._create_delivery_state_info(
message)
date_info = PrivateMessageWidget._create_date_info(
message["timestamp"] / 1000)
info = PrivateMessageWidget._create_info(username_info, date_info)
info = PrivateMessageWidget._create_info(
username_info,
delivery_state_info,
date_info
)
body_content = PrivateMessageWidget._create_body_content(
message["text"])
......@@ -64,6 +70,22 @@ class PrivateMessageWidget(Gtk.ListBoxRow):
username_event_box.add(username_label)
return username_event_box
@staticmethod
def _create_delivery_state_info(message):
file_name = "message_stored"
if not message.get("local", True):
return Gtk.EventBox()
# TODO: Remove once web events updating is implemented
if message.get("no_stored_indicator", False):
return Gtk.EventBox()
if message.get("sent", False):
file_name = "message_sent"
if message.get("seen", False):
file_name = "message_delivered"
delivery_state = Gtk.Image.new_from_icon_name(file_name,
Gtk.IconSize.MENU)
return delivery_state
@staticmethod
def _create_date_info(timestamp):
time = PrivateMessageWidget._make_timestamp_readable(timestamp)
......@@ -83,9 +105,13 @@ class PrivateMessageWidget(Gtk.ListBoxRow):
return time.strftime("%x %H:%M")
@staticmethod
def _create_info(username_info, date_info):
def _create_info(username_info, delivery_state_info, date_info):
info = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
info.pack_start(username_info, True, True, 0)
if isinstance(delivery_state_info, Gtk.Image):
info.pack_end(delivery_state_info, False, False, 3)
else:
info.pack_end(delivery_state_info, False, False, 11)
info.pack_end(date_info, False, False, 0)
return info
......@@ -123,6 +149,10 @@ class PrivateMessageWidget(Gtk.ListBoxRow):
return True
if message["local"] != previous_message["local"]:
return True
if message["sent"] != previous_message["sent"]:
return True
if message["seen"] != previous_message["seen"]:
return True
time = datetime.fromtimestamp(message.get("timestamp", 0) / 1000)
previous_time = datetime.fromtimestamp(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment