Skip to content

Commit

Permalink
nctalk: Format rich object strings
Browse files Browse the repository at this point in the history
  • Loading branch information
tilosp committed Aug 30, 2020
1 parent ad90cf0 commit fad78e2
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion bridge/nctalk/nctalk.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"crypto/tls"
"strconv"
"strings"

"github.com/42wim/matterbridge/bridge"
"github.com/42wim/matterbridge/bridge/config"
Expand Down Expand Up @@ -78,7 +79,7 @@ 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,
Expand Down Expand Up @@ -123,3 +124,24 @@ 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
}

0 comments on commit fad78e2

Please sign in to comment.