mirror of
https://github.com/badkaktus/gorocket.git
synced 2025-07-17 01:22:21 +02:00
fix struct, add leader and owner rest
This commit is contained in:
2
go.mod
2
go.mod
@ -1,3 +1,3 @@
|
|||||||
module github.com/badkaktus/gorocket
|
module github.com/fkrasnovid/gorocket
|
||||||
|
|
||||||
go 1.13
|
go 1.13
|
||||||
|
63
groups.go
63
groups.go
@ -36,7 +36,7 @@ type CreateGroupRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CreateGroupResponse struct {
|
type CreateGroupResponse struct {
|
||||||
Group channel `json:"group"`
|
Group Channel `json:"group"`
|
||||||
Success bool `json:"success"`
|
Success bool `json:"success"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ type groupInfo struct {
|
|||||||
T string `json:"t"`
|
T string `json:"t"`
|
||||||
Msgs int `json:"msgs"`
|
Msgs int `json:"msgs"`
|
||||||
UsersCount int `json:"usersCount"`
|
UsersCount int `json:"usersCount"`
|
||||||
U uChat `json:"u"`
|
U UChat `json:"u"`
|
||||||
CustomFields struct {
|
CustomFields struct {
|
||||||
} `json:"customFields"`
|
} `json:"customFields"`
|
||||||
Broadcast bool `json:"broadcast"`
|
Broadcast bool `json:"broadcast"`
|
||||||
@ -102,7 +102,7 @@ type groupList struct {
|
|||||||
T string `json:"t"`
|
T string `json:"t"`
|
||||||
Usernames []string `json:"usernames"`
|
Usernames []string `json:"usernames"`
|
||||||
Msgs int `json:"msgs"`
|
Msgs int `json:"msgs"`
|
||||||
U uChat `json:"u"`
|
U UChat `json:"u"`
|
||||||
Ts time.Time `json:"ts"`
|
Ts time.Time `json:"ts"`
|
||||||
Ro bool `json:"ro"`
|
Ro bool `json:"ro"`
|
||||||
SysMes bool `json:"sysMes"`
|
SysMes bool `json:"sysMes"`
|
||||||
@ -110,7 +110,7 @@ type groupList struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GroupMembersResponse struct {
|
type GroupMembersResponse struct {
|
||||||
Members []member `json:"members"`
|
Members []Member `json:"members"`
|
||||||
Count int `json:"count"`
|
Count int `json:"count"`
|
||||||
Offset int `json:"offset"`
|
Offset int `json:"offset"`
|
||||||
Total int `json:"total"`
|
Total int `json:"total"`
|
||||||
@ -127,6 +127,11 @@ type RenameGroupResponse struct {
|
|||||||
Success bool `json:"success"`
|
Success bool `json:"success"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AddGroupPermissionRequest struct {
|
||||||
|
RoomId string `json:"roomId"`
|
||||||
|
UserId string `json:"userId"`
|
||||||
|
}
|
||||||
|
|
||||||
// Archives a group.
|
// Archives a group.
|
||||||
func (c *Client) ArchiveGroup(param *SimpleGroupId) (*SimpleSuccessResponse, error) {
|
func (c *Client) ArchiveGroup(param *SimpleGroupId) (*SimpleSuccessResponse, error) {
|
||||||
opt, _ := json.Marshal(param)
|
opt, _ := json.Marshal(param)
|
||||||
@ -413,6 +418,56 @@ func (c *Client) RenameGroup(param *RenameGroupRequest) (*RenameGroupResponse, e
|
|||||||
return &res, nil
|
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.
|
// Sets the announcement for the group.
|
||||||
func (c *Client) SetAnnouncementGroup(param *SetAnnouncementRequest) (*SetAnnouncementResponse, error) {
|
func (c *Client) SetAnnouncementGroup(param *SetAnnouncementRequest) (*SetAnnouncementResponse, error) {
|
||||||
opt, _ := json.Marshal(param)
|
opt, _ := json.Marshal(param)
|
||||||
|
4
users.go
4
users.go
@ -48,7 +48,7 @@ type userCreateInfo struct {
|
|||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
Services userServices `json:"services"`
|
Services userServices `json:"services"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Emails []email `json:"emails"`
|
Emails []Email `json:"emails"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Active bool `json:"active"`
|
Active bool `json:"active"`
|
||||||
@ -173,7 +173,7 @@ type userUpdateInfo struct {
|
|||||||
} `json:"password"`
|
} `json:"password"`
|
||||||
} `json:"services"`
|
} `json:"services"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Emails []email `json:"emails"`
|
Emails []Email `json:"emails"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Active bool `json:"active"`
|
Active bool `json:"active"`
|
||||||
|
Reference in New Issue
Block a user