summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/realtime/channels.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2019-02-15 18:20:32 +0100
committerGitHub <noreply@github.com>2019-02-15 18:20:32 +0100
commit716751cf7685471bbc969e19fe26f23e66f3c0b4 (patch)
tree6db2350f28a76ae6e1cf7c3cea7263503057d82f /vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/realtime/channels.go
parent077b818d82a98855d5577f4f9de5d2b2d2cc6a50 (diff)
parent6ebd5cbbd8a941e0bc5f99f0d8e99cfd1d8ac0d7 (diff)
downloadmatterbridge-msglm-716751cf7685471bbc969e19fe26f23e66f3c0b4.tar.gz
matterbridge-msglm-716751cf7685471bbc969e19fe26f23e66f3c0b4.tar.bz2
matterbridge-msglm-716751cf7685471bbc969e19fe26f23e66f3c0b4.zip
Refactor and update RocketChat bridge (#707)
* Add support for editing/deleting messages * Add support for uploading files * Add support for avatars * Use the Rocket.Chat.Go.SDK * Use the rest and streaming api
Diffstat (limited to 'vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/realtime/channels.go')
-rw-r--r--vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/realtime/channels.go263
1 files changed, 263 insertions, 0 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
new file mode 100644
index 00000000..5779cb38
--- /dev/null
+++ b/vendor/github.com/matterbridge/Rocket.Chat.Go.SDK/realtime/channels.go
@@ -0,0 +1,263 @@
+package realtime
+
+import (
+ "github.com/Jeffail/gabs"
+ "github.com/matterbridge/Rocket.Chat.Go.SDK/models"
+)
+
+func (c *Client) GetChannelId(name string) (string, error) {
+ rawResponse, err := c.ddp.Call("getRoomIdByNameOrId", name)
+ if err != nil {
+ return "", err
+ }
+
+ //log.Println(rawResponse)
+
+ return rawResponse.(string), nil
+}
+
+// GetChannelsIn returns list of channels
+// Optionally includes date to get all since last check or 0 to get all
+//
+// https://rocket.chat/docs/developer-guides/realtime-api/method-calls/get-rooms/
+func (c *Client) GetChannelsIn() ([]models.Channel, error) {
+ rawResponse, err := c.ddp.Call("rooms/get", map[string]int{
+ "$date": 0,
+ })
+ if err != nil {
+ return nil, err
+ }
+
+ document, _ := gabs.Consume(rawResponse.(map[string]interface{})["update"])
+
+ chans, err := document.Children()
+
+ var channels []models.Channel
+
+ for _, i := range chans {
+ channels = append(channels, models.Channel{
+ ID: stringOrZero(i.Path("_id").Data()),
+ //Default: stringOrZero(i.Path("default").Data()),
+ Name: stringOrZero(i.Path("name").Data()),
+ Type: stringOrZero(i.Path("t").Data()),
+ })
+ }
+
+ return channels, nil
+}
+
+// GetChannelSubscriptions gets users channel subscriptions
+// Optionally includes date to get all since last check or 0 to get all
+//
+// https://rocket.chat/docs/developer-guides/realtime-api/method-calls/get-subscriptions
+func (c *Client) GetChannelSubscriptions() ([]models.ChannelSubscription, error) {
+ rawResponse, err := c.ddp.Call("subscriptions/get", map[string]int{
+ "$date": 0,
+ })
+ if err != nil {
+ return nil, err
+ }
+
+ document, _ := gabs.Consume(rawResponse.(map[string]interface{})["update"])
+
+ channelSubs, err := document.Children()
+
+ var channelSubscriptions []models.ChannelSubscription
+
+ for _, sub := range channelSubs {
+ channelSubscription := models.ChannelSubscription{
+ ID: stringOrZero(sub.Path("_id").Data()),
+ Alert: sub.Path("alert").Data().(bool),
+ Name: stringOrZero(sub.Path("name").Data()),
+ DisplayName: stringOrZero(sub.Path("fname").Data()),
+ Open: sub.Path("open").Data().(bool),
+ Type: stringOrZero(sub.Path("t").Data()),
+ User: models.User{
+ ID: stringOrZero(sub.Path("u._id").Data()),
+ UserName: stringOrZero(sub.Path("u.username").Data()),
+ },
+ Unread: sub.Path("unread").Data().(float64),
+ }
+
+ if sub.Path("roles").Data() != nil {
+ var roles []string
+ for _, role := range sub.Path("roles").Data().([]interface{}) {
+ roles = append(roles, role.(string))
+ }
+
+ channelSubscription.Roles = roles
+ }
+
+ channelSubscriptions = append(channelSubscriptions, channelSubscription)
+ }
+
+ return channelSubscriptions, nil
+}
+
+// GetChannelRoles returns room roles
+//
+// https://rocket.chat/docs/developer-guides/realtime-api/method-calls/get-room-roles
+func (c *Client) GetChannelRoles(roomId string) error {
+ _, err := c.ddp.Call("getRoomRoles", roomId)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+// CreateChannel creates a channel
+// Takes name and users array
+//
+// https://rocket.chat/docs/developer-guides/realtime-api/method-calls/create-channels
+func (c *Client) CreateChannel(name string, users []string) error {
+ _, err := c.ddp.Call("createChannel", name, users)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+// CreateGroup creates a private group
+// Takes group name and array of users
+//
+// https://rocket.chat/docs/developer-guides/realtime-api/method-calls/create-private-groups
+func (c *Client) CreateGroup(name string, users []string) error {
+ _, err := c.ddp.Call("createPrivateGroup", name, users)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+// JoinChannel joins a channel
+// Takes roomId
+//
+// https://rocket.chat/docs/developer-guides/realtime-api/method-calls/joining-channels
+func (c *Client) JoinChannel(roomId string) error {
+ _, err := c.ddp.Call("joinRoom", roomId)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+// LeaveChannel leaves a channel
+// Takes roomId
+//
+// https://rocket.chat/docs/developer-guides/realtime-api/method-calls/leaving-rooms
+func (c *Client) LeaveChannel(roomId string) error {
+ _, err := c.ddp.Call("leaveRoom", roomId)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+// ArchiveChannel archives the channel
+// Takes roomId
+//
+// https://rocket.chat/docs/developer-guides/realtime-api/method-calls/archive-rooms
+func (c *Client) ArchiveChannel(roomId string) error {
+ _, err := c.ddp.Call("archiveRoom", roomId)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+// UnArchiveChannel unarchives the channel
+// Takes roomId
+//
+// https://rocket.chat/docs/developer-guides/realtime-api/method-calls/unarchive-rooms
+func (c *Client) UnArchiveChannel(roomId string) error {
+ _, err := c.ddp.Call("unarchiveRoom", roomId)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+// DeleteChannel deletes the channel
+// Takes roomId
+//
+// https://rocket.chat/docs/developer-guides/realtime-api/method-calls/delete-rooms
+func (c *Client) DeleteChannel(roomId string) error {
+ _, err := c.ddp.Call("eraseRoom", roomId)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+// SetChannelTopic sets channel topic
+// takes roomId and topic
+//
+// https://rocket.chat/docs/developer-guides/realtime-api/method-calls/save-room-settings
+func (c *Client) SetChannelTopic(roomId string, topic string) error {
+ _, err := c.ddp.Call("saveRoomSettings", roomId, "roomTopic", topic)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+// SetChannelType sets the channel type
+// takes roomId and roomType
+//
+// https://rocket.chat/docs/developer-guides/realtime-api/method-calls/save-room-settings
+func (c *Client) SetChannelType(roomId string, roomType string) error {
+ _, err := c.ddp.Call("saveRoomSettings", roomId, "roomType", roomType)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+// SetChannelJoinCode sets channel join code
+// takes roomId and joinCode
+//
+// https://rocket.chat/docs/developer-guides/realtime-api/method-calls/save-room-settings
+func (c *Client) SetChannelJoinCode(roomId string, joinCode string) error {
+ _, err := c.ddp.Call("saveRoomSettings", roomId, "joinCode", joinCode)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+// SetChannelReadOnly sets channel as read only
+// takes roomId and boolean
+//
+// https://rocket.chat/docs/developer-guides/realtime-api/method-calls/save-room-settings
+func (c *Client) SetChannelReadOnly(roomId string, readOnly bool) error {
+ _, err := c.ddp.Call("saveRoomSettings", roomId, "readOnly", readOnly)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
+// SetChannelDescription sets channels description
+// takes roomId and description
+//
+// https://rocket.chat/docs/developer-guides/realtime-api/method-calls/save-room-settings
+func (c *Client) SetChannelDescription(roomId string, description string) error {
+ _, err := c.ddp.Call("saveRoomSettings", roomId, "roomDescription", description)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}