Add option to only bridge mute status and tags when creating portal

This commit is contained in:
Tulir Asokan 2021-04-29 11:57:05 +03:00
parent b0d433ea66
commit 2742d90299
4 changed files with 28 additions and 5 deletions

View file

@ -74,6 +74,7 @@ type BridgeConfig struct {
MuteBridging bool `yaml:"mute_bridging"`
ArchiveTag string `yaml:"archive_tag"`
PinnedTag string `yaml:"pinned_tag"`
TagOnlyOnCreate bool `yaml:"tag_only_on_create"`
WhatsappThumbnail bool `yaml:"whatsapp_thumbnail"`

View file

@ -191,6 +191,8 @@ bridge:
archive_tag: null
# Same as above, but for pinned chats. The favorite tag is called m.favourite
pinned_tag: null
# Whether or not mute status and tags should only be bridged when the portal room is created.
tag_only_on_create: true
# Whether or not thumbnails from WhatsApp should be sent.
# They're disabled by default due to very low resolution.

View file

@ -192,6 +192,22 @@ type Portal struct {
const MaxMessageAgeToCreatePortal = 5 * 60 // 5 minutes
func (portal *Portal) syncDoublePuppetDetailsAfterCreate(source *User) {
doublePuppet := portal.bridge.GetPuppetByCustomMXID(source.MXID)
if doublePuppet == nil {
return
}
chat, ok := source.Conn.Store.Chats[portal.Key.JID]
if !ok {
portal.log.Debugln("Not syncing chat mute/tags with %s: chat info not found", source.MXID)
return
}
source.syncChatDoublePuppetDetails(doublePuppet, Chat{
Chat: chat,
Portal: portal,
}, true)
}
func (portal *Portal) handleMessageLoop() {
for msg := range portal.messages {
if len(portal.MXID) == 0 {
@ -208,6 +224,7 @@ func (portal *Portal) handleMessageLoop() {
portal.log.Errorln("Failed to create portal room:", err)
return
}
portal.syncDoublePuppetDetailsAfterCreate(msg.source)
}
portal.backfillLock.Lock()
portal.handleMessage(msg, false)

13
user.go
View file

@ -744,7 +744,7 @@ func (user *User) updateChatTag(intent *appservice.IntentAPI, portal *Portal, ta
}
}
func (user *User) syncChatDoublePuppetDetails(doublePuppet *Puppet, chat Chat) {
func (user *User) syncChatDoublePuppetDetails(doublePuppet *Puppet, chat Chat, justCreated bool) {
if doublePuppet == nil || doublePuppet.CustomIntent() == nil {
return
}
@ -758,9 +758,11 @@ func (user *User) syncChatDoublePuppetDetails(doublePuppet *Puppet, chat Chat) {
}
}
}
user.updateChatMute(intent, chat.Portal, chat.MutedUntil)
user.updateChatTag(intent, chat.Portal, user.bridge.Config.Bridge.ArchiveTag, chat.IsArchived)
user.updateChatTag(intent, chat.Portal, user.bridge.Config.Bridge.PinnedTag, chat.IsPinned)
if justCreated || !user.bridge.Config.Bridge.TagOnlyOnCreate {
user.updateChatMute(intent, chat.Portal, chat.MutedUntil)
user.updateChatTag(intent, chat.Portal, user.bridge.Config.Bridge.ArchiveTag, chat.IsArchived)
user.updateChatTag(intent, chat.Portal, user.bridge.Config.Bridge.PinnedTag, chat.IsPinned)
}
}
func (user *User) syncPortal(chat Chat) {
@ -832,8 +834,9 @@ func (user *User) syncPortals(chatMap map[string]whatsapp.Chat, createAll bool)
}
create := (chat.LastMessageTime >= user.LastConnection && user.LastConnection > 0) || i < limit
if len(chat.Portal.MXID) > 0 || create || createAll {
justCreated := len(chat.Portal.MXID) == 0
user.syncPortal(chat)
user.syncChatDoublePuppetDetails(doublePuppet, chat)
user.syncChatDoublePuppetDetails(doublePuppet, chat, justCreated)
}
}
if user.Conn != connAtStart {