forked from MirrorHub/mautrix-whatsapp
Merge pull request #232 from rreuvekamp/fix_228
Set RestrictMessageSending in portal create+update
This commit is contained in:
commit
cccaa62a20
2 changed files with 18 additions and 3 deletions
19
portal.go
19
portal.go
|
@ -514,6 +514,9 @@ func (portal *Portal) UpdateMetadata(user *User) bool {
|
||||||
update := false
|
update := false
|
||||||
update = portal.UpdateName(metadata.Name, metadata.NameSetBy, false) || update
|
update = portal.UpdateName(metadata.Name, metadata.NameSetBy, false) || update
|
||||||
update = portal.UpdateTopic(metadata.Topic, metadata.TopicSetBy, false) || update
|
update = portal.UpdateTopic(metadata.Topic, metadata.TopicSetBy, false) || update
|
||||||
|
|
||||||
|
portal.RestrictMessageSending(metadata.Announce)
|
||||||
|
|
||||||
return update
|
return update
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -640,11 +643,17 @@ func (portal *Portal) RestrictMessageSending(restrict bool) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
levels = portal.GetBasePowerLevels()
|
levels = portal.GetBasePowerLevels()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newLevel := 0
|
||||||
if restrict {
|
if restrict {
|
||||||
levels.EventsDefault = 50
|
newLevel = 50
|
||||||
} else {
|
|
||||||
levels.EventsDefault = 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if levels.EventsDefault == newLevel {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
levels.EventsDefault = newLevel
|
||||||
_, err = portal.MainIntent().SetPowerLevels(portal.MXID, levels)
|
_, err = portal.MainIntent().SetPowerLevels(portal.MXID, levels)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
portal.log.Errorln("Failed to change power levels:", err)
|
portal.log.Errorln("Failed to change power levels:", err)
|
||||||
|
@ -954,6 +963,7 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
bridgeInfoStateKey, bridgeInfo := portal.getBridgeInfo()
|
bridgeInfoStateKey, bridgeInfo := portal.getBridgeInfo()
|
||||||
|
|
||||||
initialState := []*event.Event{{
|
initialState := []*event.Event{{
|
||||||
Type: event.StatePowerLevels,
|
Type: event.StatePowerLevels,
|
||||||
Content: event.Content{
|
Content: event.Content{
|
||||||
|
@ -1021,6 +1031,9 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
|
||||||
|
|
||||||
if metadata != nil {
|
if metadata != nil {
|
||||||
portal.SyncParticipants(metadata)
|
portal.SyncParticipants(metadata)
|
||||||
|
if metadata.Announce {
|
||||||
|
portal.RestrictMessageSending(metadata.Announce)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
customPuppet := portal.bridge.GetPuppetByCustomMXID(user.MXID)
|
customPuppet := portal.bridge.GetPuppetByCustomMXID(user.MXID)
|
||||||
if customPuppet != nil && customPuppet.CustomIntent() != nil {
|
if customPuppet != nil && customPuppet.CustomIntent() != nil {
|
||||||
|
|
|
@ -84,6 +84,8 @@ type GroupInfo struct {
|
||||||
NameSetTime int64 `json:"subjectTime"`
|
NameSetTime int64 `json:"subjectTime"`
|
||||||
NameSetBy string `json:"subjectOwner"`
|
NameSetBy string `json:"subjectOwner"`
|
||||||
|
|
||||||
|
Announce bool `json:"announce"` // Can only admins send messages?
|
||||||
|
|
||||||
Topic string `json:"desc"`
|
Topic string `json:"desc"`
|
||||||
TopicID string `json:"descId"`
|
TopicID string `json:"descId"`
|
||||||
TopicSetAt int64 `json:"descTime"`
|
TopicSetAt int64 `json:"descTime"`
|
||||||
|
|
Loading…
Reference in a new issue