1
0
mirror of https://github.com/badkaktus/gorocket.git synced 2024-12-12 11:15:05 +02:00

Added method for receiving group messages

This commit is contained in:
abataloff 2022-10-25 16:00:57 +03:00
parent 3efd7fce87
commit eebc5da248

View File

@ -117,6 +117,27 @@ type GroupMembersResponse struct {
Success bool `json:"success"` Success bool `json:"success"`
} }
type GroupMessage struct {
ID string `json:"_id"`
Rid string `json:"rid"`
Msg string `json:"msg"`
Ts time.Time `json:"ts"`
U U `json:"u"`
UpdatedAt time.Time `json:"_updatedAt"`
Reactions []interface{} `json:"reactions"`
Mentions []U `json:"mentions"`
Channels []interface{} `json:"channels"`
Starred []interface{} `json:"starred"`
}
type GroupMessagesResponse struct {
Messages []GroupMessage `json:"messages"`
Count int `json:"count"`
Offset int `json:"offset"`
Total int `json:"total"`
Success bool `json:"success"`
}
type RenameGroupRequest struct { type RenameGroupRequest struct {
RoomId string `json:"roomId"` RoomId string `json:"roomId"`
NewName string `json:"name"` NewName string `json:"name"`
@ -376,6 +397,39 @@ func (c *Client) GroupMembers(param *SimpleGroupRequest) (*GroupMembersResponse,
return &res, nil return &res, nil
} }
// Gets group messages
func (c *Client) GroupMessages(param *SimpleGroupRequest) (*GroupMessagesResponse, error) {
req, err := http.NewRequest("GET",
fmt.Sprintf("%s/%s/groups.messages", c.baseURL, c.apiVersion),
nil)
if param.RoomName == "" && param.RoomId == "" {
return nil, fmt.Errorf("False parameters")
}
url := req.URL.Query()
if param.RoomName != "" {
url.Add("roomName", param.RoomName)
}
if param.RoomId != "" {
url.Add("roomId", param.RoomId)
}
req.URL.RawQuery = url.Encode()
if err != nil {
return nil, err
}
res := GroupMessagesResponse{}
if err := c.sendRequest(req, &res); err != nil {
return nil, err
}
return &res, nil
}
// Adds the group back to the user's list of groups. // Adds the group back to the user's list of groups.
func (c *Client) OpenGroup(param *SimpleGroupId) (*SimpleSuccessResponse, error) { func (c *Client) OpenGroup(param *SimpleGroupId) (*SimpleSuccessResponse, error) {
opt, _ := json.Marshal(param) opt, _ := json.Marshal(param)