Update whatsmeow to read group disappearing message timer

This commit is contained in:
Tulir Asokan 2022-01-07 15:05:09 +02:00
parent a61a3f5cf9
commit 7f636e6aef
4 changed files with 40 additions and 10 deletions

2
go.mod
View file

@ -8,7 +8,7 @@ require (
github.com/mattn/go-sqlite3 v1.14.10
github.com/prometheus/client_golang v1.11.0
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
go.mau.fi/whatsmeow v0.0.0-20211231085557-666a92779bf5
go.mau.fi/whatsmeow v0.0.0-20220107125553-190be349f174
golang.org/x/image v0.0.0-20211028202545-6944b10bf410
google.golang.org/protobuf v1.27.1
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b

4
go.sum
View file

@ -139,8 +139,8 @@ github.com/tidwall/sjson v1.2.3 h1:5+deguEhHSEjmuICXZ21uSSsXotWMA0orU783+Z7Cp8=
github.com/tidwall/sjson v1.2.3/go.mod h1:5WdjKx3AQMvCJ4RG6/2UYT7dLrGvJUV1x4jdTAyGvZs=
go.mau.fi/libsignal v0.0.0-20211109153248-a67163214910 h1:9FFhG0OmkuMau5UEaTgiUQ+7cSbtbOQ7hiWKdN8OI3I=
go.mau.fi/libsignal v0.0.0-20211109153248-a67163214910/go.mod h1:AufGrvVh+00Nc07Jm4hTquh7yleZyn20tKJI2wCPAKg=
go.mau.fi/whatsmeow v0.0.0-20211231085557-666a92779bf5 h1:tzQ3IRQtZJi1U3JpNCvvm0cL4SGd9PbyJUe2XodfqCs=
go.mau.fi/whatsmeow v0.0.0-20211231085557-666a92779bf5/go.mod h1:8jUjOAi3xtGubxcZgG8uSHpAdyQXBRbWAfxkctX/4y4=
go.mau.fi/whatsmeow v0.0.0-20220107125553-190be349f174 h1:RJNCmrezldkWTttNO1yyORKizd7uEmQMSW/4TpWe1jU=
go.mau.fi/whatsmeow v0.0.0-20220107125553-190be349f174/go.mod h1:8jUjOAi3xtGubxcZgG8uSHpAdyQXBRbWAfxkctX/4y4=
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=

View file

@ -417,17 +417,11 @@ func (portal *Portal) convertMessage(intent *appservice.IntentAPI, source *User,
case waMsg.ProtocolMessage != nil && waMsg.ProtocolMessage.GetType() == waProto.ProtocolMessage_EPHEMERAL_SETTING:
portal.ExpirationTime = waMsg.ProtocolMessage.GetEphemeralExpiration()
portal.Update()
var msg string
if portal.ExpirationTime == 0 {
msg = "Turned off disappearing messages"
} else {
msg = fmt.Sprintf("Set the disappearing message timer to %s", formatDuration(time.Duration(portal.ExpirationTime)*time.Second))
}
return &ConvertedMessage{
Intent: intent,
Type: event.EventMessage,
Content: &event.MessageEventContent{
Body: msg,
Body: portal.formatDisappearingMessageNotice(),
MsgType: event.MsgNotice,
},
}
@ -436,6 +430,36 @@ func (portal *Portal) convertMessage(intent *appservice.IntentAPI, source *User,
}
}
func (portal *Portal) UpdateGroupDisappearingMessages(sender *types.JID, timestamp time.Time, timer uint32) {
portal.ExpirationTime = timer
portal.Update()
intent := portal.MainIntent()
if sender != nil {
intent = portal.bridge.GetPuppetByJID(sender.ToNonAD()).IntentFor(portal)
} else {
sender = &types.EmptyJID
}
_, err := portal.sendMessage(intent, event.EventMessage, &event.MessageEventContent{
Body: portal.formatDisappearingMessageNotice(),
MsgType: event.MsgNotice,
}, nil, timestamp.UnixMilli())
if err != nil {
portal.log.Warnfln("Failed to notify portal about disappearing message timer change by %s to %d", *sender, timer)
}
}
func (portal *Portal) formatDisappearingMessageNotice() string {
if portal.ExpirationTime == 0 {
return "Turned off disappearing messages"
} else {
msg := fmt.Sprintf("Set the disappearing message timer to %s", formatDuration(time.Duration(portal.ExpirationTime)*time.Second))
if !portal.bridge.Config.Bridge.DisappearingMessagesInGroups && portal.IsGroupChat() {
msg += ". However, this bridge is not configured to disappear messages in group chats."
}
return msg
}
}
const UndecryptableMessageNotice = "Decrypting message from WhatsApp failed, waiting for sender to re-send... " +
"([learn more](https://faq.whatsapp.com/general/security-and-privacy/seeing-waiting-for-this-message-this-may-take-a-while))"
@ -887,6 +911,10 @@ func (portal *Portal) UpdateMetadata(user *User, groupInfo *types.GroupInfo) boo
update := false
update = portal.UpdateName(groupInfo.Name, groupInfo.NameSetBy, false) || update
update = portal.UpdateTopic(groupInfo.Topic, groupInfo.TopicSetBy, false) || update
if portal.ExpirationTime != groupInfo.DisappearingTimer {
update = true
portal.ExpirationTime = groupInfo.DisappearingTimer
}
portal.RestrictMessageSending(groupInfo.IsAnnounce)
portal.RestrictMetadataChanges(groupInfo.IsLocked)

View file

@ -937,6 +937,8 @@ func (user *User) handleGroupUpdate(evt *events.GroupInfo) {
portal.ChangeAdminStatus(evt.Promote, true)
case evt.Demote != nil:
portal.ChangeAdminStatus(evt.Demote, false)
case evt.Ephemeral != nil:
portal.UpdateGroupDisappearingMessages(evt.Sender, evt.Timestamp, evt.Ephemeral.DisappearingTimer)
}
}