From 75b2958988df02e3682293093ec2fe337e0edc37 Mon Sep 17 00:00:00 2001 From: kolyuchy Date: Sat, 29 Aug 2020 22:56:09 +0300 Subject: [PATCH] finish channels --- channels.go | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) diff --git a/channels.go b/channels.go index 421c04d..45b91c0 100644 --- a/channels.go +++ b/channels.go @@ -154,6 +154,46 @@ type member struct { Status string `json:"status"` } +type RenameChannelRequest struct { + RoomId string `json:"roomId"` + NewName string `json:"name"` +} + +type RenameChannelResponse struct { + Channel channelList `json:"channel"` + Success bool `json:"success"` +} + +type SetAnnouncementRequest struct { + RoomId string `json:"roomId"` + Announcement string `json:"announcement"` +} + +type SetAnnouncementResponse struct { + Announcement string `json:"announcement"` + Success bool `json:"success"` +} + +type SetDescriptionRequest struct { + RoomId string `json:"roomId"` + Description string `json:"description"` +} + +type SetDescriptionResponse struct { + Description string `json:"description"` + Success bool `json:"success"` +} + +type SetTopicRequest struct { + RoomId string `json:"roomId"` + Topic string `json:"topic"` +} + +type SetTopicResponse struct { + Topic string `json:"topic"` + Success bool `json:"success"` +} + // Adds all of the users on the server to a channel. func (c *Client) AddAllToChannel(params *AddAllRequest) (*AddAllResponse, error) { opt, _ := json.Marshal(params) @@ -439,3 +479,108 @@ func (c *Client) OpenChannel(param *SimpleChannelId) (*SimpleSuccessResponse, er return &res, nil } + +// Changes a channel's name. +func (c *Client) RenameChannel(param *RenameChannelRequest) (*RenameChannelResponse, error) { + opt, _ := json.Marshal(param) + + req, err := http.NewRequest("POST", + fmt.Sprintf("%s/%s/channels.rename", c.baseURL, c.apiVersion), + bytes.NewBuffer(opt)) + + if err != nil { + return nil, err + } + + res := RenameChannelResponse{} + + if err := c.sendRequest(req, &res); err != nil { + return nil, err + } + + return &res, nil +} + +// Sets the announcement for the channel. +func (c *Client) SetAnnouncementChannel(param *SetAnnouncementRequest) (*SetAnnouncementResponse, error) { + opt, _ := json.Marshal(param) + + req, err := http.NewRequest("POST", + fmt.Sprintf("%s/%s/channels.setAnnouncement", c.baseURL, c.apiVersion), + bytes.NewBuffer(opt)) + + if err != nil { + return nil, err + } + + res := SetAnnouncementResponse{} + + if err := c.sendRequest(req, &res); err != nil { + return nil, err + } + + return &res, nil +} + +// Sets the Description for the channel. +func (c *Client) SetDescriptionChannel(param *SetDescriptionRequest) (*SetDescriptionResponse, error) { + opt, _ := json.Marshal(param) + + req, err := http.NewRequest("POST", + fmt.Sprintf("%s/%s/channels.setDescription", c.baseURL, c.apiVersion), + bytes.NewBuffer(opt)) + + if err != nil { + return nil, err + } + + res := SetDescriptionResponse{} + + if err := c.sendRequest(req, &res); err != nil { + return nil, err + } + + return &res, nil +} + +// Sets the topic for the channel. +func (c *Client) SetTopicChannel(param *SetTopicRequest) (*SetTopicResponse, error) { + opt, _ := json.Marshal(param) + + req, err := http.NewRequest("POST", + fmt.Sprintf("%s/%s/channels.setTopic", c.baseURL, c.apiVersion), + bytes.NewBuffer(opt)) + + if err != nil { + return nil, err + } + + res := SetTopicResponse{} + + if err := c.sendRequest(req, &res); err != nil { + return nil, err + } + + return &res, nil +} + +// Unarchive a channel. +func (c *Client) UnarchiveChannel(param *SimpleChannelId) (*SimpleSuccessResponse, error) { + opt, _ := json.Marshal(param) + + req, err := http.NewRequest("POST", + fmt.Sprintf("%s/%s/channels.unarchive", c.baseURL, c.apiVersion), + bytes.NewBuffer(opt)) + + if err != nil { + return nil, err + } + + res := SimpleSuccessResponse{} + + if err := c.sendRequest(req, &res); err != nil { + return nil, err + } + + return &res, nil +}