forked from jshiffer/matterbridge
Format rich object strings (nctalk) (#1222)
Signed-off-by: Tilo Spannagel <development@tilosp.de>
This commit is contained in:
parent
ad90cf09fe
commit
712385ffd5
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/42wim/matterbridge/bridge"
|
"github.com/42wim/matterbridge/bridge"
|
||||||
"github.com/42wim/matterbridge/bridge/config"
|
"github.com/42wim/matterbridge/bridge/config"
|
||||||
@ -78,7 +79,7 @@ func (b *Btalk) JoinChannel(channel config.ChannelInfo) error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
remoteMessage := config.Message{
|
remoteMessage := config.Message{
|
||||||
Text: msg.Message,
|
Text: formatRichObjectString(msg.Message, msg.MessageParameters),
|
||||||
Channel: newRoom.room.Token,
|
Channel: newRoom.room.Token,
|
||||||
Username: msg.ActorDisplayName,
|
Username: msg.ActorDisplayName,
|
||||||
UserID: msg.ActorID,
|
UserID: msg.ActorID,
|
||||||
@ -123,3 +124,23 @@ func (b *Btalk) getRoom(token string) *Broom {
|
|||||||
}
|
}
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user