Add map marker for own device

This commit is contained in:
Mark Qvist 2023-10-21 01:02:43 +02:00
parent 71234d9b9d
commit a0b97bf4a3
4 changed files with 104 additions and 8 deletions

View File

@ -3080,17 +3080,67 @@ class SidebandApp(MDApp):
# RNS.log("Update map markers", RNS.LOG_WARNING) # RNS.log("Update map markers", RNS.LOG_WARNING)
earliest = time.time() - self.sideband.config["map_history_limit"] earliest = time.time() - self.sideband.config["map_history_limit"]
telemetry_entries = self.sideband.list_telemetry(after=earliest) telemetry_entries = self.sideband.list_telemetry(after=earliest)
own_address = self.sideband.lxmf_destination.hash
changes = False changes = False
# Add own marker if available # Add own marker if available
retain_own = False
own_telemetry = self.sideband.get_telemetry()
if own_telemetry != None and "location" in own_telemetry and own_telemetry["location"]["latitude"] != None and own_telemetry["location"]["longtitude"] != None:
retain_own = True
o = own_telemetry["location"]
if not own_address in self.map_markers:
# TODO: Remove
RNS.log("Adding own marker", RNS.LOG_WARNING)
marker = MapMarker(lat=o["latitude"], lon=o["longtitude"])
marker.source_dest = own_address
marker.latest_timestamp = o["last_update"]
self.map_markers[own_address] = marker
self.root.ids.map_layout.map.add_widget(marker)
changes = True
else:
marker = self.map_markers[own_address]
if o["last_update"] > marker.latest_timestamp:
# TODO: Remove
RNS.log("Updating own marker", RNS.LOG_WARNING)
marker.latest_timestamp = o["last_update"]
marker.lat = o["latitude"]
marker.lon = o["longtitude"]
changes = True
else:
# TODO: Remove
RNS.log("Skipped updating own marker, no new location", RNS.LOG_WARNING)
else:
# TODO: Remove
RNS.log("Not adding own marker, no data", RNS.LOG_WARNING)
stale_markers = []
for marker in self.map_markers:
if not marker in telemetry_entries:
if marker == own_address:
if not retain_own:
# TODO: Remove
RNS.log("Setting own marker for removal: "+str(marker), RNS.LOG_WARNING)
stale_markers.append(marker)
else:
# TODO: Remove
RNS.log("Setting marker for removal: "+str(marker), RNS.LOG_WARNING)
stale_markers.append(marker)
for marker in stale_markers:
try:
self.root.ids.map_layout.map.remove_widget(self.map_markers[marker])
self.map_markers.pop(marker)
except Exception as e:
RNS.log("Error while removing map marker: "+str(e), RNS.LOG_ERROR)
for telemetry_source in telemetry_entries: for telemetry_source in telemetry_entries:
skip = False skip = False
# TODO: Remove # TODO: Remove
RNS.log("Processing telemetry for "+RNS.prettyhexrep(telemetry_source), RNS.LOG_WARNING) RNS.log("Processing telemetry for "+RNS.prettyhexrep(telemetry_source)+"/"+RNS.prettyhexrep(self.sideband.lxmf_destination.hash), RNS.LOG_WARNING)
if telemetry_source == self.sideband.lxmf_destination.hash: if telemetry_source == own_address:
# TODO: Remove # TODO: Remove
RNS.log("Skipping own telemetry", RNS.LOG_WARNING) RNS.log("Skipping own telemetry", RNS.LOG_WARNING)
skip = True skip = True

View File

@ -18,7 +18,7 @@ from mapview.constants import CACHE_DIR
# if "MAPVIEW_DEBUG_DOWNLOADER" in environ: # if "MAPVIEW_DEBUG_DOWNLOADER" in environ:
# Logger.setLevel(LOG_LEVELS['debug']) # Logger.setLevel(LOG_LEVELS['debug'])
Logger.setLevel(LOG_LEVELS['error']) # Logger.setLevel(LOG_LEVELS['error'])
# user agent is needed because since may 2019 OSM gives me a 429 or 403 server error # user agent is needed because since may 2019 OSM gives me a 429 or 403 server error
# I tried it with a simpler one (just Mozilla/5.0) this also gets rejected # I tried it with a simpler one (just Mozilla/5.0) this also gets rejected

View File

