mirror of
https://github.com/liberatedsystems/openCom-Companion.git
synced 2024-11-24 22:30:37 +01:00
Added propagation nodes to announce stream. Added keyboard shortcuts.
This commit is contained in:
parent
23ab36a34f
commit
efefdbebe8
16
main.py
16
main.py
@ -99,6 +99,16 @@ class SidebandApp(MDApp):
|
||||
def keydown_event(self, instance, keyboard, keycode, text, modifiers):
|
||||
if len(modifiers) > 0 and modifiers[0] == 'ctrl' and (text == "w" or text == "q"):
|
||||
self.quit_action(self)
|
||||
if len(modifiers) > 0 and modifiers[0] == 'ctrl' and (text == "s" or text == "d"):
|
||||
if self.root.ids.screen_manager.current == "messages_screen":
|
||||
self.message_send_action()
|
||||
if len(modifiers) > 0 and modifiers[0] == 'ctrl' and (text == "l"):
|
||||
self.announces_action(self)
|
||||
if len(modifiers) > 0 and modifiers[0] == 'ctrl' and (text == "n"):
|
||||
if self.root.ids.screen_manager.current == "conversations_screen":
|
||||
if not hasattr(self, "dialog_open") or not self.dialog_open:
|
||||
self.new_conversation_action(self)
|
||||
|
||||
|
||||
def keyboard_event(self, window, key, *largs):
|
||||
# Handle escape/back
|
||||
@ -443,9 +453,15 @@ class SidebandApp(MDApp):
|
||||
def dl_no(s):
|
||||
dialog.dismiss()
|
||||
|
||||
def dl_ds(s):
|
||||
self.dialog_open = False
|
||||
|
||||
yes_button.bind(on_release=dl_yes)
|
||||
no_button.bind(on_release=dl_no)
|
||||
|
||||
dialog.bind(on_dismiss=dl_ds)
|
||||
dialog.open()
|
||||
self.dialog_open = True
|
||||
|
||||
except Exception as e:
|
||||
RNS.log("Error while creating new conversation dialog: "+str(e), RNS.LOG_ERROR)
|
||||
|
@ -32,6 +32,7 @@ class PropagationNodeDetector():
|
||||
pass
|
||||
|
||||
RNS.log("Detected active propagation node "+RNS.prettyhexrep(destination_hash)+" emission "+str(age)+" seconds ago, "+str(hops)+" hops away")
|
||||
self.owner.log_announce(destination_hash, RNS.prettyhexrep(destination_hash).encode("utf-8"), dest_type=PropagationNodeDetector.aspect_filter)
|
||||
|
||||
if self.owner.config["lxmf_propagation_node"] == None:
|
||||
if self.owner.active_propagation_node == None:
|
||||
@ -63,7 +64,7 @@ class SidebandCore():
|
||||
def received_announce(self, destination_hash, announced_identity, app_data):
|
||||
# Add the announce to the directory announce
|
||||
# stream logger
|
||||
self.log_announce(destination_hash, app_data)
|
||||
self.log_announce(destination_hash, app_data, dest_type=SidebandCore.aspect_filter)
|
||||
|
||||
def __init__(self, owner_app):
|
||||
self.owner_app = owner_app
|
||||
@ -202,10 +203,10 @@ class SidebandCore():
|
||||
RNS.log("Error while setting LXMF propagation node: "+str(e), RNS.LOG_ERROR)
|
||||
|
||||
|
||||
def log_announce(self, dest, app_data):
|
||||
def log_announce(self, dest, app_data, dest_type):
|
||||
try:
|
||||
RNS.log("Received LXMF destination announce for "+RNS.prettyhexrep(dest)+" with data: "+app_data.decode("utf-8"))
|
||||
self._db_save_announce(dest, app_data)
|
||||
RNS.log("Received "+str(dest_type)+" announce for "+RNS.prettyhexrep(dest)+" with data: "+app_data.decode("utf-8"))
|
||||
self._db_save_announce(dest, app_data, dest_type)
|
||||
self.owner_app.flag_new_announces = True
|
||||
|
||||
except Exception as e:
|
||||
@ -290,7 +291,7 @@ class SidebandCore():
|
||||
|
||||
|
||||
except Exception as e:
|
||||
RNS.log("Error while getting peer name: "+str(e), RNS.LOG_ERROR)
|
||||
RNS.log("Could not decode a valid peer name from data: "+str(e), RNS.LOG_DEBUG)
|
||||
return RNS.prettyhexrep(context_dest)
|
||||
|
||||
def clear_conversation(self, context_dest):
|
||||
@ -342,7 +343,7 @@ class SidebandCore():
|
||||
dbc.execute("CREATE TABLE conv (dest_context BLOB PRIMARY KEY, last_tx INTEGER, last_rx INTEGER, unread INTEGER, type INTEGER, trust INTEGER, name BLOB, data BLOB)")
|
||||
|
||||
dbc.execute("DROP TABLE IF EXISTS announce")
|
||||
dbc.execute("CREATE TABLE announce (id PRIMARY KEY, received INTEGER, source BLOB, data BLOB)")
|
||||
dbc.execute("CREATE TABLE announce (id PRIMARY KEY, received INTEGER, source BLOB, data BLOB, dest_type BLOB)")
|
||||
|
||||
db.commit()
|
||||
db.close()
|
||||
@ -424,6 +425,7 @@ class SidebandCore():
|
||||
"dest": entry[2],
|
||||
"data": entry[3].decode("utf-8"),
|
||||
"time": entry[1],
|
||||
"type": entry[4]
|
||||
}
|
||||
announces.append(announce)
|
||||
except Exception as e:
|
||||
@ -649,15 +651,16 @@ class SidebandCore():
|
||||
|
||||
self.__event_conversation_changed(context_dest)
|
||||
|
||||
def _db_save_announce(self, destination_hash, app_data):
|
||||
def _db_save_announce(self, destination_hash, app_data, dest_type="lxmf.delivery"):
|
||||
db = sqlite3.connect(self.db_path)
|
||||
dbc = db.cursor()
|
||||
|
||||
query = "INSERT INTO announce (received, source, data) values (?, ?, ?)"
|
||||
query = "INSERT INTO announce (received, source, data, dest_type) values (?, ?, ?, ?)"
|
||||
data = (
|
||||
time.time(),
|
||||
destination_hash,
|
||||
app_data,
|
||||
dest_type,
|
||||
)
|
||||
|
||||
dbc.execute(query, data)
|
||||
|
@ -48,6 +48,7 @@ class Announces():
|
||||
context_dest = announce["dest"]
|
||||
ts = announce["time"]
|
||||
a_data = announce["data"]
|
||||
dest_type = announce["type"]
|
||||
|
||||
if not context_dest in self.added_item_dests:
|
||||
if self.app.sideband.is_trusted(context_dest):
|
||||
@ -55,14 +56,20 @@ class Announces():
|
||||
else:
|
||||
trust_icon = "account-question"
|
||||
|
||||
def gen_info(ts, dest, name):
|
||||
def gen_info(ts, dest, name, dtype):
|
||||
def x(sender):
|
||||
yes_button = MDFlatButton(
|
||||
text="OK",
|
||||
)
|
||||
|
||||
if dtype == "lxmf.delivery":
|
||||
ad_text = "[size=22dp]LXMF Peer[/size]\n\nReceived: "+ts+"\nAnnounced Name: "+name+"\nAddress: "+RNS.prettyhexrep(dest)
|
||||
|
||||
if dtype == "lxmf.propagation":
|
||||
ad_text = "[size=22dp]LXMF Propagation Node[/size]\n\nReceived: "+ts+"\nAddress: "+RNS.prettyhexrep(dest)
|
||||
|
||||
dialog = MDDialog(
|
||||
text="Announce Received: "+ts+"\nAnnounced Name: "+name+"\nLXMF Address: "+RNS.prettyhexrep(dest),
|
||||
text=ad_text,
|
||||
buttons=[ yes_button ],
|
||||
)
|
||||
def dl_yes(s):
|
||||
@ -74,9 +81,21 @@ class Announces():
|
||||
return x
|
||||
|
||||
time_string = time.strftime(ts_format, time.localtime(ts))
|
||||
disp_name = self.app.sideband.peer_display_name(context_dest)
|
||||
iconl = IconLeftWidget(icon=trust_icon)
|
||||
item = OneLineAvatarIconListItem(text=time_string+": "+disp_name, on_release=gen_info(time_string, context_dest, a_data))
|
||||
|
||||
if dest_type == "lxmf.delivery":
|
||||
disp_name = self.app.sideband.peer_display_name(context_dest)
|
||||
iconl = IconLeftWidget(icon=trust_icon)
|
||||
|
||||
elif dest_type == "lxmf.propagation":
|
||||
disp_name = "Propagation Node "+RNS.prettyhexrep(context_dest)
|
||||
iconl = IconLeftWidget(icon="upload-network")
|
||||
|
||||
else:
|
||||
disp_name = "Unknown Announce"
|
||||
iconl = IconLeftWidget(icon="progress-question")
|
||||
|
||||
|
||||
item = OneLineAvatarIconListItem(text=time_string+": "+disp_name, on_release=gen_info(time_string, context_dest, a_data, dest_type))
|
||||
item.add_widget(iconl)
|
||||
item.sb_uid = context_dest
|
||||
|
||||
@ -111,20 +130,42 @@ class Announces():
|
||||
self.app.conversation_from_announce_action(dest)
|
||||
return x
|
||||
|
||||
dm_items = [
|
||||
{
|
||||
"viewclass": "OneLineListItem",
|
||||
"text": "Converse",
|
||||
"height": dp(40),
|
||||
"on_release": gen_conv(context_dest, item)
|
||||
},
|
||||
# {
|
||||
# "text": "Delete Announce",
|
||||
# "viewclass": "OneLineListItem",
|
||||
# "height": dp(64),
|
||||
# "on_release": gen_del(context_dest, item)
|
||||
# }
|
||||
]
|
||||
def gen_set_node(dest, item):
|
||||
def x():
|
||||
item.dmenu.dismiss()
|
||||
self.app.sideband.set_active_propagation_node(dest)
|
||||
self.app.sideband.config["lxmf_propagation_node"] = dest
|
||||
self.app.sideband.save_configuration()
|
||||
return x
|
||||
|
||||
if dest_type == "lxmf.delivery":
|
||||
dm_items = [
|
||||
{
|
||||
"viewclass": "OneLineListItem",
|
||||
"text": "Converse",
|
||||
"height": dp(40),
|
||||
"on_release": gen_conv(context_dest, item)
|
||||
},
|
||||
# {
|
||||
# "text": "Delete Announce",
|
||||
# "viewclass": "OneLineListItem",
|
||||
# "height": dp(40),
|
||||
# "on_release": gen_del(context_dest, item)
|
||||
# }
|
||||
]
|
||||
|
||||
elif dest_type == "lxmf.propagation":
|
||||
dm_items = [
|
||||
{
|
||||
"viewclass": "OneLineListItem",
|
||||
"text": "Use this Propagation Node",
|
||||
"height": dp(40),
|
||||
"on_release": gen_set_node(context_dest, item)
|
||||
},
|
||||
]
|
||||
|
||||
else:
|
||||
dm_items = []
|
||||
|
||||
item.iconr = IconRightWidget(icon="dots-vertical");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user