Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set RestrictMessageSending in portal create+update #232

Merged
merged 1 commit into from
Oct 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,9 @@ func (portal *Portal) UpdateMetadata(user *User) bool {
update := false
update = portal.UpdateName(metadata.Name, metadata.NameSetBy, false) || update
update = portal.UpdateTopic(metadata.Topic, metadata.TopicSetBy, false) || update

portal.RestrictMessageSending(metadata.Announce)

return update
}

Expand Down Expand Up @@ -640,11 +643,17 @@ func (portal *Portal) RestrictMessageSending(restrict bool) {
if err != nil {
levels = portal.GetBasePowerLevels()
}

newLevel := 0
if restrict {
levels.EventsDefault = 50
} else {
levels.EventsDefault = 0
newLevel = 50
}

if levels.EventsDefault == newLevel {
return
}

levels.EventsDefault = newLevel
_, err = portal.MainIntent().SetPowerLevels(portal.MXID, levels)
if err != nil {
portal.log.Errorln("Failed to change power levels:", err)
Expand Down Expand Up @@ -954,6 +963,7 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
}

bridgeInfoStateKey, bridgeInfo := portal.getBridgeInfo()

initialState := []*event.Event{{
Type: event.StatePowerLevels,
Content: event.Content{
Expand Down Expand Up @@ -1021,6 +1031,9 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {

if metadata != nil {
portal.SyncParticipants(metadata)
if metadata.Announce {
portal.RestrictMessageSending(metadata.Announce)
}
} else {
customPuppet := portal.bridge.GetPuppetByCustomMXID(user.MXID)
if customPuppet != nil && customPuppet.CustomIntent() != nil {
Expand Down
2 changes: 2 additions & 0 deletions whatsapp-ext/whatsapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ type GroupInfo struct {
NameSetTime int64 `json:"subjectTime"`
NameSetBy string `json:"subjectOwner"`

Announce bool `json:"announce"` // Can only admins send messages?

Topic string `json:"desc"`
TopicID string `json:"descId"`
TopicSetAt int64 `json:"descTime"`
Expand Down