mirror of
https://github.com/markqvist/Sideband.git
synced 2024-10-01 03:15:37 -04: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):
|
def keydown_event(self, instance, keyboard, keycode, text, modifiers):
|
||||||
if len(modifiers) > 0 and modifiers[0] == 'ctrl' and (text == "w" or text == "q"):
|
if len(modifiers) > 0 and modifiers[0] == 'ctrl' and (text == "w" or text == "q"):
|
||||||
self.quit_action(self)
|
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):
|
def keyboard_event(self, window, key, *largs):
|
||||||
# Handle escape/back
|
# Handle escape/back
|
||||||
@ -443,9 +453,15 @@ class SidebandApp(MDApp):
|
|||||||
def dl_no(s):
|
def dl_no(s):
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
|
|
||||||
|
def dl_ds(s):
|
||||||
|
self.dialog_open = False
|
||||||
|
|
||||||
yes_button.bind(on_release=dl_yes)
|
yes_button.bind(on_release=dl_yes)
|
||||||
no_button.bind(on_release=dl_no)
|
no_button.bind(on_release=dl_no)
|
||||||
|
|
||||||
|
dialog.bind(on_dismiss=dl_ds)
|
||||||
dialog.open()
|
dialog.open()
|
||||||
|
self.dialog_open = True
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log("Error while creating new conversation dialog: "+str(e), RNS.LOG_ERROR)
|
RNS.log("Error while creating new conversation dialog: "+str(e), RNS.LOG_ERROR)
|
||||||
|
@ -32,6 +32,7 @@ class PropagationNodeDetector():
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
RNS.log("Detected active propagation node "+RNS.prettyhexrep(destination_hash)+" emission "+str(age)+" seconds ago, "+str(hops)+" hops away")
|
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.config["lxmf_propagation_node"] == None:
|
||||||
if self.owner.active_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):
|
def received_announce(self, destination_hash, announced_identity, app_data):
|
||||||
# Add the announce to the directory announce
|
# Add the announce to the directory announce
|
||||||
# stream logger
|
# 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):
|
def __init__(self, owner_app):
|
||||||
self.owner_app = 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)
|
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:
|
try:
|
||||||
RNS.log("Received LXMF destination announce for "+RNS.prettyhexrep(dest)+" with data: "+app_data.decode("utf-8"))
|
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)
|
self._db_save_announce(dest, app_data, dest_type)
|
||||||
self.owner_app.flag_new_announces = True
|
self.owner_app.flag_new_announces = True
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -290,7 +291,7 @@ class SidebandCore():
|
|||||||
|
|
||||||
|
|
||||||
except Exception as e:
|
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)
|
return RNS.prettyhexrep(context_dest)
|
||||||
|
|
||||||
def clear_conversation(self, 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("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("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.commit()
|
||||||
db.close()
|
db.close()
|
||||||
@ -424,6 +425,7 @@ class SidebandCore():
|
|||||||
"dest": entry[2],
|
"dest": entry[2],
|
||||||
"data": entry[3].decode("utf-8"),
|
"data": entry[3].decode("utf-8"),
|
||||||
"time": entry[1],
|
"time": entry[1],
|
||||||
|
"type": entry[4]
|
||||||
}
|
}
|
||||||
announces.append(announce)
|
announces.append(announce)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -649,15 +651,16 @@ class SidebandCore():
|
|||||||
|
|
||||||
self.__event_conversation_changed(context_dest)
|
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)
|
db = sqlite3.connect(self.db_path)
|
||||||
dbc = db.cursor()
|
dbc = db.cursor()
|
||||||
|
|
||||||
query = "INSERT INTO announce (received, source, data) values (?, ?, ?)"
|
query = "INSERT INTO announce (received, source, data, dest_type) values (?, ?, ?, ?)"
|
||||||
data = (
|
data = (
|
||||||
time.time(),
|
time.time(),
|
||||||
destination_hash,
|
destination_hash,
|
||||||
app_data,
|
app_data,
|
||||||
|
dest_type,
|
||||||
)
|
)
|
||||||
|
|
||||||
dbc.execute(query, data)
|
dbc.execute(query, data)
|
||||||
|
@ -48,6 +48,7 @@ class Announces():
|
|||||||
context_dest = announce["dest"]
|
context_dest = announce["dest"]
|
||||||
ts = announce["time"]
|
ts = announce["time"]
|
||||||
a_data = announce["data"]
|
a_data = announce["data"]
|
||||||
|
dest_type = announce["type"]
|
||||||
|
|
||||||
if not context_dest in self.added_item_dests:
|
if not context_dest in self.added_item_dests:
|
||||||
if self.app.sideband.is_trusted(context_dest):
|
if self.app.sideband.is_trusted(context_dest):
|
||||||
@ -55,14 +56,20 @@ class Announces():
|
|||||||
else:
|
else:
|
||||||
trust_icon = "account-question"
|
trust_icon = "account-question"
|
||||||
|
|
||||||
def gen_info(ts, dest, name):
|
def gen_info(ts, dest, name, dtype):
|
||||||
def x(sender):
|
def x(sender):
|
||||||
yes_button = MDFlatButton(
|
yes_button = MDFlatButton(
|
||||||
text="OK",
|
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(
|
dialog = MDDialog(
|
||||||
text="Announce Received: "+ts+"\nAnnounced Name: "+name+"\nLXMF Address: "+RNS.prettyhexrep(dest),
|
text=ad_text,
|
||||||
buttons=[ yes_button ],
|
buttons=[ yes_button ],
|
||||||
)
|
)
|
||||||
def dl_yes(s):
|
def dl_yes(s):
|
||||||
@ -74,9 +81,21 @@ class Announces():
|
|||||||
return x
|
return x
|
||||||
|
|
||||||
time_string = time.strftime(ts_format, time.localtime(ts))
|
time_string = time.strftime(ts_format, time.localtime(ts))
|
||||||
disp_name = self.app.sideband.peer_display_name(context_dest)
|
|
||||||
iconl = IconLeftWidget(icon=trust_icon)
|
if dest_type == "lxmf.delivery":
|
||||||
item = OneLineAvatarIconListItem(text=time_string+": "+disp_name, on_release=gen_info(time_string, context_dest, a_data))
|
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.add_widget(iconl)
|
||||||
item.sb_uid = context_dest
|
item.sb_uid = context_dest
|
||||||
|
|
||||||
@ -111,20 +130,42 @@ class Announces():
|
|||||||
self.app.conversation_from_announce_action(dest)
|
self.app.conversation_from_announce_action(dest)
|
||||||
return x
|
return x
|
||||||
|
|
||||||
dm_items = [
|
def gen_set_node(dest, item):
|
||||||
{
|
def x():
|
||||||
"viewclass": "OneLineListItem",
|
item.dmenu.dismiss()
|
||||||
"text": "Converse",
|
self.app.sideband.set_active_propagation_node(dest)
|
||||||
"height": dp(40),
|
self.app.sideband.config["lxmf_propagation_node"] = dest
|
||||||
"on_release": gen_conv(context_dest, item)
|
self.app.sideband.save_configuration()
|
||||||
},
|
return x
|
||||||
# {
|
|
||||||
# "text": "Delete Announce",
|
if dest_type == "lxmf.delivery":
|
||||||
# "viewclass": "OneLineListItem",
|
dm_items = [
|
||||||
# "height": dp(64),
|
{
|
||||||
# "on_release": gen_del(context_dest, item)
|
"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");
|
item.iconr = IconRightWidget(icon="dots-vertical");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user