mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-12-13 17:13:11 +01:00
Add bridge info state events for new portal rooms
This commit is contained in:
parent
7947ba616c
commit
f1b50a22f3
1 changed files with 42 additions and 0 deletions
42
portal.go
42
portal.go
|
@ -717,6 +717,26 @@ func (portal *Portal) handleHistory(user *User, messages []interface{}) {
|
|||
}
|
||||
}
|
||||
|
||||
type BridgeInfoSection struct {
|
||||
ID string `json:"id"`
|
||||
DisplayName string `json:"display_name,omitempty"`
|
||||
AvatarURL id.ContentURIString `json:"avatar_url,omitempty"`
|
||||
ExternalURL string `json:"external_url,omitempty"`
|
||||
}
|
||||
|
||||
type BridgeInfoContent struct {
|
||||
BridgeBot id.UserID `json:"bridgebot"`
|
||||
Creator id.UserID `json:"creator,omitempty"`
|
||||
Protocol BridgeInfoSection `json:"protocol"`
|
||||
Network *BridgeInfoSection `json:"network,omitempty"`
|
||||
Channel BridgeInfoSection `json:"channel"`
|
||||
}
|
||||
|
||||
var (
|
||||
StateBridgeInfo = event.Type{Type: "m.bridge", Class: event.StateEventType}
|
||||
StateHalfShotBridgeInfo = event.Type{Type: "uk.half-shot.bridge", Class: event.StateEventType}
|
||||
)
|
||||
|
||||
func (portal *Portal) CreateMatrixRoom(user *User) error {
|
||||
portal.roomCreateLock.Lock()
|
||||
defer portal.roomCreateLock.Unlock()
|
||||
|
@ -755,11 +775,33 @@ func (portal *Portal) CreateMatrixRoom(user *User) error {
|
|||
portal.UpdateAvatar(user, nil)
|
||||
}
|
||||
|
||||
bridgeInfo := event.Content{
|
||||
Parsed: BridgeInfoContent{
|
||||
BridgeBot: portal.bridge.Bot.UserID,
|
||||
Creator: portal.MainIntent().UserID,
|
||||
Protocol: BridgeInfoSection{
|
||||
ID: "whatsapp",
|
||||
DisplayName: "WhatsApp",
|
||||
AvatarURL: id.ContentURIString(portal.bridge.Config.AppService.Bot.Avatar),
|
||||
ExternalURL: "https://www.whatsapp.com/",
|
||||
},
|
||||
Channel: BridgeInfoSection{
|
||||
ID: portal.Key.JID,
|
||||
},
|
||||
},
|
||||
}
|
||||
initialState := []*event.Event{{
|
||||
Type: event.StatePowerLevels,
|
||||
Content: event.Content{
|
||||
Parsed: portal.GetBasePowerLevels(),
|
||||
},
|
||||
}, {
|
||||
Type: StateBridgeInfo,
|
||||
Content: bridgeInfo,
|
||||
}, {
|
||||
// TODO remove this once https://github.com/matrix-org/matrix-doc/pull/2346 is in spec
|
||||
Type: StateHalfShotBridgeInfo,
|
||||
Content: bridgeInfo,
|
||||
}}
|
||||
if !portal.AvatarURL.IsEmpty() {
|
||||
initialState = append(initialState, &event.Event{
|
||||
|
|
Loading…
Reference in a new issue