From a79e632cdc26f3870b0d8b37f9a94bdcf6f47711 Mon Sep 17 00:00:00 2001 From: Gary Kim Date: Sat, 19 Jun 2021 15:45:19 -0400 Subject: Add support for separate display name (nctalk) (#1506) Signed-off-by: Gary Kim --- vendor/gomod.garykim.dev/nc-talk/room/room.go | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'vendor/gomod.garykim.dev') diff --git a/vendor/gomod.garykim.dev/nc-talk/room/room.go b/vendor/gomod.garykim.dev/nc-talk/room/room.go index eb72c2c0..9e94f9d7 100644 --- a/vendor/gomod.garykim.dev/nc-talk/room/room.go +++ b/vendor/gomod.garykim.dev/nc-talk/room/room.go @@ -56,6 +56,21 @@ type TalkRoom struct { Token string } +// Message represents a message to be sent +type Message struct { + Message string + ActorDisplayName string + ReplyTo int +} + +func (t *Message) toParameters() map[string]string { + return map[string]string{ + "message": t.Message, + "actorDisplayName": t.ActorDisplayName, + "replyTo": strconv.Itoa(t.ReplyTo), + } +} + // NewTalkRoom returns a new TalkRoom instance // Token should be the Nextcloud Room Token (e.g. "d6zoa2zs" if the room URL is https://cloud.mydomain.me/call/d6zoa2zs) func NewTalkRoom(tuser *user.TalkUser, token string) (*TalkRoom, error) { @@ -71,17 +86,19 @@ func NewTalkRoom(tuser *user.TalkUser, token string) (*TalkRoom, error) { }, nil } -// SendMessage sends a message in the Talk room +// SendMessage sends a string message in the Talk room func (t *TalkRoom) SendMessage(msg string) (*ocs.TalkRoomMessageData, error) { + return t.SendComplexMessage(&Message{Message: msg}) +} + +// SendComplexMessage sends a Message type message in the talk room +func (t *TalkRoom) SendComplexMessage(msg *Message) (*ocs.TalkRoomMessageData, error) { url := t.User.NextcloudURL + constants.BaseEndpoint + "chat/" + t.Token - requestParams := map[string]string{ - "message": msg, - } client := t.User.RequestClient(request.Client{ URL: url, Method: "POST", - Params: requestParams, + Params: msg.toParameters(), }) res, err := client.Do() if err != nil { -- cgit v1.2.3