Skip to content

Commit

Permalink
Fix join and part/leave on replay
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hloeung committed Nov 24, 2023
1 parent 0416774 commit 6ae4f02
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
27 changes: 18 additions & 9 deletions mm-go-irckit/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,17 @@ func (ch *channel) Part(u *User, text string) {

if _, ok := ch.usersIdx[u.ID()]; !ok {
ch.mu.Unlock()

for _, to := range ch.usersIdx {
if !to.Ghost {
to.Encode(msg)
}
}
u.Encode(&irc.Message{
Prefix: ch.Prefix(),
Command: irc.ERR_NOTONCHANNEL,
Params: []string{ch.name},
Trailing: "You're not on that channel",
Trailing: "User not on that channel",
})

return
}

Expand Down Expand Up @@ -335,8 +338,20 @@ func (ch *channel) Join(u *User) error {
return nil
}

msg := &irc.Message{
Prefix: u.Prefix(),
Command: irc.JOIN,
Params: []string{ch.name},
}

if _, exists := ch.usersIdx[u.ID()]; exists {
ch.mu.Unlock()
for _, to := range ch.usersIdx {
// only send join messages to real users
if !to.Ghost {
to.Encode(msg)
}
}
return nil
}

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

msg := &irc.Message{
Prefix: u.Prefix(),
Command: irc.JOIN,
Params: []string{ch.name},
}

// send regular users a notification of the join
ch.mu.RLock()

Expand Down
24 changes: 20 additions & 4 deletions mm-go-irckit/userbridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,9 +698,6 @@ func (u *User) addUserToChannelWorker(channels <-chan *bridge.ChannelInfo, throt
// traverse the order in reverse
for i := len(mmPostList.Order) - 1; i >= 0; i-- {
p := mmPostList.Posts[mmPostList.Order[i]]
if p.Type == model.PostTypeJoinLeave {
continue
}

if p.DeleteAt > p.CreateAt {
continue
Expand All @@ -725,8 +722,27 @@ func (u *User) addUserToChannelWorker(channels <-chan *bridge.ChannelInfo, throt
nick = botname
}

if p.Type == model.PostTypeAddToTeam || p.Type == model.PostTypeRemoveFromTeam {
switch {
case p.Type == model.PostTypeAddToTeam:
nick = systemUser
ghost := u.createUserFromInfo(user)
u.Srv.Channel(brchannel.ID).Join(ghost) //nolint:errcheck
case p.Type == model.PostTypeRemoveFromTeam:
nick = systemUser
ghost := u.createUserFromInfo(user)
u.Srv.Channel(brchannel.ID).Part(ghost, "") //nolint:errcheck
case p.Type == model.PostTypeJoinChannel:
ghost := u.createUserFromInfo(user)
u.Srv.Channel(brchannel.ID).Join(ghost) //nolint:errcheck
case p.Type == model.PostTypeLeaveChannel:
ghost := u.createUserFromInfo(user)
u.Srv.Channel(brchannel.ID).Part(ghost, "") //nolint:errcheck
case p.Type == model.PostTypeAddToChannel:
ghost := u.createUserFromInfo(u.br.GetUser(props["addedUserId"]))

Check failure on line 741 in mm-go-irckit/userbridge.go

View workflow job for this annotation

GitHub Actions / test-build-upload (1.21.x, ubuntu-latest)

cannot use props["addedUserId"] (map index expression of type interface{}) as string value in argument to u.br.GetUser: need type assertion
u.Srv.Channel(brchannel.ID).Join(ghost) //nolint:errcheck
case p.Type == model.PostTypeRemoveFromChannel:
ghost := u.createUserFromInfo(u.br.GetUser(props["removedUserId"]))

Check failure on line 744 in mm-go-irckit/userbridge.go

View workflow job for this annotation

GitHub Actions / test-build-upload (1.21.x, ubuntu-latest)

cannot use props["removedUserId"] (map index expression of type interface{}) as string value in argument to u.br.GetUser: need type assertion
u.Srv.Channel(brchannel.ID).Part(ghost, "") //nolint:errcheck
}

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

0 comments on commit 6ae4f02

Please sign in to comment.