2018-08-13 22:24:44 +02:00
|
|
|
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
2022-02-23 13:30:21 +01:00
|
|
|
// Copyright (C) 2022 Tulir Asokan
|
2018-08-13 00:00:23 +02:00
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2022-05-22 00:06:30 +02:00
|
|
|
"maunium.net/go/mautrix/bridge/bridgeconfig"
|
2021-11-07 21:31:22 +01:00
|
|
|
"maunium.net/go/mautrix/id"
|
2018-08-13 00:00:23 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2022-05-22 00:06:30 +02:00
|
|
|
*bridgeconfig.BaseConfig `yaml:",inline"`
|
2018-08-13 00:00:23 +02:00
|
|
|
|
2022-05-16 12:46:18 +02:00
|
|
|
SegmentKey string `yaml:"segment_key"`
|
|
|
|
|
2020-06-17 16:50:06 +02:00
|
|
|
Metrics struct {
|
|
|
|
Enabled bool `yaml:"enabled"`
|
|
|
|
Listen string `yaml:"listen"`
|
|
|
|
} `yaml:"metrics"`
|
|
|
|
|
2020-06-25 16:59:44 +02:00
|
|
|
WhatsApp struct {
|
2021-06-01 14:19:47 +02:00
|
|
|
OSName string `yaml:"os_name"`
|
|
|
|
BrowserName string `yaml:"browser_name"`
|
2020-06-25 16:59:44 +02:00
|
|
|
} `yaml:"whatsapp"`
|
|
|
|
|
2018-08-13 00:00:23 +02:00
|
|
|
Bridge BridgeConfig `yaml:"bridge"`
|
|
|
|
}
|
|
|
|
|
2021-11-06 12:57:35 +01:00
|
|
|
func (config *Config) CanAutoDoublePuppet(userID id.UserID) bool {
|
|
|
|
_, homeserver, _ := userID.Parse()
|
|
|
|
_, hasSecret := config.Bridge.LoginSharedSecretMap[homeserver]
|
|
|
|
return hasSecret
|
2021-02-11 19:47:10 +01:00
|
|
|
}
|
|
|
|
|
2021-11-06 14:33:27 +01:00
|
|
|
func (config *Config) CanDoublePuppetBackfill(userID id.UserID) bool {
|
|
|
|
if !config.Bridge.HistorySync.DoublePuppetBackfill {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
_, homeserver, _ := userID.Parse()
|
|
|
|
// Batch sending can only use local users, so don't allow double puppets on other servers.
|
2022-08-25 11:04:42 +02:00
|
|
|
if homeserver != config.Homeserver.Domain && config.Homeserver.Software != "hungry" {
|
2021-11-06 14:33:27 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|