Kick left users when syncing members
This commit is contained in:
parent
07927741bf
commit
4a673b92fa
22
portal.go
22
portal.go
@ -351,7 +351,9 @@ func (portal *Portal) SyncParticipants(metadata *whatsappExt.GroupInfo) {
|
||||
levels = portal.GetBasePowerLevels()
|
||||
changed = true
|
||||
}
|
||||
participantMap := make(map[string]bool)
|
||||
for _, participant := range metadata.Participants {
|
||||
participantMap[participant.JID] = true
|
||||
user := portal.bridge.GetUserByJID(participant.JID)
|
||||
portal.userMXIDAction(user, portal.ensureMXIDInvited)
|
||||
|
||||
@ -378,6 +380,26 @@ func (portal *Portal) SyncParticipants(metadata *whatsappExt.GroupInfo) {
|
||||
portal.log.Errorln("Failed to change power levels:", err)
|
||||
}
|
||||
}
|
||||
members, err := portal.MainIntent().JoinedMembers(portal.MXID)
|
||||
if err != nil {
|
||||
portal.log.Warnln("Failed to get member list:", err)
|
||||
} else {
|
||||
for member := range members.Joined {
|
||||
jid, ok := portal.bridge.ParsePuppetMXID(member)
|
||||
if ok {
|
||||
_, shouldBePresent := participantMap[jid]
|
||||
if !shouldBePresent {
|
||||
_, err := portal.MainIntent().KickUser(portal.MXID, &mautrix.ReqKickUser{
|
||||
UserID: member,
|
||||
Reason: "User had left this WhatsApp chat",
|
||||
})
|
||||
if err != nil {
|
||||
portal.log.Warnfln("Failed to kick user %s who had left: %v", member, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (portal *Portal) UpdateAvatar(user *User, avatar *whatsappExt.ProfilePicInfo, updateInfo bool) bool {
|
||||
|
Loading…
Reference in New Issue
Block a user