summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/matterbridge/Rocket.Chat.Go.SDK
diff options
context:
space:
mode:
authorWim <wim@42.be>2020-12-06 23:16:02 +0100
committerGitHub <noreply@github.com>2020-12-06 23:16:02 +0100
commit0d7315249d20bf9856605068074a7b6c6bcce835 (patch)
treef8ab7e0f3e96491e439eb49beebf3fae658215c4 /vendor/github.com/matterbridge/Rocket.Chat.Go.SDK
parent4913766d58cd1fe204b27dc93172c5dd4a95a88a (diff)
downloadmatterbridge-msglm-0d7315249d20bf9856605068074a7b6c6bcce835.tar.gz
matterbridge-msglm-0d7315249d20bf9856605068074a7b6c6bcce835.tar.bz2
matterbridge-msglm-0d7315249d20bf9856605068074a7b6c6bcce835.zip
Update vendor (#1330)
Diffstat (limited to 'vendor/github.com/matterbridge/Rocket.Chat.Go.SDK')
-rw-r--r--vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/models/message.go37
-rw-r--r--vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/models/user.go1
-rw-r--r--vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/realtime/channels.go1
-rw-r--r--vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/realtime/messages.go54
-rw-r--r--vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/rest/channels.go12
-rw-r--r--vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/rest/permissions.go33
6 files changed, 124 insertions, 14 deletions
diff --git a/vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/models/message.go b/vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/models/message.go
index 0c5e9b01..f3dc1c6f 100644
--- a/vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/models/message.go
+++ b/vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/models/message.go
@@ -66,6 +66,9 @@ type Attachment struct {
AudioURL string `json:"audio_url,omitempty"`
VideoURL string `json:"video_url,omitempty"`
+ Actions []AttachmentAction `json:"actions,omitempty"`
+ ActionButtonsAlignment AttachmentActionButtonsAlignment `json:"button_alignment,omitempty"`
+
Fields []AttachmentField `json:"fields,omitempty"`
}
@@ -77,3 +80,37 @@ type AttachmentField struct {
Title string `json:"title"`
Value string `json:"value"`
}
+
+type AttachmentActionType string
+
+const (
+ AttachmentActionTypeButton AttachmentActionType = "button"
+)
+
+// AttachmentAction are action buttons on message attachments
+type AttachmentAction struct {
+ Type AttachmentActionType `json:"type"`
+ Text string `json:"text"`
+ Url string `json:"url"`
+ ImageURL string `json:"image_url"`
+ IsWebView bool `json:"is_webview"`
+ WebviewHeightRatio string `json:"webview_height_ratio"`
+ Msg string `json:"msg"`
+ MsgInChatWindow bool `json:"msg_in_chat_window"`
+ MsgProcessingType MessageProcessingType `json:"msg_processing_type"`
+}
+
+// AttachmentActionButtonAlignment configures how the actions buttons will be aligned
+type AttachmentActionButtonsAlignment string
+
+const (
+ ActionButtonAlignVertical AttachmentActionButtonsAlignment = "vertical"
+ ActionButtonAlignHorizontal AttachmentActionButtonsAlignment = "horizontal"
+)
+
+type MessageProcessingType string
+
+const (
+ ProcessingTypeSendMessage MessageProcessingType = "sendMessage"
+ ProcessingTypeRespondWithMessage MessageProcessingType = "respondWithMessage"
+)
diff --git a/vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/models/user.go b/vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/models/user.go
index ee56bdc3..703f2c57 100644
--- a/vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/models/user.go
+++ b/vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/models/user.go
@@ -14,6 +14,7 @@ type CreateUserRequest struct {
Email string `json:"email"`
Password string `json:"password"`
Username string `json:"username"`
+ Roles []string `json:"roles,omitempty"`
CustomFields map[string]string `json:"customFields,omitempty"`
}
diff --git a/vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/realtime/channels.go b/vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/realtime/channels.go
index 5779cb38..ed9dd5b0 100644
--- a/vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/realtime/channels.go
+++ b/vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/realtime/channels.go
@@ -72,6 +72,7 @@ func (c *Client) GetChannelSubscriptions() ([]models.ChannelSubscription, error)
DisplayName: stringOrZero(sub.Path("fname").Data()),
Open: sub.Path("open").Data().(bool),
Type: stringOrZero(sub.Path("t").Data()),
+ RoomId: stringOrZero(sub.Path("rid").Data()),
User: models.User{
ID: stringOrZero(sub.Path("u._id").Data()),
UserName: stringOrZero(sub.Path("u.username").Data()),
diff --git a/vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/realtime/messages.go b/vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/realtime/messages.go
index 2c112155..89ad9178 100644
--- a/vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/realtime/messages.go
+++ b/vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/realtime/messages.go
@@ -2,6 +2,7 @@ package realtime
import (
"fmt"
+ "log"
"strconv"
"time"
@@ -16,27 +17,54 @@ const (
default_buffer_size = 100
)
+var messageListenerAdded = false
+
+// NewMessage creates basic message with an ID, a RoomID, and a Msg
+// Takes channel and text
+func (c *Client) NewMessage(channel *models.Channel, text string) *models.Message {
+ return &models.Message{
+ ID: c.newRandomId(),
+ RoomID: channel.ID,
+ Msg: text,
+ }
+}
+
// LoadHistory loads history
-// Takes roomId
+// Takes roomID
//
// https://rocket.chat/docs/developer-guides/realtime-api/method-calls/load-history
-func (c *Client) LoadHistory(roomId string) error {
- _, err := c.ddp.Call("loadHistory", roomId)
+func (c *Client) LoadHistory(roomID string) ([]models.Message, error) {
+ m, err := c.ddp.Call("loadHistory", roomID)
if err != nil {
- return err
+ return nil, err
}
- return nil
+ history := m.(map[string]interface{})
+
+ document, _ := gabs.Consume(history["messages"])
+ msgs, err := document.Children()
+ if err != nil {
+ log.Printf("response is in an unexpected format: %v", err)
+ return make([]models.Message, 0), nil
+ }
+
+ messages := make([]models.Message, len(msgs))
+
+ for i, arg := range msgs {
+ messages[i] = *getMessageFromDocument(arg)
+ }
+
+ // log.Println(messages)
+
+ return messages, nil
}
// SendMessage sends message to channel
-// takes channel and message
+// takes message
//
// https://rocket.chat/docs/developer-guides/realtime-api/method-calls/send-message
-func (c *Client) SendMessage(m *models.Message) (*models.Message, error) {
- m.ID = c.newRandomId()
-
- rawResponse, err := c.ddp.Call("sendMessage", m)
+func (c *Client) SendMessage(message *models.Message) (*models.Message, error) {
+ rawResponse, err := c.ddp.Call("sendMessage", message)
if err != nil {
return nil, err
}
@@ -158,8 +186,10 @@ func (c *Client) SubscribeToMessageStream(channel *models.Channel, msgChannel ch
return err
}
- // msgChannel := make(chan models.Message, default_buffer_size)
- c.ddp.CollectionByName("stream-room-messages").AddUpdateListener(messageExtractor{msgChannel, "update"})
+ if !messageListenerAdded {
+ c.ddp.CollectionByName("stream-room-messages").AddUpdateListener(messageExtractor{msgChannel, "update"})
+ messageListenerAdded = true
+ }
return nil
}
diff --git a/vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/rest/channels.go b/vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/rest/channels.go
index 71377500..d5c8fa85 100644
--- a/vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/rest/channels.go
+++ b/vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/rest/channels.go
@@ -56,9 +56,17 @@ func (c *Client) LeaveChannel(channel *models.Channel) error {
// https://rocket.chat/docs/developer-guides/rest-api/channels/info
func (c *Client) GetChannelInfo(channel *models.Channel) (*models.Channel, error) {
response := new(ChannelResponse)
- if err := c.Get("channels.info", url.Values{"roomId": []string{channel.ID}}, response); err != nil {
- return nil, err
+ switch {
+ case channel.Name != "" && channel.ID == "":
+ if err := c.Get("channels.info", url.Values{"roomName": []string{channel.Name}}, response); err != nil {
+ return nil, err
+ }
+ default:
+ if err := c.Get("channels.info", url.Values{"roomId": []string{channel.ID}}, response); err != nil {
+ return nil, err
+ }
}
return &response.Channel, nil
}
+
diff --git a/vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/rest/permissions.go b/vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/rest/permissions.go
new file mode 100644
index 00000000..2ccbd2f1
--- /dev/null
+++ b/vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/rest/permissions.go
@@ -0,0 +1,33 @@
+package rest
+
+import (
+ "bytes"
+ "encoding/json"
+
+ "github.com/matterbridge/Rocket.Chat.Go.SDK/models"
+)
+
+type UpdatePermissionsRequest struct {
+ Permissions []models.Permission `json:"permissions"`
+}
+
+type UpdatePermissionsResponse struct {
+ Status
+ Permissions []models.Permission `json:"permissions"`
+}
+
+// UpdatePermissions updates permissions
+//
+// https://rocket.chat/docs/developer-guides/rest-api/permissions/update/
+func (c *Client) UpdatePermissions(req *UpdatePermissionsRequest) (*UpdatePermissionsResponse, error) {
+ body, err := json.Marshal(req)
+ if err != nil {
+ return nil, err
+ }
+
+ response := new(UpdatePermissionsResponse)
+ if err := c.Post("permissions.update", bytes.NewBuffer(body), response); err != nil {
+ return nil, err
+ }
+ return response, nil
+}