Skip to content

Commit cfacfdc

Browse files
committed
Fix join and part/leave on replay
Without this, on matterircd reconnect & relay, users in channels can be out of sync. This causes issues with trying to auto-complete IRC nicks for example.
1 parent 0416774 commit cfacfdc

File tree

2 files changed

+42
-13
lines changed

2 files changed

+42
-13
lines changed

mm-go-irckit/channel.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,17 @@ func (ch *channel) Part(u *User, text string) {
162162

163163
if _, ok := ch.usersIdx[u.ID()]; !ok {
164164
ch.mu.Unlock()
165-
165+
for _, to := range ch.usersIdx {
166+
if !to.Ghost {
167+
to.Encode(msg)
168+
}
169+
}
166170
u.Encode(&irc.Message{
167171
Prefix: ch.Prefix(),
168172
Command: irc.ERR_NOTONCHANNEL,
169173
Params: []string{ch.name},
170-
Trailing: "You're not on that channel",
174+
Trailing: "User not on that channel",
171175
})
172-
173176
return
174177
}
175178

@@ -335,8 +338,20 @@ func (ch *channel) Join(u *User) error {
335338
return nil
336339
}
337340

341+
msg := &irc.Message{
342+
Prefix: u.Prefix(),
343+
Command: irc.JOIN,
344+
Params: []string{ch.name},
345+
}
346+
338347
if _, exists := ch.usersIdx[u.ID()]; exists {
339348
ch.mu.Unlock()
349+
for _, to := range ch.usersIdx {
350+
// only send join messages to real users
351+
if !to.Ghost {
352+
to.Encode(msg)
353+
}
354+
}
340355
return nil
341356
}
342357

@@ -354,12 +369,6 @@ func (ch *channel) Join(u *User) error {
354369
return nil
355370
}
356371

357-
msg := &irc.Message{
358-
Prefix: u.Prefix(),
359-
Command: irc.JOIN,
360-
Params: []string{ch.name},
361-
}
362-
363372
// send regular users a notification of the join
364373
ch.mu.RLock()
365374

mm-go-irckit/userbridge.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -698,9 +698,6 @@ func (u *User) addUserToChannelWorker(channels <-chan *bridge.ChannelInfo, throt
698698
// traverse the order in reverse
699699
for i := len(mmPostList.Order) - 1; i >= 0; i-- {
700700
p := mmPostList.Posts[mmPostList.Order[i]]
701-
if p.Type == model.PostTypeJoinLeave {
702-
continue
703-
}
704701

705702
if p.DeleteAt > p.CreateAt {
706703
continue
@@ -725,8 +722,31 @@ func (u *User) addUserToChannelWorker(channels <-chan *bridge.ChannelInfo, throt
725722
nick = botname
726723
}
727724

728-
if p.Type == model.PostTypeAddToTeam || p.Type == model.PostTypeRemoveFromTeam {
725+
switch {
726+
case p.Type == model.PostTypeAddToTeam:
727+
nick = systemUser
728+
ghost := u.createUserFromInfo(user)
729+
u.Srv.Channel(brchannel.ID).Join(ghost) //nolint:errcheck
730+
case p.Type == model.PostTypeRemoveFromTeam:
729731
nick = systemUser
732+
ghost := u.createUserFromInfo(user)
733+
u.Srv.Channel(brchannel.ID).Part(ghost, "") //nolint:errcheck
734+
case p.Type == model.PostTypeJoinChannel:
735+
ghost := u.createUserFromInfo(user)
736+
u.Srv.Channel(brchannel.ID).Join(ghost) //nolint:errcheck
737+
case p.Type == model.PostTypeLeaveChannel:
738+
ghost := u.createUserFromInfo(user)
739+
u.Srv.Channel(brchannel.ID).Part(ghost, "") //nolint:errcheck
740+
case p.Type == model.PostTypeAddToChannel:
741+
if addedUserId, ok := props["addedUserId"].(string); ok {
742+
ghost := u.createUserFromInfo(u.br.GetUser(addedUserId))
743+
u.Srv.Channel(brchannel.ID).Join(ghost) //nolint:errcheck
744+
}
745+
case p.Type == model.PostTypeRemoveFromChannel:
746+
if removedUserId, ok := props["removedUserId"].(string); ok {
747+
ghost := u.createUserFromInfo(u.br.GetUser(removedUserId))
748+
u.Srv.Channel(brchannel.ID).Part(ghost, "") //nolint:errcheck
749+
}
730750
}
731751

732752
for _, post := range strings.Split(p.Message, "\n") {

0 commit comments

Comments
 (0)