mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-21 01:09:01 +08:00
pkg
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package a2r
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/apiresp"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
|
||||
"github.com/gin-gonic/gin"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func Call[A, B, C any](
|
||||
rpc func(client C, ctx context.Context, req *A, options ...grpc.CallOption) (*B, error),
|
||||
client func() (C, error),
|
||||
c *gin.Context,
|
||||
) {
|
||||
var req A
|
||||
if err := c.BindJSON(&req); err != nil {
|
||||
log.ZWarn(c, "gin bind json error", err, "req", req)
|
||||
apiresp.GinError(c, errs.ErrArgs.WithDetail(err.Error()).Wrap()) // 参数错误
|
||||
return
|
||||
}
|
||||
if check, ok := any(&req).(interface{ Check() error }); ok {
|
||||
if err := check.Check(); err != nil {
|
||||
log.ZWarn(c, "custom check error", err, "req", req)
|
||||
apiresp.GinError(c, errs.ErrArgs.Wrap(err.Error())) // 参数校验失败
|
||||
return
|
||||
}
|
||||
}
|
||||
cli, err := client()
|
||||
if err != nil {
|
||||
log.ZError(c, "get conn error", err, "req", req)
|
||||
apiresp.GinError(c, errs.ErrInternalServer.Wrap(err.Error())) // 获取RPC连接失败
|
||||
return
|
||||
}
|
||||
data, err := rpc(cli, c, &req)
|
||||
if err != nil {
|
||||
apiresp.GinError(c, err) // RPC调用失败
|
||||
return
|
||||
}
|
||||
apiresp.GinSuccess(c, data) // 成功
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package apiresp
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GinError(c *gin.Context, err error) {
|
||||
if err == nil {
|
||||
GinSuccess(c, nil)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, apiError(err))
|
||||
}
|
||||
|
||||
func GinSuccess(c *gin.Context, data any) {
|
||||
c.JSON(http.StatusOK, apiSuccess(data))
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package apiresp
|
||||
|
||||
import (
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type apiResponse struct {
|
||||
ErrCode int `json:"errCode"`
|
||||
ErrMsg string `json:"errMsg"`
|
||||
ErrDlt string `json:"errDlt"`
|
||||
Data any `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
func isAllFieldsPrivate(v any) bool {
|
||||
typeOf := reflect.TypeOf(v)
|
||||
if typeOf.Kind() == reflect.Ptr {
|
||||
typeOf = typeOf.Elem()
|
||||
}
|
||||
if typeOf.Kind() != reflect.Struct {
|
||||
return false
|
||||
}
|
||||
num := typeOf.NumField()
|
||||
for i := 0; i < num; i++ {
|
||||
c := typeOf.Field(i).Name[0]
|
||||
if c >= 'A' && c <= 'Z' {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func apiSuccess(data any) *apiResponse {
|
||||
if isAllFieldsPrivate(data) {
|
||||
return &apiResponse{}
|
||||
}
|
||||
return &apiResponse{
|
||||
Data: data,
|
||||
}
|
||||
}
|
||||
|
||||
func apiError(err error) *apiResponse {
|
||||
unwrap := errs.Unwrap(err)
|
||||
if codeErr, ok := unwrap.(errs.CodeError); ok {
|
||||
return &apiResponse{ErrCode: codeErr.Code(), ErrMsg: codeErr.Msg(), ErrDlt: codeErr.Detail()}
|
||||
}
|
||||
return &apiResponse{ErrCode: errs.ServerInternalError, ErrMsg: err.Error()}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package network
|
||||
|
||||
import (
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||
utils "github.com/OpenIMSDK/open_utils"
|
||||
)
|
||||
|
||||
func GetRpcRegisterIP(configIP string) (string, error) {
|
||||
registerIP := configIP
|
||||
if registerIP == "" {
|
||||
ip, err := utils.GetLocalIP()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
registerIP = ip
|
||||
}
|
||||
return registerIP, nil
|
||||
}
|
||||
|
||||
func GetListenIP(configIP string) string {
|
||||
if configIP == "" {
|
||||
return constant.LocalHost
|
||||
} else {
|
||||
return configIP
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package check
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/tokenverify"
|
||||
)
|
||||
|
||||
func (u *UserCheck) Access(ctx context.Context, ownerUserID string) (err error) {
|
||||
_, err = u.GetUserInfo(ctx, ownerUserID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return tokenverify.CheckAccessV3(ctx, ownerUserID)
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package check
|
||||
|
||||
import (
|
||||
"context"
|
||||
discoveryRegistry "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
||||
)
|
||||
|
||||
type BlackChecker struct {
|
||||
zk discoveryRegistry.SvcDiscoveryRegistry
|
||||
}
|
||||
|
||||
func NewBlackChecker(zk discoveryRegistry.SvcDiscoveryRegistry) *BlackChecker {
|
||||
return &BlackChecker{
|
||||
zk: zk,
|
||||
}
|
||||
}
|
||||
|
||||
// possibleBlackUserID是否被userID拉黑,也就是是否在userID的黑名单中
|
||||
func (b *BlackChecker) IsBlocked(ctx context.Context, possibleBlackUserID, userID string) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package check
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||
discoveryRegistry "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation"
|
||||
pbConversation "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type ConversationChecker struct {
|
||||
zk discoveryRegistry.SvcDiscoveryRegistry
|
||||
}
|
||||
|
||||
func NewConversationChecker(zk discoveryRegistry.SvcDiscoveryRegistry) *ConversationChecker {
|
||||
return &ConversationChecker{zk: zk}
|
||||
}
|
||||
|
||||
func (c *ConversationChecker) ModifyConversationField(ctx context.Context, req *pbConversation.ModifyConversationFieldReq) error {
|
||||
cc, err := c.getConn()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = conversation.NewConversationClient(cc).ModifyConversationField(ctx, req)
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *ConversationChecker) getConn() (*grpc.ClientConn, error) {
|
||||
return c.zk.GetConn(config.Config.RpcRegisterName.OpenImConversationName)
|
||||
}
|
||||
|
||||
func (c *ConversationChecker) GetSingleConversationRecvMsgOpt(ctx context.Context, userID, conversationID string) (int32, error) {
|
||||
cc, err := c.getConn()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
var req conversation.GetConversationReq
|
||||
req.OwnerUserID = userID
|
||||
req.ConversationID = conversationID
|
||||
sConversation, err := conversation.NewConversationClient(cc).GetConversation(ctx, &req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return sConversation.GetConversation().RecvMsgOpt, err
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package check
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||
discoveryRegistry "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/friend"
|
||||
sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type FriendChecker struct {
|
||||
zk discoveryRegistry.SvcDiscoveryRegistry
|
||||
}
|
||||
|
||||
func NewFriendChecker(zk discoveryRegistry.SvcDiscoveryRegistry) *FriendChecker {
|
||||
return &FriendChecker{
|
||||
zk: zk,
|
||||
}
|
||||
}
|
||||
|
||||
func (f *FriendChecker) GetFriendsInfo(ctx context.Context, ownerUserID, friendUserID string) (resp *sdkws.FriendInfo, err error) {
|
||||
cc, err := f.getConn()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r, err := friend.NewFriendClient(cc).GetDesignatedFriends(ctx, &friend.GetDesignatedFriendsReq{OwnerUserID: ownerUserID, FriendUserIDs: []string{friendUserID}})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp = r.FriendsInfo[0]
|
||||
return
|
||||
}
|
||||
func (f *FriendChecker) getConn() (*grpc.ClientConn, error) {
|
||||
return f.zk.GetConn(config.Config.RpcRegisterName.OpenImFriendName)
|
||||
}
|
||||
|
||||
// possibleFriendUserID是否在userID的好友中
|
||||
func (f *FriendChecker) IsFriend(ctx context.Context, possibleFriendUserID, userID string) (bool, error) {
|
||||
cc, err := f.getConn()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
resp, err := friend.NewFriendClient(cc).IsFriend(ctx, &friend.IsFriendReq{UserID1: userID, UserID2: possibleFriendUserID})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return resp.InUser1Friends, nil
|
||||
|
||||
}
|
||||
|
||||
func (f *FriendChecker) GetFriendIDs(ctx context.Context, ownerUserID string) (friendIDs []string, err error) {
|
||||
cc, err := f.getConn()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req := friend.GetFriendIDsReq{UserID: ownerUserID}
|
||||
resp, err := friend.NewFriendClient(cc).GetFriendIDs(ctx, &req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.FriendIDs, err
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package check
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||
discoveryRegistry "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/group"
|
||||
sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
|
||||
"google.golang.org/grpc"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type GroupChecker struct {
|
||||
zk discoveryRegistry.SvcDiscoveryRegistry
|
||||
}
|
||||
|
||||
func NewGroupChecker(zk discoveryRegistry.SvcDiscoveryRegistry) *GroupChecker {
|
||||
return &GroupChecker{
|
||||
zk: zk,
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GroupChecker) getConn() (*grpc.ClientConn, error) {
|
||||
return g.zk.GetConn(config.Config.RpcRegisterName.OpenImGroupName)
|
||||
}
|
||||
|
||||
func (g *GroupChecker) GetGroupInfos(ctx context.Context, groupIDs []string, complete bool) ([]*sdkws.GroupInfo, error) {
|
||||
cc, err := g.getConn()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := group.NewGroupClient(cc).GetGroupsInfo(ctx, &group.GetGroupsInfoReq{
|
||||
GroupIDs: groupIDs,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if complete {
|
||||
if ids := utils.Single(groupIDs, utils.Slice(resp.GroupInfos, func(e *sdkws.GroupInfo) string {
|
||||
return e.GroupID
|
||||
})); len(ids) > 0 {
|
||||
return nil, errs.ErrGroupIDNotFound.Wrap(strings.Join(ids, ","))
|
||||
}
|
||||
}
|
||||
return resp.GroupInfos, nil
|
||||
}
|
||||
|
||||
func (g *GroupChecker) GetGroupInfo(ctx context.Context, groupID string) (*sdkws.GroupInfo, error) {
|
||||
groups, err := g.GetGroupInfos(ctx, []string{groupID}, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return groups[0], nil
|
||||
}
|
||||
|
||||
func (g *GroupChecker) GetGroupInfoMap(ctx context.Context, groupIDs []string, complete bool) (map[string]*sdkws.GroupInfo, error) {
|
||||
groups, err := g.GetGroupInfos(ctx, groupIDs, complete)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return utils.SliceToMap(groups, func(e *sdkws.GroupInfo) string {
|
||||
return e.GroupID
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (g *GroupChecker) GetGroupMemberInfos(ctx context.Context, groupID string, userIDs []string, complete bool) ([]*sdkws.GroupMemberFullInfo, error) {
|
||||
cc, err := g.getConn()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := group.NewGroupClient(cc).GetGroupMembersInfo(ctx, &group.GetGroupMembersInfoReq{
|
||||
GroupID: groupID,
|
||||
Members: userIDs,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if complete {
|
||||
if ids := utils.Single(userIDs, utils.Slice(resp.Members, func(e *sdkws.GroupMemberFullInfo) string {
|
||||
return e.UserID
|
||||
})); len(ids) > 0 {
|
||||
return nil, errs.ErrNotInGroupYet.Wrap(strings.Join(ids, ","))
|
||||
}
|
||||
}
|
||||
return resp.Members, nil
|
||||
}
|
||||
|
||||
func (g *GroupChecker) GetGroupMemberInfo(ctx context.Context, groupID string, userID string) (*sdkws.GroupMemberFullInfo, error) {
|
||||
members, err := g.GetGroupMemberInfos(ctx, groupID, []string{userID}, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return members[0], nil
|
||||
}
|
||||
|
||||
func (g *GroupChecker) GetGroupMemberInfoMap(ctx context.Context, groupID string, userIDs []string, complete bool) (map[string]*sdkws.GroupMemberFullInfo, error) {
|
||||
members, err := g.GetGroupMemberInfos(ctx, groupID, userIDs, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return utils.SliceToMap(members, func(e *sdkws.GroupMemberFullInfo) string {
|
||||
return e.UserID
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (g *GroupChecker) GetOwnerAndAdminInfos(ctx context.Context, groupID string) ([]*sdkws.GroupMemberFullInfo, error) {
|
||||
cc, err := g.getConn()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := group.NewGroupClient(cc).GetGroupMemberRoleLevel(ctx, &group.GetGroupMemberRoleLevelReq{
|
||||
GroupID: groupID,
|
||||
RoleLevels: []int32{constant.GroupOwner, constant.GroupAdmin},
|
||||
})
|
||||
return resp.Members, err
|
||||
}
|
||||
|
||||
func (g *GroupChecker) GetOwnerInfo(ctx context.Context, groupID string) (*sdkws.GroupMemberFullInfo, error) {
|
||||
cc, err := g.getConn()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := group.NewGroupClient(cc).GetGroupMemberRoleLevel(ctx, &group.GetGroupMemberRoleLevelReq{
|
||||
GroupID: groupID,
|
||||
RoleLevels: []int32{constant.GroupOwner},
|
||||
})
|
||||
return resp.Members[0], err
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package check
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||
discoveryRegistry "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type MsgCheck struct {
|
||||
zk discoveryRegistry.SvcDiscoveryRegistry
|
||||
}
|
||||
|
||||
func NewMsgCheck(zk discoveryRegistry.SvcDiscoveryRegistry) *MsgCheck {
|
||||
return &MsgCheck{zk: zk}
|
||||
}
|
||||
|
||||
func (m *MsgCheck) getConn() (*grpc.ClientConn, error) {
|
||||
return m.zk.GetConn(config.Config.RpcRegisterName.OpenImMsgName)
|
||||
}
|
||||
|
||||
func (m *MsgCheck) SendMsg(ctx context.Context, req *msg.SendMsgReq) (*msg.SendMsgResp, error) {
|
||||
cc, err := m.getConn()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := msg.NewMsgClient(cc).SendMsg(ctx, req)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (m *MsgCheck) GetMaxAndMinSeq(ctx context.Context, req *sdkws.GetMaxAndMinSeqReq) (*sdkws.GetMaxAndMinSeqResp, error) {
|
||||
cc, err := m.getConn()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := msg.NewMsgClient(cc).GetMaxAndMinSeq(ctx, req)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (m *MsgCheck) PullMessageBySeqList(ctx context.Context, req *sdkws.PullMessageBySeqsReq) (*sdkws.PullMessageBySeqsResp, error) {
|
||||
cc, err := m.getConn()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := msg.NewMsgClient(cc).PullMessageBySeqs(ctx, req)
|
||||
return resp, err
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package check
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/user"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
|
||||
"google.golang.org/grpc"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func NewUserCheck(client discoveryregistry.SvcDiscoveryRegistry) *UserCheck {
|
||||
return &UserCheck{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
|
||||
type UserCheck struct {
|
||||
client discoveryregistry.SvcDiscoveryRegistry
|
||||
}
|
||||
|
||||
func (u *UserCheck) getConn() (*grpc.ClientConn, error) {
|
||||
return u.client.GetConn(config.Config.RpcRegisterName.OpenImUserName)
|
||||
}
|
||||
|
||||
func (u *UserCheck) GetUsersInfos(ctx context.Context, userIDs []string, complete bool) ([]*sdkws.UserInfo, error) {
|
||||
cc, err := u.getConn()
|
||||
if err != nil {
|
||||
log.Error("", "call getConn err", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
resp, err := user.NewUserClient(cc).GetDesignateUsers(ctx, &user.GetDesignateUsersReq{
|
||||
UserIDs: userIDs,
|
||||
})
|
||||
if err != nil {
|
||||
log.Error("", "call GetDesignateUsers err", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
if complete {
|
||||
if ids := utils.Single(userIDs, utils.Slice(resp.UsersInfo, func(e *sdkws.UserInfo) string {
|
||||
return e.UserID
|
||||
})); len(ids) > 0 {
|
||||
return nil, errs.ErrUserIDNotFound.Wrap(strings.Join(ids, ","))
|
||||
}
|
||||
}
|
||||
return resp.UsersInfo, nil
|
||||
}
|
||||
|
||||
func (u *UserCheck) GetUserInfo(ctx context.Context, userID string) (*sdkws.UserInfo, error) {
|
||||
users, err := u.GetUsersInfos(ctx, []string{userID}, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return users[0], nil
|
||||
}
|
||||
|
||||
func (u *UserCheck) GetUsersInfoMap(ctx context.Context, userIDs []string, complete bool) (map[string]*sdkws.UserInfo, error) {
|
||||
users, err := u.GetUsersInfos(ctx, userIDs, complete)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return utils.SliceToMap(users, func(e *sdkws.UserInfo) string {
|
||||
return e.UserID
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (u *UserCheck) GetPublicUserInfos(ctx context.Context, userIDs []string, complete bool) ([]*sdkws.PublicUserInfo, error) {
|
||||
users, err := u.GetUsersInfos(ctx, userIDs, complete)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return utils.Slice(users, func(e *sdkws.UserInfo) *sdkws.PublicUserInfo {
|
||||
return &sdkws.PublicUserInfo{
|
||||
UserID: e.UserID,
|
||||
Nickname: e.Nickname,
|
||||
FaceURL: e.FaceURL,
|
||||
Gender: e.Gender,
|
||||
Ex: e.Ex,
|
||||
}
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (u *UserCheck) GetPublicUserInfo(ctx context.Context, userID string) (*sdkws.PublicUserInfo, error) {
|
||||
users, err := u.GetPublicUserInfos(ctx, []string{userID}, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return users[0], nil
|
||||
}
|
||||
|
||||
func (u *UserCheck) GetPublicUserInfoMap(ctx context.Context, userIDs []string, complete bool) (map[string]*sdkws.PublicUserInfo, error) {
|
||||
users, err := u.GetPublicUserInfos(ctx, userIDs, complete)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return utils.SliceToMap(users, func(e *sdkws.PublicUserInfo) string {
|
||||
return e.UserID
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (u *UserCheck) GetUserGlobalMsgRecvOpt(ctx context.Context, userID string) (int32, error) {
|
||||
cc, err := u.getConn()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
resp, err := user.NewUserClient(cc).GetGlobalRecvMessageOpt(ctx, &user.GetGlobalRecvMessageOptReq{
|
||||
UserID: userID,
|
||||
})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return resp.GlobalRecvMsgOpt, err
|
||||
}
|
||||
@@ -0,0 +1,475 @@
|
||||
package convert
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
|
||||
discoveryRegistry "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
||||
sdk "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/check"
|
||||
utils2 "github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
|
||||
utils "github.com/OpenIMSDK/open_utils"
|
||||
"time"
|
||||
)
|
||||
|
||||
type DBFriend struct {
|
||||
*relation.FriendModel
|
||||
userCheck *check.UserCheck
|
||||
}
|
||||
|
||||
func NewDBFriend(friend *relation.FriendModel, zk discoveryRegistry.SvcDiscoveryRegistry) *DBFriend {
|
||||
return &DBFriend{FriendModel: friend, userCheck: check.NewUserCheck(zk)}
|
||||
}
|
||||
|
||||
type PBFriend struct {
|
||||
*sdk.FriendInfo
|
||||
}
|
||||
|
||||
func NewPBFriend(friendInfo *sdk.FriendInfo) *PBFriend {
|
||||
return &PBFriend{FriendInfo: friendInfo}
|
||||
}
|
||||
|
||||
func (*PBFriend) PB2DB(friends []*sdk.FriendInfo) (DBFriends []*relation.FriendModel, err error) {
|
||||
for _, v := range friends {
|
||||
u, err := NewPBFriend(v).Convert()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
DBFriends = append(DBFriends, u)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (db *DBFriend) DB2PB(ctx context.Context, friends []*relation.FriendModel) (PBFriends []*sdk.FriendInfo, err error) {
|
||||
userIDs := utils2.Slice(friends, func(e *relation.FriendModel) string { return e.FriendUserID })
|
||||
users, err := db.userCheck.GetUsersInfoMap(ctx, userIDs, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range friends {
|
||||
pbfriend := &sdk.FriendInfo{FriendUser: &sdk.UserInfo{}}
|
||||
utils.CopyStructFields(pbfriend, users[v.OwnerUserID])
|
||||
utils.CopyStructFields(pbfriend.FriendUser, users[v.FriendUserID])
|
||||
pbfriend.CreateTime = v.CreateTime.Unix()
|
||||
pbfriend.FriendUser.CreateTime = v.CreateTime.Unix()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (db *DBFriend) Convert(ctx context.Context) (*sdk.FriendInfo, error) {
|
||||
pbfriend := &sdk.FriendInfo{FriendUser: &sdk.UserInfo{}}
|
||||
utils.CopyStructFields(pbfriend, db)
|
||||
user, err := db.userCheck.GetUserInfo(ctx, db.FriendUserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
utils.CopyStructFields(pbfriend.FriendUser, user)
|
||||
pbfriend.CreateTime = db.CreateTime.Unix()
|
||||
|
||||
pbfriend.FriendUser.CreateTime = db.CreateTime.Unix()
|
||||
return pbfriend, nil
|
||||
}
|
||||
|
||||
func (pb *PBFriend) Convert() (*relation.FriendModel, error) {
|
||||
dbFriend := &relation.FriendModel{}
|
||||
utils.CopyStructFields(dbFriend, pb)
|
||||
dbFriend.FriendUserID = pb.FriendUser.UserID
|
||||
dbFriend.CreateTime = utils.UnixSecondToTime(pb.CreateTime)
|
||||
return dbFriend, nil
|
||||
}
|
||||
|
||||
type DBFriendRequest struct {
|
||||
*relation.FriendRequestModel
|
||||
userCheck *check.UserCheck
|
||||
}
|
||||
|
||||
func NewDBFriendRequest(friendRequest *relation.FriendRequestModel, zk discoveryRegistry.SvcDiscoveryRegistry) *DBFriendRequest {
|
||||
return &DBFriendRequest{FriendRequestModel: friendRequest, userCheck: check.NewUserCheck(zk)}
|
||||
}
|
||||
|
||||
type PBFriendRequest struct {
|
||||
*sdk.FriendRequest
|
||||
}
|
||||
|
||||
func NewPBFriendRequest(friendRequest *sdk.FriendRequest) *PBFriendRequest {
|
||||
return &PBFriendRequest{FriendRequest: friendRequest}
|
||||
}
|
||||
|
||||
func (*PBFriendRequest) PB2DB(friendRequests []*sdk.FriendRequest) (DBFriendRequests []*relation.FriendRequestModel, err error) {
|
||||
for _, v := range friendRequests {
|
||||
u, err := NewPBFriendRequest(v).Convert()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
DBFriendRequests = append(DBFriendRequests, u)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (db *DBFriendRequest) DB2PB(ctx context.Context, friendRequests []*relation.FriendRequestModel) (PBFriendRequests []*sdk.FriendRequest, err error) {
|
||||
userIDs := make([]string, 0)
|
||||
if len(friendRequests) > 0 {
|
||||
userIDs = append(userIDs, friendRequests[0].FromUserID)
|
||||
}
|
||||
users, err := db.userCheck.GetUsersInfoMap(ctx, userIDs, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range friendRequests {
|
||||
pbFriendRequest := &sdk.FriendRequest{}
|
||||
pbFriendRequest.FromNickname = users[v.FromUserID].Nickname
|
||||
pbFriendRequest.FromFaceURL = users[v.FromUserID].FaceURL
|
||||
pbFriendRequest.FromGender = users[v.FromUserID].Gender
|
||||
pbFriendRequest.ToNickname = users[v.ToUserID].Nickname
|
||||
pbFriendRequest.ToFaceURL = users[v.ToUserID].FaceURL
|
||||
pbFriendRequest.ToGender = users[v.ToUserID].Gender
|
||||
pbFriendRequest.CreateTime = db.CreateTime.Unix()
|
||||
pbFriendRequest.HandleTime = db.HandleTime.Unix()
|
||||
PBFriendRequests = append(PBFriendRequests, pbFriendRequest)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (pb *PBFriendRequest) Convert() (*relation.FriendRequestModel, error) {
|
||||
dbFriendRequest := &relation.FriendRequestModel{}
|
||||
utils.CopyStructFields(dbFriendRequest, pb)
|
||||
dbFriendRequest.CreateTime = utils.UnixSecondToTime(int64(pb.CreateTime))
|
||||
dbFriendRequest.HandleTime = utils.UnixSecondToTime(int64(pb.HandleTime))
|
||||
return dbFriendRequest, nil
|
||||
}
|
||||
func (db *DBFriendRequest) Convert(ctx context.Context) (*sdk.FriendRequest, error) {
|
||||
pbFriendRequest := &sdk.FriendRequest{}
|
||||
utils.CopyStructFields(pbFriendRequest, db)
|
||||
user, err := db.userCheck.GetUserInfo(ctx, db.FromUserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pbFriendRequest.FromNickname = user.Nickname
|
||||
pbFriendRequest.FromFaceURL = user.FaceURL
|
||||
pbFriendRequest.FromGender = user.Gender
|
||||
user, err = db.userCheck.GetUserInfo(ctx, db.ToUserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pbFriendRequest.ToNickname = user.Nickname
|
||||
pbFriendRequest.ToFaceURL = user.FaceURL
|
||||
pbFriendRequest.ToGender = user.Gender
|
||||
pbFriendRequest.CreateTime = db.CreateTime.Unix()
|
||||
pbFriendRequest.HandleTime = db.HandleTime.Unix()
|
||||
return pbFriendRequest, nil
|
||||
}
|
||||
|
||||
type DBBlack struct {
|
||||
*relation.BlackModel
|
||||
userCheck *check.UserCheck
|
||||
}
|
||||
|
||||
func (*PBBlack) PB2DB(blacks []*sdk.BlackInfo) (DBBlacks []*relation.BlackModel, err error) {
|
||||
for _, v := range blacks {
|
||||
u, err := NewPBBlack(v).Convert()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
DBBlacks = append(DBBlacks, u)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (db *DBBlack) DB2PB(ctx context.Context, blacks []*relation.BlackModel) (PBBlacks []*sdk.BlackInfo, err error) {
|
||||
userIDs := make([]string, 0)
|
||||
for _, v := range blacks {
|
||||
userIDs = append(userIDs, v.BlockUserID)
|
||||
}
|
||||
if len(blacks) > 0 {
|
||||
userIDs = append(userIDs, blacks[0].OwnerUserID)
|
||||
}
|
||||
|
||||
users, err := db.userCheck.GetUsersInfoMap(ctx, userIDs, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, v := range blacks {
|
||||
pbBlack := &sdk.BlackInfo{}
|
||||
utils.CopyStructFields(pbBlack, users[v.OwnerUserID])
|
||||
utils.CopyStructFields(pbBlack.BlackUserInfo, users[v.BlockUserID])
|
||||
PBBlacks = append(PBBlacks, pbBlack)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func NewDBBlack(black *relation.BlackModel, zk discoveryRegistry.SvcDiscoveryRegistry) *DBBlack {
|
||||
return &DBBlack{BlackModel: black, userCheck: check.NewUserCheck(zk)}
|
||||
}
|
||||
|
||||
type PBBlack struct {
|
||||
*sdk.BlackInfo
|
||||
}
|
||||
|
||||
func NewPBBlack(blackInfo *sdk.BlackInfo) *PBBlack {
|
||||
return &PBBlack{BlackInfo: blackInfo}
|
||||
}
|
||||
|
||||
func (pb *PBBlack) Convert() (*relation.BlackModel, error) {
|
||||
dbBlack := &relation.BlackModel{}
|
||||
dbBlack.BlockUserID = pb.BlackUserInfo.UserID
|
||||
dbBlack.CreateTime = utils.UnixSecondToTime(pb.CreateTime)
|
||||
return dbBlack, nil
|
||||
}
|
||||
func (db *DBBlack) Convert(ctx context.Context) (*sdk.BlackInfo, error) {
|
||||
pbBlack := &sdk.BlackInfo{}
|
||||
utils.CopyStructFields(pbBlack, db)
|
||||
pbBlack.CreateTime = db.CreateTime.Unix()
|
||||
user, err := db.userCheck.GetUserInfo(ctx, db.BlockUserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
utils.CopyStructFields(pbBlack.BlackUserInfo, user)
|
||||
return pbBlack, nil
|
||||
}
|
||||
|
||||
type DBGroup struct {
|
||||
*relation.GroupModel
|
||||
zk discoveryRegistry.SvcDiscoveryRegistry
|
||||
groupCheck *check.GroupChecker
|
||||
}
|
||||
|
||||
func (*PBGroup) PB2DB(groups []*sdk.GroupInfo) (DBGroups []*relation.GroupModel, err error) {
|
||||
for _, v := range groups {
|
||||
u, err := NewPBGroup(v).Convert()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
DBGroups = append(DBGroups, u)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//func (db *DBGroup) DB2PB(ctx context.Context, zk discoveryRegistry.SvcDiscoveryRegistry, groups []*relation.GroupModel) (PBGroups []*sdk.GroupInfo, err error) {
|
||||
// for _, v := range groups {
|
||||
// u, err := NewDBGroup(v, zk).Convert(ctx)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// PBGroups = append(PBGroups, u)
|
||||
// }
|
||||
// return
|
||||
//}
|
||||
|
||||
func NewDBGroup(groupModel *relation.GroupModel, zk discoveryRegistry.SvcDiscoveryRegistry) *DBGroup {
|
||||
return &DBGroup{GroupModel: groupModel, groupCheck: check.NewGroupChecker(zk)}
|
||||
}
|
||||
|
||||
type PBGroup struct {
|
||||
*sdk.GroupInfo
|
||||
}
|
||||
|
||||
func NewPBGroup(groupInfo *sdk.GroupInfo) *PBGroup {
|
||||
return &PBGroup{GroupInfo: groupInfo}
|
||||
}
|
||||
|
||||
func (pb *PBGroup) Convert() (*relation.GroupModel, error) {
|
||||
dst := &relation.GroupModel{}
|
||||
err := utils.CopyStructFields(dst, pb)
|
||||
return dst, err
|
||||
}
|
||||
func (db *DBGroup) Convert(ctx context.Context) (*sdk.GroupInfo, error) {
|
||||
dst := &sdk.GroupInfo{}
|
||||
utils.CopyStructFields(dst, db)
|
||||
user, err := db.groupCheck.GetOwnerInfo(ctx, db.GroupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dst.OwnerUserID = user.UserID
|
||||
|
||||
g, err := db.groupCheck.GetGroupInfo(ctx, db.GroupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dst.MemberCount = g.MemberCount
|
||||
dst.CreateTime = db.CreateTime.Unix()
|
||||
dst.NotificationUpdateTime = db.NotificationUpdateTime.Unix()
|
||||
if db.NotificationUpdateTime.Unix() < 0 {
|
||||
dst.NotificationUpdateTime = 0
|
||||
}
|
||||
return dst, nil
|
||||
}
|
||||
|
||||
type DBGroupMember struct {
|
||||
*relation.GroupMemberModel
|
||||
userCheck *check.UserCheck
|
||||
}
|
||||
|
||||
func (*PBGroupMember) PB2DB(groupMembers []*sdk.GroupMemberFullInfo) (DBGroupMembers []*relation.GroupMemberModel, err error) {
|
||||
for _, v := range groupMembers {
|
||||
u, err := NewPBGroupMember(v).Convert()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
DBGroupMembers = append(DBGroupMembers, u)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//func (*DBGroupMember) DB2PB(ctx context.Context, groupMembers []*relation.GroupMemberModel) (PBGroupMembers []*sdk.GroupMemberFullInfo, err error) {
|
||||
// for _, v := range groupMembers {
|
||||
// u, err := NewDBGroupMember(v).Convert(ctx)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// PBGroupMembers = append(PBGroupMembers, u)
|
||||
// }
|
||||
// return
|
||||
//}
|
||||
|
||||
func NewDBGroupMember(groupMember *relation.GroupMemberModel) *DBGroupMember {
|
||||
return &DBGroupMember{GroupMemberModel: groupMember}
|
||||
}
|
||||
|
||||
type PBGroupMember struct {
|
||||
*sdk.GroupMemberFullInfo
|
||||
}
|
||||
|
||||
func NewPBGroupMember(groupMemberFullInfo *sdk.GroupMemberFullInfo) *PBGroupMember {
|
||||
return &PBGroupMember{GroupMemberFullInfo: groupMemberFullInfo}
|
||||
}
|
||||
|
||||
func (pb *PBGroupMember) Convert() (*relation.GroupMemberModel, error) {
|
||||
dst := &relation.GroupMemberModel{}
|
||||
utils.CopyStructFields(dst, pb)
|
||||
dst.JoinTime = utils.UnixSecondToTime(int64(pb.JoinTime))
|
||||
dst.MuteEndTime = utils.UnixSecondToTime(int64(pb.MuteEndTime))
|
||||
return dst, nil
|
||||
}
|
||||
func (db *DBGroupMember) Convert(ctx context.Context) (*sdk.GroupMemberFullInfo, error) {
|
||||
dst := &sdk.GroupMemberFullInfo{}
|
||||
utils.CopyStructFields(dst, db)
|
||||
|
||||
user, err := db.userCheck.GetUserInfo(ctx, db.UserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dst.AppMangerLevel = user.AppMangerLevel
|
||||
|
||||
dst.JoinTime = db.JoinTime.Unix()
|
||||
if db.JoinTime.Unix() < 0 {
|
||||
dst.JoinTime = 0
|
||||
}
|
||||
dst.MuteEndTime = db.MuteEndTime.Unix()
|
||||
if dst.MuteEndTime < time.Now().Unix() {
|
||||
dst.MuteEndTime = 0
|
||||
}
|
||||
return dst, nil
|
||||
}
|
||||
|
||||
type DBGroupRequest struct {
|
||||
*relation.GroupRequestModel
|
||||
}
|
||||
|
||||
func (*PBGroupRequest) PB2DB(groupRequests []*sdk.GroupRequest) (DBGroupRequests []*relation.GroupRequestModel, err error) {
|
||||
for _, v := range groupRequests {
|
||||
u, err := NewPBGroupRequest(v).Convert()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
DBGroupRequests = append(DBGroupRequests, u)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//func (*DBGroupRequest) DB2PB(groupRequests []*relation.GroupRequestModel) (PBGroupRequests []*sdk.GroupRequest, err error) {
|
||||
// for _, v := range groupRequests {
|
||||
// u, err := NewDBGroupRequest(v).Convert()
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// PBGroupRequests = append(PBGroupRequests, u)
|
||||
// }
|
||||
// return
|
||||
//}
|
||||
|
||||
func NewDBGroupRequest(groupRequest *relation.GroupRequestModel) *DBGroupRequest {
|
||||
return &DBGroupRequest{GroupRequestModel: groupRequest}
|
||||
}
|
||||
|
||||
type PBGroupRequest struct {
|
||||
*sdk.GroupRequest
|
||||
}
|
||||
|
||||
func NewPBGroupRequest(groupRequest *sdk.GroupRequest) *PBGroupRequest {
|
||||
return &PBGroupRequest{GroupRequest: groupRequest}
|
||||
}
|
||||
|
||||
func (pb *PBGroupRequest) Convert() (*relation.GroupRequestModel, error) {
|
||||
dst := &relation.GroupRequestModel{}
|
||||
utils.CopyStructFields(dst, pb)
|
||||
dst.ReqTime = utils.UnixSecondToTime(int64(pb.ReqTime))
|
||||
dst.HandledTime = utils.UnixSecondToTime(int64(pb.HandleTime))
|
||||
return dst, nil
|
||||
}
|
||||
func (db *DBGroupRequest) Convert() (*sdk.GroupRequest, error) {
|
||||
dst := &sdk.GroupRequest{}
|
||||
utils.CopyStructFields(dst, db)
|
||||
dst.ReqTime = db.ReqTime.Unix()
|
||||
dst.HandleTime = db.HandledTime.Unix()
|
||||
return dst, nil
|
||||
}
|
||||
|
||||
type DBUser struct {
|
||||
*relation.UserModel
|
||||
}
|
||||
|
||||
func NewDBUser(user *relation.UserModel) *DBUser {
|
||||
return &DBUser{UserModel: user}
|
||||
}
|
||||
|
||||
type PBUser struct {
|
||||
*sdk.UserInfo
|
||||
}
|
||||
|
||||
func NewPBUser(userInfo *sdk.UserInfo) *PBUser {
|
||||
return &PBUser{UserInfo: userInfo}
|
||||
}
|
||||
|
||||
func (*PBUser) PB2DB(users []*sdk.UserInfo) (DBUsers []*relation.UserModel, err error) {
|
||||
for _, v := range users {
|
||||
u, err := NewPBUser(v).Convert()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
DBUsers = append(DBUsers, u)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (*DBUser) DB2PB(users []*relation.UserModel) (PBUsers []*sdk.UserInfo, err error) {
|
||||
for _, v := range users {
|
||||
u, err := NewDBUser(v).Convert()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
PBUsers = append(PBUsers, u)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (pb *PBUser) Convert() (*relation.UserModel, error) {
|
||||
dst := &relation.UserModel{}
|
||||
utils.CopyStructFields(dst, pb)
|
||||
dst.Birth = utils.UnixSecondToTime(pb.Birthday)
|
||||
dst.CreateTime = utils.UnixSecondToTime(pb.CreateTime)
|
||||
return dst, nil
|
||||
}
|
||||
|
||||
func (db *DBUser) Convert() (*sdk.UserInfo, error) {
|
||||
dst := &sdk.UserInfo{}
|
||||
utils.CopyStructFields(dst, db)
|
||||
dst.CreateTime = db.CreateTime.Unix()
|
||||
dst.Birthday = db.Birth.Unix()
|
||||
return dst, nil
|
||||
}
|
||||
|
||||
func (db *DBUser) ConvertPublic() (*sdk.PublicUserInfo, error) {
|
||||
dst := &sdk.PublicUserInfo{}
|
||||
utils.CopyStructFields(dst, db)
|
||||
return dst, nil
|
||||
}
|
||||
@@ -0,0 +1,299 @@
|
||||
package notification
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||
discoveryRegistry "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/check"
|
||||
utils "github.com/OpenIMSDK/open_utils"
|
||||
)
|
||||
|
||||
type Check struct {
|
||||
user *check.UserCheck
|
||||
group *check.GroupChecker
|
||||
Msg *check.MsgCheck
|
||||
friend *check.FriendChecker
|
||||
conversation *check.ConversationChecker
|
||||
}
|
||||
|
||||
func NewCheck(zk discoveryRegistry.SvcDiscoveryRegistry) *Check {
|
||||
return &Check{
|
||||
user: check.NewUserCheck(zk),
|
||||
group: check.NewGroupChecker(zk),
|
||||
Msg: check.NewMsgCheck(zk),
|
||||
friend: check.NewFriendChecker(zk),
|
||||
conversation: check.NewConversationChecker(zk),
|
||||
}
|
||||
}
|
||||
|
||||
type NotificationMsg struct {
|
||||
SendID string
|
||||
RecvID string
|
||||
Content []byte // sdkws.TipsComm
|
||||
MsgFrom int32
|
||||
ContentType int32
|
||||
SessionType int32
|
||||
SenderNickname string
|
||||
SenderFaceURL string
|
||||
}
|
||||
|
||||
func (c *Check) Notification(ctx context.Context, notificationMsg *NotificationMsg) error {
|
||||
var err error
|
||||
var req msg.SendMsgReq
|
||||
var msg sdkws.MsgData
|
||||
var offlineInfo sdkws.OfflinePushInfo
|
||||
var title, desc, ex string
|
||||
var pushSwitch, unReadCount bool
|
||||
var reliabilityLevel int
|
||||
msg.SendID = notificationMsg.SendID
|
||||
msg.RecvID = notificationMsg.RecvID
|
||||
msg.Content = notificationMsg.Content
|
||||
msg.MsgFrom = notificationMsg.MsgFrom
|
||||
msg.ContentType = notificationMsg.ContentType
|
||||
msg.SessionType = notificationMsg.SessionType
|
||||
msg.CreateTime = utils.GetCurrentTimestampByMill()
|
||||
msg.ClientMsgID = utils.GetMsgID(notificationMsg.SendID)
|
||||
msg.Options = make(map[string]bool, 7)
|
||||
msg.SenderNickname = notificationMsg.SenderNickname
|
||||
msg.SenderFaceURL = notificationMsg.SenderFaceURL
|
||||
switch notificationMsg.SessionType {
|
||||
case constant.GroupChatType, constant.SuperGroupChatType:
|
||||
msg.RecvID = ""
|
||||
msg.GroupID = notificationMsg.RecvID
|
||||
}
|
||||
offlineInfo.IOSBadgeCount = config.Config.IOSPush.BadgeCount
|
||||
offlineInfo.IOSPushSound = config.Config.IOSPush.PushSound
|
||||
switch msg.ContentType {
|
||||
case constant.GroupCreatedNotification:
|
||||
pushSwitch = config.Config.Notification.GroupCreated.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupCreated.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupCreated.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupCreated.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupCreated.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupCreated.Conversation.UnreadCount
|
||||
case constant.GroupInfoSetNotification:
|
||||
pushSwitch = config.Config.Notification.GroupInfoSet.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupInfoSet.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupInfoSet.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupInfoSet.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupInfoSet.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupInfoSet.Conversation.UnreadCount
|
||||
case constant.JoinGroupApplicationNotification:
|
||||
pushSwitch = config.Config.Notification.JoinGroupApplication.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.JoinGroupApplication.OfflinePush.Title
|
||||
desc = config.Config.Notification.JoinGroupApplication.OfflinePush.Desc
|
||||
ex = config.Config.Notification.JoinGroupApplication.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.JoinGroupApplication.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.JoinGroupApplication.Conversation.UnreadCount
|
||||
case constant.MemberQuitNotification:
|
||||
pushSwitch = config.Config.Notification.MemberQuit.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.MemberQuit.OfflinePush.Title
|
||||
desc = config.Config.Notification.MemberQuit.OfflinePush.Desc
|
||||
ex = config.Config.Notification.MemberQuit.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.MemberQuit.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.MemberQuit.Conversation.UnreadCount
|
||||
case constant.GroupApplicationAcceptedNotification:
|
||||
pushSwitch = config.Config.Notification.GroupApplicationAccepted.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupApplicationAccepted.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupApplicationAccepted.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupApplicationAccepted.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupApplicationAccepted.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupApplicationAccepted.Conversation.UnreadCount
|
||||
case constant.GroupApplicationRejectedNotification:
|
||||
pushSwitch = config.Config.Notification.GroupApplicationRejected.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupApplicationRejected.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupApplicationRejected.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupApplicationRejected.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupApplicationRejected.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupApplicationRejected.Conversation.UnreadCount
|
||||
case constant.GroupOwnerTransferredNotification:
|
||||
pushSwitch = config.Config.Notification.GroupOwnerTransferred.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupOwnerTransferred.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupOwnerTransferred.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupOwnerTransferred.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupOwnerTransferred.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupOwnerTransferred.Conversation.UnreadCount
|
||||
case constant.MemberKickedNotification:
|
||||
pushSwitch = config.Config.Notification.MemberKicked.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.MemberKicked.OfflinePush.Title
|
||||
desc = config.Config.Notification.MemberKicked.OfflinePush.Desc
|
||||
ex = config.Config.Notification.MemberKicked.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.MemberKicked.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.MemberKicked.Conversation.UnreadCount
|
||||
case constant.MemberInvitedNotification:
|
||||
pushSwitch = config.Config.Notification.MemberInvited.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.MemberInvited.OfflinePush.Title
|
||||
desc = config.Config.Notification.MemberInvited.OfflinePush.Desc
|
||||
ex = config.Config.Notification.MemberInvited.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.MemberInvited.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.MemberInvited.Conversation.UnreadCount
|
||||
case constant.MemberEnterNotification:
|
||||
pushSwitch = config.Config.Notification.MemberEnter.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.MemberEnter.OfflinePush.Title
|
||||
desc = config.Config.Notification.MemberEnter.OfflinePush.Desc
|
||||
ex = config.Config.Notification.MemberEnter.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.MemberEnter.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.MemberEnter.Conversation.UnreadCount
|
||||
case constant.UserInfoUpdatedNotification:
|
||||
pushSwitch = config.Config.Notification.UserInfoUpdated.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.UserInfoUpdated.OfflinePush.Title
|
||||
desc = config.Config.Notification.UserInfoUpdated.OfflinePush.Desc
|
||||
ex = config.Config.Notification.UserInfoUpdated.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.UserInfoUpdated.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.UserInfoUpdated.Conversation.UnreadCount
|
||||
case constant.FriendApplicationNotification:
|
||||
pushSwitch = config.Config.Notification.FriendApplication.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.FriendApplication.OfflinePush.Title
|
||||
desc = config.Config.Notification.FriendApplication.OfflinePush.Desc
|
||||
ex = config.Config.Notification.FriendApplication.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.FriendApplication.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.FriendApplication.Conversation.UnreadCount
|
||||
case constant.FriendApplicationApprovedNotification:
|
||||
pushSwitch = config.Config.Notification.FriendApplicationApproved.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.FriendApplicationApproved.OfflinePush.Title
|
||||
desc = config.Config.Notification.FriendApplicationApproved.OfflinePush.Desc
|
||||
ex = config.Config.Notification.FriendApplicationApproved.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.FriendApplicationApproved.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.FriendApplicationApproved.Conversation.UnreadCount
|
||||
case constant.FriendApplicationRejectedNotification:
|
||||
pushSwitch = config.Config.Notification.FriendApplicationRejected.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.FriendApplicationRejected.OfflinePush.Title
|
||||
desc = config.Config.Notification.FriendApplicationRejected.OfflinePush.Desc
|
||||
ex = config.Config.Notification.FriendApplicationRejected.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.FriendApplicationRejected.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.FriendApplicationRejected.Conversation.UnreadCount
|
||||
case constant.FriendAddedNotification:
|
||||
pushSwitch = config.Config.Notification.FriendAdded.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.FriendAdded.OfflinePush.Title
|
||||
desc = config.Config.Notification.FriendAdded.OfflinePush.Desc
|
||||
ex = config.Config.Notification.FriendAdded.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.FriendAdded.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.FriendAdded.Conversation.UnreadCount
|
||||
case constant.FriendDeletedNotification:
|
||||
pushSwitch = config.Config.Notification.FriendDeleted.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.FriendDeleted.OfflinePush.Title
|
||||
desc = config.Config.Notification.FriendDeleted.OfflinePush.Desc
|
||||
ex = config.Config.Notification.FriendDeleted.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.FriendDeleted.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.FriendDeleted.Conversation.UnreadCount
|
||||
case constant.FriendRemarkSetNotification:
|
||||
pushSwitch = config.Config.Notification.FriendRemarkSet.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.FriendRemarkSet.OfflinePush.Title
|
||||
desc = config.Config.Notification.FriendRemarkSet.OfflinePush.Desc
|
||||
ex = config.Config.Notification.FriendRemarkSet.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.FriendRemarkSet.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.FriendRemarkSet.Conversation.UnreadCount
|
||||
case constant.BlackAddedNotification:
|
||||
pushSwitch = config.Config.Notification.BlackAdded.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.BlackAdded.OfflinePush.Title
|
||||
desc = config.Config.Notification.BlackAdded.OfflinePush.Desc
|
||||
ex = config.Config.Notification.BlackAdded.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.BlackAdded.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.BlackAdded.Conversation.UnreadCount
|
||||
case constant.BlackDeletedNotification:
|
||||
pushSwitch = config.Config.Notification.BlackDeleted.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.BlackDeleted.OfflinePush.Title
|
||||
desc = config.Config.Notification.BlackDeleted.OfflinePush.Desc
|
||||
ex = config.Config.Notification.BlackDeleted.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.BlackDeleted.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.BlackDeleted.Conversation.UnreadCount
|
||||
case constant.ConversationOptChangeNotification:
|
||||
pushSwitch = config.Config.Notification.ConversationOptUpdate.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.ConversationOptUpdate.OfflinePush.Title
|
||||
desc = config.Config.Notification.ConversationOptUpdate.OfflinePush.Desc
|
||||
ex = config.Config.Notification.ConversationOptUpdate.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.ConversationOptUpdate.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.ConversationOptUpdate.Conversation.UnreadCount
|
||||
|
||||
case constant.GroupDismissedNotification:
|
||||
pushSwitch = config.Config.Notification.GroupDismissed.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupDismissed.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupDismissed.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupDismissed.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupDismissed.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupDismissed.Conversation.UnreadCount
|
||||
|
||||
case constant.GroupMutedNotification:
|
||||
pushSwitch = config.Config.Notification.GroupMuted.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupMuted.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupMuted.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupMuted.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupMuted.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupMuted.Conversation.UnreadCount
|
||||
|
||||
case constant.GroupCancelMutedNotification:
|
||||
pushSwitch = config.Config.Notification.GroupCancelMuted.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupCancelMuted.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupCancelMuted.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupCancelMuted.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupCancelMuted.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupCancelMuted.Conversation.UnreadCount
|
||||
|
||||
case constant.GroupMemberMutedNotification:
|
||||
pushSwitch = config.Config.Notification.GroupMemberMuted.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupMemberMuted.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupMemberMuted.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupMemberMuted.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupMemberMuted.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupMemberMuted.Conversation.UnreadCount
|
||||
|
||||
case constant.GroupMemberCancelMutedNotification:
|
||||
pushSwitch = config.Config.Notification.GroupMemberCancelMuted.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupMemberCancelMuted.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupMemberCancelMuted.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupMemberCancelMuted.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupMemberCancelMuted.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupMemberCancelMuted.Conversation.UnreadCount
|
||||
|
||||
case constant.GroupMemberInfoSetNotification:
|
||||
pushSwitch = config.Config.Notification.GroupMemberInfoSet.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupMemberInfoSet.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupMemberInfoSet.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupMemberInfoSet.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupMemberInfoSet.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupMemberInfoSet.Conversation.UnreadCount
|
||||
|
||||
case constant.ConversationPrivateChatNotification:
|
||||
pushSwitch = config.Config.Notification.ConversationSetPrivate.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.ConversationSetPrivate.OfflinePush.Title
|
||||
desc = config.Config.Notification.ConversationSetPrivate.OfflinePush.Desc
|
||||
ex = config.Config.Notification.ConversationSetPrivate.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.ConversationSetPrivate.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.ConversationSetPrivate.Conversation.UnreadCount
|
||||
case constant.FriendInfoUpdatedNotification:
|
||||
pushSwitch = config.Config.Notification.FriendInfoUpdated.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.FriendInfoUpdated.OfflinePush.Title
|
||||
desc = config.Config.Notification.FriendInfoUpdated.OfflinePush.Desc
|
||||
ex = config.Config.Notification.FriendInfoUpdated.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.FriendInfoUpdated.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.FriendInfoUpdated.Conversation.UnreadCount
|
||||
case constant.DeleteMessageNotification:
|
||||
reliabilityLevel = constant.ReliableNotificationNoMsg
|
||||
case constant.ConversationUnreadNotification, constant.SuperGroupUpdateNotification:
|
||||
reliabilityLevel = constant.UnreliableNotification
|
||||
}
|
||||
switch reliabilityLevel {
|
||||
case constant.UnreliableNotification:
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsHistory, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsPersistent, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsConversationUpdate, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsSenderConversationUpdate, false)
|
||||
case constant.ReliableNotificationNoMsg:
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsConversationUpdate, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsSenderConversationUpdate, false)
|
||||
case constant.ReliableNotificationMsg:
|
||||
|
||||
}
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsUnreadCount, unReadCount)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsOfflinePush, pushSwitch)
|
||||
offlineInfo.Title = title
|
||||
offlineInfo.Desc = desc
|
||||
offlineInfo.Ex = ex
|
||||
msg.OfflinePushInfo = &offlineInfo
|
||||
req.MsgData = &msg
|
||||
_, err = c.Msg.SendMsg(ctx, &req)
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package notification
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||
sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
func (c *Check) SetConversationNotification(ctx context.Context, sendID, recvID string, contentType int, m proto.Message, tips sdkws.TipsComm) {
|
||||
var err error
|
||||
tips.Detail, err = proto.Marshal(m)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
marshaler := jsonpb.Marshaler{
|
||||
OrigName: true,
|
||||
EnumsAsInts: false,
|
||||
EmitDefaults: false,
|
||||
}
|
||||
tips.JsonDetail, _ = marshaler.MarshalToString(m)
|
||||
var n NotificationMsg
|
||||
n.SendID = sendID
|
||||
n.RecvID = recvID
|
||||
n.ContentType = int32(contentType)
|
||||
n.SessionType = constant.SingleChatType
|
||||
n.MsgFrom = constant.SysMsgType
|
||||
n.Content, err = proto.Marshal(&tips)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
c.Notification(ctx, &n)
|
||||
}
|
||||
|
||||
// SetPrivate调用
|
||||
func (c *Check) ConversationSetPrivateNotification(ctx context.Context, sendID, recvID string, isPrivateChat bool) {
|
||||
|
||||
conversationSetPrivateTips := &sdkws.ConversationSetPrivateTips{
|
||||
RecvID: recvID,
|
||||
SendID: sendID,
|
||||
IsPrivate: isPrivateChat,
|
||||
}
|
||||
var tips sdkws.TipsComm
|
||||
var tipsMsg string
|
||||
if isPrivateChat == true {
|
||||
tipsMsg = config.Config.Notification.ConversationSetPrivate.DefaultTips.OpenTips
|
||||
} else {
|
||||
tipsMsg = config.Config.Notification.ConversationSetPrivate.DefaultTips.CloseTips
|
||||
}
|
||||
tips.DefaultTips = tipsMsg
|
||||
c.SetConversationNotification(ctx, sendID, recvID, constant.ConversationPrivateChatNotification, conversationSetPrivateTips, tips)
|
||||
}
|
||||
|
||||
// 会话改变
|
||||
func (c *Check) ConversationChangeNotification(ctx context.Context, userID string) {
|
||||
|
||||
ConversationChangedTips := &sdkws.ConversationUpdateTips{
|
||||
UserID: userID,
|
||||
}
|
||||
var tips sdkws.TipsComm
|
||||
tips.DefaultTips = config.Config.Notification.ConversationOptUpdate.DefaultTips.Tips
|
||||
c.SetConversationNotification(ctx, userID, userID, constant.ConversationOptChangeNotification, ConversationChangedTips, tips)
|
||||
}
|
||||
|
||||
// 会话未读数同步
|
||||
func (c *Check) ConversationUnreadChangeNotification(ctx context.Context, userID, conversationID string, updateUnreadCountTime int64) {
|
||||
|
||||
ConversationChangedTips := &sdkws.ConversationUpdateTips{
|
||||
UserID: userID,
|
||||
ConversationIDList: []string{conversationID},
|
||||
UpdateUnreadCountTime: updateUnreadCountTime,
|
||||
}
|
||||
var tips sdkws.TipsComm
|
||||
tips.DefaultTips = config.Config.Notification.ConversationOptUpdate.DefaultTips.Tips
|
||||
c.SetConversationNotification(ctx, userID, userID, constant.ConversationUnreadNotification, ConversationChangedTips, tips)
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package notification
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/apistruct"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/tracelog"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
|
||||
sdkws "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
|
||||
)
|
||||
|
||||
func (c *Check) ExtendMessageUpdatedNotification(ctx context.Context, sendID string, sourceID string, sessionType int32,
|
||||
req *msg.SetMessageReactionExtensionsReq, resp *msg.SetMessageReactionExtensionsResp, isHistory bool, isReactionFromCache bool) {
|
||||
var m apistruct.ReactionMessageModifierNotification
|
||||
m.SourceID = req.SourceID
|
||||
m.OpUserID = tracelog.GetOpUserID(ctx)
|
||||
m.SessionType = req.SessionType
|
||||
keyMap := make(map[string]*sdkws.KeyValue)
|
||||
for _, valueResp := range resp.Result {
|
||||
if valueResp.ErrCode == 0 {
|
||||
keyMap[valueResp.KeyValue.TypeKey] = valueResp.KeyValue
|
||||
}
|
||||
}
|
||||
if len(keyMap) == 0 {
|
||||
return
|
||||
}
|
||||
m.SuccessReactionExtensions = keyMap
|
||||
m.ClientMsgID = req.ClientMsgID
|
||||
m.IsReact = resp.IsReact
|
||||
m.IsExternalExtensions = req.IsExternalExtensions
|
||||
m.MsgFirstModifyTime = resp.MsgFirstModifyTime
|
||||
c.messageReactionSender(ctx, sendID, sourceID, sessionType, constant.ReactionMessageModifier, utils.StructToJsonString(m), isHistory, isReactionFromCache)
|
||||
}
|
||||
func (c *Check) ExtendMessageDeleteNotification(ctx context.Context, sendID string, sourceID string, sessionType int32,
|
||||
req *msg.DeleteMessagesReactionExtensionsReq, resp *msg.DeleteMessagesReactionExtensionsResp, isHistory bool, isReactionFromCache bool) {
|
||||
var m apistruct.ReactionMessageDeleteNotification
|
||||
m.SourceID = req.SourceID
|
||||
m.OpUserID = req.OpUserID
|
||||
m.SessionType = req.SessionType
|
||||
keyMap := make(map[string]*sdkws.KeyValue)
|
||||
for _, valueResp := range resp.Result {
|
||||
if valueResp.ErrCode == 0 {
|
||||
keyMap[valueResp.KeyValue.TypeKey] = valueResp.KeyValue
|
||||
}
|
||||
}
|
||||
if len(keyMap) == 0 {
|
||||
return
|
||||
}
|
||||
m.SuccessReactionExtensions = keyMap
|
||||
m.ClientMsgID = req.ClientMsgID
|
||||
m.MsgFirstModifyTime = req.MsgFirstModifyTime
|
||||
|
||||
c.messageReactionSender(ctx, sendID, sourceID, sessionType, constant.ReactionMessageDeleter, utils.StructToJsonString(m), isHistory, isReactionFromCache)
|
||||
}
|
||||
func (c *Check) messageReactionSender(ctx context.Context, sendID string, sourceID string, sessionType, contentType int32, content string, isHistory bool, isReactionFromCache bool) error {
|
||||
options := make(map[string]bool, 5)
|
||||
utils.SetSwitchFromOptions(options, constant.IsOfflinePush, false)
|
||||
utils.SetSwitchFromOptions(options, constant.IsConversationUpdate, false)
|
||||
utils.SetSwitchFromOptions(options, constant.IsSenderConversationUpdate, false)
|
||||
utils.SetSwitchFromOptions(options, constant.IsUnreadCount, false)
|
||||
utils.SetSwitchFromOptions(options, constant.IsReactionFromCache, isReactionFromCache)
|
||||
if !isHistory {
|
||||
utils.SetSwitchFromOptions(options, constant.IsHistory, false)
|
||||
utils.SetSwitchFromOptions(options, constant.IsPersistent, false)
|
||||
}
|
||||
pbData := msg.SendMsgReq{
|
||||
MsgData: &sdkws.MsgData{
|
||||
SendID: sendID,
|
||||
ClientMsgID: utils.GetMsgID(sendID),
|
||||
SessionType: sessionType,
|
||||
MsgFrom: constant.SysMsgType,
|
||||
ContentType: contentType,
|
||||
Content: []byte(content),
|
||||
CreateTime: utils.GetCurrentTimestampByMill(),
|
||||
Options: options,
|
||||
},
|
||||
}
|
||||
switch sessionType {
|
||||
case constant.SingleChatType, constant.NotificationChatType:
|
||||
pbData.MsgData.RecvID = sourceID
|
||||
case constant.GroupChatType, constant.SuperGroupChatType:
|
||||
pbData.MsgData.GroupID = sourceID
|
||||
}
|
||||
_, err := c.Msg.SendMsg(ctx, &pbData)
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
package notification
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||
pbFriend "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/friend"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
func (c *Check) getFromToUserNickname(ctx context.Context, fromUserID, toUserID string) (string, string, error) {
|
||||
users, err := c.user.GetUsersInfoMap(ctx, []string{fromUserID, toUserID}, true)
|
||||
if err != nil {
|
||||
return "", "", nil
|
||||
}
|
||||
return users[fromUserID].Nickname, users[toUserID].Nickname, nil
|
||||
}
|
||||
|
||||
func (c *Check) friendNotification(ctx context.Context, fromUserID, toUserID string, contentType int32, m proto.Message) {
|
||||
var err error
|
||||
var tips sdkws.TipsComm
|
||||
tips.Detail, err = proto.Marshal(m)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
marshaler := jsonpb.Marshaler{
|
||||
OrigName: true,
|
||||
EnumsAsInts: false,
|
||||
EmitDefaults: false,
|
||||
}
|
||||
|
||||
tips.JsonDetail, _ = marshaler.MarshalToString(m)
|
||||
|
||||
fromUserNickname, toUserNickname, err := c.getFromToUserNickname(ctx, fromUserID, toUserID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
cn := config.Config.Notification
|
||||
switch contentType {
|
||||
case constant.FriendApplicationNotification:
|
||||
tips.DefaultTips = fromUserNickname + cn.FriendApplication.DefaultTips.Tips
|
||||
case constant.FriendApplicationApprovedNotification:
|
||||
tips.DefaultTips = fromUserNickname + cn.FriendApplicationApproved.DefaultTips.Tips
|
||||
case constant.FriendApplicationRejectedNotification:
|
||||
tips.DefaultTips = fromUserNickname + cn.FriendApplicationRejected.DefaultTips.Tips
|
||||
case constant.FriendAddedNotification:
|
||||
tips.DefaultTips = cn.FriendAdded.DefaultTips.Tips
|
||||
case constant.FriendDeletedNotification:
|
||||
tips.DefaultTips = cn.FriendDeleted.DefaultTips.Tips + toUserNickname
|
||||
case constant.FriendRemarkSetNotification:
|
||||
tips.DefaultTips = fromUserNickname + cn.FriendRemarkSet.DefaultTips.Tips
|
||||
case constant.BlackAddedNotification:
|
||||
tips.DefaultTips = cn.BlackAdded.DefaultTips.Tips
|
||||
case constant.BlackDeletedNotification:
|
||||
tips.DefaultTips = cn.BlackDeleted.DefaultTips.Tips + toUserNickname
|
||||
case constant.UserInfoUpdatedNotification:
|
||||
tips.DefaultTips = cn.UserInfoUpdated.DefaultTips.Tips
|
||||
case constant.FriendInfoUpdatedNotification:
|
||||
tips.DefaultTips = cn.FriendInfoUpdated.DefaultTips.Tips + toUserNickname
|
||||
default:
|
||||
return
|
||||
}
|
||||
|
||||
var n NotificationMsg
|
||||
n.SendID = fromUserID
|
||||
n.RecvID = toUserID
|
||||
n.ContentType = contentType
|
||||
n.SessionType = constant.SingleChatType
|
||||
n.MsgFrom = constant.SysMsgType
|
||||
n.Content, err = proto.Marshal(&tips)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
c.Notification(ctx, &n)
|
||||
}
|
||||
|
||||
func (c *Check) FriendApplicationAddNotification(ctx context.Context, req *pbFriend.ApplyToAddFriendReq) {
|
||||
FriendApplicationTips := sdkws.FriendApplicationTips{FromToUserID: &sdkws.FromToUserID{}}
|
||||
FriendApplicationTips.FromToUserID.FromUserID = req.FromUserID
|
||||
FriendApplicationTips.FromToUserID.ToUserID = req.ToUserID
|
||||
c.friendNotification(ctx, req.FromUserID, req.ToUserID, constant.FriendApplicationNotification, &FriendApplicationTips)
|
||||
}
|
||||
|
||||
func (c *Check) FriendApplicationAgreedNotification(ctx context.Context, req *pbFriend.RespondFriendApplyReq) {
|
||||
FriendApplicationApprovedTips := sdkws.FriendApplicationApprovedTips{FromToUserID: &sdkws.FromToUserID{}}
|
||||
FriendApplicationApprovedTips.FromToUserID.FromUserID = req.FromUserID
|
||||
FriendApplicationApprovedTips.FromToUserID.ToUserID = req.ToUserID
|
||||
FriendApplicationApprovedTips.HandleMsg = req.HandleMsg
|
||||
c.friendNotification(ctx, req.ToUserID, req.FromUserID, constant.FriendApplicationApprovedNotification, &FriendApplicationApprovedTips)
|
||||
}
|
||||
|
||||
func (c *Check) FriendApplicationRefusedNotification(ctx context.Context, req *pbFriend.RespondFriendApplyReq) {
|
||||
FriendApplicationApprovedTips := sdkws.FriendApplicationApprovedTips{FromToUserID: &sdkws.FromToUserID{}}
|
||||
FriendApplicationApprovedTips.FromToUserID.FromUserID = req.FromUserID
|
||||
FriendApplicationApprovedTips.FromToUserID.ToUserID = req.ToUserID
|
||||
FriendApplicationApprovedTips.HandleMsg = req.HandleMsg
|
||||
c.friendNotification(ctx, req.ToUserID, req.FromUserID, constant.FriendApplicationRejectedNotification, &FriendApplicationApprovedTips)
|
||||
}
|
||||
|
||||
func (c *Check) FriendAddedNotification(ctx context.Context, operationID, opUserID, fromUserID, toUserID string) {
|
||||
friendAddedTips := sdkws.FriendAddedTips{Friend: &sdkws.FriendInfo{}, OpUser: &sdkws.PublicUserInfo{}}
|
||||
user, err := c.user.GetUsersInfos(ctx, []string{opUserID}, true)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
friendAddedTips.OpUser.UserID = user[0].UserID
|
||||
friendAddedTips.OpUser.Ex = user[0].Ex
|
||||
friendAddedTips.OpUser.Nickname = user[0].Nickname
|
||||
friendAddedTips.OpUser.FaceURL = user[0].FaceURL
|
||||
|
||||
friend, err := c.friend.GetFriendsInfo(ctx, fromUserID, toUserID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
friendAddedTips.Friend = friend
|
||||
c.friendNotification(ctx, fromUserID, toUserID, constant.FriendAddedNotification, &friendAddedTips)
|
||||
}
|
||||
|
||||
func (c *Check) FriendDeletedNotification(ctx context.Context, req *pbFriend.DeleteFriendReq) {
|
||||
friendDeletedTips := sdkws.FriendDeletedTips{FromToUserID: &sdkws.FromToUserID{}}
|
||||
friendDeletedTips.FromToUserID.FromUserID = req.OwnerUserID
|
||||
friendDeletedTips.FromToUserID.ToUserID = req.FriendUserID
|
||||
c.friendNotification(ctx, req.OwnerUserID, req.FriendUserID, constant.FriendDeletedNotification, &friendDeletedTips)
|
||||
}
|
||||
|
||||
func (c *Check) FriendRemarkSetNotification(ctx context.Context, fromUserID, toUserID string) {
|
||||
friendInfoChangedTips := sdkws.FriendInfoChangedTips{FromToUserID: &sdkws.FromToUserID{}}
|
||||
friendInfoChangedTips.FromToUserID.FromUserID = fromUserID
|
||||
friendInfoChangedTips.FromToUserID.ToUserID = toUserID
|
||||
c.friendNotification(ctx, fromUserID, toUserID, constant.FriendRemarkSetNotification, &friendInfoChangedTips)
|
||||
}
|
||||
|
||||
func (c *Check) BlackAddedNotification(ctx context.Context, req *pbFriend.AddBlackReq) {
|
||||
blackAddedTips := sdkws.BlackAddedTips{FromToUserID: &sdkws.FromToUserID{}}
|
||||
blackAddedTips.FromToUserID.FromUserID = req.OwnerUserID
|
||||
blackAddedTips.FromToUserID.ToUserID = req.BlackUserID
|
||||
c.friendNotification(ctx, req.OwnerUserID, req.BlackUserID, constant.BlackAddedNotification, &blackAddedTips)
|
||||
}
|
||||
|
||||
func (c *Check) BlackDeletedNotification(ctx context.Context, req *pbFriend.RemoveBlackReq) {
|
||||
blackDeletedTips := sdkws.BlackDeletedTips{FromToUserID: &sdkws.FromToUserID{}}
|
||||
blackDeletedTips.FromToUserID.FromUserID = req.OwnerUserID
|
||||
blackDeletedTips.FromToUserID.ToUserID = req.BlackUserID
|
||||
c.friendNotification(ctx, req.OwnerUserID, req.BlackUserID, constant.BlackDeletedNotification, &blackDeletedTips)
|
||||
}
|
||||
|
||||
func (c *Check) FriendInfoUpdatedNotification(ctx context.Context, changedUserID string, needNotifiedUserID string, opUserID string) {
|
||||
selfInfoUpdatedTips := sdkws.UserInfoUpdatedTips{UserID: changedUserID}
|
||||
c.friendNotification(ctx, opUserID, needNotifiedUserID, constant.FriendInfoUpdatedNotification, &selfInfoUpdatedTips)
|
||||
}
|
||||
@@ -0,0 +1,548 @@
|
||||
package notification
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/tokenverify"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/tracelog"
|
||||
pbGroup "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/group"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/wrapperspb"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
func (c *Check) setOpUserInfo(ctx context.Context, groupID string, groupMemberInfo *sdkws.GroupMemberFullInfo) error {
|
||||
opUserID := tracelog.GetOpUserID(ctx)
|
||||
if tokenverify.IsManagerUserID(opUserID) {
|
||||
user, err := c.user.GetUsersInfos(ctx, []string{opUserID}, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
groupMemberInfo.GroupID = groupID
|
||||
groupMemberInfo.UserID = user[0].UserID
|
||||
groupMemberInfo.Nickname = user[0].Nickname
|
||||
groupMemberInfo.AppMangerLevel = user[0].AppMangerLevel
|
||||
groupMemberInfo.FaceURL = user[0].FaceURL
|
||||
return nil
|
||||
}
|
||||
u, err := c.group.GetGroupMemberInfo(ctx, groupID, opUserID)
|
||||
if err == nil {
|
||||
*groupMemberInfo = *u
|
||||
return nil
|
||||
}
|
||||
user, err := c.user.GetUsersInfos(ctx, []string{opUserID}, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
groupMemberInfo.GroupID = groupID
|
||||
groupMemberInfo.UserID = user[0].UserID
|
||||
groupMemberInfo.Nickname = user[0].Nickname
|
||||
groupMemberInfo.AppMangerLevel = user[0].AppMangerLevel
|
||||
groupMemberInfo.FaceURL = user[0].FaceURL
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Check) setGroupInfo(ctx context.Context, groupID string, groupInfo *sdkws.GroupInfo) error {
|
||||
group, err := c.group.GetGroupInfos(ctx, []string{groupID}, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*groupInfo = *group[0]
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Check) setGroupMemberInfo(ctx context.Context, groupID, userID string, groupMemberInfo *sdkws.GroupMemberFullInfo) error {
|
||||
groupMember, err := c.group.GetGroupMemberInfo(ctx, groupID, userID)
|
||||
if err == nil {
|
||||
*groupMemberInfo = *groupMember
|
||||
return nil
|
||||
}
|
||||
user, err := c.user.GetUsersInfos(ctx, []string{userID}, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
groupMemberInfo.GroupID = groupID
|
||||
groupMemberInfo.UserID = user[0].UserID
|
||||
groupMemberInfo.Nickname = user[0].Nickname
|
||||
groupMemberInfo.AppMangerLevel = user[0].AppMangerLevel
|
||||
groupMemberInfo.FaceURL = user[0].FaceURL
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Check) setGroupOwnerInfo(ctx context.Context, groupID string, groupMemberInfo *sdkws.GroupMemberFullInfo) error {
|
||||
group, err := c.group.GetGroupInfo(ctx, groupID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
groupMember, err := c.group.GetGroupMemberInfo(ctx, groupID, group.OwnerUserID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*groupMemberInfo = *groupMember
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Check) setPublicUserInfo(ctx context.Context, userID string, publicUserInfo *sdkws.PublicUserInfo) error {
|
||||
user, err := c.user.GetPublicUserInfos(ctx, []string{userID}, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*publicUserInfo = *user[0]
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Check) groupNotification(ctx context.Context, contentType int32, m proto.Message, sendID, groupID, recvUserID string) {
|
||||
var err error
|
||||
var tips sdkws.TipsComm
|
||||
tips.Detail, err = proto.Marshal(m)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
marshaler := jsonpb.Marshaler{
|
||||
OrigName: true,
|
||||
EnumsAsInts: false,
|
||||
EmitDefaults: false,
|
||||
}
|
||||
tips.JsonDetail, _ = marshaler.MarshalToString(m)
|
||||
var nickname, toNickname string
|
||||
if sendID != "" {
|
||||
|
||||
from, err := c.user.GetUsersInfos(ctx, []string{sendID}, true)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
nickname = from[0].Nickname
|
||||
}
|
||||
if recvUserID != "" {
|
||||
to, err := c.user.GetUsersInfos(ctx, []string{recvUserID}, true)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
toNickname = to[0].Nickname
|
||||
}
|
||||
|
||||
cn := config.Config.Notification
|
||||
switch contentType {
|
||||
case constant.GroupCreatedNotification:
|
||||
tips.DefaultTips = nickname + " " + cn.GroupCreated.DefaultTips.Tips
|
||||
case constant.GroupInfoSetNotification:
|
||||
tips.DefaultTips = nickname + " " + cn.GroupInfoSet.DefaultTips.Tips
|
||||
case constant.JoinGroupApplicationNotification:
|
||||
tips.DefaultTips = nickname + " " + cn.JoinGroupApplication.DefaultTips.Tips
|
||||
case constant.MemberQuitNotification:
|
||||
tips.DefaultTips = nickname + " " + cn.MemberQuit.DefaultTips.Tips
|
||||
case constant.GroupApplicationAcceptedNotification: //
|
||||
tips.DefaultTips = toNickname + " " + cn.GroupApplicationAccepted.DefaultTips.Tips
|
||||
case constant.GroupApplicationRejectedNotification: //
|
||||
tips.DefaultTips = toNickname + " " + cn.GroupApplicationRejected.DefaultTips.Tips
|
||||
case constant.GroupOwnerTransferredNotification: //
|
||||
tips.DefaultTips = toNickname + " " + cn.GroupOwnerTransferred.DefaultTips.Tips
|
||||
case constant.MemberKickedNotification: //
|
||||
tips.DefaultTips = toNickname + " " + cn.MemberKicked.DefaultTips.Tips
|
||||
case constant.MemberInvitedNotification: //
|
||||
tips.DefaultTips = toNickname + " " + cn.MemberInvited.DefaultTips.Tips
|
||||
case constant.MemberEnterNotification:
|
||||
tips.DefaultTips = toNickname + " " + cn.MemberEnter.DefaultTips.Tips
|
||||
case constant.GroupDismissedNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupDismissed.DefaultTips.Tips
|
||||
case constant.GroupMutedNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupMuted.DefaultTips.Tips
|
||||
case constant.GroupCancelMutedNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupCancelMuted.DefaultTips.Tips
|
||||
case constant.GroupMemberMutedNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupMemberMuted.DefaultTips.Tips
|
||||
case constant.GroupMemberCancelMutedNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupMemberCancelMuted.DefaultTips.Tips
|
||||
case constant.GroupMemberInfoSetNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupMemberInfoSet.DefaultTips.Tips
|
||||
case constant.GroupMemberSetToAdminNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupMemberSetToAdmin.DefaultTips.Tips
|
||||
case constant.GroupMemberSetToOrdinaryUserNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupMemberSetToOrdinary.DefaultTips.Tips
|
||||
default:
|
||||
return
|
||||
}
|
||||
|
||||
var n NotificationMsg
|
||||
n.SendID = sendID
|
||||
if groupID != "" {
|
||||
n.RecvID = groupID
|
||||
|
||||
group, err := c.group.GetGroupInfo(ctx, groupID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
switch group.GroupType {
|
||||
case constant.NormalGroup:
|
||||
n.SessionType = constant.GroupChatType
|
||||
default:
|
||||
n.SessionType = constant.SuperGroupChatType
|
||||
}
|
||||
} else {
|
||||
n.RecvID = recvUserID
|
||||
n.SessionType = constant.SingleChatType
|
||||
}
|
||||
n.ContentType = contentType
|
||||
n.Content, err = proto.Marshal(&tips)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
c.Notification(ctx, &n)
|
||||
}
|
||||
|
||||
// 创建群后调用
|
||||
func (c *Check) GroupCreatedNotification(ctx context.Context, groupID string, initMemberList []string) {
|
||||
GroupCreatedTips := sdkws.GroupCreatedTips{Group: &sdkws.GroupInfo{},
|
||||
OpUser: &sdkws.GroupMemberFullInfo{}, GroupOwnerUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := c.setOpUserInfo(ctx, groupID, GroupCreatedTips.OpUser); err != nil {
|
||||
return
|
||||
}
|
||||
err := c.setGroupInfo(ctx, groupID, GroupCreatedTips.Group)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.setGroupOwnerInfo(ctx, groupID, GroupCreatedTips.GroupOwnerUser); err != nil {
|
||||
return
|
||||
}
|
||||
for _, v := range initMemberList {
|
||||
var groupMemberInfo sdkws.GroupMemberFullInfo
|
||||
if err := c.setGroupMemberInfo(ctx, groupID, v, &groupMemberInfo); err != nil {
|
||||
continue
|
||||
}
|
||||
GroupCreatedTips.MemberList = append(GroupCreatedTips.MemberList, &groupMemberInfo)
|
||||
if len(GroupCreatedTips.MemberList) == constant.MaxNotificationNum {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
c.groupNotification(ctx, constant.GroupCreatedNotification, &GroupCreatedTips, tracelog.GetOpUserID(ctx), groupID, "")
|
||||
}
|
||||
|
||||
// 群信息改变后掉用
|
||||
// groupName := ""
|
||||
//
|
||||
// notification := ""
|
||||
// introduction := ""
|
||||
// faceURL := ""
|
||||
func (c *Check) GroupInfoSetNotification(ctx context.Context, groupID string, groupName, notification, introduction, faceURL string, needVerification *wrapperspb.Int32Value) {
|
||||
GroupInfoChangedTips := sdkws.GroupInfoSetTips{Group: &sdkws.GroupInfo{}, OpUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := c.setGroupInfo(ctx, groupID, GroupInfoChangedTips.Group); err != nil {
|
||||
return
|
||||
}
|
||||
GroupInfoChangedTips.Group.GroupName = groupName
|
||||
GroupInfoChangedTips.Group.Notification = notification
|
||||
GroupInfoChangedTips.Group.Introduction = introduction
|
||||
GroupInfoChangedTips.Group.FaceURL = faceURL
|
||||
if needVerification != nil {
|
||||
GroupInfoChangedTips.Group.NeedVerification = needVerification.Value
|
||||
}
|
||||
|
||||
if err := c.setOpUserInfo(ctx, groupID, GroupInfoChangedTips.OpUser); err != nil {
|
||||
return
|
||||
}
|
||||
c.groupNotification(ctx, constant.GroupInfoSetNotification, &GroupInfoChangedTips, tracelog.GetOpUserID(ctx), groupID, "")
|
||||
}
|
||||
|
||||
func (c *Check) GroupMutedNotification(ctx context.Context, groupID string) {
|
||||
tips := sdkws.GroupMutedTips{Group: &sdkws.GroupInfo{},
|
||||
OpUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := c.setGroupInfo(ctx, groupID, tips.Group); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setOpUserInfo(ctx, groupID, tips.OpUser); err != nil {
|
||||
return
|
||||
}
|
||||
c.groupNotification(ctx, constant.GroupMutedNotification, &tips, tracelog.GetOpUserID(ctx), groupID, "")
|
||||
}
|
||||
|
||||
func (c *Check) GroupCancelMutedNotification(ctx context.Context, groupID string) {
|
||||
tips := sdkws.GroupCancelMutedTips{Group: &sdkws.GroupInfo{},
|
||||
OpUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := c.setGroupInfo(ctx, groupID, tips.Group); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setOpUserInfo(ctx, groupID, tips.OpUser); err != nil {
|
||||
return
|
||||
}
|
||||
c.groupNotification(ctx, constant.GroupCancelMutedNotification, &tips, tracelog.GetOpUserID(ctx), groupID, "")
|
||||
}
|
||||
|
||||
func (c *Check) GroupMemberMutedNotification(ctx context.Context, groupID, groupMemberUserID string, mutedSeconds uint32) {
|
||||
tips := sdkws.GroupMemberMutedTips{Group: &sdkws.GroupInfo{},
|
||||
OpUser: &sdkws.GroupMemberFullInfo{}, MutedUser: &sdkws.GroupMemberFullInfo{}}
|
||||
tips.MutedSeconds = mutedSeconds
|
||||
if err := c.setGroupInfo(ctx, groupID, tips.Group); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setOpUserInfo(ctx, groupID, tips.OpUser); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setGroupMemberInfo(ctx, groupID, groupMemberUserID, tips.MutedUser); err != nil {
|
||||
return
|
||||
}
|
||||
c.groupNotification(ctx, constant.GroupMemberMutedNotification, &tips, tracelog.GetOpUserID(ctx), groupID, "")
|
||||
}
|
||||
|
||||
func (c *Check) GroupMemberInfoSetNotification(ctx context.Context, groupID, groupMemberUserID string) {
|
||||
tips := sdkws.GroupMemberInfoSetTips{Group: &sdkws.GroupInfo{},
|
||||
OpUser: &sdkws.GroupMemberFullInfo{}, ChangedUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := c.setGroupInfo(ctx, groupID, tips.Group); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setOpUserInfo(ctx, groupID, tips.OpUser); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setGroupMemberInfo(ctx, groupID, groupMemberUserID, tips.ChangedUser); err != nil {
|
||||
return
|
||||
}
|
||||
c.groupNotification(ctx, constant.GroupMemberInfoSetNotification, &tips, tracelog.GetOpUserID(ctx), groupID, "")
|
||||
}
|
||||
|
||||
func (c *Check) GroupMemberRoleLevelChangeNotification(ctx context.Context, operationID, opUserID, groupID, groupMemberUserID string, notificationType int32) {
|
||||
if notificationType != constant.GroupMemberSetToAdminNotification && notificationType != constant.GroupMemberSetToOrdinaryUserNotification {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "invalid notificationType: ", notificationType)
|
||||
return
|
||||
}
|
||||
tips := sdkws.GroupMemberInfoSetTips{Group: &sdkws.GroupInfo{},
|
||||
OpUser: &sdkws.GroupMemberFullInfo{}, ChangedUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := c.setGroupInfo(ctx, groupID, tips.Group); err != nil {
|
||||
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
|
||||
return
|
||||
}
|
||||
if err := c.setOpUserInfo(ctx, groupID, tips.OpUser); err != nil {
|
||||
log.Error(operationID, "setOpUserInfo failed ", err.Error(), opUserID, groupID)
|
||||
return
|
||||
}
|
||||
if err := c.setGroupMemberInfo(ctx, groupID, groupMemberUserID, tips.ChangedUser); err != nil {
|
||||
log.Error(operationID, "setGroupMemberInfo failed ", err.Error(), groupID, groupMemberUserID)
|
||||
return
|
||||
}
|
||||
c.groupNotification(ctx, notificationType, &tips, tracelog.GetOpUserID(ctx), groupID, "")
|
||||
}
|
||||
|
||||
func (c *Check) GroupMemberCancelMutedNotification(ctx context.Context, groupID, groupMemberUserID string) {
|
||||
tips := sdkws.GroupMemberCancelMutedTips{Group: &sdkws.GroupInfo{},
|
||||
OpUser: &sdkws.GroupMemberFullInfo{}, MutedUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := c.setGroupInfo(ctx, groupID, tips.Group); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setOpUserInfo(ctx, groupID, tips.OpUser); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setGroupMemberInfo(ctx, groupID, groupMemberUserID, tips.MutedUser); err != nil {
|
||||
return
|
||||
}
|
||||
c.groupNotification(ctx, constant.GroupMemberCancelMutedNotification, &tips, tracelog.GetOpUserID(ctx), groupID, "")
|
||||
}
|
||||
|
||||
// message ReceiveJoinApplicationTips{
|
||||
// GroupInfo Group = 1;
|
||||
// PublicUserInfo Applicant = 2;
|
||||
// string Reason = 3;
|
||||
// } apply->all managers GroupID string `protobuf:"bytes,1,opt,name=GroupID" json:"GroupID,omitempty"`
|
||||
//
|
||||
// ReqMessage string `protobuf:"bytes,2,opt,name=ReqMessage" json:"ReqMessage,omitempty"`
|
||||
// OpUserID string `protobuf:"bytes,3,opt,name=OpUserID" json:"OpUserID,omitempty"`
|
||||
// OperationID string `protobuf:"bytes,4,opt,name=OperationID" json:"OperationID,omitempty"`
|
||||
//
|
||||
// 申请进群后调用
|
||||
func (c *Check) JoinGroupApplicationNotification(ctx context.Context, req *pbGroup.JoinGroupReq) {
|
||||
JoinGroupApplicationTips := sdkws.JoinGroupApplicationTips{Group: &sdkws.GroupInfo{}, Applicant: &sdkws.PublicUserInfo{}}
|
||||
err := c.setGroupInfo(ctx, req.GroupID, JoinGroupApplicationTips.Group)
|
||||
if err != nil {
|
||||
|
||||
return
|
||||
}
|
||||
if err = c.setPublicUserInfo(ctx, tracelog.GetOpUserID(ctx), JoinGroupApplicationTips.Applicant); err != nil {
|
||||
|
||||
return
|
||||
}
|
||||
JoinGroupApplicationTips.ReqMsg = req.ReqMessage
|
||||
managerList, err := c.group.GetOwnerAndAdminInfos(ctx, req.GroupID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, v := range managerList {
|
||||
c.groupNotification(ctx, constant.JoinGroupApplicationNotification, &JoinGroupApplicationTips, tracelog.GetOpUserID(ctx), "", v.UserID)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Check) MemberQuitNotification(ctx context.Context, req *pbGroup.QuitGroupReq) {
|
||||
MemberQuitTips := sdkws.MemberQuitTips{Group: &sdkws.GroupInfo{}, QuitUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := c.setGroupInfo(ctx, req.GroupID, MemberQuitTips.Group); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setOpUserInfo(ctx, req.GroupID, MemberQuitTips.QuitUser); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
c.groupNotification(ctx, constant.MemberQuitNotification, &MemberQuitTips, tracelog.GetOpUserID(ctx), req.GroupID, "")
|
||||
}
|
||||
|
||||
// message ApplicationProcessedTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo OpUser = 2;
|
||||
// int32 Result = 3;
|
||||
// string Reason = 4;
|
||||
// }
|
||||
//
|
||||
// 处理进群请求后调用
|
||||
func (c *Check) GroupApplicationAcceptedNotification(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) {
|
||||
GroupApplicationAcceptedTips := sdkws.GroupApplicationAcceptedTips{Group: &sdkws.GroupInfo{}, OpUser: &sdkws.GroupMemberFullInfo{}, HandleMsg: req.HandledMsg}
|
||||
if err := c.setGroupInfo(ctx, req.GroupID, GroupApplicationAcceptedTips.Group); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setOpUserInfo(ctx, req.GroupID, GroupApplicationAcceptedTips.OpUser); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
c.groupNotification(ctx, constant.GroupApplicationAcceptedNotification, &GroupApplicationAcceptedTips, tracelog.GetOpUserID(ctx), "", req.FromUserID)
|
||||
adminList, err := c.group.GetOwnerAndAdminInfos(ctx, req.GroupID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, v := range adminList {
|
||||
if v.UserID == tracelog.GetOpUserID(ctx) {
|
||||
continue
|
||||
}
|
||||
GroupApplicationAcceptedTips.ReceiverAs = 1
|
||||
c.groupNotification(ctx, constant.GroupApplicationAcceptedNotification, &GroupApplicationAcceptedTips, tracelog.GetOpUserID(ctx), "", v.UserID)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Check) GroupApplicationRejectedNotification(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) {
|
||||
GroupApplicationRejectedTips := sdkws.GroupApplicationRejectedTips{Group: &sdkws.GroupInfo{}, OpUser: &sdkws.GroupMemberFullInfo{}, HandleMsg: req.HandledMsg}
|
||||
if err := c.setGroupInfo(ctx, req.GroupID, GroupApplicationRejectedTips.Group); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setOpUserInfo(ctx, req.GroupID, GroupApplicationRejectedTips.OpUser); err != nil {
|
||||
return
|
||||
}
|
||||
c.groupNotification(ctx, constant.GroupApplicationRejectedNotification, &GroupApplicationRejectedTips, tracelog.GetOpUserID(ctx), "", req.FromUserID)
|
||||
adminList, err := c.group.GetOwnerAndAdminInfos(ctx, req.GroupID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, v := range adminList {
|
||||
if v.UserID == tracelog.GetOpUserID(ctx) {
|
||||
continue
|
||||
}
|
||||
GroupApplicationRejectedTips.ReceiverAs = 1
|
||||
c.groupNotification(ctx, constant.GroupApplicationRejectedNotification, &GroupApplicationRejectedTips, tracelog.GetOpUserID(ctx), "", v.UserID)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Check) GroupOwnerTransferredNotification(ctx context.Context, req *pbGroup.TransferGroupOwnerReq) {
|
||||
GroupOwnerTransferredTips := sdkws.GroupOwnerTransferredTips{Group: &sdkws.GroupInfo{}, OpUser: &sdkws.GroupMemberFullInfo{}, NewGroupOwner: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := c.setGroupInfo(ctx, req.GroupID, GroupOwnerTransferredTips.Group); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setOpUserInfo(ctx, req.GroupID, GroupOwnerTransferredTips.OpUser); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setGroupMemberInfo(ctx, req.GroupID, req.NewOwnerUserID, GroupOwnerTransferredTips.NewGroupOwner); err != nil {
|
||||
return
|
||||
}
|
||||
c.groupNotification(ctx, constant.GroupOwnerTransferredNotification, &GroupOwnerTransferredTips, tracelog.GetOpUserID(ctx), req.GroupID, "")
|
||||
}
|
||||
|
||||
func (c *Check) GroupDismissedNotification(ctx context.Context, req *pbGroup.DismissGroupReq) {
|
||||
tips := sdkws.GroupDismissedTips{Group: &sdkws.GroupInfo{}, OpUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := c.setGroupInfo(ctx, req.GroupID, tips.Group); err != nil {
|
||||
|
||||
return
|
||||
}
|
||||
if err := c.setOpUserInfo(ctx, req.GroupID, tips.OpUser); err != nil {
|
||||
|
||||
return
|
||||
}
|
||||
c.groupNotification(ctx, constant.GroupDismissedNotification, &tips, tracelog.GetOpUserID(ctx), req.GroupID, "")
|
||||
}
|
||||
|
||||
// message MemberKickedTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo OpUser = 2;
|
||||
// GroupMemberFullInfo KickedUser = 3;
|
||||
// uint64 OperationTime = 4;
|
||||
// }
|
||||
//
|
||||
// 被踢后调用
|
||||
func (c *Check) MemberKickedNotification(ctx context.Context, req *pbGroup.KickGroupMemberReq, kickedUserIDList []string) {
|
||||
MemberKickedTips := sdkws.MemberKickedTips{Group: &sdkws.GroupInfo{}, OpUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := c.setGroupInfo(ctx, req.GroupID, MemberKickedTips.Group); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setOpUserInfo(ctx, req.GroupID, MemberKickedTips.OpUser); err != nil {
|
||||
return
|
||||
}
|
||||
for _, v := range kickedUserIDList {
|
||||
var groupMemberInfo sdkws.GroupMemberFullInfo
|
||||
if err := c.setGroupMemberInfo(ctx, req.GroupID, v, &groupMemberInfo); err != nil {
|
||||
continue
|
||||
}
|
||||
MemberKickedTips.KickedUserList = append(MemberKickedTips.KickedUserList, &groupMemberInfo)
|
||||
}
|
||||
c.groupNotification(ctx, constant.MemberKickedNotification, &MemberKickedTips, tracelog.GetOpUserID(ctx), req.GroupID, "")
|
||||
//
|
||||
//for _, v := range kickedUserIDList {
|
||||
// groupNotification(constant.MemberKickedNotification, &MemberKickedTips, req.OpUserID, "", v, req.OperationID)
|
||||
//}
|
||||
}
|
||||
|
||||
// message MemberInvitedTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo OpUser = 2;
|
||||
// GroupMemberFullInfo InvitedUser = 3;
|
||||
// uint64 OperationTime = 4;
|
||||
// }
|
||||
//
|
||||
// 被邀请进群后调用
|
||||
func (c *Check) MemberInvitedNotification(ctx context.Context, groupID, reason string, invitedUserIDList []string) {
|
||||
MemberInvitedTips := sdkws.MemberInvitedTips{Group: &sdkws.GroupInfo{}, OpUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := c.setGroupInfo(ctx, groupID, MemberInvitedTips.Group); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setOpUserInfo(ctx, groupID, MemberInvitedTips.OpUser); err != nil {
|
||||
|
||||
return
|
||||
}
|
||||
for _, v := range invitedUserIDList {
|
||||
var groupMemberInfo sdkws.GroupMemberFullInfo
|
||||
if err := c.setGroupMemberInfo(ctx, groupID, v, &groupMemberInfo); err != nil {
|
||||
continue
|
||||
}
|
||||
MemberInvitedTips.InvitedUserList = append(MemberInvitedTips.InvitedUserList, &groupMemberInfo)
|
||||
}
|
||||
c.groupNotification(ctx, constant.MemberInvitedNotification, &MemberInvitedTips, tracelog.GetOpUserID(ctx), groupID, "")
|
||||
}
|
||||
|
||||
// 群成员主动申请进群,管理员同意后调用,
|
||||
func (c *Check) MemberEnterNotification(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) {
|
||||
MemberEnterTips := sdkws.MemberEnterTips{Group: &sdkws.GroupInfo{}, EntrantUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := c.setGroupInfo(ctx, req.GroupID, MemberEnterTips.Group); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setGroupMemberInfo(ctx, req.GroupID, req.FromUserID, MemberEnterTips.EntrantUser); err != nil {
|
||||
return
|
||||
}
|
||||
c.groupNotification(ctx, constant.MemberEnterNotification, &MemberEnterTips, tracelog.GetOpUserID(ctx), req.GroupID, "")
|
||||
}
|
||||
|
||||
func (c *Check) MemberEnterDirectlyNotification(ctx context.Context, groupID string, entrantUserID string, operationID string) {
|
||||
MemberEnterTips := sdkws.MemberEnterTips{Group: &sdkws.GroupInfo{}, EntrantUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := c.setGroupInfo(ctx, groupID, MemberEnterTips.Group); err != nil {
|
||||
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID, MemberEnterTips.Group)
|
||||
return
|
||||
}
|
||||
if err := c.setGroupMemberInfo(ctx, groupID, entrantUserID, MemberEnterTips.EntrantUser); err != nil {
|
||||
log.Error(operationID, "setGroupMemberInfo failed ", err.Error(), groupID, entrantUserID, MemberEnterTips.EntrantUser)
|
||||
return
|
||||
}
|
||||
c.groupNotification(ctx, constant.MemberEnterNotification, &MemberEnterTips, entrantUserID, groupID, "")
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package notification
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
func (c *Check) DeleteMessageNotification(ctx context.Context, userID string, seqs []int64, operationID string) {
|
||||
DeleteMessageTips := sdkws.DeleteMessageTips{UserID: userID, Seqs: seqs}
|
||||
c.MessageNotification(ctx, userID, userID, constant.DeleteMessageNotification, &DeleteMessageTips)
|
||||
}
|
||||
|
||||
func (c *Check) MessageNotification(ctx context.Context, sendID, recvID string, contentType int32, m proto.Message) {
|
||||
var err error
|
||||
var tips sdkws.TipsComm
|
||||
tips.Detail, err = proto.Marshal(m)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
marshaler := jsonpb.Marshaler{
|
||||
OrigName: true,
|
||||
EnumsAsInts: false,
|
||||
EmitDefaults: false,
|
||||
}
|
||||
|
||||
tips.JsonDetail, _ = marshaler.MarshalToString(m)
|
||||
var n NotificationMsg
|
||||
n.SendID = sendID
|
||||
n.RecvID = recvID
|
||||
n.ContentType = contentType
|
||||
n.SessionType = constant.SingleChatType
|
||||
n.MsgFrom = constant.SysMsgType
|
||||
n.Content, err = proto.Marshal(&tips)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
c.Notification(ctx, &n)
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package notification
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||
//"github.com/golang/protobuf/jsonpb"
|
||||
//"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
func (c *Check) SuperGroupNotification(ctx context.Context, sendID, recvID string) {
|
||||
n := &NotificationMsg{
|
||||
SendID: sendID,
|
||||
RecvID: recvID,
|
||||
MsgFrom: constant.SysMsgType,
|
||||
ContentType: constant.SuperGroupUpdateNotification,
|
||||
SessionType: constant.SingleChatType,
|
||||
}
|
||||
c.Notification(ctx, n)
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package notification
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
||||
)
|
||||
|
||||
// send to myself
|
||||
func (c *Check) UserInfoUpdatedNotification(ctx context.Context, opUserID string, changedUserID string) {
|
||||
selfInfoUpdatedTips := sdkws.UserInfoUpdatedTips{UserID: changedUserID}
|
||||
c.friendNotification(ctx, opUserID, changedUserID, constant.UserInfoUpdatedNotification, &selfInfoUpdatedTips)
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package startrpc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mw"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/network"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/prome"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
|
||||
"github.com/OpenIMSDK/openKeeper"
|
||||
grpcPrometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"net"
|
||||
)
|
||||
|
||||
func Start(rpcPort int, rpcRegisterName string, prometheusPort int, rpcFn func(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error, options ...grpc.ServerOption) error {
|
||||
fmt.Println("start", rpcRegisterName, "rpc server, port: ", rpcPort, "prometheusPort:", prometheusPort, ", OpenIM version: ", config.Version)
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", config.Config.ListenIP, rpcPort))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer listener.Close()
|
||||
fmt.Println(config.Config.Zookeeper.ZkAddr, config.Config.Zookeeper.Schema, rpcRegisterName)
|
||||
zkClient, err := openKeeper.NewClient(config.Config.Zookeeper.ZkAddr, config.Config.Zookeeper.Schema, 10, "", "")
|
||||
if err != nil {
|
||||
return utils.Wrap1(err)
|
||||
}
|
||||
defer zkClient.Close()
|
||||
zkClient.AddOption(mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
registerIP, err := network.GetRpcRegisterIP(config.Config.RpcRegisterIP)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
options = append(options, mw.GrpcServer()) // ctx 中间件
|
||||
if config.Config.Prometheus.Enable {
|
||||
prome.NewGrpcRequestCounter()
|
||||
prome.NewGrpcRequestFailedCounter()
|
||||
prome.NewGrpcRequestSuccessCounter()
|
||||
options = append(options, []grpc.ServerOption{
|
||||
//grpc.UnaryInterceptor(prome.UnaryServerInterceptorPrometheus),
|
||||
grpc.StreamInterceptor(grpcPrometheus.StreamServerInterceptor),
|
||||
grpc.UnaryInterceptor(grpcPrometheus.UnaryServerInterceptor),
|
||||
}...)
|
||||
}
|
||||
srv := grpc.NewServer(options...)
|
||||
defer srv.GracefulStop()
|
||||
err = rpcFn(zkClient, srv)
|
||||
if err != nil {
|
||||
return utils.Wrap1(err)
|
||||
}
|
||||
err = zkClient.Register(rpcRegisterName, registerIP, rpcPort, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
return utils.Wrap1(err)
|
||||
}
|
||||
go func() {
|
||||
if config.Config.Prometheus.Enable && prometheusPort != 0 {
|
||||
if err := prome.StartPrometheusSrv(prometheusPort); err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
return utils.Wrap1(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user