diff --git a/go.mod b/go.mod index 5a5baf1..2e39668 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module github.com/badkaktus/gorocket +module github.com/fkrasnovid/gorocket go 1.13 diff --git a/groups.go b/groups.go index 3708b41..5f34b57 100644 --- a/groups.go +++ b/groups.go @@ -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) diff --git a/users.go b/users.go index b3a0a5e..caad417 100644 --- a/users.go +++ b/users.go @@ -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"`