notification

test-errcode
wangchuxiao 2 years ago
parent c80babaef6
commit 94b5703399

@ -2,6 +2,7 @@ package msggateway
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/prome"
@ -9,14 +10,14 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msggateway"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/notification"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"github.com/OpenIMSDK/Open-IM-Server/pkg/startrpc"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
"google.golang.org/grpc"
)
func (s *Server) InitServer(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error {
s.LongConnServer.SetMessageHandler(notification.NewCheck(client))
s.LongConnServer.SetMessageHandler(rpcclient.NewMsgClient(client))
msggateway.RegisterMsgGatewayServer(server, s)
return nil
}
@ -26,7 +27,6 @@ func (s *Server) Start() error {
}
type Server struct {
notification *notification.Check
rpcPort int
prometheusPort int
LongConnServer LongConnServer
@ -37,10 +37,6 @@ func (s *Server) SetLongConnServer(LongConnServer LongConnServer) {
s.LongConnServer = LongConnServer
}
func (s *Server) Notification() *notification.Check {
return s.notification
}
func NewServer(rpcPort int, longConnServer LongConnServer) *Server {
return &Server{rpcPort: rpcPort, LongConnServer: longConnServer, pushTerminal: []int{constant.IOSPlatformID, constant.AndroidPlatformID}}
}

@ -5,7 +5,7 @@ import (
"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/notification"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
"github.com/go-playground/validator/v10"
"github.com/golang/protobuf/proto"
@ -49,12 +49,12 @@ type MessageHandler interface {
var _ MessageHandler = (*GrpcHandler)(nil)
type GrpcHandler struct {
notification *notification.Check
msgRpcClient *rpcclient.MsgClient
validate *validator.Validate
}
func NewGrpcHandler(validate *validator.Validate, notification *notification.Check) *GrpcHandler {
return &GrpcHandler{notification: notification, validate: validate}
func NewGrpcHandler(validate *validator.Validate, msgRpcClient *rpcclient.MsgClient) *GrpcHandler {
return &GrpcHandler{msgRpcClient: msgRpcClient, validate: validate}
}
func (g GrpcHandler) GetSeq(context context.Context, data Req) ([]byte, error) {
@ -65,7 +65,7 @@ func (g GrpcHandler) GetSeq(context context.Context, data Req) ([]byte, error) {
if err := g.validate.Struct(&req); err != nil {
return nil, err
}
resp, err := g.notification.Msg.GetMaxAndMinSeq(context, &req)
resp, err := g.msgRpcClient.GetMaxAndMinSeq(context, &req)
if err != nil {
return nil, err
}
@ -85,7 +85,7 @@ func (g GrpcHandler) SendMessage(context context.Context, data Req) ([]byte, err
return nil, err
}
req := msg.SendMsgReq{MsgData: &msgData}
resp, err := g.notification.Msg.SendMsg(context, &req)
resp, err := g.msgRpcClient.SendMsg(context, &req)
if err != nil {
return nil, err
}
@ -106,7 +106,7 @@ func (g GrpcHandler) SendSignalMessage(context context.Context, data Req) ([]byt
}
//req := pbRtc.SignalMessageAssembleReq{SignalReq: &signalReq, OperationID: "111"}
//todo rtc rpc call
resp, err := g.notification.Msg.SendMsg(context, nil)
resp, err := g.msgRpcClient.SendMsg(context, nil)
if err != nil {
return nil, err
}
@ -125,7 +125,7 @@ func (g GrpcHandler) PullMessageBySeqList(context context.Context, data Req) ([]
if err := g.validate.Struct(data); err != nil {
return nil, err
}
resp, err := g.notification.Msg.PullMessageBySeqList(context, &req)
resp, err := g.msgRpcClient.PullMessageBySeqList(context, &req)
if err != nil {
return nil, err
}
@ -138,7 +138,7 @@ func (g GrpcHandler) PullMessageBySeqList(context context.Context, data Req) ([]
func (g GrpcHandler) UserLogout(context context.Context, data Req) ([]byte, error) {
//todo
resp, err := g.notification.Msg.PullMessageBySeqList(context, nil)
resp, err := g.msgRpcClient.PullMessageBySeqList(context, nil)
if err != nil {
return nil, err
}

@ -2,16 +2,17 @@ package msggateway
import (
"errors"
"net/http"
"sync"
"sync/atomic"
"time"
"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/errs"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/notification"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
"github.com/go-playground/validator/v10"
"net/http"
"sync"
"sync/atomic"
"time"
)
type LongConnServer interface {
@ -20,7 +21,7 @@ type LongConnServer interface {
GetUserAllCons(userID string) ([]*Client, bool)
GetUserPlatformCons(userID string, platform int) ([]*Client, bool, bool)
Validate(s interface{}) error
SetMessageHandler(rpcClient *notification.Check)
SetMessageHandler(msgRpcClient *rpcclient.MsgClient)
UnRegister(c *Client)
Compressor
Encoder
@ -50,7 +51,7 @@ type WsServer struct {
MessageHandler
}
func (ws *WsServer) SetMessageHandler(rpcClient *notification.Check) {
func (ws *WsServer) SetMessageHandler(rpcClient *rpcclient.MsgClient) {
ws.MessageHandler = NewGrpcHandler(ws.validate, rpcClient)
}

@ -2,6 +2,8 @@ package fcm
import (
"context"
"path/filepath"
firebase "firebase.google.com/go"
"firebase.google.com/go/messaging"
"github.com/OpenIMSDK/Open-IM-Server/internal/push/offlinepush"
@ -10,7 +12,6 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache"
"github.com/go-redis/redis/v8"
"google.golang.org/api/option"
"path/filepath"
)
const SinglePushCountLimit = 400

@ -2,6 +2,7 @@ package auth
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/db/cache"
@ -12,14 +13,14 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
pbAuth "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/auth"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msggateway"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/check"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
"google.golang.org/grpc"
)
type authServer struct {
authDatabase controller.AuthDatabase
userCheck *check.UserCheck
userRpcClient *rpcclient.UserClient
RegisterCenter discoveryregistry.SvcDiscoveryRegistry
}
@ -29,7 +30,7 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
return err
}
pbAuth.RegisterAuthServer(server, &authServer{
userCheck: check.NewUserCheck(client),
userRpcClient: rpcclient.NewUserClient(client),
RegisterCenter: client,
authDatabase: controller.NewAuthDatabase(cache.NewCacheModel(rdb), config.Config.TokenPolicy.AccessSecret, config.Config.TokenPolicy.AccessExpire),
})
@ -38,7 +39,7 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
func (s *authServer) UserToken(ctx context.Context, req *pbAuth.UserTokenReq) (*pbAuth.UserTokenResp, error) {
resp := pbAuth.UserTokenResp{}
if _, err := s.userCheck.GetUserInfo(ctx, req.UserID); err != nil {
if _, err := s.userRpcClient.GetUserInfo(ctx, req.UserID); err != nil {
return nil, err
}
token, err := s.authDatabase.CreateToken(ctx, req.UserID, constant.PlatformIDToName(int(req.PlatformID)))

@ -12,16 +12,15 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
pbConversation "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/check"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/notification"
notification "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/notification2"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
"google.golang.org/grpc"
)
type conversationServer struct {
groupChecker *check.GroupChecker
// groupChecker *check.GroupChecker
controller.ConversationDatabase
notify *notification.Check
conversationNotificationSender *notification.ConversationNotificationSender
}
func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error {
@ -38,8 +37,8 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
}
conversationDB := relation.NewConversationGorm(db)
pbConversation.RegisterConversationServer(server, &conversationServer{
notify: notification.NewCheck(client),
groupChecker: check.NewGroupChecker(client),
conversationNotificationSender: notification.NewConversationNotificationSender(client),
// groupChecker: check.NewGroupChecker(client),
ConversationDatabase: controller.NewConversationDatabase(conversationDB, cache.NewConversationRedis(rdb, cache.GetDefaultOpt(), conversationDB), tx.NewGorm(db)),
})
return nil
@ -93,7 +92,7 @@ func (c *conversationServer) BatchSetConversations(ctx context.Context, req *pbC
if err != nil {
return nil, err
}
c.notify.ConversationChangeNotification(ctx, req.OwnerUserID)
c.conversationNotificationSender.ConversationChangeNotification(ctx, req.OwnerUserID)
resp := &pbConversation.BatchSetConversationsResp{}
return resp, nil
}
@ -107,7 +106,7 @@ func (c *conversationServer) SetConversation(ctx context.Context, req *pbConvers
if err != nil {
return nil, err
}
c.notify.ConversationChangeNotification(ctx, req.Conversation.OwnerUserID)
c.conversationNotificationSender.ConversationChangeNotification(ctx, req.Conversation.OwnerUserID)
resp := &pbConversation.SetConversationResp{}
return resp, nil
}
@ -142,7 +141,7 @@ func (c *conversationServer) ModifyConversationField(ctx context.Context, req *p
if err != nil {
return nil, err
}
c.notify.ConversationSetPrivateNotification(ctx, req.Conversation.OwnerUserID, req.Conversation.UserID, req.Conversation.IsPrivateChat)
c.conversationNotificationSender.ConversationSetPrivateNotification(ctx, req.Conversation.OwnerUserID, req.Conversation.UserID, req.Conversation.IsPrivateChat)
return resp, nil
}
filedMap := make(map[string]interface{})
@ -172,11 +171,11 @@ func (c *conversationServer) ModifyConversationField(ctx context.Context, req *p
if isSyncConversation {
for _, v := range req.UserIDList {
c.notify.ConversationChangeNotification(ctx, v)
c.conversationNotificationSender.ConversationChangeNotification(ctx, v)
}
} else {
for _, v := range req.UserIDList {
c.notify.ConversationUnreadChangeNotification(ctx, v, req.Conversation.ConversationID, req.Conversation.UpdateUnreadCountTime)
c.conversationNotificationSender.ConversationUnreadChangeNotification(ctx, v, req.Conversation.ConversationID, req.Conversation.UpdateUnreadCountTime)
}
}
return resp, nil

@ -10,6 +10,7 @@ import (
"time"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mw/specialerror"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache"
@ -48,19 +49,19 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
return err
}
pbGroup.RegisterGroupServer(server, &groupServer{
GroupDatabase: controller.InitGroupDatabase(db, rdb, mongo.GetDatabase()),
UserCheck: check.NewUserCheck(client),
Notification: notification.NewCheck(client),
ConversationChecker: check.NewConversationChecker(client),
GroupDatabase: controller.InitGroupDatabase(db, rdb, mongo.GetDatabase()),
UserCheck: check.NewUserCheck(client),
Notification: notification.NewCheck(client),
conversationRpcClient: rpcclient.NewConversationClient(client),
})
return nil
}
type groupServer struct {
GroupDatabase controller.GroupDatabase
UserCheck *check.UserCheck
Notification *notification.Check
ConversationChecker *check.ConversationChecker
GroupDatabase controller.GroupDatabase
UserCheck *check.UserCheck
Notification *notification.Check
conversationRpcClient *rpcclient.ConversationClient
}
func (s *groupServer) CheckGroupAdmin(ctx context.Context, groupID string) error {
@ -750,7 +751,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
FieldType: constant.FieldGroupAtType,
UserIDList: userIDs,
}
if err := s.ConversationChecker.ModifyConversationField(ctx, args); err != nil {
if err := s.conversationRpcClient.ModifyConversationField(ctx, args); err != nil {
log.ZWarn(ctx, "modifyConversationField failed", err, "args", args)
}
}

@ -2,6 +2,7 @@ package msg
import (
"context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller"
@ -14,7 +15,7 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
"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"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"github.com/go-redis/redis/v8"
"google.golang.org/grpc"
)
@ -24,12 +25,12 @@ type msgServer struct {
RegisterCenter discoveryregistry.SvcDiscoveryRegistry
MsgDatabase controller.MsgDatabase
ExtendMsgDatabase controller.ExtendMsgDatabase
Group *check.GroupChecker
User *check.UserCheck
Conversation *check.ConversationChecker
friend *check.FriendChecker
// Group *check.GroupChecker
User *rpcclient.UserClient
Conversation *rpcclient.ConversationClient
friend *rpcclient.FriendClient
*localcache.GroupLocalCache
black *check.BlackChecker
black *rpcclient.BlackClient
MessageLocker MessageLocker
Handlers MessageInterceptorChain
}
@ -64,15 +65,15 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
msgDatabase := controller.NewMsgDatabase(msgDocModel, cacheModel)
s := &msgServer{
Conversation: check.NewConversationChecker(client),
User: check.NewUserCheck(client),
Group: check.NewGroupChecker(client),
Conversation: rpcclient.NewConversationClient(client),
User: rpcclient.NewUserClient(client),
// Group: check.NewGroupChecker(client),
MsgDatabase: msgDatabase,
ExtendMsgDatabase: extendMsgDatabase,
RegisterCenter: client,
GroupLocalCache: localcache.NewGroupLocalCache(client),
black: check.NewBlackChecker(client),
friend: check.NewFriendChecker(client),
black: rpcclient.NewBlackClient(client),
friend: rpcclient.NewFriendClient(client),
MessageLocker: NewLockerMessage(cacheModel),
}
s.addInterceptorHandler(MessageHasReadEnabled, MessageModifyCallback)

@ -2,6 +2,8 @@ package third
import (
"context"
"net/url"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller"
@ -10,9 +12,8 @@ import (
relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/third"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/check"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"google.golang.org/grpc"
"net/url"
)
func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) error {
@ -37,7 +38,7 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
}
third.RegisterThirdServer(server, &thirdServer{
thirdDatabase: controller.NewThirdDatabase(cache.NewCacheModel(rdb)),
userCheck: check.NewUserCheck(client),
userRpcClient: rpcclient.NewUserClient(client),
s3dataBase: controller.NewS3Database(o, relation.NewObjectHash(db), relation.NewObjectInfo(db), relation.NewObjectPut(db), u),
})
return nil
@ -46,7 +47,7 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
type thirdServer struct {
thirdDatabase controller.ThirdDatabase
s3dataBase controller.S3Database
userCheck *check.UserCheck
userRpcClient *rpcclient.UserClient
}
func (t *thirdServer) FcmUpdateToken(ctx context.Context, req *third.FcmUpdateTokenReq) (resp *third.FcmUpdateTokenResp, err error) {

@ -17,20 +17,18 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
pbuser "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/user"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/check"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/convert"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/notification"
notification "github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient/notification2"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
"google.golang.org/grpc"
)
type userServer struct {
controller.UserDatabase
notification *notification.Check
userCheck *check.UserCheck
conversationChecker *check.ConversationChecker
RegisterCenter registry.SvcDiscoveryRegistry
friendCheck *check.FriendChecker
notificationSender *notification.FriendNotificationSender
friendRpcClient *rpcclient.FriendClient
RegisterCenter registry.SvcDiscoveryRegistry
}
func Start(client registry.SvcDiscoveryRegistry, server *grpc.Server) error {
@ -54,13 +52,12 @@ func Start(client registry.SvcDiscoveryRegistry, server *grpc.Server) error {
}
userDB := relation.NewUserGorm(db)
cache := cache.NewUserCacheRedis(rdb, userDB, cache.GetDefaultOpt())
database := controller.NewUserDatabase(userDB, cache, tx.NewGorm(db))
u := &userServer{
UserDatabase: controller.NewUserDatabase(userDB, cache, tx.NewGorm(db)),
notification: notification.NewCheck(client),
userCheck: check.NewUserCheck(client),
friendCheck: check.NewFriendChecker(client),
conversationChecker: check.NewConversationChecker(client),
RegisterCenter: client,
UserDatabase: database,
RegisterCenter: client,
friendRpcClient: rpcclient.NewFriendClient(client),
notificationSender: notification.NewFriendNotificationSender(client, notification.WithDBFunc(database.FindWithError)),
}
pbuser.RegisterUserServer(server, u)
return u.UserDatabase.InitOnce(context.Background(), users)
@ -73,7 +70,7 @@ func (s *userServer) GetDesignateUsers(ctx context.Context, req *pbuser.GetDesig
if err != nil {
return nil, err
}
resp.UsersInfo, err = (*convert.DBUser)(nil).DB2PB(users)
resp.UsersInfo = convert.UsersDB2Pb(users)
if err != nil {
return nil, err
}
@ -87,7 +84,7 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbuser.UpdateUserI
if err != nil {
return nil, err
}
user, err := convert.NewPBUser(req.UserInfo).Convert()
user := convert.UserPb2DB(req.UserInfo)
if err != nil {
return nil, err
}
@ -95,16 +92,16 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbuser.UpdateUserI
if err != nil {
return nil, err
}
friends, err := s.friendCheck.GetFriendIDs(ctx, req.UserInfo.UserID)
friends, err := s.friendRpcClient.GetFriendIDs(ctx, req.UserInfo.UserID)
if err != nil {
return nil, err
}
go func() {
for _, v := range friends {
s.notification.FriendInfoUpdatedNotification(ctx, req.UserInfo.UserID, v, mcontext.GetOpUserID(ctx))
s.notificationSender.FriendInfoUpdatedNotification(ctx, req.UserInfo.UserID, v, mcontext.GetOpUserID(ctx))
}
}()
s.notification.UserInfoUpdatedNotification(ctx, mcontext.GetOpUserID(ctx), req.UserInfo.UserID)
s.notificationSender.UserInfoUpdatedNotification(ctx, mcontext.GetOpUserID(ctx), req.UserInfo.UserID)
return resp, nil
}
@ -119,7 +116,7 @@ func (s *userServer) SetGlobalRecvMessageOpt(ctx context.Context, req *pbuser.Se
if err := s.UpdateByMap(ctx, req.UserID, m); err != nil {
return nil, err
}
s.notification.UserInfoUpdatedNotification(ctx, req.UserID, req.UserID)
s.notificationSender.UserInfoUpdatedNotification(ctx, req.UserID, req.UserID)
return resp, nil
}
@ -155,14 +152,16 @@ func (s *userServer) AccountCheck(ctx context.Context, req *pbuser.AccountCheckR
// ok
func (s *userServer) GetPaginationUsers(ctx context.Context, req *pbuser.GetPaginationUsersReq) (resp *pbuser.GetPaginationUsersResp, err error) {
resp = &pbuser.GetPaginationUsersResp{}
usersDB, total, err := s.Page(ctx, req.Pagination.PageNumber, req.Pagination.ShowNumber)
var pageNumber, showNumber int32
if req.Pagination != nil {
pageNumber = req.Pagination.PageNumber
showNumber = req.Pagination.ShowNumber
}
users, total, err := s.Page(ctx, pageNumber, showNumber)
if err != nil {
return nil, err
}
resp.Total = int32(total)
resp.Users, err = (*convert.DBUser)(nil).DB2PB(usersDB)
return resp, err
return &pbuser.GetPaginationUsersResp{Total: int32(total), Users: convert.UsersDB2Pb(users)}, err
}
// ok
@ -208,13 +207,11 @@ func (s *userServer) UserRegister(ctx context.Context, req *pbuser.UserRegisterR
}
func (s *userServer) GetGlobalRecvMessageOpt(ctx context.Context, req *pbuser.GetGlobalRecvMessageOptReq) (resp *pbuser.GetGlobalRecvMessageOptResp, err error) {
resp = &pbuser.GetGlobalRecvMessageOptResp{}
user, err := s.FindWithError(ctx, []string{req.UserID})
if err != nil {
return nil, err
}
resp.GlobalRecvMsgOpt = user[0].GlobalRecvMsgOpt
return resp, nil
return &pbuser.GetGlobalRecvMessageOptResp{GlobalRecvMsgOpt: user[0].GlobalRecvMsgOpt}, nil
}
func (s *userServer) GetAllUserID(ctx context.Context, req *pbuser.GetAllUserIDReq) (resp *pbuser.GetAllUserIDResp, err error) {
@ -222,6 +219,5 @@ func (s *userServer) GetAllUserID(ctx context.Context, req *pbuser.GetAllUserIDR
if err != nil {
return nil, err
}
resp = &pbuser.GetAllUserIDResp{UserIDs: userIDs}
return resp, nil
return &pbuser.GetAllUserIDResp{UserIDs: userIDs}, nil
}

@ -0,0 +1,30 @@
package rpcclient
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"
)
type BlackClient struct {
*MetaClient
}
func NewBlackClient(zk discoveryRegistry.SvcDiscoveryRegistry) *BlackClient {
return &BlackClient{NewMetaClient(zk, config.Config.RpcRegisterName.OpenImFriendName)}
}
// possibleBlackUserID是否被userID拉黑也就是是否在userID的黑名单中
func (b *BlackClient) IsBlocked(ctx context.Context, possibleBlackUserID, userID string) (bool, error) {
cc, err := b.getConn()
if err != nil {
return false, err
}
r, err := friend.NewFriendClient(cc).IsBlack(ctx, &friend.IsBlackReq{UserID1: possibleBlackUserID, UserID2: userID})
if err != nil {
return false, err
}
return r.InUser2Blacks, nil
}

@ -1,14 +0,0 @@
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)
}

@ -1,21 +0,0 @@
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
}

@ -1,46 +0,0 @@
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
}

@ -1,63 +0,0 @@
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
}

@ -1,49 +0,0 @@
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
}

@ -1,114 +0,0 @@
package check
import (
"context"
"strings"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"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"
)
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 {
return nil, err
}
resp, err := user.NewUserClient(cc).GetDesignateUsers(ctx, &user.GetDesignateUsersReq{
UserIDs: userIDs,
})
if err != nil {
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,
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,42 @@
package rpcclient
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"
)
type ConversationClient struct {
*MetaClient
}
func NewConversationClient(zk discoveryRegistry.SvcDiscoveryRegistry) *ConversationClient {
return &ConversationClient{NewMetaClient(zk, config.Config.RpcRegisterName.OpenImConversationName)}
}
func (c *ConversationClient) 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 *ConversationClient) 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
conversation, err := conversation.NewConversationClient(cc).GetConversation(ctx, &req)
if err != nil {
return 0, err
}
return conversation.GetConversation().RecvMsgOpt, err
}

@ -8,172 +8,11 @@ import (
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"
)
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()
pbfriend.OperatorUserID = v.OperatorUserID
pbfriend.OwnerUserID = v.OwnerUserID
pbfriend.Remark = v.Remark
pbfriend.AddSource = v.AddSource
pbfriend.Ex = v.Ex
pbFriends = append(pbFriends, pbfriend)
}
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)
}
for _, v := range friendRequests {
userIDs = append(userIDs, v.ToUserID)
}
users, err := db.userCheck.GetUsersInfoMap(ctx, userIDs, true)
if err != nil {
return nil, err
}
for _, v := range friendRequests {
pbFriendRequest := &sdk.FriendRequest{}
pbFriendRequest.FromUserID = users[v.FromUserID].UserID
pbFriendRequest.FromNickname = users[v.FromUserID].Nickname
pbFriendRequest.FromFaceURL = users[v.FromUserID].FaceURL
pbFriendRequest.ToUserID = users[v.ToUserID].UserID
pbFriendRequest.ToNickname = users[v.ToUserID].Nickname
pbFriendRequest.ToFaceURL = users[v.ToUserID].FaceURL
pbFriendRequest.CreateTime = v.CreateTime.Unix()
pbFriendRequest.HandleTime = v.HandleTime.Unix()
pbFriendRequest.HandlerUserID = v.HandlerUserID
pbFriendRequest.HandleResult = v.HandleResult
pbFriendRequest.Ex = v.Ex
pbFriendRequest.HandleMsg = v.HandleMsg
pbFriendRequest.ReqMsg = v.ReqMsg
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
user, err = db.userCheck.GetUserInfo(ctx, db.ToUserID)
if err != nil {
return nil, err
}
pbFriendRequest.ToNickname = user.Nickname
pbFriendRequest.ToFaceURL = user.FaceURL
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) {

@ -0,0 +1,34 @@
package convert
import (
"time"
relationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
)
func UsersDB2Pb(users []*relationTb.UserModel) (result []*sdkws.UserInfo) {
for _, user := range users {
var userPb sdkws.UserInfo
userPb.UserID = user.UserID
userPb.Nickname = user.Nickname
userPb.FaceURL = user.FaceURL
userPb.Ex = user.Ex
userPb.CreateTime = user.CreateTime.Unix()
userPb.AppMangerLevel = user.AppMangerLevel
userPb.GlobalRecvMsgOpt = user.GlobalRecvMsgOpt
}
return result
}
func UserPb2DB(user *sdkws.UserInfo) *relationTb.UserModel {
var userDB relationTb.UserModel
userDB.UserID = user.UserID
userDB.Nickname = user.Nickname
userDB.FaceURL = user.FaceURL
userDB.Ex = user.Ex
userDB.CreateTime = time.Unix(user.CreateTime, 0)
userDB.AppMangerLevel = user.AppMangerLevel
userDB.GlobalRecvMsgOpt = user.GlobalRecvMsgOpt
return &userDB
}

@ -1,299 +0,0 @@
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
}

@ -1,153 +0,0 @@
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)
}

@ -1,42 +0,0 @@
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)
}

