mirror of
https://github.com/liberatedsystems/openCom-Companion.git
synced 2024-11-22 13:30:36 +01:00
Add map marker for own device
This commit is contained in:
parent
71234d9b9d
commit
a0b97bf4a3
@ -3080,17 +3080,67 @@ class SidebandApp(MDApp):
|
||||
# RNS.log("Update map markers", RNS.LOG_WARNING)
|
||||
earliest = time.time() - self.sideband.config["map_history_limit"]
|
||||
telemetry_entries = self.sideband.list_telemetry(after=earliest)
|
||||
own_address = self.sideband.lxmf_destination.hash
|
||||
changes = False
|
||||
|
||||
# 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:
|
||||
skip = False
|
||||
|
||||
# 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
|
||||
RNS.log("Skipping own telemetry", RNS.LOG_WARNING)
|
||||
skip = True
|
||||
|
@ -18,7 +18,7 @@ from mapview.constants import CACHE_DIR
|
||||
|
||||
# if "MAPVIEW_DEBUG_DOWNLOADER" in environ:
|
||||
# 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
|
||||
# I tried it with a simpler one (just Mozilla/5.0) this also gets rejected
|
||||
|
@ -682,11 +682,15 @@ class SidebandCore():
|
||||
def clear_conversation(self, 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):
|
||||
self._db_delete_announce(context_dest)
|
||||
|
||||
def delete_conversation(self, context_dest):
|
||||
self._db_clear_conversation(context_dest)
|
||||
self._db_clear_telemetry(context_dest)
|
||||
self._db_delete_conversation(context_dest)
|
||||
|
||||
def delete_message(self, message_hash):
|
||||
@ -724,7 +728,7 @@ class SidebandCore():
|
||||
return 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):
|
||||
result = self._db_messages(context_dest, after, before, limit)
|
||||
@ -1252,6 +1256,17 @@ class SidebandCore():
|
||||
dbc.execute(query, {"ctx_dst": context_dest})
|
||||
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):
|
||||
RNS.log("Deleting conversation with "+RNS.prettyhexrep(context_dest), RNS.LOG_DEBUG)
|
||||
db = self.__db_connect()
|
||||
@ -1441,7 +1456,7 @@ class SidebandCore():
|
||||
messages = messages[-limit:]
|
||||
return messages
|
||||
|
||||
def _db_save_lxm(self, lxm, context_dest):
|
||||
def _db_save_lxm(self, lxm, context_dest, originator = False):
|
||||
state = lxm.state
|
||||
|
||||
db = self.__db_connect()
|
||||
@ -1474,7 +1489,7 @@ class SidebandCore():
|
||||
|
||||
db.commit()
|
||||
|
||||
if lxm.fields != None:
|
||||
if not originator and lxm.fields != None:
|
||||
if LXMF.FIELD_ICON_APPEARANCE in lxm.fields:
|
||||
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)
|
||||
else:
|
||||
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:
|
||||
should_notify = True
|
||||
|
@ -37,6 +37,7 @@ class Conversations():
|
||||
self.conversation_dropdown = None
|
||||
self.delete_dialog = None
|
||||
self.clear_dialog = None
|
||||
self.clear_telemetry_dialog = None
|
||||
|
||||
self.update()
|
||||
|
||||
@ -195,6 +196,30 @@ class Conversations():
|
||||
self.clear_dialog.open()
|
||||
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 x():
|
||||
if self.delete_dialog == None:
|
||||
@ -250,6 +275,12 @@ class Conversations():
|
||||
"height": dp(dmi_h),
|
||||
"on_release": gen_clear(item)
|
||||
},
|
||||
{
|
||||
"text": "Clear Telemetry",
|
||||
"viewclass": "OneLineListItem",
|
||||
"height": dp(dmi_h),
|
||||
"on_release": gen_clear_telemetry(item)
|
||||
},
|
||||
{
|
||||
"text": "Delete Conversation",
|
||||
"viewclass": "OneLineListItem",
|
||||
|
Loading…
Reference in New Issue
Block a user