浏览代码

Send presence when typing changes

abmantis 3 年之前
父节点
当前提交
50a6e383e7
共有 4 个文件被更改,包括 12 次插入0 次删除
  1. 1 0
      config/bridge.go
  2. 1 0
      config/upgrade.go
  3. 4 0
      example-config.yaml
  4. 6 0
      portal.go

+ 1 - 0
config/bridge.go

@@ -54,6 +54,7 @@ type BridgeConfig struct {
 	SyncDirectChatList    bool `yaml:"sync_direct_chat_list"`
 	SyncDirectChatList    bool `yaml:"sync_direct_chat_list"`
 	DefaultBridgeReceipts bool `yaml:"default_bridge_receipts"`
 	DefaultBridgeReceipts bool `yaml:"default_bridge_receipts"`
 	DefaultBridgePresence bool `yaml:"default_bridge_presence"`
 	DefaultBridgePresence bool `yaml:"default_bridge_presence"`
+	SendPresenceOnTyping  bool `yaml:"send_presence_on_typing"`
 
 
 	ForceActiveDeliveryReceipts bool `yaml:"force_active_delivery_receipts"`
 	ForceActiveDeliveryReceipts bool `yaml:"force_active_delivery_receipts"`
 
 

+ 1 - 0
config/upgrade.go

@@ -82,6 +82,7 @@ func (helper *UpgradeHelper) doUpgrade() {
 	helper.Copy(Bool, "bridge", "sync_direct_chat_list")
 	helper.Copy(Bool, "bridge", "sync_direct_chat_list")
 	helper.Copy(Bool, "bridge", "default_bridge_receipts")
 	helper.Copy(Bool, "bridge", "default_bridge_receipts")
 	helper.Copy(Bool, "bridge", "default_bridge_presence")
 	helper.Copy(Bool, "bridge", "default_bridge_presence")
+	helper.Copy(Bool, "bridge", "send_presence_on_typing")
 	helper.Copy(Bool, "bridge", "force_active_delivery_receipts")
 	helper.Copy(Bool, "bridge", "force_active_delivery_receipts")
 	helper.Copy(Map, "bridge", "double_puppet_server_map")
 	helper.Copy(Map, "bridge", "double_puppet_server_map")
 	helper.Copy(Bool, "bridge", "double_puppet_allow_discovery")
 	helper.Copy(Bool, "bridge", "double_puppet_allow_discovery")

+ 4 - 0
example-config.yaml

@@ -147,6 +147,10 @@ bridge:
     # Existing users won't be affected when these are changed.
     # Existing users won't be affected when these are changed.
     default_bridge_receipts: true
     default_bridge_receipts: true
     default_bridge_presence: true
     default_bridge_presence: true
+    # Send the presence as "available" to whatsapp when users start typing on a portal. 
+    # This works as a workaround for homeservers that do not support presence, and allows 
+    # users to see when the whatsapp user on the other side is typing during a conversation.
+    send_presence_on_typing: false
     # Should the bridge always send "active" delivery receipts (two gray ticks on WhatsApp)
     # Should the bridge always send "active" delivery receipts (two gray ticks on WhatsApp)
     # even if the user isn't marked as online (e.g. when presence bridging isn't enabled)?
     # even if the user isn't marked as online (e.g. when presence bridging isn't enabled)?
     #
     #

+ 6 - 0
portal.go

@@ -2815,6 +2815,12 @@ func (portal *Portal) setTyping(userIDs []id.UserID, state types.ChatPresence) {
 		if err != nil {
 		if err != nil {
 			portal.log.Warnln("Error sending chat presence:", err)
 			portal.log.Warnln("Error sending chat presence:", err)
 		}
 		}
+		if portal.bridge.Config.Bridge.SendPresenceOnTyping {
+			err = user.Client.SendPresence(types.PresenceAvailable)
+			if err != nil {
+				user.log.Warnln("Failed to set presence:", err)
+			}
+		}
 	}
 	}
 }
 }