@ -1,13 +0,0 @@
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)
}

@ -1,15 +1,26 @@
package notification
package notification2
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/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"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) {
type ConversationNotificationSender struct {
*rpcclient.MsgClient
}
func NewConversationNotificationSender(client discoveryregistry.SvcDiscoveryRegistry) *ConversationNotificationSender {
return &ConversationNotificationSender{rpcclient.NewMsgClient(client)}
}
func (c *ConversationNotificationSender) 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 {
@ -21,13 +32,13 @@ func (c *Check) SetConversationNotification(ctx context.Context, sendID, recvID
EmitDefaults: false,
}
tips.JsonDetail, _ = marshaler.MarshalToString(m)
var n NotificationMsg
var n rpcclient.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)
n.Content, err = proto.Marshal(tips)
if err != nil {
return
}
@ -35,8 +46,7 @@ func (c *Check) SetConversationNotification(ctx context.Context, sendID, recvID
}
// SetPrivate调用
func (c *Check) ConversationSetPrivateNotification(ctx context.Context, sendID, recvID string, isPrivateChat bool) {
func (c *ConversationNotificationSender) ConversationSetPrivateNotification(ctx context.Context, sendID, recvID string, isPrivateChat bool) {
conversationSetPrivateTips := &sdkws.ConversationSetPrivateTips{
RecvID: recvID,
SendID: sendID,
@ -50,23 +60,21 @@ func (c *Check) ConversationSetPrivateNotification(ctx context.Context, sendID,
tipsMsg = config.Config.Notification.ConversationSetPrivate.DefaultTips.CloseTips
}
tips.DefaultTips = tipsMsg
c.SetConversationNotification(ctx, sendID, recvID, constant.ConversationPrivateChatNotification, conversationSetPrivateTips, tips)
c.SetConversationNotification(ctx, sendID, recvID, constant.ConversationPrivateChatNotification, conversationSetPrivateTips, &tips)
}
// 会话改变
func (c *Check) ConversationChangeNotification(ctx context.Context, userID string) {
func (c *ConversationNotificationSender) 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)
c.SetConversationNotification(ctx, userID, userID, constant.ConversationOptChangeNotification, ConversationChangedTips, &tips)
}
// 会话未读数同步
func (c *Check) ConversationUnreadChangeNotification(ctx context.Context, userID, conversationID string, updateUnreadCountTime int64) {
func (c *ConversationNotificationSender) ConversationUnreadChangeNotification(ctx context.Context, userID, conversationID string, updateUnreadCountTime int64) {
ConversationChangedTips := &sdkws.ConversationUpdateTips{
UserID: userID,
ConversationIDList: []string{conversationID},
@ -74,5 +82,5 @@ func (c *Check) ConversationUnreadChangeNotification(ctx context.Context, userID
}
var tips sdkws.TipsComm
tips.DefaultTips = config.Config.Notification.ConversationOptUpdate.DefaultTips.Tips
c.SetConversationNotification(ctx, userID, userID, constant.ConversationUnreadNotification, ConversationChangedTips, tips)
c.SetConversationNotification(ctx, userID, userID, constant.ConversationUnreadNotification, ConversationChangedTips, &tips)
}

@ -1,21 +1,32 @@
package notification
package notification2
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/mcontext"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
"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/proto/sdkws"
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
)
func (c *Check) ExtendMessageUpdatedNotification(ctx context.Context, sendID string, sourceID string, sessionType int32,
type ExtendMsgNotificationSender struct {
*rpcclient.MsgClient
}
func NewExtendMsgNotificationSender(client discoveryregistry.SvcDiscoveryRegistry) *ExtendMsgNotificationSender {
return &ExtendMsgNotificationSender{rpcclient.NewMsgClient(client)}
}
func (e *ExtendMsgNotificationSender) 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 = mcontext.GetOpUserID(ctx)
m.SessionType = req.SessionType
var content apistruct.ReactionMessageModifierNotification
content.SourceID = req.SourceID
content.OpUserID = mcontext.GetOpUserID(ctx)
content.SessionType = req.SessionType
keyMap := make(map[string]*sdkws.KeyValue)
for _, valueResp := range resp.Result {
if valueResp.ErrCode == 0 {
@ -25,19 +36,19 @@ func (c *Check) ExtendMessageUpdatedNotification(ctx context.Context, sendID str
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)
content.SuccessReactionExtensions = keyMap
content.ClientMsgID = req.ClientMsgID
content.IsReact = resp.IsReact
content.IsExternalExtensions = req.IsExternalExtensions
content.MsgFirstModifyTime = resp.MsgFirstModifyTime
e.messageReactionSender(ctx, sendID, sourceID, sessionType, constant.ReactionMessageModifier, utils.StructToJsonString(content), isHistory, isReactionFromCache)
}
func (c *Check) ExtendMessageDeleteNotification(ctx context.Context, sendID string, sourceID string, sessionType int32,
func (e *ExtendMsgNotificationSender) 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
var content apistruct.ReactionMessageDeleteNotification
content.SourceID = req.SourceID
content.OpUserID = req.OpUserID
content.SessionType = req.SessionType
keyMap := make(map[string]*sdkws.KeyValue)
for _, valueResp := range resp.Result {
if valueResp.ErrCode == 0 {
@ -47,13 +58,12 @@ func (c *Check) ExtendMessageDeleteNotification(ctx context.Context, sendID stri
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)
content.SuccessReactionExtensions = keyMap
content.ClientMsgID = req.ClientMsgID
content.MsgFirstModifyTime = req.MsgFirstModifyTime
e.messageReactionSender(ctx, sendID, sourceID, sessionType, constant.ReactionMessageDeleter, utils.StructToJsonString(content), isHistory, isReactionFromCache)
}
func (c *Check) messageReactionSender(ctx context.Context, sendID string, sourceID string, sessionType, contentType int32, content string, isHistory bool, isReactionFromCache bool) error {
func (e *ExtendMsgNotificationSender) 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)
@ -82,6 +92,6 @@ func (c *Check) messageReactionSender(ctx context.Context, sendID string, source
case constant.GroupChatType, constant.SuperGroupChatType:
pbData.MsgData.GroupID = sourceID
}
_, err := c.Msg.SendMsg(ctx, &pbData)
_, err := e.SendMsg(ctx, &pbData)
return err
}

@ -26,6 +26,12 @@ type FriendNotificationSender struct {
type friendNotificationSenderOptions func(*FriendNotificationSender)
func WithFriendDB(db controller.FriendDatabase) friendNotificationSenderOptions {
return func(s *FriendNotificationSender) {
s.db = db
}
}
func WithDBFunc(fn func(ctx context.Context, userIDs []string) (users []*relationTb.UserModel, err error)) friendNotificationSenderOptions {
return func(s *FriendNotificationSender) {
f := func(ctx context.Context, userIDs []string) (result []rpcclient.CommonUser, err error) {
@ -146,6 +152,11 @@ func (c *FriendNotificationSender) friendNotification(ctx context.Context, fromU
c.Notification(ctx, &n)
}
func (u *FriendNotificationSender) UserInfoUpdatedNotification(ctx context.Context, opUserID string, changedUserID string) {
selfInfoUpdatedTips := sdkws.UserInfoUpdatedTips{UserID: changedUserID}
u.friendNotification(ctx, opUserID, changedUserID, constant.UserInfoUpdatedNotification, &selfInfoUpdatedTips)
}
func (c *FriendNotificationSender) FriendApplicationAddNotification(ctx context.Context, req *pbFriend.ApplyToAddFriendReq) {
FriendApplicationTips := sdkws.FriendApplicationTips{FromToUserID: &sdkws.FromToUserID{}}
FriendApplicationTips.FromToUserID.FromUserID = req.FromUserID
@ -185,6 +196,9 @@ func (c *FriendNotificationSender) FriendAddedNotification(ctx context.Context,
return
}
friendAddedTips.Friend, err = convert.FriendDB2Pb(ctx, friends[0], c.getUsersInfoMap)
if err != nil {
return
}
c.friendNotification(ctx, fromUserID, toUserID, constant.FriendAddedNotification, &friendAddedTips)
}

Loading…
Cancel
Save