3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-12-25 04:02:45 +01:00

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.
This commit is contained in:
James Lu 2015-07-20 13:18:04 -07:00
parent e76d31d14e
commit b1e409ff3e
3 changed files with 19 additions and 21 deletions

View File

@ -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()}

View File

@ -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):

View File

@ -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):