@ -682,11 +682,15 @@ class SidebandCore():
def clear_conversation(self, context_dest): def clear_conversation(self, context_dest):
self._db_clear_conversation(context_dest) self._db_clear_conversation(context_dest)
def clear_telemetry(self, context_dest):
self._db_clear_telemetry(context_dest)
def delete_announce(self, context_dest): def delete_announce(self, context_dest):
self._db_delete_announce(context_dest) self._db_delete_announce(context_dest)
def delete_conversation(self, context_dest): def delete_conversation(self, context_dest):
self._db_clear_conversation(context_dest) self._db_clear_conversation(context_dest)
self._db_clear_telemetry(context_dest)
self._db_delete_conversation(context_dest) self._db_delete_conversation(context_dest)
def delete_message(self, message_hash): def delete_message(self, message_hash):
@ -724,7 +728,7 @@ class SidebandCore():
return None return None
def list_telemetry(self, context_dest = None, after = None, before = None, limit = None): def list_telemetry(self, context_dest = None, after = None, before = None, limit = None):
return self._db_telemetry(context_dest = context_dest, after = after, before = before, limit = limit) return self._db_telemetry(context_dest = context_dest, after = after, before = before, limit = limit) or []
def list_messages(self, context_dest, after = None, before = None, limit = None): def list_messages(self, context_dest, after = None, before = None, limit = None):
result = self._db_messages(context_dest, after, before, limit) result = self._db_messages(context_dest, after, before, limit)
@ -1252,6 +1256,17 @@ class SidebandCore():
dbc.execute(query, {"ctx_dst": context_dest}) dbc.execute(query, {"ctx_dst": context_dest})
db.commit() db.commit()
def _db_clear_telemetry(self, context_dest):
RNS.log("Clearing telemetry for "+RNS.prettyhexrep(context_dest), RNS.LOG_DEBUG)
db = self.__db_connect()
dbc = db.cursor()
query = "delete from telemetry where dest_context=:ctx_dst;"
dbc.execute(query, {"ctx_dst": context_dest})
db.commit()
self.setstate("app.flags.last_telemetry", time.time())
def _db_delete_conversation(self, context_dest): def _db_delete_conversation(self, context_dest):
RNS.log("Deleting conversation with "+RNS.prettyhexrep(context_dest), RNS.LOG_DEBUG) RNS.log("Deleting conversation with "+RNS.prettyhexrep(context_dest), RNS.LOG_DEBUG)
db = self.__db_connect() db = self.__db_connect()
@ -1441,7 +1456,7 @@ class SidebandCore():
messages = 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, originator = False):
state = lxm.state state = lxm.state
db = self.__db_connect() db = self.__db_connect()
@ -1474,7 +1489,7 @@ class SidebandCore():
db.commit() db.commit()
if lxm.fields != None: if not originator and lxm.fields != None:
if LXMF.FIELD_ICON_APPEARANCE in lxm.fields: if LXMF.FIELD_ICON_APPEARANCE in lxm.fields:
self._db_update_appearance(context_dest, lxm.timestamp, lxm.fields[LXMF.FIELD_ICON_APPEARANCE]) self._db_update_appearance(context_dest, lxm.timestamp, lxm.fields[LXMF.FIELD_ICON_APPEARANCE])
@ -2375,7 +2390,7 @@ class SidebandCore():
self._db_message_set_state(message.hash, message.state) self._db_message_set_state(message.hash, message.state)
else: else:
RNS.log("Message does not exist, saving", RNS.LOG_DEBUG) RNS.log("Message does not exist, saving", RNS.LOG_DEBUG)
self._db_save_lxm(message, context_dest) self._db_save_lxm(message, context_dest, originator)
if is_trusted: if is_trusted:
should_notify = True should_notify = True

View File

@ -37,6 +37,7 @@ class Conversations():
self.conversation_dropdown = None self.conversation_dropdown = None
self.delete_dialog = None self.delete_dialog = None
self.clear_dialog = None self.clear_dialog = None
self.clear_telemetry_dialog = None
self.update() self.update()
@ -195,6 +196,30 @@ class Conversations():
self.clear_dialog.open() self.clear_dialog.open()
return x return x
def gen_clear_telemetry(item):
def x():
if self.clear_telemetry_dialog == None:
yes_button = MDRectangleFlatButton(text="Yes",font_size=dp(18), theme_text_color="Custom", line_color=self.app.color_reject, text_color=self.app.color_reject)
no_button = MDRectangleFlatButton(text="No",font_size=dp(18))
self.clear_telemetry_dialog = MDDialog(
title="Clear all telemetry related to this peer?",
buttons=[ yes_button, no_button ],
# elevation=0,
)
def dl_yes(s):
self.clear_telemetry_dialog.dismiss()
self.app.sideband.clear_telemetry(self.conversation_dropdown.context_dest)
def dl_no(s):
self.clear_telemetry_dialog.dismiss()
yes_button.bind(on_release=dl_yes)
no_button.bind(on_release=dl_no)
item.dmenu.dismiss()
self.clear_telemetry_dialog.open()
return x
def gen_del(item): def gen_del(item):
def x(): def x():
if self.delete_dialog == None: if self.delete_dialog == None:
@ -250,6 +275,12 @@ class Conversations():
"height": dp(dmi_h), "height": dp(dmi_h),
"on_release": gen_clear(item) "on_release": gen_clear(item)
}, },
{
"text": "Clear Telemetry",
"viewclass": "OneLineListItem",
"height": dp(dmi_h),
"on_release": gen_clear_telemetry(item)
},
{ {
"text": "Delete Conversation", "text": "Delete Conversation",
"viewclass": "OneLineListItem", "viewclass": "OneLineListItem",