Эх сурвалжийг харах

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

Tulir Asokan 4 жил өмнө
parent
commit
2742d90299
4 өөрчлөгдсөн 28 нэмэгдсэн , 5 устгасан
  1. 1 0
      config/bridge.go
  2. 2 0
      example-config.yaml
  3. 17 0
      portal.go
  4. 8 5
      user.go

+ 1 - 0
config/bridge.go

@@ -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"`
 

+ 2 - 0
example-config.yaml

@@ -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.

+ 17 - 0
portal.go

@@ -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)

+ 8 - 5
user.go

@@ -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 {