mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-11-05 06:18:59 +01:00
Add puppet to personal filtering community when adding portal
This commit is contained in:
parent
a7601fa4cc
commit
8c3807a16d
3 changed files with 37 additions and 0 deletions
29
community.go
29
community.go
|
@ -83,6 +83,35 @@ func (user *User) createCommunity() {
|
|||
}
|
||||
}
|
||||
|
||||
func (user *User) addPuppetToCommunity(puppet *Puppet) bool {
|
||||
if user.IsRelaybot || len(user.CommunityID) == 0 {
|
||||
return false
|
||||
}
|
||||
bot := user.bridge.Bot
|
||||
url := bot.BuildURL("groups", user.CommunityID, "admin", "users", "invite", puppet.MXID)
|
||||
blankReqBody := map[string]interface{}{}
|
||||
_, err := bot.MakeRequest(http.MethodPut, url, &blankReqBody, nil)
|
||||
if err != nil {
|
||||
user.log.Warnfln("Failed to invite %s to %s: %v", puppet.MXID, user.CommunityID, err)
|
||||
return false
|
||||
}
|
||||
reqBody := map[string]map[string]string{
|
||||
"m.visibility": {
|
||||
"type": "private",
|
||||
},
|
||||
}
|
||||
url = bot.BuildURLWithQuery([]string{"groups", user.CommunityID, "self", "accept_invite"}, map[string]string{
|
||||
"user_id": puppet.MXID,
|
||||
})
|
||||
_, err = bot.MakeRequest(http.MethodPut, url, &reqBody, nil)
|
||||
if err != nil {
|
||||
user.log.Warnfln("Failed to join %s as %s: %v", user.CommunityID, puppet.MXID, err)
|
||||
return false
|
||||
}
|
||||
user.log.Debugln("Added", puppet.MXID, "to", user.CommunityID)
|
||||
return true
|
||||
}
|
||||
|
||||
func (user *User) addPortalToCommunity(portal *Portal) bool {
|
||||
if user.IsRelaybot || len(user.CommunityID) == 0 || len(portal.MXID) == 0 {
|
||||
return false
|
||||
|
|
|
@ -791,6 +791,10 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
|
|||
}
|
||||
}
|
||||
user.addPortalToCommunity(portal)
|
||||
if portal.IsPrivateChat() {
|
||||
puppet := user.bridge.GetPuppetByJID(portal.Key.JID)
|
||||
user.addPuppetToCommunity(puppet)
|
||||
}
|
||||
err = portal.FillInitialHistory(user)
|
||||
if err != nil {
|
||||
portal.log.Errorln("Failed to fill history:", err)
|
||||
|
|
4
user.go
4
user.go
|
@ -449,6 +449,10 @@ func (user *User) syncPortals(chatMap map[string]whatsapp.Chat, createAll bool)
|
|||
var inCommunity, ok bool
|
||||
if inCommunity, ok = existingKeys[portal.Key]; !ok || !inCommunity {
|
||||
inCommunity = user.addPortalToCommunity(portal)
|
||||
if portal.IsPrivateChat() {
|
||||
puppet := user.bridge.GetPuppetByJID(portal.Key.JID)
|
||||
user.addPuppetToCommunity(puppet)
|
||||
}
|
||||
}
|
||||
portalKeys = append(portalKeys, database.PortalKeyWithMeta{PortalKey: portal.Key, InCommunity: inCommunity})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue