From b1e409ff3eba03423e3c3908216d454cca583bcc Mon Sep 17 00:00:00 2001 From: James Lu Date: Mon, 20 Jul 2015 13:18:04 -0700 Subject: [PATCH] relay: unbreak topic handling (closes #68) Introducing a new .topicset attributing in IrcChannel denoting whether we've received a TOPIC for this channel from the uplink yet. --- classes.py | 1 + plugins/relay.py | 37 ++++++++++++++++--------------------- protocols/inspircd.py | 2 ++ 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/classes.py b/classes.py index b3b4d54..0e956d1 100644 --- a/classes.py +++ b/classes.py @@ -49,6 +49,7 @@ class IrcChannel(): self.modes = set() self.topic = '' self.ts = int(time.time()) + self.topicset = False self.prefixmodes = {'ops': set(), 'halfops': set(), 'voices': set(), 'owners': set(), 'admins': set()} diff --git a/plugins/relay.py b/plugins/relay.py index 8acf8cb..1ef1509 100644 --- a/plugins/relay.py +++ b/plugins/relay.py @@ -210,9 +210,9 @@ def initializeChannel(irc, channel): relayModes(remoteirc, irc, remoteirc.sid, remotechan) relayModes(irc, remoteirc, irc.sid, channel) topic = remoteirc.channels[relay[1]].topic - # XXX: find a more elegant way to do this - # Only update the topic if it's different from what we already have. - if topic and topic != irc.channels[channel].topic: + # Only update the topic if it's different from what we already have, + # and topic bursting is complete. + if remoteirc.channels[channel].topicset and topic != irc.channels[channel].topic: irc.proto.topicServer(irc, irc.sid, channel, topic) log.debug('(%s) initializeChannel: joining our users: %s', irc.name, c.users) @@ -506,25 +506,20 @@ utils.add_hook(handle_mode, 'MODE') def handle_topic(irc, numeric, command, args): channel = args['channel'] topic = args['topic'] - # XXX: find a more elegant way to do this - # Topics with content take precedence over empty topics. - # This prevents us from overwriting topics on channels with - # emptiness just because a leaf network hasn't received it yet. - if topic: - for name, remoteirc in utils.networkobjects.items(): - if irc.name == name: - continue + for name, remoteirc in utils.networkobjects.items(): + if irc.name == name: + continue - remotechan = findRemoteChan(irc, remoteirc, channel) - # Don't send if the remote topic is the same as ours. - if remotechan is None or topic == remoteirc.channels[remotechan].topic: - continue - # This might originate from a server too. - remoteuser = getRemoteUser(irc, remoteirc, numeric, spawnIfMissing=False) - if remoteuser: - remoteirc.proto.topicClient(remoteirc, remoteuser, remotechan, topic) - else: - remoteirc.proto.topicServer(remoteirc, remoteirc.sid, remotechan, topic) + remotechan = findRemoteChan(irc, remoteirc, channel) + # Don't send if the remote topic is the same as ours. + if remotechan is None or topic == remoteirc.channels[remotechan].topic: + continue + # This might originate from a server too. + remoteuser = getRemoteUser(irc, remoteirc, numeric, spawnIfMissing=False) + if remoteuser: + remoteirc.proto.topicClient(remoteirc, remoteuser, remotechan, topic) + else: + remoteirc.proto.topicServer(remoteirc, remoteirc.sid, remotechan, topic) utils.add_hook(handle_topic, 'TOPIC') def handle_kill(irc, numeric, command, args): diff --git a/protocols/inspircd.py b/protocols/inspircd.py index d311b39..3867e65 100644 --- a/protocols/inspircd.py +++ b/protocols/inspircd.py @@ -610,6 +610,7 @@ def handle_ftopic(irc, numeric, command, args): setter = args[2] topic = args[-1] irc.channels[channel].topic = topic + irc.channels[channel].topicset = True return {'channel': channel, 'setter': setter, 'ts': ts, 'topic': topic} def handle_topic(irc, numeric, command, args): @@ -618,6 +619,7 @@ def handle_topic(irc, numeric, command, args): topic = args[1] ts = int(time.time()) irc.channels[channel].topic = topic + irc.channels[channel].topicset = True return {'channel': channel, 'setter': numeric, 'ts': ts, 'topic': topic} def handle_invite(irc, numeric, command, args):