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

Merge pull request #3 from fkrasnovid/master

fix struct, add leader and owner rest
This commit is contained in:
Nickolay 2022-09-08 16:09:07 +03:00 committed by GitHub
commit 521ed9a905
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 7 deletions

2
go.mod
View File

@ -1,3 +1,3 @@
module github.com/badkaktus/gorocket
module github.com/fkrasnovid/gorocket
go 1.13

View File

@ -36,7 +36,7 @@ type CreateGroupRequest struct {
}
type CreateGroupResponse struct {
Group channel `json:"group"`
Group Channel `json:"group"`
Success bool `json:"success"`
}
@ -57,7 +57,7 @@ type groupInfo struct {
T string `json:"t"`
Msgs int `json:"msgs"`
UsersCount int `json:"usersCount"`
U uChat `json:"u"`
U UChat `json:"u"`
CustomFields struct {
} `json:"customFields"`
Broadcast bool `json:"broadcast"`
@ -102,7 +102,7 @@ type groupList struct {
T string `json:"t"`
Usernames []string `json:"usernames"`
Msgs int `json:"msgs"`
U uChat `json:"u"`
U UChat `json:"u"`
Ts time.Time `json:"ts"`
Ro bool `json:"ro"`
SysMes bool `json:"sysMes"`
@ -110,7 +110,7 @@ type groupList struct {
}
type GroupMembersResponse struct {
Members []member `json:"members"`
Members []Member `json:"members"`
Count int `json:"count"`
Offset int `json:"offset"`
Total int `json:"total"`
@ -127,6 +127,11 @@ type RenameGroupResponse struct {
Success bool `json:"success"`
}
type AddGroupPermissionRequest struct {
RoomId string `json:"roomId"`
UserId string `json:"userId"`
}
// Archives a group.
func (c *Client) ArchiveGroup(param *SimpleGroupId) (*SimpleSuccessResponse, error) {
opt, _ := json.Marshal(param)
@ -413,6 +418,56 @@ func (c *Client) RenameGroup(param *RenameGroupRequest) (*RenameGroupResponse, e
return &res, nil
}
// Add leader for the group.
func (c *Client) AddLeaderGroup(param *AddGroupPermissionRequest) (*SimpleSuccessResponse, error) {
if param.UserId == "" && param.RoomId == "" {
return nil, fmt.Errorf("False parameters")
}
opt, _ := json.Marshal(param)
req, err := http.NewRequest("POST",
fmt.Sprintf("%s/%s/groups.addLeader", 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
}
// Add owner for the group.
func (c *Client) AddOwnerGroup(param *AddGroupPermissionRequest) (*SimpleSuccessResponse, error) {
if param.UserId == "" && param.RoomId == "" {
return nil, fmt.Errorf("False parameters")
}
opt, _ := json.Marshal(param)
req, err := http.NewRequest("POST",
fmt.Sprintf("%s/%s/groups.addOwner", 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
}
// Sets the announcement for the group.
func (c *Client) SetAnnouncementGroup(param *SetAnnouncementRequest) (*SetAnnouncementResponse, error) {
opt, _ := json.Marshal(param)

View File

@ -48,7 +48,7 @@ type userCreateInfo struct {
CreatedAt time.Time `json:"createdAt"`
Services userServices `json:"services"`
Username string `json:"username"`
Emails []email `json:"emails"`
Emails []Email `json:"emails"`
Type string `json:"type"`
Status string `json:"status"`
Active bool `json:"active"`
@ -173,7 +173,7 @@ type userUpdateInfo struct {
} `json:"password"`
} `json:"services"`
Username string `json:"username"`
Emails []email `json:"emails"`
Emails []Email `json:"emails"`
Type string `json:"type"`
Status string `json:"status"`
Active bool `json:"active"`