mirror of
https://github.com/markqvist/NomadNet.git
synced 2026-06-05 03:51:18 +00:00
Run UI-side message cleaning with hub lock
This commit is contained in:
+5
-3
@@ -815,9 +815,11 @@ class RRCHub:
|
||||
self._append_history(target_room, msg)
|
||||
self._clean_history()
|
||||
|
||||
def get_messages(self, room):
|
||||
with self._lock:
|
||||
buf = list(self.messages.get(room, []))
|
||||
def get_messages(self, room, take_lock=True):
|
||||
if take_lock:
|
||||
with self._lock: buf = list(self.messages.get(room, []))
|
||||
else: buf = list(self.messages.get(room, []))
|
||||
|
||||
return buf
|
||||
|
||||
def _on_packet(self, data):
|
||||
|
||||
@@ -773,20 +773,21 @@ class RoomWidget(urwid.WidgetWrap):
|
||||
|
||||
if self.hub.clean_last_removed > self.last_history_clean:
|
||||
try:
|
||||
hub_msgs = self.hub.get_messages(self.room) if (self.hub is not None and self.room is not None) else []
|
||||
self.last_history_clean = time.time()
|
||||
c = self.messagelist.body_len()
|
||||
old = set()
|
||||
for i in range(0, c):
|
||||
msg = None
|
||||
w = self.messagelist.get_item(i)
|
||||
if hasattr(w, "_original_widget"): o = w._original_widget
|
||||
else: o = None
|
||||
if hasattr(o, "msg"): msg = o.msg
|
||||
elif hasattr(w, "msg"): msg = w.msg
|
||||
if msg and not msg in hub_msgs: old.add(i)
|
||||
with self.hub._lock:
|
||||
hub_msgs = self.hub.get_messages(self.room, take_lock=False) if (self.hub is not None and self.room is not None) else []
|
||||
self.last_history_clean = time.time()
|
||||
c = self.messagelist.body_len()
|
||||
old = set()
|
||||
for i in range(0, c):
|
||||
msg = None
|
||||
w = self.messagelist.get_item(i)
|
||||
if hasattr(w, "_original_widget"): o = w._original_widget
|
||||
else: o = None
|
||||
if hasattr(o, "msg"): msg = o.msg
|
||||
elif hasattr(w, "msg"): msg = w.msg
|
||||
if msg and not msg in hub_msgs: old.add(i)
|
||||
|
||||
for i in reversed(list(old)): self.messagelist.delete_position(i)
|
||||
for i in reversed(list(old)): self.messagelist.delete_position(i)
|
||||
|
||||
except Exception as e:
|
||||
RNS.log("Error while cleaning room history", RNS.LOG_ERROR)
|
||||
|
||||
Reference in New Issue
Block a user