From 3350692eb0515f1863a1102912e62fb601087cf1 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 13 Jan 2023 19:35:17 +0200 Subject: [PATCH] Add beeper room type to m.bridge info --- portal.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/portal.go b/portal.go index ef7cf3c..f20159b 100644 --- a/portal.go +++ b/portal.go @@ -4,6 +4,7 @@ import ( "bytes" "errors" "fmt" + "reflect" "strconv" "strings" "sync" @@ -253,7 +254,17 @@ func (portal *Portal) MainIntent() *appservice.IntentAPI { return portal.bridge.Bot } -func (portal *Portal) getBridgeInfo() (string, event.BridgeEventContent) { +type CustomBridgeInfoContent struct { + event.BridgeEventContent + RoomType string `json:"com.beeper.room_type,omitempty"` +} + +func init() { + event.TypeMap[event.StateBridge] = reflect.TypeOf(CustomBridgeInfoContent{}) + event.TypeMap[event.StateHalfShotBridge] = reflect.TypeOf(CustomBridgeInfoContent{}) +} + +func (portal *Portal) getBridgeInfo() (string, CustomBridgeInfoContent) { bridgeInfo := event.BridgeEventContent{ BridgeBot: portal.bridge.Bot.UserID, Creator: portal.MainIntent().UserID, @@ -284,7 +295,11 @@ func (portal *Portal) getBridgeInfo() (string, event.BridgeEventContent) { bridgeInfoStateKey = fmt.Sprintf("fi.mau.discord://discord/%s/%s", portal.GuildID, portal.Key.ChannelID) bridgeInfo.Channel.ExternalURL = fmt.Sprintf("https://discord.com/channels/%s/%s", portal.GuildID, portal.Key.ChannelID) } - return bridgeInfoStateKey, bridgeInfo + var roomType string + if portal.Type == discordgo.ChannelTypeDM || portal.Type == discordgo.ChannelTypeGroupDM { + roomType = "dm" + } + return bridgeInfoStateKey, CustomBridgeInfoContent{bridgeInfo, roomType} } func (portal *Portal) UpdateBridgeInfo() {