use last-seen msgid to prevent duplicate messages in chathistory BATCH

This commit is contained in:
jesopo 2019-06-02 15:19:05 +01:00
parent c44424b5a1
commit 5f8c93ea92

29
modules/chathistory.py Normal file
View file

@ -0,0 +1,29 @@
#--depends-on msgid
from src import ModuleManager, utils
TAG = utils.irc.MessageTag("msgid", "draft/msgid")
class Module(ModuleManager.BaseModule):
@utils.hook("received.batch.end")
def batch_end(self, event):
if event["batch"].type == "chathistory":
target_name = event["batch"].args[0]
if target_name in event["server"].channels:
target = event["server"].channels.get(target_name)
else:
target = event["server"].get_user(target_name)
last_msgid = target.get_setting("last-msgid", None)
if not last_msgid == None:
lines = event["batch"].get_lines()
stop_index = -1
for i, line in enumerate(lines):
msgid = TAG.get_value(line.tags)
if msgid == last_msgid:
stop_index = i
break
if not stop_index == -1:
return lines[stop_index+1:]