From ed10d0349f8029e70b5053166d5070d3a2cfa324 Mon Sep 17 00:00:00 2001 From: liamcottle Date: Sun, 2 Jun 2024 11:50:58 +1200 Subject: [PATCH] implement updating auto announce config via ui --- public/index.html | 50 +++++++++++++++++++++++++++++++++++++++++++---- web.py | 18 ++++++++++++++++- 2 files changed, 63 insertions(+), 5 deletions(-) diff --git a/public/index.html b/public/index.html index b5ff64c..fa16fd4 100644 --- a/public/index.html +++ b/public/index.html @@ -144,7 +144,7 @@
My Identity
-
@@ -161,6 +161,23 @@
LXMF Address
{{ config.lxmf_address_hash }}
+
+
Auto Announce
+ +
+ Last announced: {{ formatSecondsAgo(config.last_announced_at) }} + Last announced: Never +
+
@@ -1299,6 +1316,15 @@ container.scrollTop = container.scrollHeight; }); }, + async getConfig() { + try { + const response = await window.axios.get(`/api/v1/config`); + this.config = response.data.config; + } catch(e) { + // do nothing if failed to load config + console.log(e); + } + }, async sendAnnounce() { // do nothing if not connected to websocket @@ -1318,6 +1344,9 @@ console.error(e); } + // fetch config so it updates last announced timestamp + await this.getConfig(); + }, async sendMessage() { @@ -1415,9 +1444,10 @@ } }, - async saveDisplayName() { + async saveIdentitySettings() { await this.updateConfig({ "display_name": this.displayName, + "auto_announce_interval_seconds": this.config.auto_announce_interval_seconds, }); }, async startNewLXMFConversation() { @@ -2082,10 +2112,22 @@ }; }, formatTimeAgo: function(datetimeString) { - const millisecondsAgo = Date.now() - new Date(datetimeString).getTime(); const secondsAgo = Math.round(millisecondsAgo / 1000); - const parsedSeconds = this.parseSeconds(secondsAgo); + return this.formatSecondsAgo(secondsAgo); + }, + formatSecondsAgo: function(seconds) { + const secondsAgo = Math.round((Date.now() / 1000) - seconds); + return this.formatSeconds(secondsAgo); + }, + formatSeconds: function(seconds) { + + const parsedSeconds = this.parseSeconds(seconds); + + console.log({ + seconds: seconds, + parsedSeconds: parsedSeconds, + }); if(parsedSeconds.days > 0){ return parsedSeconds.days + " days ago"; diff --git a/web.py b/web.py index e383cdc..cffdd9a 100644 --- a/web.py +++ b/web.py @@ -954,6 +954,19 @@ class ReticulumWebChat: if "display_name" in config and config["display_name"] != "": self.config.display_name.set(config["display_name"]) + # update auto announce interval + if "auto_announce_interval_seconds" in config: + + # auto auto announce interval + auto_announce_interval_seconds = int(config["auto_announce_interval_seconds"]) + self.config.auto_announce_interval_seconds.set(config["auto_announce_interval_seconds"]) + + # enable or disable auto announce based on interval + if auto_announce_interval_seconds > 0: + self.config.auto_announce_enabled.set(True) + else: + self.config.auto_announce_enabled.set(False) + # send config to websocket clients await self.send_config_to_websocket_clients() @@ -1130,6 +1143,9 @@ class ReticulumWebChat: "identity_hash": self.identity.hexhash, "lxmf_address_hash": self.local_lxmf_destination.hexhash, "audio_call_address_hash": self.audio_call_manager.audio_call_receiver.destination.hexhash, + "auto_announce_enabled": self.config.auto_announce_enabled.get(), + "auto_announce_interval_seconds": self.config.auto_announce_interval_seconds.get(), + "last_announced_at": self.config.last_announced_at.get(), } # convert audio call to dict @@ -1650,7 +1666,7 @@ class Config: # all possible config items display_name = StringConfig("display_name", "Anonymous Peer") auto_announce_enabled = BoolConfig("auto_announce_enabled", False) - auto_announce_interval_seconds = IntConfig("auto_announce_interval_seconds", False) + auto_announce_interval_seconds = IntConfig("auto_announce_interval_seconds", 3600) last_announced_at = IntConfig("last_announced_at", None)