Skip to content
Snippets Groups Projects
Commit 859cbe62 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 58268754
No related branches found
No related tags found
No related merge requests found
...@@ -40,6 +40,12 @@ class PrivateChatContainer(Container): ...@@ -40,6 +40,12 @@ class PrivateChatContainer(Container):
{ {
"text": message, "text": message,
"local": True, "local": True,
"sent": False,
"seen": False,
# TODO: Remove once web events updating is implemented
"no_stored_indicator": True,
"timestamp": int(round(time.time() * 1000)) "timestamp": int(round(time.time() * 1000))
}) })
widget.set_text("") widget.set_text("")
......
...@@ -32,9 +32,15 @@ class PrivateMessageWidget(Gtk.ListBoxRow): ...@@ -32,9 +32,15 @@ class PrivateMessageWidget(Gtk.ListBoxRow):
username_info = PrivateMessageWidget._create_username_info( username_info = PrivateMessageWidget._create_username_info(
username, username_style_class) username, username_style_class)
delivery_state_info = PrivateMessageWidget._create_delivery_state_info(
message)
date_info = PrivateMessageWidget._create_date_info( date_info = PrivateMessageWidget._create_date_info(
message["timestamp"] / 1000) 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( body_content = PrivateMessageWidget._create_body_content(
message["text"]) message["text"])
...@@ -63,6 +69,21 @@ class PrivateMessageWidget(Gtk.ListBoxRow): ...@@ -63,6 +69,21 @@ class PrivateMessageWidget(Gtk.ListBoxRow):
username_event_box.add(username_label) username_event_box.add(username_label)
return username_event_box return username_event_box
@staticmethod
def _create_delivery_state_info(message):
file_name = "message_stored"
if not message.get("local", True):
return Gtk.EventBox()
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 @staticmethod
def _create_date_info(timestamp): def _create_date_info(timestamp):
time = PrivateMessageWidget._make_timestamp_readable(timestamp) time = PrivateMessageWidget._make_timestamp_readable(timestamp)
...@@ -82,10 +103,11 @@ class PrivateMessageWidget(Gtk.ListBoxRow): ...@@ -82,10 +103,11 @@ class PrivateMessageWidget(Gtk.ListBoxRow):
return time.strftime("%x %H:%M") return time.strftime("%x %H:%M")
@staticmethod @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 = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
info.pack_start(username_info, True, True, 0) info.pack_start(username_info, True, True, 0)
info.pack_end(date_info, False, False, 0) info.pack_end(date_info, False, False, 0)
info.pack_end(delivery_state_info, False, False, 3)
return info return info
@staticmethod @staticmethod
...@@ -122,6 +144,10 @@ class PrivateMessageWidget(Gtk.ListBoxRow): ...@@ -122,6 +144,10 @@ class PrivateMessageWidget(Gtk.ListBoxRow):
return True return True
if message["local"] != previous_message["local"]: if message["local"] != previous_message["local"]:
return True 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) time = datetime.fromtimestamp(message.get("timestamp", 0) / 1000)
previous_time = datetime.fromtimestamp( 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