summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/realtime
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/realtime
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/realtime')
-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
2 files changed, 43 insertions, 12 deletions
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
}