Kick users who don't belong in portal (ref #6)

This commit is contained in:
Tulir Asokan 2023-08-02 14:58:27 +03:00
parent 13a8d9b9a9
commit b45185beab

View file

@ -748,6 +748,33 @@ func (portal *Portal) SyncParticipants(source *User, metadata *gmproto.Conversat
portal.OtherUserID = firstParticipant.ID.ParticipantID portal.OtherUserID = firstParticipant.ID.ParticipantID
changed = true changed = true
} }
if portal.MXID != "" {
members, err := portal.MainIntent().JoinedMembers(portal.MXID)
if err != nil {
portal.zlog.Warn().Err(err).Msg("Failed to get joined members")
} else {
delete(members.Joined, portal.bridge.Bot.UserID)
delete(members.Joined, source.MXID)
for _, userID := range userIDs {
delete(members.Joined, userID)
}
for userID := range members.Joined {
_, err = portal.MainIntent().KickUser(portal.MXID, &mautrix.ReqKickUser{
UserID: userID,
Reason: "User is not participating in chat",
})
if err != nil {
portal.zlog.Warn().Err(err).
Str("user_id", userID.String()).
Msg("Failed to kick extra user from portal")
} else {
portal.zlog.Debug().
Str("user_id", userID.String()).
Msg("Kicked extra user from portal")
}
}
}
}
return userIDs, changed return userIDs, changed
} }