|
|
|
|
@ -17,7 +17,10 @@ package api
|
|
|
|
|
import (
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
"github.com/openimsdk/protocol/group"
|
|
|
|
|
"github.com/openimsdk/protocol/wrapperspb"
|
|
|
|
|
"github.com/openimsdk/tools/a2r"
|
|
|
|
|
"github.com/openimsdk/tools/apiresp"
|
|
|
|
|
"github.com/openimsdk/tools/errs"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type GroupApi struct {
|
|
|
|
|
@ -40,6 +43,258 @@ func (o *GroupApi) SetGroupInfoEx(c *gin.Context) {
|
|
|
|
|
a2r.Call(c, group.GroupClient.SetGroupInfoEx, o.Client)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetSendMessageSetting 设置群成员发消息权限:allowSendMsg 0=全员可发,1=仅群主/管理员可发(委托 SetGroupInfoEx)。
|
|
|
|
|
func (o *GroupApi) SetSendMessageSetting(c *gin.Context) {
|
|
|
|
|
var req struct {
|
|
|
|
|
GroupID string `json:"groupID"`
|
|
|
|
|
AllowSendMsg int32 `json:"allowSendMsg"`
|
|
|
|
|
}
|
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
|
apiresp.GinError(c, errs.ErrArgs.WrapMsg(err.Error()))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if req.GroupID == "" {
|
|
|
|
|
apiresp.GinError(c, errs.ErrArgs.WrapMsg("groupID is empty"))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if req.AllowSendMsg != 0 && req.AllowSendMsg != 1 {
|
|
|
|
|
apiresp.GinError(c, errs.ErrArgs.WrapMsg("allowSendMsg must be 0 or 1"))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
resp, err := o.Client.SetGroupInfoEx(c.Request.Context(), &group.SetGroupInfoExReq{
|
|
|
|
|
GroupID: req.GroupID,
|
|
|
|
|
AllowSendMsg: wrapperspb.Int32(req.AllowSendMsg),
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
apiresp.GinError(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
apiresp.GinSuccess(c, resp)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetSendMessageSetting 返回当前群的 allowSendMsg:0=全员可发,1=仅群主/管理员可发(与 get_groups_info 中字段一致)。
|
|
|
|
|
func (o *GroupApi) GetSendMessageSetting(c *gin.Context) {
|
|
|
|
|
var req struct {
|
|
|
|
|
GroupID string `json:"groupID"`
|
|
|
|
|
}
|
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
|
apiresp.GinError(c, errs.ErrArgs.WrapMsg(err.Error()))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if req.GroupID == "" {
|
|
|
|
|
apiresp.GinError(c, errs.ErrArgs.WrapMsg("groupID is empty"))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
resp, err := o.Client.GetGroupsInfo(c.Request.Context(), &group.GetGroupsInfoReq{
|
|
|
|
|
GroupIDs: []string{req.GroupID},
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
apiresp.GinError(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if len(resp.GroupInfos) == 0 {
|
|
|
|
|
apiresp.GinError(c, errs.ErrRecordNotFound.WrapMsg("group not found", "groupID", req.GroupID))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
gi := resp.GroupInfos[0]
|
|
|
|
|
apiresp.GinSuccess(c, struct {
|
|
|
|
|
GroupID string `json:"groupID"`
|
|
|
|
|
AllowSendMsg int32 `json:"allowSendMsg"`
|
|
|
|
|
}{
|
|
|
|
|
GroupID: gi.GroupID,
|
|
|
|
|
AllowSendMsg: gi.GetAllowSendMsg(),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetInviteSetting 设置群成员邀请他人入群权限:allowAddMember 0=全员可邀请/拉人,1=仅群主/管理员(委托 SetGroupInfoEx;邀请走 InviteUserToGroup 时 RPC 已校验)。
|
|
|
|
|
func (o *GroupApi) SetInviteSetting(c *gin.Context) {
|
|
|
|
|
var req struct {
|
|
|
|
|
GroupID string `json:"groupID"`
|
|
|
|
|
AllowAddMember int32 `json:"allowAddMember"`
|
|
|
|
|
}
|
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
|
apiresp.GinError(c, errs.ErrArgs.WrapMsg(err.Error()))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if req.GroupID == "" {
|
|
|
|
|
apiresp.GinError(c, errs.ErrArgs.WrapMsg("groupID is empty"))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if req.AllowAddMember != 0 && req.AllowAddMember != 1 {
|
|
|
|
|
apiresp.GinError(c, errs.ErrArgs.WrapMsg("allowAddMember must be 0 or 1"))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
resp, err := o.Client.SetGroupInfoEx(c.Request.Context(), &group.SetGroupInfoExReq{
|
|
|
|
|
GroupID: req.GroupID,
|
|
|
|
|
AllowAddMember: wrapperspb.Int32(req.AllowAddMember),
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
apiresp.GinError(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
apiresp.GinSuccess(c, resp)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetInviteSetting 返回当前群的 allowAddMember(与 get_groups_info 中字段一致)。
|
|
|
|
|
func (o *GroupApi) GetInviteSetting(c *gin.Context) {
|
|
|
|
|
var req struct {
|
|
|
|
|
GroupID string `json:"groupID"`
|
|
|
|
|
}
|
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
|
apiresp.GinError(c, errs.ErrArgs.WrapMsg(err.Error()))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if req.GroupID == "" {
|
|
|
|
|
apiresp.GinError(c, errs.ErrArgs.WrapMsg("groupID is empty"))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
resp, err := o.Client.GetGroupsInfo(c.Request.Context(), &group.GetGroupsInfoReq{
|
|
|
|
|
GroupIDs: []string{req.GroupID},
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
apiresp.GinError(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if len(resp.GroupInfos) == 0 {
|
|
|
|
|
apiresp.GinError(c, errs.ErrRecordNotFound.WrapMsg("group not found", "groupID", req.GroupID))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
gi := resp.GroupInfos[0]
|
|
|
|
|
apiresp.GinSuccess(c, struct {
|
|
|
|
|
GroupID string `json:"groupID"`
|
|
|
|
|
AllowAddMember int32 `json:"allowAddMember"`
|
|
|
|
|
}{
|
|
|
|
|
GroupID: gi.GroupID,
|
|
|
|
|
AllowAddMember: gi.GetAllowAddMember(),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetPinSetting 设置群成员置顶消息权限:allowPinMsg 0=全员可置顶,1=仅群主/管理员(委托 SetGroupInfoEx;置顶/取消置顶走 pin_group_message / unpin_group_message 时 RPC 已校验)。
|
|
|
|
|
func (o *GroupApi) SetPinSetting(c *gin.Context) {
|
|
|
|
|
var req struct {
|
|
|
|
|
GroupID string `json:"groupID"`
|
|
|
|
|
AllowPinMsg int32 `json:"allowPinMsg"`
|
|
|
|
|
}
|
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
|
apiresp.GinError(c, errs.ErrArgs.WrapMsg(err.Error()))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if req.GroupID == "" {
|
|
|
|
|
apiresp.GinError(c, errs.ErrArgs.WrapMsg("groupID is empty"))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if req.AllowPinMsg != 0 && req.AllowPinMsg != 1 {
|
|
|
|
|
apiresp.GinError(c, errs.ErrArgs.WrapMsg("allowPinMsg must be 0 or 1"))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
resp, err := o.Client.SetGroupInfoEx(c.Request.Context(), &group.SetGroupInfoExReq{
|
|
|
|
|
GroupID: req.GroupID,
|
|
|
|
|
AllowPinMsg: wrapperspb.Int32(req.AllowPinMsg),
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
apiresp.GinError(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
apiresp.GinSuccess(c, resp)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetPinSetting 返回当前群的 allowPinMsg(与 get_groups_info 中字段一致)。
|
|
|
|
|
func (o *GroupApi) GetPinSetting(c *gin.Context) {
|
|
|
|
|
var req struct {
|
|
|
|
|
GroupID string `json:"groupID"`
|
|
|
|
|
}
|
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
|
apiresp.GinError(c, errs.ErrArgs.WrapMsg(err.Error()))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if req.GroupID == "" {
|
|
|
|
|
apiresp.GinError(c, errs.ErrArgs.WrapMsg("groupID is empty"))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
resp, err := o.Client.GetGroupsInfo(c.Request.Context(), &group.GetGroupsInfoReq{
|
|
|
|
|
GroupIDs: []string{req.GroupID},
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
apiresp.GinError(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if len(resp.GroupInfos) == 0 {
|
|
|
|
|
apiresp.GinError(c, errs.ErrRecordNotFound.WrapMsg("group not found", "groupID", req.GroupID))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
gi := resp.GroupInfos[0]
|
|
|
|
|
apiresp.GinSuccess(c, struct {
|
|
|
|
|
GroupID string `json:"groupID"`
|
|
|
|
|
AllowPinMsg int32 `json:"allowPinMsg"`
|
|
|
|
|
}{
|
|
|
|
|
GroupID: gi.GroupID,
|
|
|
|
|
AllowPinMsg: gi.GetAllowPinMsg(),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetEditSetting 设置群成员编辑群资料权限:allowEditGroupInfo 0=全员可编辑,1=仅群主/管理员(委托 SetGroupInfoEx;改群资料走 set_group_info / set_group_info_ex 时 RPC 已校验)。
|
|
|
|
|
func (o *GroupApi) SetEditSetting(c *gin.Context) {
|
|
|
|
|
var req struct {
|
|
|
|
|
GroupID string `json:"groupID"`
|
|
|
|
|
AllowEditGroupInfo int32 `json:"allowEditGroupInfo"`
|
|
|
|
|
}
|
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
|
apiresp.GinError(c, errs.ErrArgs.WrapMsg(err.Error()))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if req.GroupID == "" {
|
|
|
|
|
apiresp.GinError(c, errs.ErrArgs.WrapMsg("groupID is empty"))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if req.AllowEditGroupInfo != 0 && req.AllowEditGroupInfo != 1 {
|
|
|
|
|
apiresp.GinError(c, errs.ErrArgs.WrapMsg("allowEditGroupInfo must be 0 or 1"))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
resp, err := o.Client.SetGroupInfoEx(c.Request.Context(), &group.SetGroupInfoExReq{
|
|
|
|
|
GroupID: req.GroupID,
|
|
|
|
|
AllowEditGroupInfo: wrapperspb.Int32(req.AllowEditGroupInfo),
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
apiresp.GinError(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
apiresp.GinSuccess(c, resp)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetEditSetting 返回当前群的 allowEditGroupInfo(与 get_groups_info 中字段一致)。
|
|
|
|
|
func (o *GroupApi) GetEditSetting(c *gin.Context) {
|
|
|
|
|
var req struct {
|
|
|
|
|
GroupID string `json:"groupID"`
|
|
|
|
|
}
|
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
|
apiresp.GinError(c, errs.ErrArgs.WrapMsg(err.Error()))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if req.GroupID == "" {
|
|
|
|
|
apiresp.GinError(c, errs.ErrArgs.WrapMsg("groupID is empty"))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
resp, err := o.Client.GetGroupsInfo(c.Request.Context(), &group.GetGroupsInfoReq{
|
|
|
|
|
GroupIDs: []string{req.GroupID},
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
apiresp.GinError(c, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if len(resp.GroupInfos) == 0 {
|
|
|
|
|
apiresp.GinError(c, errs.ErrRecordNotFound.WrapMsg("group not found", "groupID", req.GroupID))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
gi := resp.GroupInfos[0]
|
|
|
|
|
apiresp.GinSuccess(c, struct {
|
|
|
|
|
GroupID string `json:"groupID"`
|
|
|
|
|
AllowEditGroupInfo int32 `json:"allowEditGroupInfo"`
|
|
|
|
|
}{
|
|
|
|
|
GroupID: gi.GroupID,
|
|
|
|
|
AllowEditGroupInfo: gi.GetAllowEditGroupInfo(),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (o *GroupApi) JoinGroup(c *gin.Context) {
|
|
|
|
|
a2r.Call(c, group.GroupClient.JoinGroup, o.Client)
|
|
|
|
|
}
|
|
|
|
|
|