Skip to content

Commit

Permalink
Merge pull request #3 from fkrasnovid/master
Browse files Browse the repository at this point in the history
fix struct, add leader and owner rest
  • Loading branch information
badkaktus authored Sep 8, 2022
2 parents 46b549f + c2514b6 commit 521ed9a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/badkaktus/gorocket
module github.com/fkrasnovid/gorocket

go 1.13
63 changes: 59 additions & 4 deletions groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type CreateGroupRequest struct {
}

type CreateGroupResponse struct {
Group channel `json:"group"`
Group Channel `json:"group"`
Success bool `json:"success"`
}

Expand All @@ -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"`
Expand Down Expand Up @@ -102,15 +102,15 @@ 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"`
UpdatedAt time.Time `json:"_updatedAt"`
}

type GroupMembersResponse struct {
Members []member `json:"members"`
Members []Member `json:"members"`
Count int `json:"count"`
Offset int `json:"offset"`
Total int `json:"total"`
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions users.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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"`
Expand Down

0 comments on commit 521ed9a

Please sign in to comment.