Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

commit 94a883ebb4f9da2e394c50cdfbb01c3d7301031c Author: Tilo Spannagel <development@tilosp.de> Date: Mon Aug 31 01:49:43 2020 +0000 Format rich object strings (nctalk) (#1222) Signed-off-by: Tilo Spannagel <development@tilosp.de> diff --git a/bridge/nctalk/nctalk.go b/bridge/nctalk/nctalk.go index 40836a4..94bb1a0 100644 --- a/bridge/nctalk/nctalk.go +++ b/bridge/nctalk/nctalk.go @@ -46 +47 @@ import (   "context"   "crypto/tls"   "strconv" + "strings"     "github.com/42wim/matterbridge/bridge"   "github.com/42wim/matterbridge/bridge/config" @@ -787 +797 @@ func (b *Btalk) JoinChannel(channel config.ChannelInfo) error {   continue   }   remoteMessage := config.Message{ - Text: msg.Message, + Text: formatRichObjectString(msg.Message, msg.MessageParameters),   Channel: newRoom.room.Token,   Username: msg.ActorDisplayName,   UserID: msg.ActorID, @@ -1233 +12423 @@ func (b *Btalk) getRoom(token string) *Broom {   }   return nil  } + +// Spec: https://github.com/nextcloud/server/issues/1706#issue-182308785 +func formatRichObjectString(message string, parameters map[string]ocs.RichObjectString) string { + for id, parameter := range parameters { + text := parameter.Name + + switch parameter.Type { + case ocs.ROSTypeUser, ocs.ROSTypeGroup: + text = "@" + text + case ocs.ROSTypeFile: + if parameter.Link != "" { + text = parameter.Link + } + } + + message = strings.ReplaceAll(message, "{"+id+"}", text) + } + + return message +}