Commit 74404d88 authored by Tijmen de Mes's avatar Tijmen de Mes

Changed chatview to add messages ordered by date and time

parent b703b4f6
...@@ -22,6 +22,7 @@ from application.system import makedirs ...@@ -22,6 +22,7 @@ from application.system import makedirs
from collections.abc import MutableSet from collections.abc import MutableSet
from collections import deque from collections import deque
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
from dateutil.tz import tzlocal
from itertools import count from itertools import count
from lxml import etree, html from lxml import etree, html
from lxml.html.clean import autolink from lxml.html.clean import autolink
...@@ -669,6 +670,7 @@ class ChatWidget(base_class, ui_class): ...@@ -669,6 +670,7 @@ class ChatWidget(base_class, ui_class):
self.last_message = None self.last_message = None
self.session = session self.session = session
self.history_loaded = False self.history_loaded = False
self.timestamp_rendered_messages = []
if session is not None: if session is not None:
notification_center = NotificationCenter() notification_center = NotificationCenter()
notification_center.add_observer(ObserverWeakrefProxy(self), sender=session.blink_session) notification_center.add_observer(ObserverWeakrefProxy(self), sender=session.blink_session)
...@@ -691,6 +693,25 @@ class ChatWidget(base_class, ui_class): ...@@ -691,6 +693,25 @@ class ChatWidget(base_class, ui_class):
exists = self.chat_element.findFirst(f'#text-{message.id}') exists = self.chat_element.findFirst(f'#text-{message.id}')
if not exists.isNull(): if not exists.isNull():
return return
if self.last_message is not None and not self.last_message.history and message.history:
message.history = False
for i, (timestamp, id) in enumerate(self.timestamp_rendered_messages):
if timestamp >= message.timestamp:
insertion_point = self.chat_element.findFirst(f'#message-{id}')
if message.is_related_to(self.last_message):
message.consecutive = True
sibling = insertion_point.previousSibling()
sibling.appendInside(message.to_html(self.style, user_icons=self.user_icons_css_class).replace("<div id=\"insert\"></div>", ''))
else:
insertion_point.prependOutside(message.to_html(self.style, user_icons=self.user_icons_css_class).replace("<div id=\"insert\"></div>", ''))
self.timestamp_rendered_messages.insert(i, (message.timestamp, message.id))
self.last_message = message
return
insertion_point = self.chat_element.findFirst('#insert') insertion_point = self.chat_element.findFirst('#insert')
if message.is_related_to(self.last_message): if message.is_related_to(self.last_message):
message.consecutive = True message.consecutive = True
...@@ -698,6 +719,9 @@ class ChatWidget(base_class, ui_class): ...@@ -698,6 +719,9 @@ class ChatWidget(base_class, ui_class):
else: else:
insertion_point.removeFromDocument() insertion_point.removeFromDocument()
self.chat_element.appendInside(message.to_html(self.style, user_icons=self.user_icons_css_class)) self.chat_element.appendInside(message.to_html(self.style, user_icons=self.user_icons_css_class))
if hasattr(message, 'id'):
self.timestamp_rendered_messages.append((message.timestamp, message.id))
self.last_message = message self.last_message = message
def update_message_text(self, id, text): def update_message_text(self, id, text):
...@@ -2523,7 +2547,7 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin): ...@@ -2523,7 +2547,7 @@ class ChatWindow(base_class, ui_class, ColorHelperMixin):
else: else:
uri = message.remote_uri uri = message.remote_uri
timestamp = message.timestamp.replace(tzinfo=timezone.utc).astimezone().replace(tzinfo=None) timestamp = message.timestamp.replace(tzinfo=timezone.utc).astimezone(tzlocal())
# print(f"t: {timestamp}") # print(f"t: {timestamp}")
account_manager = AccountManager() account_manager = AccountManager()
if account_manager.has_account(uri): if account_manager.has_account(uri):
......
<div class="{message.css_classes} {user_icons}" user="{message.sender.name}" style="background-color: {message.sender.color};" id="{message.id}"> <div class="{message.css_classes} {user_icons}" user="{message.sender.name}" style="background-color: {message.sender.color};" id="message-{message.id}">
<img class="x-icon" src="{message.sender.iconpath}" /> <img class="x-icon" src="{message.sender.iconpath}" />
<span class="x-iconmask" style="-webkit-mask-box-image: {message.sender.iconpath};"></span> <span class="x-iconmask" style="-webkit-mask-box-image: {message.sender.iconpath};"></span>
<span class="x-color" style="background-color: {message.sender.color};" src="{message.sender.iconpath}"></span> <span class="x-color" style="background-color: {message.sender.color};" src="{message.sender.iconpath}"></span>
......
<div class="{message.css_classes} {user_icons}" user="{message.sender.name}" style="background-color: {message.sender.color};"> <div id="message-{message.id}" class="{message.css_classes} {user_icons}" user="{message.sender.name}" style="background-color: {message.sender.color};">
<img class="x-icon" src="{message.sender.iconpath}" /> <img class="x-icon" src="{message.sender.iconpath}" />
<span class="x-iconmask" style="-webkit-mask-box-image: {message.sender.iconpath};"></span> <span class="x-iconmask" style="-webkit-mask-box-image: {message.sender.iconpath};"></span>
<span class="x-color" style="background-color: {message.sender.color};" src="{message.sender.iconpath}"></span> <span class="x-color" style="background-color: {message.sender.color};" src="{message.sender.iconpath}"></span>
......
<div id="{message.id}" class="x-container {message.css_classes} {user_icons} {message.text_direction}"> <div id="message-{message.id}" class="x-container {message.css_classes} {user_icons} {message.text_direction}">
<img class="x-buddyicon" src="{message.sender.iconpath}" /> <img class="x-buddyicon" src="{message.sender.iconpath}" />
<div class="x-iconoverlay"></div> <div class="x-iconoverlay"></div>
<div class="x-mentionicon" title="Mentioned!"></div> <div class="x-mentionicon" title="Mentioned!"></div>
......
<div class="x-message {message.css_classes} {message.text_direction}"> <div id="message-{message.id}" class="x-message {message.css_classes} {message.text_direction}">
<span id="encryption-{message.id}" class="stockholm"></span> <span id="encryption-{message.id}" class="stockholm"></span>
<span id="status-{message.id}">{message.status}</span> <span id="status-{message.id}">{message.status}</span>
<div class="x-time" title="{message.date}">{message.time}</div> <div class="x-time" title="{message.date}">{message.time}</div>
......
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