mirror of
https://github.com/markqvist/NomadNet.git
synced 2026-11-19 22:46:26 -05:00
Added option to filter sys and notice events from RRC room history on load
This commit is contained in:
parent
56da0e7353
commit
da201fb3b6
2 changed files with 25 additions and 5 deletions
|
|
@ -153,7 +153,7 @@ class NomadNetworkApp:
|
|||
self.accept_invalid_stamps = False
|
||||
|
||||
self.rrc_history_per_room_cap = 500
|
||||
|
||||
self.rrc_filter_loaded_history = True
|
||||
|
||||
if not os.path.isdir(self.storagepath):
|
||||
os.makedirs(self.storagepath)
|
||||
|
|
@ -909,12 +909,15 @@ class NomadNetworkApp:
|
|||
if "rrc" in self.config:
|
||||
for option in self.config["rrc"]:
|
||||
if option == "history_per_room_cap":
|
||||
try:
|
||||
value = self.config["rrc"].as_int(option)
|
||||
except Exception:
|
||||
value = None
|
||||
try: value = self.config["rrc"].as_int(option)
|
||||
except Exception: value = None
|
||||
if value is not None and value >= 0:
|
||||
self.rrc_history_per_room_cap = value
|
||||
|
||||
if option == "filter_loaded_history":
|
||||
try: value = self.config["rrc"].as_bool(option)
|
||||
except Exception: value = True
|
||||
self.rrc_filter_loaded_history = value
|
||||
|
||||
if "node" in self.config:
|
||||
if not "enable_node" in self.config["node"]:
|
||||
|
|
@ -1240,6 +1243,11 @@ sanitize_names = yes
|
|||
# in memory (full history).
|
||||
history_per_room_cap = 500
|
||||
|
||||
# You can choose whether to filter system
|
||||
# and notice events when room history is
|
||||
# loaded.
|
||||
filter_loaded_history = yes
|
||||
|
||||
[node]
|
||||
|
||||
# Whether to enable node hosting
|
||||
|
|
|
|||
|
|
@ -626,6 +626,11 @@ class RRCHub:
|
|||
return None
|
||||
return v if v > 0 else None
|
||||
|
||||
def _filter_history(self):
|
||||
try: v = getattr(self.manager.app, "rrc_filter_loaded_history", True)
|
||||
except Exception: return True
|
||||
return v
|
||||
|
||||
def _entry_for(self, msg):
|
||||
return {
|
||||
H_KIND: msg.kind,
|
||||
|
|
@ -704,9 +709,16 @@ class RRCHub:
|
|||
if decode_error is not None:
|
||||
self._log("history file for #"+room+" is corrupt, truncating to last "+str(len(window))+" valid messages: "+str(decode_error), RNS.LOG_ERROR)
|
||||
msgs = []
|
||||
filter_msgs = self._filter_history()
|
||||
for e in window:
|
||||
m = self._msg_from_entry(room, e)
|
||||
if m is not None:
|
||||
if filter_msgs:
|
||||
should_filter = False
|
||||
if m.kind == "system": should_filter = True
|
||||
elif m.kind == "notice": should_filter = True
|
||||
if should_filter: continue
|
||||
|
||||
msgs.append(m)
|
||||
with self._lock:
|
||||
self.messages[room] = msgs
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue