You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/internal/rpc/group/callback.go

140 lines
4.8 KiB

3 years ago
package group
import (
2 years ago
"OpenIM/pkg/apistruct"
"OpenIM/pkg/callbackstruct"
"OpenIM/pkg/common/config"
"OpenIM/pkg/common/constant"
"OpenIM/pkg/common/db/table/relation"
"OpenIM/pkg/common/http"
"OpenIM/pkg/common/tracelog"
"OpenIM/pkg/proto/group"
"OpenIM/pkg/utils"
2 years ago
"context"
"google.golang.org/protobuf/types/known/wrapperspb"
2 years ago
"time"
3 years ago
)
2 years ago
func CallbackBeforeCreateGroup(ctx context.Context, req *group.CreateGroupReq) (err error) {
2 years ago
if !config.Config.Callback.CallbackBeforeCreateGroup.Enable {
2 years ago
return nil
2 years ago
}
2 years ago
defer func() {
tracelog.SetCtxInfo(ctx, utils.GetFuncName(1), err, "req", req)
}()
2 years ago
cbReq := &callbackstruct.CallbackBeforeCreateGroupReq{
2 years ago
CallbackCommand: constant.CallbackBeforeCreateGroupCommand,
2 years ago
OperationID: tracelog.GetOperationID(ctx),
GroupInfo: *req.GroupInfo,
2 years ago
}
2 years ago
cbReq.InitMemberList = append(cbReq.InitMemberList, &apistruct.GroupAddMemberInfo{
2 years ago
UserID: req.OwnerUserID,
RoleLevel: constant.GroupOwner,
})
for _, userID := range req.AdminUserIDs {
2 years ago
cbReq.InitMemberList = append(cbReq.InitMemberList, &apistruct.GroupAddMemberInfo{
2 years ago
UserID: userID,
RoleLevel: constant.GroupAdmin,
})
}
for _, userID := range req.AdminUserIDs {
2 years ago
cbReq.InitMemberList = append(cbReq.InitMemberList, &apistruct.GroupAddMemberInfo{
2 years ago
UserID: userID,
RoleLevel: constant.GroupOrdinaryUsers,
})
}
2 years ago
resp := &callbackstruct.CallbackBeforeCreateGroupResp{}
2 years ago
err = http.CallBackPostReturn(config.Config.Callback.CallbackUrl, cbReq, resp, config.Config.Callback.CallbackBeforeCreateGroup)
2 years ago
if err != nil {
return err
2 years ago
}
2 years ago
utils.NotNilReplace(&req.GroupInfo.GroupID, resp.GroupID)
utils.NotNilReplace(&req.GroupInfo.GroupName, resp.GroupName)
utils.NotNilReplace(&req.GroupInfo.Notification, resp.Notification)
utils.NotNilReplace(&req.GroupInfo.Introduction, resp.Introduction)
utils.NotNilReplace(&req.GroupInfo.FaceURL, resp.FaceURL)
utils.NotNilReplace(&req.GroupInfo.OwnerUserID, resp.OwnerUserID)
utils.NotNilReplace(&req.GroupInfo.Ex, resp.Ex)
utils.NotNilReplace(&req.GroupInfo.Status, resp.Status)
utils.NotNilReplace(&req.GroupInfo.CreatorUserID, resp.CreatorUserID)
utils.NotNilReplace(&req.GroupInfo.GroupType, resp.GroupType)
utils.NotNilReplace(&req.GroupInfo.NeedVerification, resp.NeedVerification)
utils.NotNilReplace(&req.GroupInfo.LookMemberInfo, resp.LookMemberInfo)
2 years ago
return nil
3 years ago
}
2 years ago
func CallbackBeforeMemberJoinGroup(ctx context.Context, groupMember *relation.GroupMemberModel, groupEx string) (err error) {
if !config.Config.Callback.CallbackBeforeMemberJoinGroup.Enable {
2 years ago
return nil
}
2 years ago
defer func() {
tracelog.SetCtxInfo(ctx, utils.GetFuncName(1), err, "groupMember", *groupMember, "groupEx", groupEx)
}()
2 years ago
callbackReq := &callbackstruct.CallbackBeforeMemberJoinGroupReq{
CallbackCommand: constant.CallbackBeforeMemberJoinGroupCommand,
2 years ago
OperationID: tracelog.GetOperationID(ctx),
GroupID: groupMember.GroupID,
UserID: groupMember.UserID,
Ex: groupMember.Ex,
GroupEx: groupEx,
}
2 years ago
resp := &callbackstruct.CallbackBeforeMemberJoinGroupResp{}
2 years ago
err = http.CallBackPostReturn(config.Config.Callback.CallbackUrl, callbackReq, resp, config.Config.Callback.CallbackBeforeMemberJoinGroup)
2 years ago
if err != nil {
return err
}
2 years ago
if resp.MuteEndTime != nil {
2 years ago
groupMember.MuteEndTime = time.UnixMilli(*resp.MuteEndTime)
2 years ago
}
2 years ago
utils.NotNilReplace(&groupMember.FaceURL, resp.FaceURL)
utils.NotNilReplace(&groupMember.Ex, resp.Ex)
utils.NotNilReplace(&groupMember.Nickname, resp.Nickname)
utils.NotNilReplace(&groupMember.RoleLevel, resp.RoleLevel)
2 years ago
return nil
}
2 years ago
func CallbackBeforeSetGroupMemberInfo(ctx context.Context, req *group.SetGroupMemberInfo) (err error) {
if !config.Config.Callback.CallbackBeforeSetGroupMemberInfo.Enable {
2 years ago
return nil
}
2 years ago
defer func() {
tracelog.SetCtxInfo(ctx, utils.GetFuncName(1), err, "req", *req)
}()
callbackReq := callbackstruct.CallbackBeforeSetGroupMemberInfoReq{
CallbackCommand: constant.CallbackBeforeSetGroupMemberInfoCommand,
2 years ago
OperationID: tracelog.GetOperationID(ctx),
GroupID: req.GroupID,
UserID: req.UserID,
}
if req.Nickname != nil {
2 years ago
callbackReq.Nickname = &req.Nickname.Value
}
if req.FaceURL != nil {
2 years ago
callbackReq.FaceURL = &req.FaceURL.Value
}
if req.RoleLevel != nil {
2 years ago
callbackReq.RoleLevel = &req.RoleLevel.Value
}
if req.Ex != nil {
2 years ago
callbackReq.Ex = &req.Ex.Value
}
2 years ago
resp := &callbackstruct.CallbackBeforeSetGroupMemberInfoResp{}
2 years ago
err = http.CallBackPostReturn(config.Config.Callback.CallbackUrl, callbackReq, resp, config.Config.Callback.CallbackBeforeSetGroupMemberInfo)
2 years ago
if err != nil {
return err
}
if resp.FaceURL != nil {
2 years ago
req.FaceURL = wrapperspb.String(*resp.FaceURL)
2 years ago
}
if resp.Nickname != nil {
2 years ago
req.Nickname = wrapperspb.String(*resp.Nickname)
2 years ago
}
if resp.RoleLevel != nil {
2 years ago
req.RoleLevel = wrapperspb.Int32(*resp.RoleLevel)
2 years ago
}
if resp.Ex != nil {
2 years ago
req.Ex = wrapperspb.String(*resp.Ex)
}
2 years ago
return nil
}