mirror of
https://github.com/liberatedsystems/Sideband_CE.git
synced 2024-09-03 04:13:27 +02:00
Added better conversation list sorting
This commit is contained in:
parent
ce9f9f42d7
commit
458ba51445
@ -605,8 +605,11 @@ class SidebandCore():
|
||||
def read_conversation(self, context_dest):
|
||||
self._db_conversation_set_unread(context_dest, False)
|
||||
|
||||
def unread_conversation(self, context_dest):
|
||||
self._db_conversation_set_unread(context_dest, True)
|
||||
def unread_conversation(self, context_dest, tx=False):
|
||||
self._db_conversation_set_unread(context_dest, True, tx=tx)
|
||||
|
||||
def txtime_conversation(self, context_dest):
|
||||
self._db_conversation_update_txtime(context_dest)
|
||||
|
||||
def trusted_conversation(self, context_dest):
|
||||
self._db_conversation_set_trusted(context_dest, True)
|
||||
@ -883,12 +886,32 @@ class SidebandCore():
|
||||
RNS.log("An error occurred during persistent setstate database operation: "+str(e), RNS.LOG_ERROR)
|
||||
self.db = None
|
||||
|
||||
def _db_conversation_set_unread(self, context_dest, unread):
|
||||
def _db_conversation_update_txtime(self, context_dest):
|
||||
db = self.__db_connect()
|
||||
dbc = db.cursor()
|
||||
|
||||
query = "UPDATE conv set last_tx = ? where dest_context = ?"
|
||||
data = (time.time(), context_dest)
|
||||
|
||||
dbc.execute(query, data)
|
||||
result = dbc.fetchall()
|
||||
db.commit()
|
||||
|
||||
def _db_conversation_set_unread(self, context_dest, unread, tx = False):
|
||||
db = self.__db_connect()
|
||||
dbc = db.cursor()
|
||||
|
||||
if unread:
|
||||
if tx:
|
||||
query = "UPDATE conv set unread = ?, last_tx = ? where dest_context = ?"
|
||||
data = (unread, time.time(), context_dest)
|
||||
else:
|
||||
query = "UPDATE conv set unread = ?, last_rx = ? where dest_context = ?"
|
||||
data = (unread, time.time(), context_dest)
|
||||
else:
|
||||
query = "UPDATE conv set unread = ? where dest_context = ?"
|
||||
data = (unread, context_dest)
|
||||
|
||||
dbc.execute(query, data)
|
||||
result = dbc.fetchall()
|
||||
db.commit()
|
||||
@ -924,13 +947,20 @@ class SidebandCore():
|
||||
else:
|
||||
convs = []
|
||||
for entry in result:
|
||||
last_rx = entry[1]
|
||||
last_tx = entry[2]
|
||||
last_activity = max(last_rx, last_tx)
|
||||
|
||||
conv = {
|
||||
"dest": entry[0],
|
||||
"unread": entry[3],
|
||||
"last_rx": last_rx,
|
||||
"last_tx": last_tx,
|
||||
"last_activity": last_activity,
|
||||
}
|
||||
convs.append(conv)
|
||||
|
||||
return convs
|
||||
return sorted(convs, key=lambda c: c["last_activity"], reverse=True)
|
||||
|
||||
def _db_announces(self):
|
||||
db = self.__db_connect()
|
||||
@ -982,6 +1012,7 @@ class SidebandCore():
|
||||
conv["trust"] = c[5]
|
||||
conv["name"] = c[6].decode("utf-8")
|
||||
conv["data"] = msgpack.unpackb(c[7])
|
||||
conv["last_activity"] = max(c[1], c[2])
|
||||
return conv
|
||||
|
||||
def _db_clear_conversation(self, context_dest):
|
||||
@ -1019,7 +1050,7 @@ class SidebandCore():
|
||||
|
||||
def_name = "".encode("utf-8")
|
||||
query = "INSERT INTO conv (dest_context, last_tx, last_rx, unread, type, trust, name, data) values (?, ?, ?, ?, ?, ?, ?, ?)"
|
||||
data = (context_dest, 0, 0, 0, SidebandCore.CONV_P2P, 0, def_name, msgpack.packb(None))
|
||||
data = (context_dest, 0, time.time(), 0, SidebandCore.CONV_P2P, 0, def_name, msgpack.packb(None))
|
||||
|
||||
dbc.execute(query, data)
|
||||
db.commit()
|
||||
@ -2000,9 +2031,11 @@ class SidebandCore():
|
||||
def lxm_ingest(self, message, originator = False):
|
||||
should_notify = False
|
||||
is_trusted = False
|
||||
unread_reason_tx = False
|
||||
|
||||
if originator:
|
||||
context_dest = message.destination_hash
|
||||
unread_reason_tx = True
|
||||
else:
|
||||
context_dest = message.source_hash
|
||||
is_trusted = self.is_trusted(context_dest)
|
||||
@ -2023,14 +2056,16 @@ class SidebandCore():
|
||||
|
||||
if self.gui_display() == "messages_screen":
|
||||
if self.gui_conversation() != context_dest:
|
||||
self.unread_conversation(context_dest)
|
||||
self.unread_conversation(context_dest, tx=unread_reason_tx)
|
||||
self.setstate("app.flags.unread_conversations", True)
|
||||
else:
|
||||
self.txtime_conversation(context_dest)
|
||||
self.setstate("wants.viewupdate.conversations", True)
|
||||
if self.gui_foreground():
|
||||
RNS.log("Squelching notification since GUI is in foreground", RNS.LOG_DEBUG)
|
||||
should_notify = False
|
||||
else:
|
||||
self.unread_conversation(context_dest)
|
||||
self.unread_conversation(context_dest, tx=unread_reason_tx)
|
||||
self.setstate("app.flags.unread_conversations", True)
|
||||
|
||||
if RNS.vendor.platformutils.is_android():
|
||||
|
@ -97,11 +97,13 @@ class Conversations():
|
||||
for conv in self.context_dests:
|
||||
context_dest = conv["dest"]
|
||||
unread = conv["unread"]
|
||||
last_activity = conv["last_activity"]
|
||||
|
||||
if not context_dest in self.added_item_dests:
|
||||
iconl = IconLeftWidget(icon=self.trust_icon(context_dest, unread), on_release=self.app.conversation_action)
|
||||
item = OneLineAvatarIconListItem(text=self.app.sideband.peer_display_name(context_dest), on_release=self.app.conversation_action)
|
||||
item.add_widget(iconl)
|
||||
item.last_activity = last_activity
|
||||
item.iconl = iconl
|
||||
item.sb_uid = context_dest
|
||||
item.sb_unread = unread
|
||||
@ -112,7 +114,7 @@ class Conversations():
|
||||
t_s = time.time()
|
||||
dest = self.conversation_dropdown.context_dest
|
||||
try:
|
||||
disp_name = self.app.sideband.raw_display_name(dest)
|
||||
disp_name = self.app.sideband.raw_display_name(dest)+" "+str(conv["last_activity"])
|
||||
is_trusted = self.app.sideband.is_trusted(dest)
|
||||
|
||||
yes_button = MDRectangleFlatButton(text="Save",font_size=dp(18), theme_text_color="Custom", line_color=self.app.color_accept, text_color=self.app.color_accept)
|
||||
@ -282,12 +284,15 @@ class Conversations():
|
||||
if w.sb_uid == context_dest:
|
||||
disp_name = self.app.sideband.peer_display_name(context_dest)
|
||||
trust_icon = self.trust_icon(context_dest, unread)
|
||||
w.last_activity = last_activity
|
||||
if w.iconl.icon != trust_icon:
|
||||
w.iconl.icon = trust_icon
|
||||
w.sb_unread = unread
|
||||
if w.text != disp_name:
|
||||
w.text = disp_name
|
||||
|
||||
self.list.children.sort(key=lambda w: w.last_activity)
|
||||
|
||||
RNS.log("Updated conversation list widgets in "+RNS.prettytime(time.time()-us), RNS.LOG_DEBUG)
|
||||
|
||||
def get_widget(self):
|
||||
|
Loading…
Reference in New Issue
Block a user