mirror of
https://github.com/liberatedsystems/openCom-Companion.git
synced 2024-11-25 23:00:36 +01:00
Work on message screen partial loading
This commit is contained in:
parent
5cc047c758
commit
4982e37231
@ -831,7 +831,6 @@ class SidebandApp(MDApp):
|
|||||||
self.root.ids.message_send_button.disabled = False
|
self.root.ids.message_send_button.disabled = False
|
||||||
Clock.schedule_once(cb, 0.5)
|
Clock.schedule_once(cb, 0.5)
|
||||||
|
|
||||||
|
|
||||||
def message_propagation_action(self, sender):
|
def message_propagation_action(self, sender):
|
||||||
if self.outbound_mode_paper:
|
if self.outbound_mode_paper:
|
||||||
self.outbound_mode_paper = False
|
self.outbound_mode_paper = False
|
||||||
|
@ -589,8 +589,15 @@ class SidebandCore():
|
|||||||
def named_conversation(self, name, context_dest):
|
def named_conversation(self, name, context_dest):
|
||||||
self._db_conversation_set_name(context_dest, name)
|
self._db_conversation_set_name(context_dest, name)
|
||||||
|
|
||||||
def list_messages(self, context_dest, after = None):
|
def count_messages(self, context_dest):
|
||||||
result = self._db_messages(context_dest, after)
|
result = self._db_message_count(context_dest)
|
||||||
|
if result != None:
|
||||||
|
return result
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def list_messages(self, context_dest, after = None, before = None, limit = None):
|
||||||
|
result = self._db_messages(context_dest, after, before, limit)
|
||||||
if result != None:
|
if result != None:
|
||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
@ -1012,16 +1019,38 @@ class SidebandCore():
|
|||||||
}
|
}
|
||||||
return message
|
return message
|
||||||
|
|
||||||
def _db_messages(self, context_dest, after = None):
|
def _db_message_count(self, context_dest):
|
||||||
db = sqlite3.connect(self.db_path)
|
db = sqlite3.connect(self.db_path)
|
||||||
dbc = db.cursor()
|
dbc = db.cursor()
|
||||||
|
|
||||||
if after == None:
|
query = "select count(*) from lxm where dest=:context_dest or source=:context_dest"
|
||||||
query = "select * from lxm where dest=:context_dest or source=:context_dest"
|
dbc.execute(query, {"context_dest": context_dest})
|
||||||
dbc.execute(query, {"context_dest": context_dest})
|
|
||||||
|
result = dbc.fetchall()
|
||||||
|
|
||||||
|
db.close()
|
||||||
|
|
||||||
|
if len(result) < 1:
|
||||||
|
return None
|
||||||
else:
|
else:
|
||||||
|
return result[0][0]
|
||||||
|
|
||||||
|
def _db_messages(self, context_dest, after = None, before = None, limit = None):
|
||||||
|
db = sqlite3.connect(self.db_path)
|
||||||
|
dbc = db.cursor()
|
||||||
|
|
||||||
|
if after != None and before == None:
|
||||||
query = "select * from lxm where (dest=:context_dest or source=:context_dest) and rx_ts>:after_ts"
|
query = "select * from lxm where (dest=:context_dest or source=:context_dest) and rx_ts>:after_ts"
|
||||||
dbc.execute(query, {"context_dest": context_dest, "after_ts": after})
|
dbc.execute(query, {"context_dest": context_dest, "after_ts": after})
|
||||||
|
elif after == None and before != None:
|
||||||
|
query = "select * from lxm where (dest=:context_dest or source=:context_dest) and rx_ts<:before_ts"
|
||||||
|
dbc.execute(query, {"context_dest": context_dest, "before_ts": before})
|
||||||
|
elif after != None and before != None:
|
||||||
|
query = "select * from lxm where (dest=:context_dest or source=:context_dest) and rx_ts<:before_ts and rx_ts>:after_ts"
|
||||||
|
dbc.execute(query, {"context_dest": context_dest, "before_ts": before, "after_ts": after})
|
||||||
|
else:
|
||||||
|
query = "select * from lxm where dest=:context_dest or source=:context_dest"
|
||||||
|
dbc.execute(query, {"context_dest": context_dest})
|
||||||
|
|
||||||
result = dbc.fetchall()
|
result = dbc.fetchall()
|
||||||
|
|
||||||
@ -1057,8 +1086,10 @@ class SidebandCore():
|
|||||||
"method": entry[7],
|
"method": entry[7],
|
||||||
"lxm": lxm
|
"lxm": lxm
|
||||||
}
|
}
|
||||||
messages.append(message)
|
|
||||||
|
|
||||||
|
messages.append(message)
|
||||||
|
if len(messages) > limit:
|
||||||
|
messages = messages[-limit:]
|
||||||
return messages
|
return messages
|
||||||
|
|
||||||
def _db_save_lxm(self, lxm, context_dest):
|
def _db_save_lxm(self, lxm, context_dest):
|
||||||
|
@ -13,7 +13,7 @@ from kivy.uix.gridlayout import GridLayout
|
|||||||
from kivy.uix.boxlayout import BoxLayout
|
from kivy.uix.boxlayout import BoxLayout
|
||||||
from kivy.clock import Clock
|
from kivy.clock import Clock
|
||||||
|
|
||||||
from kivymd.uix.button import MDRectangleFlatButton
|
from kivymd.uix.button import MDRectangleFlatButton, MDRectangleFlatIconButton
|
||||||
from kivymd.uix.dialog import MDDialog
|
from kivymd.uix.dialog import MDDialog
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@ -43,6 +43,7 @@ class Messages():
|
|||||||
self.list = None
|
self.list = None
|
||||||
self.widgets = []
|
self.widgets = []
|
||||||
self.send_error_dialog = None
|
self.send_error_dialog = None
|
||||||
|
self.load_more_button = None
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def reload(self):
|
def reload(self):
|
||||||
@ -56,21 +57,45 @@ class Messages():
|
|||||||
|
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def update(self):
|
def update(self, limit=8):
|
||||||
self.messages = self.app.sideband.list_messages(self.context_dest, self.latest_message_timestamp)
|
s_ts = time.time()
|
||||||
|
self.messages = self.app.sideband.list_messages(self.context_dest, after=self.latest_message_timestamp,limit=limit)
|
||||||
|
|
||||||
|
self.db_message_count = self.app.sideband.count_messages(self.context_dest)
|
||||||
|
RNS.log("Total messages in db: "+str(self.db_message_count))
|
||||||
|
RNS.log("Added items: "+str(len(self.added_item_hashes)))
|
||||||
|
|
||||||
|
if self.load_more_button == None:
|
||||||
|
self.load_more_button = MDRectangleFlatIconButton(
|
||||||
|
icon="message-text-clock-outline",
|
||||||
|
text="Load earlier messages",
|
||||||
|
font_size=dp(18),
|
||||||
|
theme_text_color="Custom",
|
||||||
|
size_hint=[1.0, None],
|
||||||
|
)
|
||||||
|
|
||||||
if self.list == None:
|
if self.list == None:
|
||||||
layout = GridLayout(cols=1, spacing=dp(16), padding=dp(16), size_hint_y=None)
|
layout = GridLayout(cols=1, spacing=dp(16), padding=dp(16), size_hint_y=None)
|
||||||
layout.bind(minimum_height=layout.setter('height'))
|
layout.bind(minimum_height=layout.setter('height'))
|
||||||
self.list = layout
|
self.list = layout
|
||||||
|
|
||||||
|
if (len(self.added_item_hashes) < self.db_message_count) and not self.load_more_button in self.list.children:
|
||||||
|
# if self.load_more_button in self.list.children:
|
||||||
|
# RNS.log("Removing for reinsertion")
|
||||||
|
# self.list.remove_widget(self.load_more_button)
|
||||||
|
self.list.add_widget(self.load_more_button, len(self.list.children))
|
||||||
|
|
||||||
|
c_ts = time.time()
|
||||||
if len(self.messages) > 0:
|
if len(self.messages) > 0:
|
||||||
self.update_widget()
|
self.update_widget()
|
||||||
|
RNS.log("Cards created in "+RNS.prettytime(time.time()-c_ts), RNS.LOG_DEBUG)
|
||||||
|
|
||||||
if self.app.sideband.config["dark_ui"]:
|
if self.app.sideband.config["dark_ui"]:
|
||||||
intensity_msgs = intensity_msgs_dark
|
intensity_msgs = intensity_msgs_dark
|
||||||
else:
|
else:
|
||||||
intensity_msgs = intensity_msgs_light
|
intensity_msgs = intensity_msgs_light
|
||||||
|
|
||||||
|
upd_ts = time.time()
|
||||||
for w in self.widgets:
|
for w in self.widgets:
|
||||||
m = w.m
|
m = w.m
|
||||||
if self.app.sideband.config["dark_ui"]:
|
if self.app.sideband.config["dark_ui"]:
|
||||||
@ -116,6 +141,8 @@ class Messages():
|
|||||||
w.heading = titlestr+"[b]Sent[/b] "+txstr+"\n[b]State[/b] Failed"
|
w.heading = titlestr+"[b]Sent[/b] "+txstr+"\n[b]State[/b] Failed"
|
||||||
m["state"] = msg["state"]
|
m["state"] = msg["state"]
|
||||||
|
|
||||||
|
RNS.log("Updated message widgets in "+RNS.prettytime(time.time()-upd_ts), RNS.LOG_DEBUG)
|
||||||
|
RNS.log("Creating messages view took "+RNS.prettytime(time.time()-s_ts), RNS.LOG_DEBUG)
|
||||||
|
|
||||||
def update_widget(self):
|
def update_widget(self):
|
||||||
if self.app.sideband.config["dark_ui"]:
|
if self.app.sideband.config["dark_ui"]:
|
||||||
@ -126,6 +153,7 @@ class Messages():
|
|||||||
mt_color = [1.0, 1.0, 1.0, 0.95]
|
mt_color = [1.0, 1.0, 1.0, 0.95]
|
||||||
|
|
||||||
for m in self.messages:
|
for m in self.messages:
|
||||||
|
s_ts = time.time()
|
||||||
if not m["hash"] in self.added_item_hashes:
|
if not m["hash"] in self.added_item_hashes:
|
||||||
txstr = time.strftime(ts_format, time.localtime(m["sent"]))
|
txstr = time.strftime(ts_format, time.localtime(m["sent"]))
|
||||||
rxstr = time.strftime(ts_format, time.localtime(m["received"]))
|
rxstr = time.strftime(ts_format, time.localtime(m["received"]))
|
||||||
@ -411,6 +439,8 @@ class Messages():
|
|||||||
if self.latest_message_timestamp == None or m["received"] > self.latest_message_timestamp:
|
if self.latest_message_timestamp == None or m["received"] > self.latest_message_timestamp:
|
||||||
self.latest_message_timestamp = m["received"]
|
self.latest_message_timestamp = m["received"]
|
||||||
|
|
||||||
|
RNS.log("Created message card in "+RNS.prettytime(time.time()-s_ts), RNS.LOG_DEBUG)
|
||||||
|
|
||||||
def get_widget(self):
|
def get_widget(self):
|
||||||
return self.list
|
return self.list
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user