fix: changing naming irregularities under pkg and internal packages (#520)

pull/656/head
BanTanger 2 years ago
parent 1b5eb4a5c0
commit bbac1d9d6b

@ -69,7 +69,7 @@ cert_key =
# Unix socket path # Unix socket path
socket = /tmp/grafana.sock socket = /tmp/grafana.sock
# CDN Url # CDN URL
cdn_url = cdn_url =
# Sets the maximum time in minutes before timing out read of an incoming request and closing idle connections. # Sets the maximum time in minutes before timing out read of an incoming request and closing idle connections.

@ -27,7 +27,7 @@ func main() {
if err := pushCmd.Exec(); err != nil { if err := pushCmd.Exec(); err != nil {
panic(err.Error()) panic(err.Error())
} }
if err := pushCmd.StartSvr(config.Config.RpcRegisterName.OpenImPushName, push.Start); err != nil { if err := pushCmd.StartSvr(config.Config.RPCRegisterName.OpenImPushName, push.Start); err != nil {
panic(err.Error()) panic(err.Error())
} }
} }

@ -27,7 +27,7 @@ func main() {
if err := authCmd.Exec(); err != nil { if err := authCmd.Exec(); err != nil {
panic(err.Error()) panic(err.Error())
} }
if err := authCmd.StartSvr(config.Config.RpcRegisterName.OpenImAuthName, auth.Start); err != nil { if err := authCmd.StartSvr(config.Config.RPCRegisterName.OpenImAuthName, auth.Start); err != nil {
panic(err.Error()) panic(err.Error())
} }
} }

@ -27,7 +27,7 @@ func main() {
if err := rpcCmd.Exec(); err != nil { if err := rpcCmd.Exec(); err != nil {
panic(err.Error()) panic(err.Error())
} }
if err := rpcCmd.StartSvr(config.Config.RpcRegisterName.OpenImConversationName, conversation.Start); err != nil { if err := rpcCmd.StartSvr(config.Config.RPCRegisterName.OpenImConversationName, conversation.Start); err != nil {
panic(err.Error()) panic(err.Error())
} }
} }

@ -27,7 +27,7 @@ func main() {
if err := rpcCmd.Exec(); err != nil { if err := rpcCmd.Exec(); err != nil {
panic(err.Error()) panic(err.Error())
} }
if err := rpcCmd.StartSvr(config.Config.RpcRegisterName.OpenImFriendName, friend.Start); err != nil { if err := rpcCmd.StartSvr(config.Config.RPCRegisterName.OpenImFriendName, friend.Start); err != nil {
panic(err.Error()) panic(err.Error())
} }
} }

@ -27,7 +27,7 @@ func main() {
if err := rpcCmd.Exec(); err != nil { if err := rpcCmd.Exec(); err != nil {
panic(err.Error()) panic(err.Error())
} }
if err := rpcCmd.StartSvr(config.Config.RpcRegisterName.OpenImGroupName, group.Start); err != nil { if err := rpcCmd.StartSvr(config.Config.RPCRegisterName.OpenImGroupName, group.Start); err != nil {
panic(err.Error()) panic(err.Error())
} }
} }

@ -27,7 +27,7 @@ func main() {
if err := rpcCmd.Exec(); err != nil { if err := rpcCmd.Exec(); err != nil {
panic(err.Error()) panic(err.Error())
} }
if err := rpcCmd.StartSvr(config.Config.RpcRegisterName.OpenImMsgName, msg.Start); err != nil { if err := rpcCmd.StartSvr(config.Config.RPCRegisterName.OpenImMsgName, msg.Start); err != nil {
panic(err.Error()) panic(err.Error())
} }
} }

@ -27,7 +27,7 @@ func main() {
if err := rpcCmd.Exec(); err != nil { if err := rpcCmd.Exec(); err != nil {
panic(err.Error()) panic(err.Error())
} }
if err := rpcCmd.StartSvr(config.Config.RpcRegisterName.OpenImThirdName, third.Start); err != nil { if err := rpcCmd.StartSvr(config.Config.RPCRegisterName.OpenImThirdName, third.Start); err != nil {
panic(err.Error()) panic(err.Error())
} }
} }

@ -27,7 +27,7 @@ func main() {
if err := rpcCmd.Exec(); err != nil { if err := rpcCmd.Exec(); err != nil {
panic(err.Error()) panic(err.Error())
} }
if err := rpcCmd.StartSvr(config.Config.RpcRegisterName.OpenImUserName, user.Start); err != nil { if err := rpcCmd.StartSvr(config.Config.RPCRegisterName.OpenImUserName, user.Start); err != nil {
panic(err.Error()) panic(err.Error())
} }
} }

@ -169,7 +169,7 @@ func (m *MessageApi) SendMessage(c *gin.Context) {
apiresp.GinError(c, errs.ErrArgs.WithDetail(err.Error()).Wrap()) apiresp.GinError(c, errs.ErrArgs.WithDetail(err.Error()).Wrap())
return return
} }
if !tokenverify.IsAppManagerUid(c) { if !tokenverify.IsAppManagerUID(c) {
apiresp.GinError(c, errs.ErrNoPermission.Wrap("only app manager can send message")) apiresp.GinError(c, errs.ErrNoPermission.Wrap("only app manager can send message"))
return return
} }

@ -43,9 +43,9 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
u := NewUserApi(discov) u := NewUserApi(discov)
m := NewMessageApi(discov) m := NewMessageApi(discov)
if config.Config.Prometheus.Enable { if config.Config.Prometheus.Enable {
prome.NewApiRequestCounter() prome.NewAPIRequestCounter()
prome.NewApiRequestFailedCounter() prome.NewAPIRequestFailedCounter()
prome.NewApiRequestSuccessCounter() prome.NewAPIRequestSuccessCounter()
r.Use(prome.PrometheusMiddleware) r.Use(prome.PrometheusMiddleware)
r.GET("/metrics", prome.PrometheusHandler()) r.GET("/metrics", prome.PrometheusHandler())
} }
@ -62,7 +62,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
userRouterGroup.POST("/get_users_online_status", ParseToken, u.GetUsersOnlineStatus) userRouterGroup.POST("/get_users_online_status", ParseToken, u.GetUsersOnlineStatus)
userRouterGroup.POST("/get_users_online_token_detail", ParseToken, u.GetUsersOnlineTokenDetail) userRouterGroup.POST("/get_users_online_token_detail", ParseToken, u.GetUsersOnlineTokenDetail)
} }
//friend routing group // friend routing group
friendRouterGroup := r.Group("/friend", ParseToken) friendRouterGroup := r.Group("/friend", ParseToken)
{ {
f := NewFriendApi(discov) f := NewFriendApi(discov)
@ -109,7 +109,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
superGroupRouterGroup.POST("/get_joined_group_list", g.GetJoinedSuperGroupList) superGroupRouterGroup.POST("/get_joined_group_list", g.GetJoinedSuperGroupList)
superGroupRouterGroup.POST("/get_groups_info", g.GetSuperGroupsInfo) superGroupRouterGroup.POST("/get_groups_info", g.GetSuperGroupsInfo)
} }
//certificate // certificate
authRouterGroup := r.Group("/auth") authRouterGroup := r.Group("/auth")
{ {
a := NewAuthApi(discov) a := NewAuthApi(discov)
@ -117,7 +117,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
authRouterGroup.POST("/parse_token", a.ParseToken) authRouterGroup.POST("/parse_token", a.ParseToken)
authRouterGroup.POST("/force_logout", ParseToken, a.ForceLogout) authRouterGroup.POST("/force_logout", ParseToken, a.ForceLogout)
} }
//Third service // Third service
thirdGroup := r.Group("/third", ParseToken) thirdGroup := r.Group("/third", ParseToken)
{ {
t := NewThirdApi(discov) t := NewThirdApi(discov)
@ -134,7 +134,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
objectGroup.POST("/access_url", t.AccessURL) objectGroup.POST("/access_url", t.AccessURL)
objectGroup.GET("/*name", t.ObjectRedirect) objectGroup.GET("/*name", t.ObjectRedirect)
} }
//Message // Message
msgGroup := r.Group("/msg", ParseToken) msgGroup := r.Group("/msg", ParseToken)
{ {
msgGroup.POST("/newest_seq", m.GetSeq) msgGroup.POST("/newest_seq", m.GetSeq)
@ -155,7 +155,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive
msgGroup.POST("/batch_send_msg", m.ManagementBatchSendMsg) msgGroup.POST("/batch_send_msg", m.ManagementBatchSendMsg)
msgGroup.POST("/check_msg_is_send_success", m.CheckMsgIsSendSuccess) msgGroup.POST("/check_msg_is_send_success", m.CheckMsgIsSendSuccess)
} }
//Conversation // Conversation
conversationGroup := r.Group("/conversation", ParseToken) conversationGroup := r.Group("/conversation", ParseToken)
{ {
c := NewConversationApi(discov) c := NewConversationApi(discov)

@ -69,7 +69,7 @@ func (u *UserApi) GetUsersOnlineStatus(c *gin.Context) {
apiresp.GinError(c, errs.ErrArgs.WithDetail(err.Error()).Wrap()) apiresp.GinError(c, errs.ErrArgs.WithDetail(err.Error()).Wrap())
return return
} }
conns, err := u.Discov.GetConns(c, config.Config.RpcRegisterName.OpenImMessageGatewayName) conns, err := u.Discov.GetConns(c, config.Config.RPCRegisterName.OpenImMessageGatewayName)
if err != nil { if err != nil {
apiresp.GinError(c, err) apiresp.GinError(c, err)
return return
@ -79,7 +79,7 @@ func (u *UserApi) GetUsersOnlineStatus(c *gin.Context) {
var respResult []*msggateway.GetUsersOnlineStatusResp_SuccessResult var respResult []*msggateway.GetUsersOnlineStatusResp_SuccessResult
flag := false flag := false
//Online push message // Online push message
for _, v := range conns { for _, v := range conns {
msgClient := msggateway.NewMsgGatewayClient(v) msgClient := msggateway.NewMsgGatewayClient(v)
reply, err := msgClient.GetUsersOnlineStatus(c, &req) reply, err := msgClient.GetUsersOnlineStatus(c, &req)
@ -127,12 +127,12 @@ func (u *UserApi) GetUsersOnlineTokenDetail(c *gin.Context) {
apiresp.GinError(c, errs.ErrArgs.WithDetail(err.Error()).Wrap()) apiresp.GinError(c, errs.ErrArgs.WithDetail(err.Error()).Wrap())
return return
} }
conns, err := u.Discov.GetConns(c, config.Config.RpcRegisterName.OpenImMessageGatewayName) conns, err := u.Discov.GetConns(c, config.Config.RPCRegisterName.OpenImMessageGatewayName)
if err != nil { if err != nil {
apiresp.GinError(c, err) apiresp.GinError(c, err)
return return
} }
//Online push message // Online push message
for _, v := range conns { for _, v := range conns {
msgClient := msggateway.NewMsgGatewayClient(v) msgClient := msggateway.NewMsgGatewayClient(v)
reply, err := msgClient.GetUsersOnlineStatus(c, &req) reply, err := msgClient.GetUsersOnlineStatus(c, &req)

@ -26,7 +26,7 @@ import (
) )
func url() string { func url() string {
return config.Config.Callback.CallbackUrl return config.Config.Callback.CallbackURL
} }
func CallbackUserOnline(ctx context.Context, userID string, platformID int, isAppBackground bool, connID string) error { func CallbackUserOnline(ctx context.Context, userID string, platformID int, isAppBackground bool, connID string) error {
@ -114,15 +114,15 @@ func CallbackUserKickOff(ctx context.Context, userID string, platformID int) err
// ConnID: connID, // ConnID: connID,
// } // }
// callbackUserOnlineResp := &cbApi.CallbackUserOnlineResp{CommonCallbackResp: &callbackResp} // callbackUserOnlineResp := &cbApi.CallbackUserOnlineResp{CommonCallbackResp: &callbackResp}
// if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, constant.CallbackUserOnlineCommand, // if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackURL, constant.CallbackUserOnlineCommand,
// callbackUserOnlineReq, callbackUserOnlineResp, config.Config.Callback.CallbackUserOnline.CallbackTimeOut); err != nil // callbackUserOnlineReq, callbackUserOnlineResp, config.Config.Callback.CallbackUserOnline.CallbackTimeOut); err != nil
// { // {
// callbackResp.ErrCode = http2.StatusInternalServerError // callbackResp.ErrCode = http2.StatusInternalServerError
// callbackResp.ErrMsg = err.Error() // callbackResp.ErrMsg = err.Error()
// } // }
// return callbackResp // return callbackResp
//} // }
//func callbackUserOffline(operationID, userID string, platformID int, connID string) cbApi.CommonCallbackResp { // func callbackUserOffline(operationID, userID string, platformID int, connID string) cbApi.CommonCallbackResp {
// callbackResp := cbApi.CommonCallbackResp{OperationID: operationID} // callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
// if !config.Config.Callback.CallbackUserOffline.Enable { // if !config.Config.Callback.CallbackUserOffline.Enable {
// return callbackResp // return callbackResp
@ -141,15 +141,15 @@ func CallbackUserKickOff(ctx context.Context, userID string, platformID int) err
// ConnID: connID, // ConnID: connID,
// } // }
// callbackUserOfflineResp := &cbApi.CallbackUserOfflineResp{CommonCallbackResp: &callbackResp} // callbackUserOfflineResp := &cbApi.CallbackUserOfflineResp{CommonCallbackResp: &callbackResp}
// if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, constant.CallbackUserOfflineCommand, // if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackURL, constant.CallbackUserOfflineCommand,
// callbackOfflineReq, callbackUserOfflineResp, config.Config.Callback.CallbackUserOffline.CallbackTimeOut); err != nil // callbackOfflineReq, callbackUserOfflineResp, config.Config.Callback.CallbackUserOffline.CallbackTimeOut); err != nil
// { // {
// callbackResp.ErrCode = http2.StatusInternalServerError // callbackResp.ErrCode = http2.StatusInternalServerError
// callbackResp.ErrMsg = err.Error() // callbackResp.ErrMsg = err.Error()
// } // }
// return callbackResp // return callbackResp
//} // }
//func callbackUserKickOff(operationID string, userID string, platformID int) cbApi.CommonCallbackResp { // func callbackUserKickOff(operationID string, userID string, platformID int) cbApi.CommonCallbackResp {
// callbackResp := cbApi.CommonCallbackResp{OperationID: operationID} // callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
// if !config.Config.Callback.CallbackUserKickOff.Enable { // if !config.Config.Callback.CallbackUserKickOff.Enable {
// return callbackResp // return callbackResp
@ -167,11 +167,11 @@ func CallbackUserKickOff(ctx context.Context, userID string, platformID int) err
// Seq: int(time.Now().UnixNano() / 1e6), // Seq: int(time.Now().UnixNano() / 1e6),
// } // }
// callbackUserKickOffResp := &cbApi.CallbackUserKickOffResp{CommonCallbackResp: &callbackResp} // callbackUserKickOffResp := &cbApi.CallbackUserKickOffResp{CommonCallbackResp: &callbackResp}
// if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, constant.CallbackUserKickOffCommand, // if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackURL, constant.CallbackUserKickOffCommand,
// callbackUserKickOffReq, callbackUserKickOffResp, config.Config.Callback.CallbackUserOffline.CallbackTimeOut); err != // callbackUserKickOffReq, callbackUserKickOffResp, config.Config.Callback.CallbackUserOffline.CallbackTimeOut); err !=
// nil { // nil {
// callbackResp.ErrCode = http2.StatusInternalServerError // callbackResp.ErrCode = http2.StatusInternalServerError
// callbackResp.ErrMsg = err.Error() // callbackResp.ErrMsg = err.Error()
// } // }
// return callbackResp // return callbackResp
//} // }

@ -116,7 +116,7 @@ func (c *Client) readMessage() {
return return
} }
log.ZDebug(c.ctx, "readMessage", "messageType", messageType) log.ZDebug(c.ctx, "readMessage", "messageType", messageType)
if c.closed == true { //连接刚置位已经关闭,但是协程还没退出的场景 if c.closed == true { // 连接刚置位已经关闭,但是协程还没退出的场景
c.closedErr = ErrConnClosed c.closedErr = ErrConnClosed
return return
} }
@ -191,7 +191,7 @@ func (c *Client) setAppBackgroundStatus(ctx context.Context, req Req) ([]byte, e
return nil, messageErr return nil, messageErr
} }
c.IsBackground = isBackground c.IsBackground = isBackground
//todo callback // todo callback
return resp, nil return resp, nil
} }
@ -254,8 +254,6 @@ func (c *Client) writeBinaryMsg(resp Resp) error {
if c.closed == true { if c.closed == true {
return nil return nil
} }
encodedBuf := bufferPool.Get().([]byte)
resultBuf := bufferPool.Get().([]byte)
encodedBuf, err := c.longConnServer.Encode(resp) encodedBuf, err := c.longConnServer.Encode(resp)
if err != nil { if err != nil {
return utils.Wrap(err, "") return utils.Wrap(err, "")
@ -263,7 +261,7 @@ func (c *Client) writeBinaryMsg(resp Resp) error {
_ = c.conn.SetWriteDeadline(writeWait) _ = c.conn.SetWriteDeadline(writeWait)
if c.IsCompress { if c.IsCompress {
var compressErr error var compressErr error
resultBuf, compressErr = c.longConnServer.Compress(encodedBuf) resultBuf, compressErr := c.longConnServer.Compress(encodedBuf)
if compressErr != nil { if compressErr != nil {
return utils.Wrap(compressErr, "") return utils.Wrap(compressErr, "")
} }

@ -48,7 +48,7 @@ func (s *Server) InitServer(client discoveryregistry.SvcDiscoveryRegistry, serve
func (s *Server) Start() error { func (s *Server) Start() error {
return startrpc.Start( return startrpc.Start(
s.rpcPort, s.rpcPort,
config.Config.RpcRegisterName.OpenImMessageGatewayName, config.Config.RPCRegisterName.OpenImMessageGatewayName,
s.prometheusPort, s.prometheusPort,
s.InitServer, s.InitServer,
) )
@ -84,7 +84,7 @@ func (s *Server) GetUsersOnlineStatus(
ctx context.Context, ctx context.Context,
req *msggateway.GetUsersOnlineStatusReq, req *msggateway.GetUsersOnlineStatusReq,
) (*msggateway.GetUsersOnlineStatusResp, error) { ) (*msggateway.GetUsersOnlineStatusResp, error) {
if !tokenverify.IsAppManagerUid(ctx) { if !tokenverify.IsAppManagerUID(ctx) {
return nil, errs.ErrNoPermission.Wrap("only app manager") return nil, errs.ErrNoPermission.Wrap("only app manager")
} }
var resp msggateway.GetUsersOnlineStatusResp var resp msggateway.GetUsersOnlineStatusResp
@ -197,6 +197,6 @@ func (s *Server) MultiTerminalLoginCheck(
ctx context.Context, ctx context.Context,
req *msggateway.MultiTerminalLoginCheckReq, req *msggateway.MultiTerminalLoginCheckReq,
) (*msggateway.MultiTerminalLoginCheckResp, error) { ) (*msggateway.MultiTerminalLoginCheckResp, error) {
//TODO implement me // TODO implement me
panic("implement me") panic("implement me")
} }

@ -67,15 +67,15 @@ type MessageHandler interface {
var _ MessageHandler = (*GrpcHandler)(nil) var _ MessageHandler = (*GrpcHandler)(nil)
type GrpcHandler struct { type GrpcHandler struct {
msgRpcClient *rpcclient.MessageRpcClient msgRPCClient *rpcclient.MessageRpcClient
pushClient *rpcclient.PushRpcClient pushClient *rpcclient.PushRPCClient
validate *validator.Validate validate *validator.Validate
} }
func NewGrpcHandler(validate *validator.Validate, client discoveryregistry.SvcDiscoveryRegistry) *GrpcHandler { func NewGrpcHandler(validate *validator.Validate, client discoveryregistry.SvcDiscoveryRegistry) *GrpcHandler {
msgRpcClient := rpcclient.NewMessageRpcClient(client) msgRPCClient := rpcclient.NewMessageRpcClient(client)
pushRpcClient := rpcclient.NewPushRpcClient(client) pushRpcClient := rpcclient.NewPushRPCClient(client)
return &GrpcHandler{msgRpcClient: &msgRpcClient, return &GrpcHandler{msgRPCClient: &msgRPCClient,
pushClient: &pushRpcClient, validate: validate} pushClient: &pushRpcClient, validate: validate}
} }
@ -87,7 +87,7 @@ func (g GrpcHandler) GetSeq(context context.Context, data Req) ([]byte, error) {
if err := g.validate.Struct(&req); err != nil { if err := g.validate.Struct(&req); err != nil {
return nil, err return nil, err
} }
resp, err := g.msgRpcClient.GetMaxSeq(context, &req) resp, err := g.msgRPCClient.GetMaxSeq(context, &req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -107,7 +107,7 @@ func (g GrpcHandler) SendMessage(context context.Context, data Req) ([]byte, err
return nil, err return nil, err
} }
req := msg.SendMsgReq{MsgData: &msgData} req := msg.SendMsgReq{MsgData: &msgData}
resp, err := g.msgRpcClient.SendMsg(context, &req) resp, err := g.msgRPCClient.SendMsg(context, &req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -119,7 +119,7 @@ func (g GrpcHandler) SendMessage(context context.Context, data Req) ([]byte, err
} }
func (g GrpcHandler) SendSignalMessage(context context.Context, data Req) ([]byte, error) { func (g GrpcHandler) SendSignalMessage(context context.Context, data Req) ([]byte, error) {
resp, err := g.msgRpcClient.SendMsg(context, nil) resp, err := g.msgRPCClient.SendMsg(context, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -138,7 +138,7 @@ func (g GrpcHandler) PullMessageBySeqList(context context.Context, data Req) ([]
if err := g.validate.Struct(data); err != nil { if err := g.validate.Struct(data); err != nil {
return nil, err return nil, err
} }
resp, err := g.msgRpcClient.PullMessageBySeqList(context, &req) resp, err := g.msgRPCClient.PullMessageBySeqList(context, &req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -194,4 +194,4 @@ func (g GrpcHandler) SetUserDeviceBackground(_ context.Context, data Req) ([]byt
// return nil, err // return nil, err
// } // }
// return c, nil // return c, nil
//} // }

@ -150,7 +150,7 @@ func (ws *WsServer) Run() error {
}() }()
http.HandleFunc("/", ws.wsHandler) http.HandleFunc("/", ws.wsHandler)
// http.HandleFunc("/metrics", func(w http.ResponseWriter, r *http.Request) {}) // http.HandleFunc("/metrics", func(w http.ResponseWriter, r *http.Request) {})
return http.ListenAndServe(":"+utils.IntToString(ws.port), nil) //Start listening return http.ListenAndServe(":"+utils.IntToString(ws.port), nil) // Start listening
} }
func (ws *WsServer) registerClient(client *Client) { func (ws *WsServer) registerClient(client *Client) {
@ -176,7 +176,7 @@ func (ws *WsServer) registerClient(client *Client) {
log.ZDebug(client.ctx, "user exist", "userID", client.UserID, "platformID", client.PlatformID) log.ZDebug(client.ctx, "user exist", "userID", client.UserID, "platformID", client.PlatformID)
if clientOK { if clientOK {
ws.clients.Set(client.UserID, client) ws.clients.Set(client.UserID, client)
//已经有同平台的连接存在 // 已经有同平台的连接存在
log.ZInfo(client.ctx, "repeat login", "userID", client.UserID, "platformID", client.PlatformID, "old remote addr", getRemoteAdders(oldClients)) log.ZInfo(client.ctx, "repeat login", "userID", client.UserID, "platformID", client.PlatformID, "old remote addr", getRemoteAdders(oldClients))
atomic.AddInt64(&ws.onlineUserConnNum, 1) atomic.AddInt64(&ws.onlineUserConnNum, 1)
} else { } else {
@ -269,11 +269,11 @@ func (ws *WsServer) multiTerminalLoginChecker(info *kickHandler) {
} }
} }
log.ZDebug(info.newClient.ctx, "set token map is ", "token map", m, "userID", info.newClient.UserID) log.ZDebug(info.newClient.ctx, "set token map is ", "token map", m, "userID", info.newClient.UserID)
err = ws.cache.SetTokenMapByUidPid(info.newClient.ctx, info.newClient.UserID, info.newClient.PlatformID, m) err = ws.cache.SetTokenMapByUIDPid(info.newClient.ctx, info.newClient.UserID, info.newClient.PlatformID, m)
if err != nil { if err != nil {
log.ZWarn( log.ZWarn(
info.newClient.ctx, info.newClient.ctx,
"SetTokenMapByUidPid err", "SetTokenMapByUIDPid err",
err, err,
"userID", "userID",
info.newClient.UserID, info.newClient.UserID,

@ -60,8 +60,8 @@ func StartTransfer(prometheusPort int) error {
msgDocModel := unrelation.NewMsgMongoDriver(mongo.GetDatabase()) msgDocModel := unrelation.NewMsgMongoDriver(mongo.GetDatabase())
chatLogDatabase := controller.NewChatLogDatabase(relation.NewChatLogGorm(db)) chatLogDatabase := controller.NewChatLogDatabase(relation.NewChatLogGorm(db))
msgDatabase := controller.NewCommonMsgDatabase(msgDocModel, msgModel) msgDatabase := controller.NewCommonMsgDatabase(msgDocModel, msgModel)
conversationRpcClient := rpcclient.NewConversationRpcClient(client) conversationRpcClient := rpcclient.NewConversationRPCClient(client)
groupRpcClient := rpcclient.NewGroupRpcClient(client) groupRpcClient := rpcclient.NewGroupRPCClient(client)
msgTransfer := NewMsgTransfer(chatLogDatabase, msgDatabase, &conversationRpcClient, &groupRpcClient) msgTransfer := NewMsgTransfer(chatLogDatabase, msgDatabase, &conversationRpcClient, &groupRpcClient)
msgTransfer.initPrometheus() msgTransfer.initPrometheus()
return msgTransfer.Start(prometheusPort) return msgTransfer.Start(prometheusPort)
@ -69,7 +69,7 @@ func StartTransfer(prometheusPort int) error {
func NewMsgTransfer(chatLogDatabase controller.ChatLogDatabase, func NewMsgTransfer(chatLogDatabase controller.ChatLogDatabase,
msgDatabase controller.CommonMsgDatabase, msgDatabase controller.CommonMsgDatabase,
conversationRpcClient *rpcclient.ConversationRpcClient, groupRpcClient *rpcclient.GroupRpcClient) *MsgTransfer { conversationRpcClient *rpcclient.ConversationRPCClient, groupRpcClient *rpcclient.GroupRPCClient) *MsgTransfer {
return &MsgTransfer{persistentCH: NewPersistentConsumerHandler(chatLogDatabase), historyCH: NewOnlineHistoryRedisConsumerHandler(msgDatabase, conversationRpcClient, groupRpcClient), return &MsgTransfer{persistentCH: NewPersistentConsumerHandler(chatLogDatabase), historyCH: NewOnlineHistoryRedisConsumerHandler(msgDatabase, conversationRpcClient, groupRpcClient),
historyMongoCH: NewOnlineHistoryMongoConsumerHandler(msgDatabase)} historyMongoCH: NewOnlineHistoryMongoConsumerHandler(msgDatabase)}
} }

@ -74,25 +74,25 @@ type OnlineHistoryRedisConsumerHandler struct {
singleMsgFailedCountMutex sync.Mutex singleMsgFailedCountMutex sync.Mutex
msgDatabase controller.CommonMsgDatabase msgDatabase controller.CommonMsgDatabase
conversationRpcClient *rpcclient.ConversationRpcClient conversationRPCClient *rpcclient.ConversationRPCClient
groupRpcClient *rpcclient.GroupRpcClient groupRPCClient *rpcclient.GroupRPCClient
} }
func NewOnlineHistoryRedisConsumerHandler( func NewOnlineHistoryRedisConsumerHandler(
database controller.CommonMsgDatabase, database controller.CommonMsgDatabase,
conversationRpcClient *rpcclient.ConversationRpcClient, conversationRPCClient *rpcclient.ConversationRPCClient,
groupRpcClient *rpcclient.GroupRpcClient, groupRPCClient *rpcclient.GroupRPCClient,
) *OnlineHistoryRedisConsumerHandler { ) *OnlineHistoryRedisConsumerHandler {
var och OnlineHistoryRedisConsumerHandler var och OnlineHistoryRedisConsumerHandler
och.msgDatabase = database och.msgDatabase = database
och.msgDistributionCh = make(chan Cmd2Value) //no buffer channel och.msgDistributionCh = make(chan Cmd2Value) // no buffer channel
go och.MessagesDistributionHandle() go och.MessagesDistributionHandle()
for i := 0; i < ChannelNum; i++ { for i := 0; i < ChannelNum; i++ {
och.chArrays[i] = make(chan Cmd2Value, 50) och.chArrays[i] = make(chan Cmd2Value, 50)
go och.Run(i) go och.Run(i)
} }
och.conversationRpcClient = conversationRpcClient och.conversationRPCClient = conversationRPCClient
och.groupRpcClient = groupRpcClient och.groupRPCClient = groupRPCClient
och.historyConsumerGroup = kafka.NewMConsumerGroup(&kafka.MConsumerGroupConfig{KafkaVersion: sarama.V2_0_0_0, och.historyConsumerGroup = kafka.NewMConsumerGroup(&kafka.MConsumerGroupConfig{KafkaVersion: sarama.V2_0_0_0,
OffsetsInitial: sarama.OffsetNewest, IsReturnErr: false}, []string{config.Config.Kafka.LatestMsgToRedis.Topic}, OffsetsInitial: sarama.OffsetNewest, IsReturnErr: false}, []string{config.Config.Kafka.LatestMsgToRedis.Topic},
config.Config.Kafka.Addr, config.Config.Kafka.ConsumerGroupID.MsgToRedis) config.Config.Kafka.Addr, config.Config.Kafka.ConsumerGroupID.MsgToRedis)
@ -165,8 +165,8 @@ func (och *OnlineHistoryRedisConsumerHandler) Run(channelID int) {
// 获取消息/通知 存储的消息列表, 不存储并且推送的消息列表, // 获取消息/通知 存储的消息列表, 不存储并且推送的消息列表,
func (och *OnlineHistoryRedisConsumerHandler) getPushStorageMsgList( func (och *OnlineHistoryRedisConsumerHandler) getPushStorageMsgList(
totalMsgs []*ContextMsg, totalMses []*ContextMsg,
) (storageMsgList, notStorageMsgList, storageNotificatoinList, notStorageNotificationList, modifyMsgList []*sdkws.MsgData) { ) (storageMsgList, notStorageMsgList, storageNotificationList, notStorageNotificationList, modifyMsgList []*sdkws.MsgData) {
isStorage := func(msg *sdkws.MsgData) bool { isStorage := func(msg *sdkws.MsgData) bool {
options2 := utils.Options(msg.Options) options2 := utils.Options(msg.Options)
if options2.IsHistory() { if options2.IsHistory() {
@ -178,7 +178,7 @@ func (och *OnlineHistoryRedisConsumerHandler) getPushStorageMsgList(
return false return false
} }
} }
for _, v := range totalMsgs { for _, v := range totalMses {
options := utils.Options(v.message.Options) options := utils.Options(v.message.Options)
if !options.IsNotNotification() { if !options.IsNotNotification() {
// clone msg from notificationMsg // clone msg from notificationMsg
@ -205,7 +205,7 @@ func (och *OnlineHistoryRedisConsumerHandler) getPushStorageMsgList(
storageMsgList = append(storageMsgList, msg) storageMsgList = append(storageMsgList, msg)
} }
if isStorage(v.message) { if isStorage(v.message) {
storageNotificatoinList = append(storageNotificatoinList, v.message) storageNotificationList = append(storageNotificationList, v.message)
} else { } else {
notStorageNotificationList = append(notStorageNotificationList, v.message) notStorageNotificationList = append(notStorageNotificationList, v.message)
} }
@ -278,16 +278,16 @@ func (och *OnlineHistoryRedisConsumerHandler) handleMsg(
if isNewConversation { if isNewConversation {
if storageList[0].SessionType == constant.SuperGroupChatType { if storageList[0].SessionType == constant.SuperGroupChatType {
log.ZInfo(ctx, "group chat first create conversation", "conversationID", conversationID) log.ZInfo(ctx, "group chat first create conversation", "conversationID", conversationID)
userIDs, err := och.groupRpcClient.GetGroupMemberIDs(ctx, storageList[0].GroupID) userIDs, err := och.groupRPCClient.GetGroupMemberIDs(ctx, storageList[0].GroupID)
if err != nil { if err != nil {
log.ZWarn(ctx, "get group member ids error", err, "conversationID", conversationID) log.ZWarn(ctx, "get group member ids error", err, "conversationID", conversationID)
} else { } else {
if err := och.conversationRpcClient.GroupChatFirstCreateConversation(ctx, storageList[0].GroupID, userIDs); err != nil { if err := och.conversationRPCClient.GroupChatFirstCreateConversation(ctx, storageList[0].GroupID, userIDs); err != nil {
log.ZWarn(ctx, "single chat first create conversation error", err, "conversationID", conversationID) log.ZWarn(ctx, "single chat first create conversation error", err, "conversationID", conversationID)
} }
} }
} else { } else {
if err := och.conversationRpcClient.SingleChatFirstCreateConversation(ctx, storageList[0].RecvID, storageList[0].SendID); err != nil { if err := och.conversationRPCClient.SingleChatFirstCreateConversation(ctx, storageList[0].RecvID, storageList[0].SendID); err != nil {
log.ZWarn(ctx, "single chat first create conversation error", err, "conversationID", conversationID) log.ZWarn(ctx, "single chat first create conversation error", err, "conversationID", conversationID)
} }
} }
@ -312,7 +312,7 @@ func (och *OnlineHistoryRedisConsumerHandler) MessagesDistributionHandle() {
triggerChannelValue := cmd.Value.(TriggerChannelValue) triggerChannelValue := cmd.Value.(TriggerChannelValue)
ctx := triggerChannelValue.ctx ctx := triggerChannelValue.ctx
consumerMessages := triggerChannelValue.cMsgList consumerMessages := triggerChannelValue.cMsgList
//Aggregation map[userid]message list // Aggregation map[userid]message list
log.ZDebug(ctx, "batch messages come to distribution center", "length", len(consumerMessages)) log.ZDebug(ctx, "batch messages come to distribution center", "length", len(consumerMessages))
for i := 0; i < len(consumerMessages); i++ { for i := 0; i < len(consumerMessages); i++ {
ctxMsg := &ContextMsg{} ctxMsg := &ContextMsg{}
@ -431,7 +431,7 @@ func (och *OnlineHistoryRedisConsumerHandler) ConsumeClaim(
ctx := mcontext.WithTriggerIDContext(context.Background(), utils.OperationIDGenerator()) ctx := mcontext.WithTriggerIDContext(context.Background(), utils.OperationIDGenerator())
log.ZDebug(ctx, "timer trigger msg consumer start", "length", len(ccMsg)) log.ZDebug(ctx, "timer trigger msg consumer start", "length", len(ccMsg))
for i := 0; i < len(ccMsg)/split; i++ { for i := 0; i < len(ccMsg)/split; i++ {
//log.Debug() // log.Debug()
och.msgDistributionCh <- Cmd2Value{Cmd: ConsumerMsgs, Value: TriggerChannelValue{ och.msgDistributionCh <- Cmd2Value{Cmd: ConsumerMsgs, Value: TriggerChannelValue{
ctx: ctx, cMsgList: ccMsg[i*split : (i+1)*split]}} ctx: ctx, cMsgList: ccMsg[i*split : (i+1)*split]}}
} }

@ -38,7 +38,7 @@ func NewPersistentConsumerHandler(database controller.ChatLogDatabase) *Persiste
return &PersistentConsumerHandler{ return &PersistentConsumerHandler{
persistentConsumerGroup: kfk.NewMConsumerGroup(&kfk.MConsumerGroupConfig{KafkaVersion: sarama.V2_0_0_0, persistentConsumerGroup: kfk.NewMConsumerGroup(&kfk.MConsumerGroupConfig{KafkaVersion: sarama.V2_0_0_0,
OffsetsInitial: sarama.OffsetNewest, IsReturnErr: false}, []string{config.Config.Kafka.LatestMsgToRedis.Topic}, OffsetsInitial: sarama.OffsetNewest, IsReturnErr: false}, []string{config.Config.Kafka.LatestMsgToRedis.Topic},
config.Config.Kafka.Addr, config.Config.Kafka.ConsumerGroupID.MsgToMySql), config.Config.Kafka.Addr, config.Config.Kafka.ConsumerGroupID.MsgToMySQL),
chatLogDatabase: database, chatLogDatabase: database,
} }
} }
@ -59,9 +59,9 @@ func (pc *PersistentConsumerHandler) handleChatWs2Mysql(
} }
return return
log.ZDebug(ctx, "handleChatWs2Mysql", "msg", msgFromMQ.MsgData) log.ZDebug(ctx, "handleChatWs2Mysql", "msg", msgFromMQ.MsgData)
//Control whether to store history messages (mysql) // Control whether to store history messages (mysql)
isPersist := utils.GetSwitchFromOptions(msgFromMQ.MsgData.Options, constant.IsPersistent) isPersist := utils.GetSwitchFromOptions(msgFromMQ.MsgData.Options, constant.IsPersistent)
//Only process receiver data // Only process receiver data
if isPersist { if isPersist {
switch msgFromMQ.MsgData.SessionType { switch msgFromMQ.MsgData.SessionType {
case constant.SingleChatType, constant.NotificationChatType: case constant.SingleChatType, constant.NotificationChatType:

@ -28,7 +28,7 @@ import (
) )
func url() string { func url() string {
return config.Config.Callback.CallbackUrl return config.Config.Callback.CallbackURL
} }
func callbackOfflinePush( func callbackOfflinePush(
@ -127,7 +127,7 @@ func callbackBeforeSuperGroupOnlinePush(
Seq: msg.Seq, Seq: msg.Seq,
} }
resp := &callbackstruct.CallbackBeforeSuperGroupOnlinePushResp{} resp := &callbackstruct.CallbackBeforeSuperGroupOnlinePushResp{}
if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackBeforeSuperGroupOnlinePush); err != nil { if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackURL, req, resp, config.Config.Callback.CallbackBeforeSuperGroupOnlinePush); err != nil {
if err == errs.ErrCallbackContinue { if err == errs.ErrCallbackContinue {
return nil return nil
} }

@ -163,7 +163,7 @@ func (g *Client) request(ctx context.Context, url string, input interface{}, tok
header := map[string]string{"token": token} header := map[string]string{"token": token}
resp := &Resp{} resp := &Resp{}
resp.Data = output resp.Data = output
return g.postReturn(ctx, config.Config.Push.GeTui.PushUrl+url, header, input, resp, 3) return g.postReturn(ctx, config.Config.Push.GeTui.PushURL+url, header, input, resp, 3)
} }
func (g *Client) postReturn( func (g *Client) postReturn(

@ -76,7 +76,7 @@ func (j *JPush) Push(ctx context.Context, userIDs []string, title, content strin
func (j *JPush) request(ctx context.Context, po body.PushObj, resp interface{}, timeout int) error { func (j *JPush) request(ctx context.Context, po body.PushObj, resp interface{}, timeout int) error {
return http2.PostReturn( return http2.PostReturn(
ctx, ctx,
config.Config.Push.Jpns.PushUrl, config.Config.Push.Jpns.PushURL,
map[string]string{ map[string]string{
"Authorization": j.getAuthorization(config.Config.Push.Jpns.AppKey, config.Config.Push.Jpns.MasterSecret), "Authorization": j.getAuthorization(config.Config.Push.Jpns.AppKey, config.Config.Push.Jpns.MasterSecret),
}, },

@ -42,8 +42,8 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
cacheModel := cache.NewMsgCacheModel(rdb) cacheModel := cache.NewMsgCacheModel(rdb)
offlinePusher := NewOfflinePusher(cacheModel) offlinePusher := NewOfflinePusher(cacheModel)
database := controller.NewPushDatabase(cacheModel) database := controller.NewPushDatabase(cacheModel)
groupRpcClient := rpcclient.NewGroupRpcClient(client) groupRpcClient := rpcclient.NewGroupRPCClient(client)
conversationRpcClient := rpcclient.NewConversationRpcClient(client) conversationRpcClient := rpcclient.NewConversationRPCClient(client)
msgRpcClient := rpcclient.NewMessageRpcClient(client) msgRpcClient := rpcclient.NewMessageRpcClient(client)
pusher := NewPusher( pusher := NewPusher(
client, client,

@ -30,9 +30,9 @@ type Pusher struct {
offlinePusher offlinepush.OfflinePusher offlinePusher offlinepush.OfflinePusher
groupLocalCache *localcache.GroupLocalCache groupLocalCache *localcache.GroupLocalCache
conversationLocalCache *localcache.ConversationLocalCache conversationLocalCache *localcache.ConversationLocalCache
msgRpcClient *rpcclient.MessageRpcClient msgRPCClient *rpcclient.MessageRpcClient
conversationRpcClient *rpcclient.ConversationRpcClient conversationRPCClient *rpcclient.ConversationRPCClient
groupRpcClient *rpcclient.GroupRpcClient groupRPCClient *rpcclient.GroupRPCClient
successCount int successCount int
} }
@ -40,16 +40,16 @@ var errNoOfflinePusher = errors.New("no offlinePusher is configured")
func NewPusher(discov discoveryregistry.SvcDiscoveryRegistry, offlinePusher offlinepush.OfflinePusher, database controller.PushDatabase, func NewPusher(discov discoveryregistry.SvcDiscoveryRegistry, offlinePusher offlinepush.OfflinePusher, database controller.PushDatabase,
groupLocalCache *localcache.GroupLocalCache, conversationLocalCache *localcache.ConversationLocalCache, groupLocalCache *localcache.GroupLocalCache, conversationLocalCache *localcache.ConversationLocalCache,
conversationRpcClient *rpcclient.ConversationRpcClient, groupRpcClient *rpcclient.GroupRpcClient, msgRpcClient *rpcclient.MessageRpcClient) *Pusher { conversationRPCClient *rpcclient.ConversationRPCClient, groupRpcClient *rpcclient.GroupRPCClient, msgRPCClient *rpcclient.MessageRpcClient) *Pusher {
return &Pusher{ return &Pusher{
discov: discov, discov: discov,
database: database, database: database,
offlinePusher: offlinePusher, offlinePusher: offlinePusher,
groupLocalCache: groupLocalCache, groupLocalCache: groupLocalCache,
conversationLocalCache: conversationLocalCache, conversationLocalCache: conversationLocalCache,
msgRpcClient: msgRpcClient, msgRPCClient: msgRPCClient,
conversationRpcClient: conversationRpcClient, conversationRPCClient: conversationRPCClient,
groupRpcClient: groupRpcClient, groupRPCClient: groupRpcClient,
} }
} }
@ -68,11 +68,11 @@ func NewOfflinePusher(cache cache.MsgModel) offlinepush.OfflinePusher {
func (p *Pusher) DeleteMemberAndSetConversationSeq(ctx context.Context, groupID string, userIDs []string) error { func (p *Pusher) DeleteMemberAndSetConversationSeq(ctx context.Context, groupID string, userIDs []string) error {
conevrsationID := utils.GetConversationIDBySessionType(constant.SuperGroupChatType, groupID) conevrsationID := utils.GetConversationIDBySessionType(constant.SuperGroupChatType, groupID)
maxSeq, err := p.msgRpcClient.GetConversationMaxSeq(ctx, conevrsationID) maxSeq, err := p.msgRPCClient.GetConversationMaxSeq(ctx, conevrsationID)
if err != nil { if err != nil {
return err return err
} }
return p.conversationRpcClient.SetConversationMaxSeq(ctx, userIDs, conevrsationID, maxSeq) return p.conversationRPCClient.SetConversationMaxSeq(ctx, userIDs, conevrsationID, maxSeq)
} }
func (p *Pusher) Push2User(ctx context.Context, userIDs []string, msg *sdkws.MsgData) error { func (p *Pusher) Push2User(ctx context.Context, userIDs []string, msg *sdkws.MsgData) error {
@ -165,7 +165,7 @@ func (p *Pusher) Push2SuperGroup(ctx context.Context, groupID string, msg *sdkws
ctx = mcontext.WithOpUserIDContext(ctx, config.Config.Manager.UserID[0]) ctx = mcontext.WithOpUserIDContext(ctx, config.Config.Manager.UserID[0])
} }
defer func(groupID string) { defer func(groupID string) {
if err := p.groupRpcClient.DismissGroup(ctx, groupID); err != nil { if err := p.groupRPCClient.DismissGroup(ctx, groupID); err != nil {
log.ZError(ctx, "DismissGroup Notification clear members", err, "groupID", groupID) log.ZError(ctx, "DismissGroup Notification clear members", err, "groupID", groupID)
} }
}(groupID) }(groupID)
@ -209,7 +209,7 @@ func (p *Pusher) Push2SuperGroup(ctx context.Context, groupID string, msg *sdkws
} }
needOfflinePushUserIDs = utils.DifferenceString(notNotificationUserIDs, needOfflinePushUserIDs) needOfflinePushUserIDs = utils.DifferenceString(notNotificationUserIDs, needOfflinePushUserIDs)
} }
//Use offline push messaging // Use offline push messaging
if len(needOfflinePushUserIDs) > 0 { if len(needOfflinePushUserIDs) > 0 {
var offlinePushUserIDs []string var offlinePushUserIDs []string
err = callbackOfflinePush(ctx, needOfflinePushUserIDs, msg, &offlinePushUserIDs) err = callbackOfflinePush(ctx, needOfflinePushUserIDs, msg, &offlinePushUserIDs)
@ -235,12 +235,12 @@ func (p *Pusher) Push2SuperGroup(ctx context.Context, groupID string, msg *sdkws
} }
func (p *Pusher) GetConnsAndOnlinePush(ctx context.Context, msg *sdkws.MsgData, pushToUserIDs []string) (wsResults []*msggateway.SingleMsgToUserResults, err error) { func (p *Pusher) GetConnsAndOnlinePush(ctx context.Context, msg *sdkws.MsgData, pushToUserIDs []string) (wsResults []*msggateway.SingleMsgToUserResults, err error) {
conns, err := p.discov.GetConns(ctx, config.Config.RpcRegisterName.OpenImMessageGatewayName) conns, err := p.discov.GetConns(ctx, config.Config.RPCRegisterName.OpenImMessageGatewayName)
log.ZDebug(ctx, "get gateway conn", "conn length", len(conns)) log.ZDebug(ctx, "get gateway conn", "conn length", len(conns))
if err != nil { if err != nil {
return nil, err return nil, err
} }
//Online push message // Online push message
for _, v := range conns { for _, v := range conns {
msgClient := msggateway.NewMsgGatewayClient(v) msgClient := msggateway.NewMsgGatewayClient(v)
reply, err := msgClient.SuperGroupOnlineBatchPushOneMsg(ctx, &msggateway.OnlineBatchPushOneMsgReq{MsgData: msg, PushToUserIDs: pushToUserIDs}) reply, err := msgClient.SuperGroupOnlineBatchPushOneMsg(ctx, &msggateway.OnlineBatchPushOneMsgReq{MsgData: msg, PushToUserIDs: pushToUserIDs})
@ -293,7 +293,7 @@ func (p *Pusher) GetOfflinePushOpts(msg *sdkws.MsgData) (opts *offlinepush.Opts,
func (p *Pusher) getOfflinePushInfos(conversationID string, msg *sdkws.MsgData) (title, content string, opts *offlinepush.Opts, err error) { func (p *Pusher) getOfflinePushInfos(conversationID string, msg *sdkws.MsgData) (title, content string, opts *offlinepush.Opts, err error) {
if p.offlinePusher == nil { if p.offlinePusher == nil {
err = errNoOfflinePusher err = errNoOfflinePusher
return return "", "", nil, err
} }
type AtContent struct { type AtContent struct {
Text string `json:"text"` Text string `json:"text"`
@ -302,7 +302,7 @@ func (p *Pusher) getOfflinePushInfos(conversationID string, msg *sdkws.MsgData)
} }
opts, err = p.GetOfflinePushOpts(msg) opts, err = p.GetOfflinePushOpts(msg)
if err != nil { if err != nil {
return return "", "", opts, err
} }
if msg.OfflinePushInfo != nil { if msg.OfflinePushInfo != nil {
title = msg.OfflinePushInfo.Title title = msg.OfflinePushInfo.Title
@ -322,7 +322,7 @@ func (p *Pusher) getOfflinePushInfos(conversationID string, msg *sdkws.MsgData)
title = constant.ContentType2PushContent[int64(msg.ContentType)] title = constant.ContentType2PushContent[int64(msg.ContentType)]
case constant.AtText: case constant.AtText:
a := AtContent{} a := AtContent{}
_ = utils.JsonStringToStruct(string(msg.Content), &a) _ = utils.JSONStringToStruct(string(msg.Content), &a)
if utils.IsContain(conversationID, a.AtUserList) { if utils.IsContain(conversationID, a.AtUserList) {
title = constant.ContentType2PushContent[constant.AtText] + constant.ContentType2PushContent[constant.Common] title = constant.ContentType2PushContent[constant.AtText] + constant.ContentType2PushContent[constant.Common]
} else { } else {
@ -337,5 +337,5 @@ func (p *Pusher) getOfflinePushInfos(conversationID string, msg *sdkws.MsgData)
if content == "" { if content == "" {
content = title content = title
} }
return return title, content, opts, err
} }

@ -35,7 +35,7 @@ import (
type authServer struct { type authServer struct {
authDatabase controller.AuthDatabase authDatabase controller.AuthDatabase
userRpcClient *rpcclient.UserRpcClient userRPCClient *rpcclient.UserRPCClient
RegisterCenter discoveryregistry.SvcDiscoveryRegistry RegisterCenter discoveryregistry.SvcDiscoveryRegistry
} }
@ -44,9 +44,9 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
if err != nil { if err != nil {
return err return err
} }
userRpcClient := rpcclient.NewUserRpcClient(client) userRPCClient := rpcclient.NewUserRPCClient(client)
pbAuth.RegisterAuthServer(server, &authServer{ pbAuth.RegisterAuthServer(server, &authServer{
userRpcClient: &userRpcClient, userRPCClient: &userRPCClient,
RegisterCenter: client, RegisterCenter: client,
authDatabase: controller.NewAuthDatabase( authDatabase: controller.NewAuthDatabase(
cache.NewMsgCacheModel(rdb), cache.NewMsgCacheModel(rdb),
@ -62,7 +62,7 @@ func (s *authServer) UserToken(ctx context.Context, req *pbAuth.UserTokenReq) (*
if req.Secret != config.Config.Secret { if req.Secret != config.Config.Secret {
return nil, errs.ErrNoPermission.Wrap("secret invalid") return nil, errs.ErrNoPermission.Wrap("secret invalid")
} }
if _, err := s.userRpcClient.GetUserInfo(ctx, req.UserID); err != nil { if _, err := s.userRPCClient.GetUserInfo(ctx, req.UserID); err != nil {
return nil, err return nil, err
} }
token, err := s.authDatabase.CreateToken(ctx, req.UserID, int(req.PlatformID)) token, err := s.authDatabase.CreateToken(ctx, req.UserID, int(req.PlatformID))
@ -125,7 +125,7 @@ func (s *authServer) ForceLogout(ctx context.Context, req *pbAuth.ForceLogoutReq
} }
func (s *authServer) forceKickOff(ctx context.Context, userID string, platformID int32, operationID string) error { func (s *authServer) forceKickOff(ctx context.Context, userID string, platformID int32, operationID string) error {
conns, err := s.RegisterCenter.GetConns(ctx, config.Config.RpcRegisterName.OpenImMessageGatewayName) conns, err := s.RegisterCenter.GetConns(ctx, config.Config.RPCRegisterName.OpenImMessageGatewayName)
if err != nil { if err != nil {
return err return err
} }

@ -21,7 +21,7 @@ import (
) )
type conversationServer struct { type conversationServer struct {
groupRpcClient *rpcclient.GroupRpcClient groupRPCClient *rpcclient.GroupRPCClient
conversationDatabase controller.ConversationDatabase conversationDatabase controller.ConversationDatabase
conversationNotificationSender *notification.ConversationNotificationSender conversationNotificationSender *notification.ConversationNotificationSender
} }
@ -39,11 +39,11 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
return err return err
} }
conversationDB := relation.NewConversationGorm(db) conversationDB := relation.NewConversationGorm(db)
groupRpcClient := rpcclient.NewGroupRpcClient(client) groupRPCClient := rpcclient.NewGroupRPCClient(client)
msgRpcClient := rpcclient.NewMessageRpcClient(client) msgRpcClient := rpcclient.NewMessageRpcClient(client)
pbConversation.RegisterConversationServer(server, &conversationServer{ pbConversation.RegisterConversationServer(server, &conversationServer{
conversationNotificationSender: notification.NewConversationNotificationSender(&msgRpcClient), conversationNotificationSender: notification.NewConversationNotificationSender(&msgRpcClient),
groupRpcClient: &groupRpcClient, groupRPCClient: &groupRPCClient,
conversationDatabase: controller.NewConversationDatabase(conversationDB, cache.NewConversationRedis(rdb, cache.GetDefaultOpt(), conversationDB), tx.NewGorm(db)), conversationDatabase: controller.NewConversationDatabase(conversationDB, cache.NewConversationRedis(rdb, cache.GetDefaultOpt(), conversationDB), tx.NewGorm(db)),
}) })
return nil return nil
@ -101,7 +101,7 @@ func (c *conversationServer) SetConversations(ctx context.Context, req *pbConver
return nil, errs.ErrArgs.Wrap("conversation must not be nil") return nil, errs.ErrArgs.Wrap("conversation must not be nil")
} }
if req.Conversation.ConversationType == constant.GroupChatType { if req.Conversation.ConversationType == constant.GroupChatType {
groupInfo, err := c.groupRpcClient.GetGroupInfo(ctx, req.Conversation.GroupID) groupInfo, err := c.groupRPCClient.GetGroupInfo(ctx, req.Conversation.GroupID)
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -29,7 +29,7 @@ func (s *friendServer) GetPaginationBlacks(
ctx context.Context, ctx context.Context,
req *pbFriend.GetPaginationBlacksReq, req *pbFriend.GetPaginationBlacksReq,
) (resp *pbFriend.GetPaginationBlacksResp, err error) { ) (resp *pbFriend.GetPaginationBlacksResp, err error) {
if err := s.userRpcClient.Access(ctx, req.UserID); err != nil { if err := s.userRPCClient.Access(ctx, req.UserID); err != nil {
return nil, err return nil, err
} }
var pageNumber, showNumber int32 var pageNumber, showNumber int32
@ -42,7 +42,7 @@ func (s *friendServer) GetPaginationBlacks(
return nil, err return nil, err
} }
resp = &pbFriend.GetPaginationBlacksResp{} resp = &pbFriend.GetPaginationBlacksResp{}
resp.Blacks, err = convert.BlackDB2Pb(ctx, blacks, s.userRpcClient.GetUsersInfoMap) resp.Blacks, err = convert.BlackDB2Pb(ctx, blacks, s.userRPCClient.GetUsersInfoMap)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -65,7 +65,7 @@ func (s *friendServer) RemoveBlack(
ctx context.Context, ctx context.Context,
req *pbFriend.RemoveBlackReq, req *pbFriend.RemoveBlackReq,
) (*pbFriend.RemoveBlackResp, error) { ) (*pbFriend.RemoveBlackResp, error) {
if err := s.userRpcClient.Access(ctx, req.OwnerUserID); err != nil { if err := s.userRPCClient.Access(ctx, req.OwnerUserID); err != nil {
return nil, err return nil, err
} }
if err := s.blackDatabase.Delete(ctx, []*relation.BlackModel{{OwnerUserID: req.OwnerUserID, BlockUserID: req.BlackUserID}}); err != nil { if err := s.blackDatabase.Delete(ctx, []*relation.BlackModel{{OwnerUserID: req.OwnerUserID, BlockUserID: req.BlackUserID}}); err != nil {
@ -79,7 +79,7 @@ func (s *friendServer) AddBlack(ctx context.Context, req *pbFriend.AddBlackReq)
if err := tokenverify.CheckAccessV3(ctx, req.OwnerUserID); err != nil { if err := tokenverify.CheckAccessV3(ctx, req.OwnerUserID); err != nil {
return nil, err return nil, err
} }
_, err := s.userRpcClient.GetUsersInfo(ctx, []string{req.OwnerUserID, req.BlackUserID}) _, err := s.userRPCClient.GetUsersInfo(ctx, []string{req.OwnerUserID, req.BlackUserID})
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -38,7 +38,7 @@ func CallbackBeforeAddFriend(ctx context.Context, req *pbfriend.ApplyToAddFriend
OperationID: mcontext.GetOperationID(ctx), OperationID: mcontext.GetOperationID(ctx),
} }
resp := &cbapi.CallbackBeforeAddFriendResp{} resp := &cbapi.CallbackBeforeAddFriendResp{}
if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, cbReq, resp, config.Config.Callback.CallbackBeforeAddFriend); err != nil { if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackURL, cbReq, resp, config.Config.Callback.CallbackBeforeAddFriend); err != nil {
if err == errs.ErrCallbackContinue { if err == errs.ErrCallbackContinue {
return nil return nil
} }

@ -40,7 +40,7 @@ import (
type friendServer struct { type friendServer struct {
friendDatabase controller.FriendDatabase friendDatabase controller.FriendDatabase
blackDatabase controller.BlackDatabase blackDatabase controller.BlackDatabase
userRpcClient *rpcclient.UserRpcClient userRPCClient *rpcclient.UserRPCClient
notificationSender *notification.FriendNotificationSender notificationSender *notification.FriendNotificationSender
RegisterCenter registry.SvcDiscoveryRegistry RegisterCenter registry.SvcDiscoveryRegistry
} }
@ -59,11 +59,11 @@ func Start(client registry.SvcDiscoveryRegistry, server *grpc.Server) error {
} }
blackDB := relation.NewBlackGorm(db) blackDB := relation.NewBlackGorm(db)
friendDB := relation.NewFriendGorm(db) friendDB := relation.NewFriendGorm(db)
userRpcClient := rpcclient.NewUserRpcClient(client) userRPCClient := rpcclient.NewUserRPCClient(client)
msgRpcClient := rpcclient.NewMessageRpcClient(client) msgRpcClient := rpcclient.NewMessageRpcClient(client)
notificationSender := notification.NewFriendNotificationSender( notificationSender := notification.NewFriendNotificationSender(
&msgRpcClient, &msgRpcClient,
notification.WithRpcFunc(userRpcClient.GetUsersInfo), notification.WithRpcFunc(userRPCClient.GetUsersInfo),
) )
pbfriend.RegisterFriendServer(server, &friendServer{ pbfriend.RegisterFriendServer(server, &friendServer{
friendDatabase: controller.NewFriendDatabase( friendDatabase: controller.NewFriendDatabase(
@ -76,7 +76,7 @@ func Start(client registry.SvcDiscoveryRegistry, server *grpc.Server) error {
blackDB, blackDB,
cache.NewBlackCacheRedis(rdb, blackDB, cache.GetDefaultOpt()), cache.NewBlackCacheRedis(rdb, blackDB, cache.GetDefaultOpt()),
), ),
userRpcClient: &userRpcClient, userRPCClient: &userRPCClient,
notificationSender: notificationSender, notificationSender: notificationSender,
RegisterCenter: client, RegisterCenter: client,
}) })
@ -99,7 +99,7 @@ func (s *friendServer) ApplyToAddFriend(
if err := CallbackBeforeAddFriend(ctx, req); err != nil && err != errs.ErrCallbackContinue { if err := CallbackBeforeAddFriend(ctx, req); err != nil && err != errs.ErrCallbackContinue {
return nil, err return nil, err
} }
if _, err := s.userRpcClient.GetUsersInfoMap(ctx, []string{req.ToUserID, req.FromUserID}); err != nil { if _, err := s.userRPCClient.GetUsersInfoMap(ctx, []string{req.ToUserID, req.FromUserID}); err != nil {
return nil, err return nil, err
} }
in1, in2, err := s.friendDatabase.CheckIn(ctx, req.FromUserID, req.ToUserID) in1, in2, err := s.friendDatabase.CheckIn(ctx, req.FromUserID, req.ToUserID)
@ -125,7 +125,7 @@ func (s *friendServer) ImportFriends(
if err := tokenverify.CheckAdmin(ctx); err != nil { if err := tokenverify.CheckAdmin(ctx); err != nil {
return nil, err return nil, err
} }
if _, err := s.userRpcClient.GetUsersInfo(ctx, append([]string{req.OwnerUserID}, req.FriendUserIDs...)); err != nil { if _, err := s.userRPCClient.GetUsersInfo(ctx, append([]string{req.OwnerUserID}, req.FriendUserIDs...)); err != nil {
return nil, err return nil, err
} }
@ -185,7 +185,7 @@ func (s *friendServer) DeleteFriend(
) (resp *pbfriend.DeleteFriendResp, err error) { ) (resp *pbfriend.DeleteFriendResp, err error) {
defer log.ZInfo(ctx, utils.GetFuncName()+" Return") defer log.ZInfo(ctx, utils.GetFuncName()+" Return")
resp = &pbfriend.DeleteFriendResp{} resp = &pbfriend.DeleteFriendResp{}
if err := s.userRpcClient.Access(ctx, req.OwnerUserID); err != nil { if err := s.userRPCClient.Access(ctx, req.OwnerUserID); err != nil {
return nil, err return nil, err
} }
_, err = s.friendDatabase.FindFriendsWithError(ctx, req.OwnerUserID, []string{req.FriendUserID}) _, err = s.friendDatabase.FindFriendsWithError(ctx, req.OwnerUserID, []string{req.FriendUserID})
@ -206,7 +206,7 @@ func (s *friendServer) SetFriendRemark(
) (resp *pbfriend.SetFriendRemarkResp, err error) { ) (resp *pbfriend.SetFriendRemarkResp, err error) {
defer log.ZInfo(ctx, utils.GetFuncName()+" Return") defer log.ZInfo(ctx, utils.GetFuncName()+" Return")
resp = &pbfriend.SetFriendRemarkResp{} resp = &pbfriend.SetFriendRemarkResp{}
if err := s.userRpcClient.Access(ctx, req.OwnerUserID); err != nil { if err := s.userRPCClient.Access(ctx, req.OwnerUserID); err != nil {
return nil, err return nil, err
} }
_, err = s.friendDatabase.FindFriendsWithError(ctx, req.OwnerUserID, []string{req.FriendUserID}) _, err = s.friendDatabase.FindFriendsWithError(ctx, req.OwnerUserID, []string{req.FriendUserID})
@ -234,7 +234,7 @@ func (s *friendServer) GetDesignatedFriends(
if err != nil { if err != nil {
return nil, err return nil, err
} }
if resp.FriendsInfo, err = convert.FriendsDB2Pb(ctx, friends, s.userRpcClient.GetUsersInfoMap); err != nil { if resp.FriendsInfo, err = convert.FriendsDB2Pb(ctx, friends, s.userRPCClient.GetUsersInfoMap); err != nil {
return nil, err return nil, err
} }
return resp, nil return resp, nil
@ -247,7 +247,7 @@ func (s *friendServer) GetPaginationFriendsApplyTo(
) (resp *pbfriend.GetPaginationFriendsApplyToResp, err error) { ) (resp *pbfriend.GetPaginationFriendsApplyToResp, err error) {
defer log.ZInfo(ctx, utils.GetFuncName()+" Return") defer log.ZInfo(ctx, utils.GetFuncName()+" Return")
resp = &pbfriend.GetPaginationFriendsApplyToResp{} resp = &pbfriend.GetPaginationFriendsApplyToResp{}
if err := s.userRpcClient.Access(ctx, req.UserID); err != nil { if err := s.userRPCClient.Access(ctx, req.UserID); err != nil {
return nil, err return nil, err
} }
pageNumber, showNumber := utils.GetPage(req.Pagination) pageNumber, showNumber := utils.GetPage(req.Pagination)
@ -255,7 +255,7 @@ func (s *friendServer) GetPaginationFriendsApplyTo(
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp.FriendRequests, err = convert.FriendRequestDB2Pb(ctx, friendRequests, s.userRpcClient.GetUsersInfoMap) resp.FriendRequests, err = convert.FriendRequestDB2Pb(ctx, friendRequests, s.userRPCClient.GetUsersInfoMap)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -270,7 +270,7 @@ func (s *friendServer) GetPaginationFriendsApplyFrom(
) (resp *pbfriend.GetPaginationFriendsApplyFromResp, err error) { ) (resp *pbfriend.GetPaginationFriendsApplyFromResp, err error) {
defer log.ZInfo(ctx, utils.GetFuncName()+" Return") defer log.ZInfo(ctx, utils.GetFuncName()+" Return")
resp = &pbfriend.GetPaginationFriendsApplyFromResp{} resp = &pbfriend.GetPaginationFriendsApplyFromResp{}
if err := s.userRpcClient.Access(ctx, req.UserID); err != nil { if err := s.userRPCClient.Access(ctx, req.UserID); err != nil {
return nil, err return nil, err
} }
pageNumber, showNumber := utils.GetPage(req.Pagination) pageNumber, showNumber := utils.GetPage(req.Pagination)
@ -278,7 +278,7 @@ func (s *friendServer) GetPaginationFriendsApplyFrom(
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp.FriendRequests, err = convert.FriendRequestDB2Pb(ctx, friendRequests, s.userRpcClient.GetUsersInfoMap) resp.FriendRequests, err = convert.FriendRequestDB2Pb(ctx, friendRequests, s.userRPCClient.GetUsersInfoMap)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -306,7 +306,7 @@ func (s *friendServer) GetPaginationFriends(
req *pbfriend.GetPaginationFriendsReq, req *pbfriend.GetPaginationFriendsReq,
) (resp *pbfriend.GetPaginationFriendsResp, err error) { ) (resp *pbfriend.GetPaginationFriendsResp, err error) {
defer log.ZInfo(ctx, utils.GetFuncName()+" Return") defer log.ZInfo(ctx, utils.GetFuncName()+" Return")
if err := s.userRpcClient.Access(ctx, req.UserID); err != nil { if err := s.userRPCClient.Access(ctx, req.UserID); err != nil {
return nil, err return nil, err
} }
pageNumber, showNumber := utils.GetPage(req.Pagination) pageNumber, showNumber := utils.GetPage(req.Pagination)
@ -315,7 +315,7 @@ func (s *friendServer) GetPaginationFriends(
return nil, err return nil, err
} }
resp = &pbfriend.GetPaginationFriendsResp{} resp = &pbfriend.GetPaginationFriendsResp{}
resp.FriendsInfo, err = convert.FriendsDB2Pb(ctx, friends, s.userRpcClient.GetUsersInfoMap) resp.FriendsInfo, err = convert.FriendsDB2Pb(ctx, friends, s.userRPCClient.GetUsersInfoMap)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -328,7 +328,7 @@ func (s *friendServer) GetFriendIDs(
req *pbfriend.GetFriendIDsReq, req *pbfriend.GetFriendIDsReq,
) (resp *pbfriend.GetFriendIDsResp, err error) { ) (resp *pbfriend.GetFriendIDsResp, err error) {
defer log.ZInfo(ctx, utils.GetFuncName()+" Return") defer log.ZInfo(ctx, utils.GetFuncName()+" Return")
if err := s.userRpcClient.Access(ctx, req.UserID); err != nil { if err := s.userRPCClient.Access(ctx, req.UserID); err != nil {
return nil, err return nil, err
} }
resp = &pbfriend.GetFriendIDsResp{} resp = &pbfriend.GetFriendIDsResp{}

@ -59,7 +59,7 @@ func CallbackBeforeCreateGroup(ctx context.Context, req *group.CreateGroupReq) (
resp := &callbackstruct.CallbackBeforeCreateGroupResp{} resp := &callbackstruct.CallbackBeforeCreateGroupResp{}
err = http.CallBackPostReturn( err = http.CallBackPostReturn(
ctx, ctx,
config.Config.Callback.CallbackUrl, config.Config.Callback.CallbackURL,
cbReq, cbReq,
resp, resp,
config.Config.Callback.CallbackBeforeCreateGroup, config.Config.Callback.CallbackBeforeCreateGroup,
@ -104,7 +104,7 @@ func CallbackBeforeMemberJoinGroup(
resp := &callbackstruct.CallbackBeforeMemberJoinGroupResp{} resp := &callbackstruct.CallbackBeforeMemberJoinGroupResp{}
err = http.CallBackPostReturn( err = http.CallBackPostReturn(
ctx, ctx,
config.Config.Callback.CallbackUrl, config.Config.Callback.CallbackURL,
callbackReq, callbackReq,
resp, resp,
config.Config.Callback.CallbackBeforeMemberJoinGroup, config.Config.Callback.CallbackBeforeMemberJoinGroup,
@ -150,7 +150,7 @@ func CallbackBeforeSetGroupMemberInfo(ctx context.Context, req *group.SetGroupMe
resp := &callbackstruct.CallbackBeforeSetGroupMemberInfoResp{} resp := &callbackstruct.CallbackBeforeSetGroupMemberInfoResp{}
err = http.CallBackPostReturn( err = http.CallBackPostReturn(
ctx, ctx,
config.Config.Callback.CallbackUrl, config.Config.Callback.CallbackURL,
callbackReq, callbackReq,
resp, resp,
config.Config.Callback.CallbackBeforeSetGroupMemberInfo, config.Config.Callback.CallbackBeforeSetGroupMemberInfo,

@ -50,36 +50,36 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
if err != nil { if err != nil {
return err return err
} }
userRpcClient := rpcclient.NewUserRpcClient(client) userRPCClient := rpcclient.NewUserRPCClient(client)
msgRpcClient := rpcclient.NewMessageRpcClient(client) msgRPCClient := rpcclient.NewMessageRpcClient(client)
conversationRpcClient := rpcclient.NewConversationRpcClient(client) conversationRPCClient := rpcclient.NewConversationRPCClient(client)
database := controller.InitGroupDatabase(db, rdb, mongo.GetDatabase()) database := controller.InitGroupDatabase(db, rdb, mongo.GetDatabase())
pbGroup.RegisterGroupServer(server, &groupServer{ pbGroup.RegisterGroupServer(server, &groupServer{
GroupDatabase: database, GroupDatabase: database,
User: userRpcClient, User: userRPCClient,
Notification: notification.NewGroupNotificationSender(database, &msgRpcClient, &userRpcClient, func(ctx context.Context, userIDs []string) ([]notification.CommonUser, error) { Notification: notification.NewGroupNotificationSender(database, &msgRPCClient, &userRPCClient, func(ctx context.Context, userIDs []string) ([]notification.CommonUser, error) {
users, err := userRpcClient.GetUsersInfo(ctx, userIDs) users, err := userRPCClient.GetUsersInfo(ctx, userIDs)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return utils.Slice(users, func(e *sdkws.UserInfo) notification.CommonUser { return e }), nil return utils.Slice(users, func(e *sdkws.UserInfo) notification.CommonUser { return e }), nil
}), }),
conversationRpcClient: conversationRpcClient, conversationRPCClient: conversationRPCClient,
msgRpcClient: msgRpcClient, msgRPCClient: msgRPCClient,
}) })
return nil return nil
} }
type groupServer struct { type groupServer struct {
GroupDatabase controller.GroupDatabase GroupDatabase controller.GroupDatabase
User rpcclient.UserRpcClient User rpcclient.UserRPCClient
Notification *notification.GroupNotificationSender Notification *notification.GroupNotificationSender
conversationRpcClient rpcclient.ConversationRpcClient conversationRPCClient rpcclient.ConversationRPCClient
msgRpcClient rpcclient.MessageRpcClient msgRPCClient rpcclient.MessageRpcClient
} }
func (s *groupServer) CheckGroupAdmin(ctx context.Context, groupID string) error { func (s *groupServer) CheckGroupAdmin(ctx context.Context, groupID string) error {
if !tokenverify.IsAppManagerUid(ctx) { if !tokenverify.IsAppManagerUID(ctx) {
groupMember, err := s.GroupDatabase.TakeGroupMember(ctx, groupID, mcontext.GetOpUserID(ctx)) groupMember, err := s.GroupDatabase.TakeGroupMember(ctx, groupID, mcontext.GetOpUserID(ctx))
if err != nil { if err != nil {
return err return err
@ -215,7 +215,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
} }
}() }()
} else { } else {
//s.Notification.GroupCreatedNotification(ctx, group, groupMembers, userMap) // s.Notification.GroupCreatedNotification(ctx, group, groupMembers, userMap)
tips := &sdkws.GroupCreatedTips{ tips := &sdkws.GroupCreatedTips{
Group: resp.GroupInfo, Group: resp.GroupInfo,
OperationTime: group.CreateTime.UnixMilli(), OperationTime: group.CreateTime.UnixMilli(),
@ -244,7 +244,7 @@ func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJo
pageNumber = req.Pagination.PageNumber pageNumber = req.Pagination.PageNumber
showNumber = req.Pagination.ShowNumber showNumber = req.Pagination.ShowNumber
} }
//total, members, err := s.GroupDatabase.PageGroupMember(ctx, nil, []string{req.FromUserID}, nil, pageNumber, showNumber) // total, members, err := s.GroupDatabase.PageGroupMember(ctx, nil, []string{req.FromUserID}, nil, pageNumber, showNumber)
total, members, err := s.GroupDatabase.PageGetJoinGroup(ctx, req.FromUserID, pageNumber, showNumber) total, members, err := s.GroupDatabase.PageGetJoinGroup(ctx, req.FromUserID, pageNumber, showNumber)
if err != nil { if err != nil {
return nil, err return nil, err
@ -304,7 +304,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
} }
var groupMember *relationTb.GroupMemberModel var groupMember *relationTb.GroupMemberModel
var opUserID string var opUserID string
if !tokenverify.IsAppManagerUid(ctx) { if !tokenverify.IsAppManagerUID(ctx) {
opUserID = mcontext.GetOpUserID(ctx) opUserID = mcontext.GetOpUserID(ctx)
groupMembers, err := s.FindGroupMember(ctx, []string{req.GroupID}, []string{opUserID}, nil) groupMembers, err := s.FindGroupMember(ctx, []string{req.GroupID}, []string{opUserID}, nil)
if err != nil { if err != nil {
@ -316,7 +316,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
groupMember = groupMembers[0] groupMember = groupMembers[0]
} }
if group.NeedVerification == constant.AllNeedVerification { if group.NeedVerification == constant.AllNeedVerification {
if !tokenverify.IsAppManagerUid(ctx) { if !tokenverify.IsAppManagerUID(ctx) {
if !(groupMember.RoleLevel == constant.GroupOwner || groupMember.RoleLevel == constant.GroupAdmin) { if !(groupMember.RoleLevel == constant.GroupOwner || groupMember.RoleLevel == constant.GroupAdmin) {
var requests []*relationTb.GroupRequestModel var requests []*relationTb.GroupRequestModel
for _, userID := range req.InvitedUserIDs { for _, userID := range req.InvitedUserIDs {
@ -349,7 +349,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
if err := s.GroupDatabase.CreateSuperGroupMember(ctx, req.GroupID, req.InvitedUserIDs); err != nil { if err := s.GroupDatabase.CreateSuperGroupMember(ctx, req.GroupID, req.InvitedUserIDs); err != nil {
return nil, err return nil, err
} }
if err := s.conversationRpcClient.GroupChatFirstCreateConversation(ctx, req.GroupID, req.InvitedUserIDs); err != nil { if err := s.conversationRPCClient.GroupChatFirstCreateConversation(ctx, req.GroupID, req.InvitedUserIDs); err != nil {
return nil, err return nil, err
} }
for _, userID := range req.InvitedUserIDs { for _, userID := range req.InvitedUserIDs {
@ -376,7 +376,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
if err := s.GroupDatabase.CreateGroup(ctx, nil, groupMembers); err != nil { if err := s.GroupDatabase.CreateGroup(ctx, nil, groupMembers); err != nil {
return nil, err return nil, err
} }
if err := s.conversationRpcClient.GroupChatFirstCreateConversation(ctx, req.GroupID, req.InvitedUserIDs); err != nil { if err := s.conversationRPCClient.GroupChatFirstCreateConversation(ctx, req.GroupID, req.InvitedUserIDs); err != nil {
return nil, err return nil, err
} }
s.Notification.MemberInvitedNotification(ctx, req.GroupID, req.Reason, req.InvitedUserIDs) s.Notification.MemberInvitedNotification(ctx, req.GroupID, req.Reason, req.InvitedUserIDs)
@ -459,7 +459,7 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
for i, member := range members { for i, member := range members {
memberMap[member.UserID] = members[i] memberMap[member.UserID] = members[i]
} }
isAppManagerUid := tokenverify.IsAppManagerUid(ctx) isAppManagerUid := tokenverify.IsAppManagerUID(ctx)
opMember := memberMap[opUserID] opMember := memberMap[opUserID]
for _, userID := range req.KickedUserIDs { for _, userID := range req.KickedUserIDs {
member, ok := memberMap[userID] member, ok := memberMap[userID]
@ -501,7 +501,7 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
Notification: group.Notification, Notification: group.Notification,
Introduction: group.Introduction, Introduction: group.Introduction,
FaceURL: group.FaceURL, FaceURL: group.FaceURL,
//OwnerUserID: owner[0].UserID, // OwnerUserID: owner[0].UserID,
CreateTime: group.CreateTime.UnixMilli(), CreateTime: group.CreateTime.UnixMilli(),
MemberCount: num, MemberCount: num,
Ex: group.Ex, Ex: group.Ex,
@ -651,7 +651,7 @@ func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup
if !utils.Contain(req.HandleResult, constant.GroupResponseAgree, constant.GroupResponseRefuse) { if !utils.Contain(req.HandleResult, constant.GroupResponseAgree, constant.GroupResponseRefuse) {
return nil, errs.ErrArgs.Wrap("HandleResult unknown") return nil, errs.ErrArgs.Wrap("HandleResult unknown")
} }
if !tokenverify.IsAppManagerUid(ctx) { if !tokenverify.IsAppManagerUID(ctx) {
groupMember, err := s.GroupDatabase.TakeGroupMember(ctx, req.GroupID, mcontext.GetOpUserID(ctx)) groupMember, err := s.GroupDatabase.TakeGroupMember(ctx, req.GroupID, mcontext.GetOpUserID(ctx))
if err != nil { if err != nil {
return nil, err return nil, err
@ -703,7 +703,7 @@ func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup
if err := s.GroupDatabase.HandlerGroupRequest(ctx, req.GroupID, req.FromUserID, req.HandledMsg, req.HandleResult, member); err != nil { if err := s.GroupDatabase.HandlerGroupRequest(ctx, req.GroupID, req.FromUserID, req.HandledMsg, req.HandleResult, member); err != nil {
return nil, err return nil, err
} }
if err := s.conversationRpcClient.GroupChatFirstCreateConversation(ctx, req.GroupID, []string{req.FromUserID}); err != nil { if err := s.conversationRPCClient.GroupChatFirstCreateConversation(ctx, req.GroupID, []string{req.FromUserID}); err != nil {
return nil, err return nil, err
} }
switch req.HandleResult { switch req.HandleResult {
@ -757,7 +757,7 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
if err := s.GroupDatabase.CreateGroup(ctx, nil, []*relationTb.GroupMemberModel{groupMember}); err != nil { if err := s.GroupDatabase.CreateGroup(ctx, nil, []*relationTb.GroupMemberModel{groupMember}); err != nil {
return nil, err return nil, err
} }
if err := s.conversationRpcClient.GroupChatFirstCreateConversation(ctx, req.GroupID, []string{req.InviterUserID}); err != nil { if err := s.conversationRPCClient.GroupChatFirstCreateConversation(ctx, req.GroupID, []string{req.InviterUserID}); err != nil {
return nil, err return nil, err
} }
s.Notification.MemberEnterDirectlyNotification(ctx, req.GroupID, req.InviterUserID) s.Notification.MemberEnterDirectlyNotification(ctx, req.GroupID, req.InviterUserID)
@ -811,16 +811,16 @@ func (s *groupServer) QuitGroup(ctx context.Context, req *pbGroup.QuitGroupReq)
func (s *groupServer) deleteMemberAndSetConversationSeq(ctx context.Context, groupID string, userIDs []string) error { func (s *groupServer) deleteMemberAndSetConversationSeq(ctx context.Context, groupID string, userIDs []string) error {
conevrsationID := utils.GetConversationIDBySessionType(constant.SuperGroupChatType, groupID) conevrsationID := utils.GetConversationIDBySessionType(constant.SuperGroupChatType, groupID)
maxSeq, err := s.msgRpcClient.GetConversationMaxSeq(ctx, conevrsationID) maxSeq, err := s.msgRPCClient.GetConversationMaxSeq(ctx, conevrsationID)
if err != nil { if err != nil {
return err return err
} }
return s.conversationRpcClient.SetConversationMaxSeq(ctx, userIDs, conevrsationID, maxSeq) return s.conversationRPCClient.SetConversationMaxSeq(ctx, userIDs, conevrsationID, maxSeq)
} }
func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInfoReq) (*pbGroup.SetGroupInfoResp, error) { func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInfoReq) (*pbGroup.SetGroupInfoResp, error) {
var opMember *relationTb.GroupMemberModel var opMember *relationTb.GroupMemberModel
if !tokenverify.IsAppManagerUid(ctx) { if !tokenverify.IsAppManagerUID(ctx) {
var err error var err error
opMember, err = s.TakeGroupMember(ctx, req.GroupInfoForSet.GroupID, mcontext.GetOpUserID(ctx)) opMember, err = s.TakeGroupMember(ctx, req.GroupInfoForSet.GroupID, mcontext.GetOpUserID(ctx))
if err != nil { if err != nil {
@ -880,7 +880,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
return return
} }
conversation.GroupAtType = &wrapperspb.Int32Value{Value: constant.GroupNotification} conversation.GroupAtType = &wrapperspb.Int32Value{Value: constant.GroupNotification}
if err := s.conversationRpcClient.SetConversations(nctx, resp.UserIDs, conversation); err != nil { if err := s.conversationRPCClient.SetConversations(nctx, resp.UserIDs, conversation); err != nil {
log.ZWarn(ctx, "SetConversations", err, resp.UserIDs, conversation) log.ZWarn(ctx, "SetConversations", err, resp.UserIDs, conversation)
} }
}() }()
@ -930,7 +930,7 @@ func (s *groupServer) TransferGroupOwner(ctx context.Context, req *pbGroup.Trans
if newOwner == nil { if newOwner == nil {
return nil, errs.ErrArgs.Wrap("NewOwnerUser not in group " + req.NewOwnerUserID) return nil, errs.ErrArgs.Wrap("NewOwnerUser not in group " + req.NewOwnerUserID)
} }
if !tokenverify.IsAppManagerUid(ctx) { if !tokenverify.IsAppManagerUID(ctx) {
if !(mcontext.GetOpUserID(ctx) == oldOwner.UserID && oldOwner.RoleLevel == constant.GroupOwner) { if !(mcontext.GetOpUserID(ctx) == oldOwner.UserID && oldOwner.RoleLevel == constant.GroupOwner) {
return nil, errs.ErrNoPermission.Wrap("no permission transfer group owner") return nil, errs.ErrNoPermission.Wrap("no permission transfer group owner")
} }
@ -1062,7 +1062,7 @@ func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGrou
if err != nil { if err != nil {
return nil, err return nil, err
} }
if !tokenverify.IsAppManagerUid(ctx) { if !tokenverify.IsAppManagerUID(ctx) {
if owner.UserID != mcontext.GetOpUserID(ctx) { if owner.UserID != mcontext.GetOpUserID(ctx) {
return nil, errs.ErrNoPermission.Wrap("not group owner") return nil, errs.ErrNoPermission.Wrap("not group owner")
} }
@ -1074,9 +1074,9 @@ func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGrou
if req.DeleteMember == false && group.Status == constant.GroupStatusDismissed { if req.DeleteMember == false && group.Status == constant.GroupStatusDismissed {
return nil, errs.ErrDismissedAlready.Wrap("group status is dismissed") return nil, errs.ErrDismissedAlready.Wrap("group status is dismissed")
} }
//if group.Status == constant.GroupStatusDismissed { // if group.Status == constant.GroupStatusDismissed {
// return nil, errs.ErrArgs.Wrap("group status is dismissed") // return nil, errs.ErrArgs.Wrap("group status is dismissed")
//} // }
if err := s.GroupDatabase.DismissGroup(ctx, req.GroupID, req.DeleteMember); err != nil { if err := s.GroupDatabase.DismissGroup(ctx, req.GroupID, req.DeleteMember); err != nil {
return nil, err return nil, err
} }
@ -1090,7 +1090,7 @@ func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGrou
if err != nil { if err != nil {
return nil, err return nil, err
} }
//s.Notification.GroupDismissedNotification(ctx, req) // s.Notification.GroupDismissedNotification(ctx, req)
tips := &sdkws.GroupDismissedTips{ tips := &sdkws.GroupDismissedTips{
Group: s.groupDB2PB(group, owner.UserID, num), Group: s.groupDB2PB(group, owner.UserID, num),
OpUser: &sdkws.GroupMemberFullInfo{}, OpUser: &sdkws.GroupMemberFullInfo{},
@ -1106,14 +1106,14 @@ func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGrou
func (s *groupServer) MuteGroupMember(ctx context.Context, req *pbGroup.MuteGroupMemberReq) (*pbGroup.MuteGroupMemberResp, error) { func (s *groupServer) MuteGroupMember(ctx context.Context, req *pbGroup.MuteGroupMemberReq) (*pbGroup.MuteGroupMemberResp, error) {
resp := &pbGroup.MuteGroupMemberResp{} resp := &pbGroup.MuteGroupMemberResp{}
//if err := tokenverify.CheckAccessV3(ctx, req.UserID); err != nil { // if err := tokenverify.CheckAccessV3(ctx, req.UserID); err != nil {
// return nil, err // return nil, err
//} // }
member, err := s.TakeGroupMember(ctx, req.GroupID, req.UserID) member, err := s.TakeGroupMember(ctx, req.GroupID, req.UserID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if !tokenverify.IsAppManagerUid(ctx) { if !tokenverify.IsAppManagerUID(ctx) {
opMember, err := s.TakeGroupMember(ctx, req.GroupID, mcontext.GetOpUserID(ctx)) opMember, err := s.TakeGroupMember(ctx, req.GroupID, mcontext.GetOpUserID(ctx))
if err != nil { if err != nil {
return nil, err return nil, err
@ -1141,11 +1141,11 @@ func (s *groupServer) MuteGroupMember(ctx context.Context, req *pbGroup.MuteGrou
func (s *groupServer) CancelMuteGroupMember(ctx context.Context, req *pbGroup.CancelMuteGroupMemberReq) (*pbGroup.CancelMuteGroupMemberResp, error) { func (s *groupServer) CancelMuteGroupMember(ctx context.Context, req *pbGroup.CancelMuteGroupMemberReq) (*pbGroup.CancelMuteGroupMemberResp, error) {
resp := &pbGroup.CancelMuteGroupMemberResp{} resp := &pbGroup.CancelMuteGroupMemberResp{}
//member, err := s.GroupDatabase.TakeGroupMember(ctx, req.GroupID, req.UserID) // member, err := s.GroupDatabase.TakeGroupMember(ctx, req.GroupID, req.UserID)
//if err != nil { // if err != nil {
// return nil, err // return nil, err
//} // }
//if !(mcontext.GetOpUserID(ctx) == req.UserID || tokenverify.IsAppManagerUid(ctx)) { // if !(mcontext.GetOpUserID(ctx) == req.UserID || tokenverify.IsAppManagerUID(ctx)) {
// opMember, err := s.GroupDatabase.TakeGroupMember(ctx, req.GroupID, mcontext.GetOpUserID(ctx)) // opMember, err := s.GroupDatabase.TakeGroupMember(ctx, req.GroupID, mcontext.GetOpUserID(ctx))
// if err != nil { // if err != nil {
// return nil, err // return nil, err
@ -1153,15 +1153,15 @@ func (s *groupServer) CancelMuteGroupMember(ctx context.Context, req *pbGroup.Ca
// if opMember.RoleLevel <= member.RoleLevel { // if opMember.RoleLevel <= member.RoleLevel {
// return nil, errs.ErrNoPermission.Wrap(fmt.Sprintf("self RoleLevel %d target %d", opMember.RoleLevel, member.RoleLevel)) // return nil, errs.ErrNoPermission.Wrap(fmt.Sprintf("self RoleLevel %d target %d", opMember.RoleLevel, member.RoleLevel))
// } // }
//} // }
//if err := tokenverify.CheckAccessV3(ctx, req.UserID); err != nil { // if err := tokenverify.CheckAccessV3(ctx, req.UserID); err != nil {
// return nil, err // return nil, err
//} // }
member, err := s.TakeGroupMember(ctx, req.GroupID, req.UserID) member, err := s.TakeGroupMember(ctx, req.GroupID, req.UserID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if !tokenverify.IsAppManagerUid(ctx) { if !tokenverify.IsAppManagerUID(ctx) {
opMember, err := s.TakeGroupMember(ctx, req.GroupID, mcontext.GetOpUserID(ctx)) opMember, err := s.TakeGroupMember(ctx, req.GroupID, mcontext.GetOpUserID(ctx))
if err != nil { if err != nil {
return nil, err return nil, err
@ -1245,7 +1245,7 @@ func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGr
memberMap := utils.SliceToMap(members, func(e *relationTb.GroupMemberModel) [2]string { memberMap := utils.SliceToMap(members, func(e *relationTb.GroupMemberModel) [2]string {
return [...]string{e.GroupID, e.UserID} return [...]string{e.GroupID, e.UserID}
}) })
if !tokenverify.IsAppManagerUid(ctx) { if !tokenverify.IsAppManagerUID(ctx) {
opUserID := mcontext.GetOpUserID(ctx) opUserID := mcontext.GetOpUserID(ctx)
for _, member := range req.Members { for _, member := range req.Members {
if member.RoleLevel != nil { if member.RoleLevel != nil {
@ -1272,15 +1272,15 @@ func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGr
if !ok { if !ok {
return nil, errs.ErrRecordNotFound.Wrap(fmt.Sprintf("user %s not in group %s", member.UserID, member.GroupID)) return nil, errs.ErrRecordNotFound.Wrap(fmt.Sprintf("user %s not in group %s", member.UserID, member.GroupID))
} }
//if opMember.RoleLevel == constant.GroupOwner { // if opMember.RoleLevel == constant.GroupOwner {
// continue // continue
//} // }
//if dbMember.RoleLevel == constant.GroupOwner { // if dbMember.RoleLevel == constant.GroupOwner {
// return nil, errs.ErrNoPermission.Wrap("change group owner") // return nil, errs.ErrNoPermission.Wrap("change group owner")
//} // }
//if opMember.RoleLevel == constant.GroupAdmin && dbMember.RoleLevel == constant.GroupAdmin { // if opMember.RoleLevel == constant.GroupAdmin && dbMember.RoleLevel == constant.GroupAdmin {
// return nil, errs.ErrNoPermission.Wrap("admin can not change other admin role info") // return nil, errs.ErrNoPermission.Wrap("admin can not change other admin role info")
//} // }
switch opMember.RoleLevel { switch opMember.RoleLevel {
case constant.GroupOrdinaryUsers: case constant.GroupOrdinaryUsers:
return nil, errs.ErrNoPermission.Wrap("ordinary users can not change other role level") return nil, errs.ErrNoPermission.Wrap("ordinary users can not change other role level")
@ -1292,9 +1292,9 @@ func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGr
return nil, errs.ErrNoPermission.Wrap("admin can not change other role level") return nil, errs.ErrNoPermission.Wrap("admin can not change other role level")
} }
case constant.GroupOwner: case constant.GroupOwner:
//if member.RoleLevel != nil && member.RoleLevel.Value == constant.GroupOwner { // if member.RoleLevel != nil && member.RoleLevel.Value == constant.GroupOwner {
// return nil, errs.ErrNoPermission.Wrap("owner only one") // return nil, errs.ErrNoPermission.Wrap("owner only one")
//} // }
} }
} }
} }

@ -71,7 +71,7 @@ func (m *msgServer) SetConversationHasReadSeq(
) (resp *msg.SetConversationHasReadSeqResp, err error) { ) (resp *msg.SetConversationHasReadSeqResp, err error) {
maxSeq, err := m.MsgDatabase.GetMaxSeq(ctx, req.ConversationID) maxSeq, err := m.MsgDatabase.GetMaxSeq(ctx, req.ConversationID)
if err != nil { if err != nil {
return return nil, err
} }
if req.HasReadSeq > maxSeq { if req.HasReadSeq > maxSeq {
return nil, errs.ErrArgs.Wrap("hasReadSeq must not be bigger than maxSeq") return nil, errs.ErrArgs.Wrap("hasReadSeq must not be bigger than maxSeq")
@ -80,7 +80,7 @@ func (m *msgServer) SetConversationHasReadSeq(
return nil, err return nil, err
} }
if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, constant.SingleChatType, req.UserID, req.UserID, nil, req.HasReadSeq); err != nil { if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, constant.SingleChatType, req.UserID, req.UserID, nil, req.HasReadSeq); err != nil {
return return nil, err
} }
return &msg.SetConversationHasReadSeqResp{}, nil return &msg.SetConversationHasReadSeqResp{}, nil
} }
@ -94,7 +94,7 @@ func (m *msgServer) MarkMsgsAsRead(
} }
maxSeq, err := m.MsgDatabase.GetMaxSeq(ctx, req.ConversationID) maxSeq, err := m.MsgDatabase.GetMaxSeq(ctx, req.ConversationID)
if err != nil { if err != nil {
return return nil, err
} }
hasReadSeq := req.Seqs[len(req.Seqs)-1] hasReadSeq := req.Seqs[len(req.Seqs)-1]
if hasReadSeq > maxSeq { if hasReadSeq > maxSeq {
@ -102,14 +102,14 @@ func (m *msgServer) MarkMsgsAsRead(
} }
conversation, err := m.Conversation.GetConversation(ctx, req.UserID, req.ConversationID) conversation, err := m.Conversation.GetConversation(ctx, req.UserID, req.ConversationID)
if err != nil { if err != nil {
return return nil, err
} }
if err = m.MsgDatabase.MarkSingleChatMsgsAsRead(ctx, req.UserID, req.ConversationID, req.Seqs); err != nil { if err = m.MsgDatabase.MarkSingleChatMsgsAsRead(ctx, req.UserID, req.ConversationID, req.Seqs); err != nil {
return return
} }
currentHasReadSeq, err := m.MsgDatabase.GetHasReadSeq(ctx, req.UserID, req.ConversationID) currentHasReadSeq, err := m.MsgDatabase.GetHasReadSeq(ctx, req.UserID, req.ConversationID)
if err != nil && errs.Unwrap(err) != redis.Nil { if err != nil && errs.Unwrap(err) != redis.Nil {
return return nil, err
} }
if hasReadSeq > currentHasReadSeq { if hasReadSeq > currentHasReadSeq {
err = m.MsgDatabase.SetHasReadSeq(ctx, req.UserID, req.ConversationID, hasReadSeq) err = m.MsgDatabase.SetHasReadSeq(ctx, req.UserID, req.ConversationID, hasReadSeq)
@ -129,11 +129,11 @@ func (m *msgServer) MarkConversationAsRead(
) (resp *msg.MarkConversationAsReadResp, err error) { ) (resp *msg.MarkConversationAsReadResp, err error) {
conversation, err := m.Conversation.GetConversation(ctx, req.UserID, req.ConversationID) conversation, err := m.Conversation.GetConversation(ctx, req.UserID, req.ConversationID)
if err != nil { if err != nil {
return return nil, err
} }
hasReadSeq, err := m.MsgDatabase.GetHasReadSeq(ctx, req.UserID, req.ConversationID) hasReadSeq, err := m.MsgDatabase.GetHasReadSeq(ctx, req.UserID, req.ConversationID)
if err != nil && errs.Unwrap(err) != redis.Nil { if err != nil && errs.Unwrap(err) != redis.Nil {
return return nil, err
} }
log.ZDebug(ctx, "MarkConversationAsRead", "hasReadSeq", hasReadSeq, "req.HasReadSeq", req.HasReadSeq) log.ZDebug(ctx, "MarkConversationAsRead", "hasReadSeq", hasReadSeq, "req.HasReadSeq", req.HasReadSeq)
var seqs []int64 var seqs []int64
@ -153,7 +153,7 @@ func (m *msgServer) MarkConversationAsRead(
if req.HasReadSeq > hasReadSeq { if req.HasReadSeq > hasReadSeq {
err = m.MsgDatabase.SetHasReadSeq(ctx, req.UserID, req.ConversationID, req.HasReadSeq) err = m.MsgDatabase.SetHasReadSeq(ctx, req.UserID, req.ConversationID, req.HasReadSeq)
if err != nil { if err != nil {
return return nil, err
} }
hasReadSeq = req.HasReadSeq hasReadSeq = req.HasReadSeq
} }
@ -177,6 +177,6 @@ func (m *msgServer) sendMarkAsReadNotification(
Seqs: seqs, Seqs: seqs,
HasReadSeq: hasReadSeq, HasReadSeq: hasReadSeq,
} }
m.notificationSender.NotificationWithSesstionType(ctx, sendID, recvID, constant.HasReadReceipt, sesstionType, tips) m.notificationSender.NotificationWithSessionType(ctx, sendID, recvID, constant.HasReadReceipt, sesstionType, tips)
return nil return nil
} }

@ -29,7 +29,7 @@ import (
) )
func cbURL() string { func cbURL() string {
return config.Config.Callback.CallbackUrl return config.Config.Callback.CallbackURL
} }
func toCommonCallback(ctx context.Context, msg *pbChat.SendMsgReq, command string) cbapi.CommonCallbackReq { func toCommonCallback(ctx context.Context, msg *pbChat.SendMsgReq, command string) cbapi.CommonCallbackReq {

@ -86,7 +86,7 @@ func (m *msgServer) DeleteMsgs(ctx context.Context, req *msg.DeleteMsgsReq) (*ms
return nil, err return nil, err
} }
tips := &sdkws.DeleteMsgsTips{UserID: req.UserID, ConversationID: req.ConversationID, Seqs: req.Seqs} tips := &sdkws.DeleteMsgsTips{UserID: req.UserID, ConversationID: req.ConversationID, Seqs: req.Seqs}
m.notificationSender.NotificationWithSesstionType( m.notificationSender.NotificationWithSessionType(
ctx, ctx,
req.UserID, req.UserID,
m.conversationAndGetRecvID(conversations[0], req.UserID), m.conversationAndGetRecvID(conversations[0], req.UserID),
@ -100,7 +100,7 @@ func (m *msgServer) DeleteMsgs(ctx context.Context, req *msg.DeleteMsgsReq) (*ms
} }
if isSyncSelf { if isSyncSelf {
tips := &sdkws.DeleteMsgsTips{UserID: req.UserID, ConversationID: req.ConversationID, Seqs: req.Seqs} tips := &sdkws.DeleteMsgsTips{UserID: req.UserID, ConversationID: req.ConversationID, Seqs: req.Seqs}
m.notificationSender.NotificationWithSesstionType(ctx, req.UserID, req.UserID, constant.DeleteMsgsNotification, constant.SingleChatType, tips) m.notificationSender.NotificationWithSessionType(ctx, req.UserID, req.UserID, constant.DeleteMsgsNotification, constant.SingleChatType, tips)
} }
} }
return &msg.DeleteMsgsResp{}, nil return &msg.DeleteMsgsResp{}, nil
@ -171,7 +171,7 @@ func (m *msgServer) clearConversation(
// notification 2 self // notification 2 self
if isSyncSelf { if isSyncSelf {
tips := &sdkws.ClearConversationTips{UserID: userID, ConversationIDs: existConversationIDs} tips := &sdkws.ClearConversationTips{UserID: userID, ConversationIDs: existConversationIDs}
m.notificationSender.NotificationWithSesstionType( m.notificationSender.NotificationWithSessionType(
ctx, ctx,
userID, userID,
userID, userID,
@ -186,7 +186,7 @@ func (m *msgServer) clearConversation(
} }
for _, conversation := range existConversations { for _, conversation := range existConversations {
tips := &sdkws.ClearConversationTips{UserID: userID, ConversationIDs: []string{conversation.ConversationID}} tips := &sdkws.ClearConversationTips{UserID: userID, ConversationIDs: []string{conversation.ConversationID}}
m.notificationSender.NotificationWithSesstionType(ctx, userID, m.conversationAndGetRecvID(conversation, userID), constant.ClearConversationNotification, conversation.ConversationType, tips) m.notificationSender.NotificationWithSessionType(ctx, userID, m.conversationAndGetRecvID(conversation, userID), constant.ClearConversationNotification, conversation.ConversationType, tips)
} }
} }
if err := m.MsgDatabase.UserSetHasReadSeqs(ctx, userID, maxSeqs); err != nil { if err := m.MsgDatabase.UserSetHasReadSeqs(ctx, userID, maxSeqs); err != nil {

@ -60,7 +60,7 @@ func (m *msgServer) RevokeMsg(ctx context.Context, req *msg.RevokeMsgReq) (*msg.
data, _ := json.Marshal(msgs[0]) data, _ := json.Marshal(msgs[0])
log.ZInfo(ctx, "GetMsgBySeqs", "conversationID", req.ConversationID, "seq", req.Seq, "msg", string(data)) log.ZInfo(ctx, "GetMsgBySeqs", "conversationID", req.ConversationID, "seq", req.Seq, "msg", string(data))
var role int32 var role int32
if !tokenverify.IsAppManagerUid(ctx) { if !tokenverify.IsAppManagerUID(ctx) {
switch msgs[0].SessionType { switch msgs[0].SessionType {
case constant.SingleChatType: case constant.SingleChatType:
if err := tokenverify.CheckAccessV3(ctx, msgs[0].SendID); err != nil { if err := tokenverify.CheckAccessV3(ctx, msgs[0].SendID); err != nil {
@ -119,7 +119,7 @@ func (m *msgServer) RevokeMsg(ctx context.Context, req *msg.RevokeMsgReq) (*msg.
} else { } else {
recvID = msgs[0].RecvID recvID = msgs[0].RecvID
} }
if err := m.notificationSender.NotificationWithSesstionType(ctx, req.UserID, recvID, constant.MsgRevokeNotification, msgs[0].SessionType, &tips); err != nil { if err := m.notificationSender.NotificationWithSessionType(ctx, req.UserID, recvID, constant.MsgRevokeNotification, msgs[0].SessionType, &tips); err != nil {
return nil, err return nil, err
} }
return &msg.RevokeMsgResp{}, nil return &msg.RevokeMsgResp{}, nil

@ -30,7 +30,6 @@ import (
) )
func (m *msgServer) SendMsg(ctx context.Context, req *pbMsg.SendMsgReq) (resp *pbMsg.SendMsgResp, error error) { func (m *msgServer) SendMsg(ctx context.Context, req *pbMsg.SendMsgReq) (resp *pbMsg.SendMsgResp, error error) {
resp = &pbMsg.SendMsgResp{}
if req.MsgData != nil { if req.MsgData != nil {
flag := isMessageHasReadEnabled(req.MsgData) flag := isMessageHasReadEnabled(req.MsgData)
if !flag { if !flag {
@ -101,9 +100,9 @@ func (m *msgServer) setConversationAtInfo(nctx context.Context, msg *sdkws.MsgDa
return return
} }
atUserID = utils.DifferenceString([]string{constant.AtAllString}, msg.AtUserIDList) atUserID = utils.DifferenceString([]string{constant.AtAllString}, msg.AtUserIDList)
if len(atUserID) == 0 { //just @everyone if len(atUserID) == 0 { // just @everyone
conversation.GroupAtType = &wrapperspb.Int32Value{Value: constant.AtAll} conversation.GroupAtType = &wrapperspb.Int32Value{Value: constant.AtAll}
} else { //@Everyone and @other people } else { // @Everyone and @other people
conversation.GroupAtType = &wrapperspb.Int32Value{Value: constant.AtAllAtMe} conversation.GroupAtType = &wrapperspb.Int32Value{Value: constant.AtAllAtMe}
err := m.Conversation.SetConversations(ctx, atUserID, conversation) err := m.Conversation.SetConversations(ctx, atUserID, conversation)
if err != nil { if err != nil {

@ -20,9 +20,9 @@ type MessageInterceptorChain []MessageInterceptorFunc
type msgServer struct { type msgServer struct {
RegisterCenter discoveryregistry.SvcDiscoveryRegistry RegisterCenter discoveryregistry.SvcDiscoveryRegistry
MsgDatabase controller.CommonMsgDatabase MsgDatabase controller.CommonMsgDatabase
Group *rpcclient.GroupRpcClient Group *rpcclient.GroupRPCClient
User *rpcclient.UserRpcClient User *rpcclient.UserRPCClient
Conversation *rpcclient.ConversationRpcClient Conversation *rpcclient.ConversationRPCClient
friend *rpcclient.FriendRpcClient friend *rpcclient.FriendRpcClient
GroupLocalCache *localcache.GroupLocalCache GroupLocalCache *localcache.GroupLocalCache
ConversationLocalCache *localcache.ConversationLocalCache ConversationLocalCache *localcache.ConversationLocalCache
@ -61,13 +61,13 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
cacheModel := cache.NewMsgCacheModel(rdb) cacheModel := cache.NewMsgCacheModel(rdb)
msgDocModel := unrelation.NewMsgMongoDriver(mongo.GetDatabase()) msgDocModel := unrelation.NewMsgMongoDriver(mongo.GetDatabase())
msgDatabase := controller.NewCommonMsgDatabase(msgDocModel, cacheModel) msgDatabase := controller.NewCommonMsgDatabase(msgDocModel, cacheModel)
conversationClient := rpcclient.NewConversationRpcClient(client) conversationClient := rpcclient.NewConversationRPCClient(client)
userRpcClient := rpcclient.NewUserRpcClient(client) userRPCClient := rpcclient.NewUserRPCClient(client)
groupRpcClient := rpcclient.NewGroupRpcClient(client) groupRpcClient := rpcclient.NewGroupRPCClient(client)
friendRpcClient := rpcclient.NewFriendRpcClient(client) friendRpcClient := rpcclient.NewFriendRpcClient(client)
s := &msgServer{ s := &msgServer{
Conversation: &conversationClient, Conversation: &conversationClient,
User: &userRpcClient, User: &userRPCClient,
Group: &groupRpcClient, Group: &groupRpcClient,
MsgDatabase: msgDatabase, MsgDatabase: msgDatabase,
RegisterCenter: client, RegisterCenter: client,

@ -62,7 +62,7 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
third.RegisterThirdServer(server, &thirdServer{ third.RegisterThirdServer(server, &thirdServer{
apiURL: apiURL, apiURL: apiURL,
thirdDatabase: controller.NewThirdDatabase(cache.NewMsgCacheModel(rdb)), thirdDatabase: controller.NewThirdDatabase(cache.NewMsgCacheModel(rdb)),
userRpcClient: rpcclient.NewUserRpcClient(client), userRPCClient: rpcclient.NewUserRPCClient(client),
s3dataBase: controller.NewS3Database(o, relation.NewObjectInfo(db)), s3dataBase: controller.NewS3Database(o, relation.NewObjectInfo(db)),
defaultExpire: time.Hour * 24 * 7, defaultExpire: time.Hour * 24 * 7,
}) })
@ -73,7 +73,7 @@ type thirdServer struct {
apiURL string apiURL string
thirdDatabase controller.ThirdDatabase thirdDatabase controller.ThirdDatabase
s3dataBase controller.S3Database s3dataBase controller.S3Database
userRpcClient rpcclient.UserRpcClient userRPCClient rpcclient.UserRPCClient
defaultExpire time.Duration defaultExpire time.Duration
} }

@ -30,7 +30,7 @@ import (
type userServer struct { type userServer struct {
controller.UserDatabase controller.UserDatabase
notificationSender *notification.FriendNotificationSender notificationSender *notification.FriendNotificationSender
friendRpcClient *rpcclient.FriendRpcClient friendRPCClient *rpcclient.FriendRpcClient
RegisterCenter registry.SvcDiscoveryRegistry RegisterCenter registry.SvcDiscoveryRegistry
} }
@ -57,12 +57,12 @@ func Start(client registry.SvcDiscoveryRegistry, server *grpc.Server) error {
cache := cache.NewUserCacheRedis(rdb, userDB, cache.GetDefaultOpt()) cache := cache.NewUserCacheRedis(rdb, userDB, cache.GetDefaultOpt())
database := controller.NewUserDatabase(userDB, cache, tx.NewGorm(db)) database := controller.NewUserDatabase(userDB, cache, tx.NewGorm(db))
friendRpcClient := rpcclient.NewFriendRpcClient(client) friendRpcClient := rpcclient.NewFriendRpcClient(client)
msgRpcClient := rpcclient.NewMessageRpcClient(client) msgRPCClient := rpcclient.NewMessageRpcClient(client)
u := &userServer{ u := &userServer{
UserDatabase: database, UserDatabase: database,
RegisterCenter: client, RegisterCenter: client,
friendRpcClient: &friendRpcClient, friendRPCClient: &friendRpcClient,
notificationSender: notification.NewFriendNotificationSender(&msgRpcClient, notification.WithDBFunc(database.FindWithError)), notificationSender: notification.NewFriendNotificationSender(&msgRPCClient, notification.WithDBFunc(database.FindWithError)),
} }
pbuser.RegisterUserServer(server, u) pbuser.RegisterUserServer(server, u)
return u.UserDatabase.InitOnce(context.Background(), users) return u.UserDatabase.InitOnce(context.Background(), users)
@ -96,7 +96,7 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbuser.UpdateUserI
return nil, err return nil, err
} }
_ = s.notificationSender.UserInfoUpdatedNotification(ctx, req.UserInfo.UserID) _ = s.notificationSender.UserInfoUpdatedNotification(ctx, req.UserInfo.UserID)
friends, err := s.friendRpcClient.GetFriendIDs(ctx, req.UserInfo.UserID) friends, err := s.friendRPCClient.GetFriendIDs(ctx, req.UserInfo.UserID)
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -69,8 +69,8 @@ func InitMsgTool() (*MsgTool, error) {
userDatabase := controller.NewUserDatabase(userDB, cache.NewUserCacheRedis(rdb, relation.NewUserGorm(db), cache.GetDefaultOpt()), tx.NewGorm(db)) userDatabase := controller.NewUserDatabase(userDB, cache.NewUserCacheRedis(rdb, relation.NewUserGorm(db), cache.GetDefaultOpt()), tx.NewGorm(db))
groupDatabase := controller.InitGroupDatabase(db, rdb, mongo.GetDatabase()) groupDatabase := controller.InitGroupDatabase(db, rdb, mongo.GetDatabase())
conversationDatabase := controller.NewConversationDatabase(relation.NewConversationGorm(db), cache.NewConversationRedis(rdb, cache.GetDefaultOpt(), relation.NewConversationGorm(db)), tx.NewGorm(db)) conversationDatabase := controller.NewConversationDatabase(relation.NewConversationGorm(db), cache.NewConversationRedis(rdb, cache.GetDefaultOpt(), relation.NewConversationGorm(db)), tx.NewGorm(db))
msgRpcClient := rpcclient.NewMessageRpcClient(discov) msgRPCClient := rpcclient.NewMessageRpcClient(discov)
msgNotificationSender := notification.NewMsgNotificationSender(rpcclient.WithRpcClient(&msgRpcClient)) msgNotificationSender := notification.NewMsgNotificationSender(rpcclient.WithRPCClient(&msgRPCClient))
msgTool := NewMsgTool(msgDatabase, userDatabase, groupDatabase, conversationDatabase, msgNotificationSender) msgTool := NewMsgTool(msgDatabase, userDatabase, groupDatabase, conversationDatabase, msgNotificationSender)
return msgTool, nil return msgTool, nil
} }

@ -19,7 +19,7 @@ import (
"net/http" "net/http"
) )
func httpJson(w http.ResponseWriter, data any) { func httpJSON(w http.ResponseWriter, data any) {
body, err := json.Marshal(data) body, err := json.Marshal(data)
if err != nil { if err != nil {
http.Error(w, "json marshal error: "+err.Error(), http.StatusInternalServerError) http.Error(w, "json marshal error: "+err.Error(), http.StatusInternalServerError)
@ -31,9 +31,9 @@ func httpJson(w http.ResponseWriter, data any) {
} }
func HttpError(w http.ResponseWriter, err error) { func HttpError(w http.ResponseWriter, err error) {
httpJson(w, ParseError(err)) httpJSON(w, ParseError(err))
} }
func HttpSuccess(w http.ResponseWriter, data any) { func HttpSuccess(w http.ResponseWriter, data any) {
httpJson(w, ApiSuccess(data)) httpJSON(w, ApiSuccess(data))
} }

@ -19,7 +19,7 @@ type AwsStorageCredentialReq struct {
} }
type AwsStorageCredentialRespData struct { type AwsStorageCredentialRespData struct {
AccessKeyId string `json:"accessKeyID"` AccessKeyID string `json:"accessKeyID"`
SecretAccessKey string `json:"secretAccessKey"` SecretAccessKey string `json:"secretAccessKey"`
SessionToken string `json:"sessionToken"` SessionToken string `json:"sessionToken"`
RegionID string `json:"regionId"` RegionID string `json:"regionId"`

@ -50,7 +50,7 @@ type PictureBaseInfo struct {
Size int64 `mapstructure:"size" ` Size int64 `mapstructure:"size" `
Width int32 `mapstructure:"width" ` Width int32 `mapstructure:"width" `
Height int32 `mapstructure:"height"` Height int32 `mapstructure:"height"`
Url string `mapstructure:"url" ` URL string `mapstructure:"url" `
} }
type PictureElem struct { type PictureElem struct {
@ -114,7 +114,7 @@ type OANotificationElem struct {
NotificationFaceURL string `mapstructure:"notificationFaceURL" json:"notificationFaceURL"` NotificationFaceURL string `mapstructure:"notificationFaceURL" json:"notificationFaceURL"`
NotificationType int32 `mapstructure:"notificationType" json:"notificationType" validate:"required"` NotificationType int32 `mapstructure:"notificationType" json:"notificationType" validate:"required"`
Text string `mapstructure:"text" json:"text" validate:"required"` Text string `mapstructure:"text" json:"text" validate:"required"`
Url string `mapstructure:"url" json:"url"` URL string `mapstructure:"url" json:"url"`
MixType int32 `mapstructure:"mixType" json:"mixType"` MixType int32 `mapstructure:"mixType" json:"mixType"`
PictureElem PictureElem `mapstructure:"pictureElem" json:"pictureElem"` PictureElem PictureElem `mapstructure:"pictureElem" json:"pictureElem"`
SoundElem SoundElem `mapstructure:"soundElem" json:"soundElem"` SoundElem SoundElem `mapstructure:"soundElem" json:"soundElem"`

@ -22,7 +22,7 @@ type OSSCredentialReq struct {
type OSSCredentialRespData struct { type OSSCredentialRespData struct {
Endpoint string `json:"endpoint"` Endpoint string `json:"endpoint"`
AccessKeyId string `json:"access_key_id"` AccessKeyID string `json:"access_key_id"`
AccessKeySecret string `json:"access_key_secret"` AccessKeySecret string `json:"access_key_secret"`
Token string `json:"token"` Token string `json:"token"`
Bucket string `json:"bucket"` Bucket string `json:"bucket"`

@ -16,15 +16,15 @@ package cmd
import "github.com/spf13/cobra" import "github.com/spf13/cobra"
type ApiCmd struct { type APICmd struct {
*RootCmd *RootCmd
} }
func NewApiCmd() *ApiCmd { func NewApiCmd() *APICmd {
return &ApiCmd{NewRootCmd("api")} return &APICmd{NewRootCmd("api")}
} }
func (a *ApiCmd) AddApi(f func(port int) error) { func (a *APICmd) AddApi(f func(port int) error) {
a.Command.RunE = func(cmd *cobra.Command, args []string) error { a.Command.RunE = func(cmd *cobra.Command, args []string) error {
return f(a.getPortFlag(cmd)) return f(a.getPortFlag(cmd))
} }

@ -64,7 +64,7 @@ func NewRootCmd(name string, opts ...func(*CmdOpts)) (rootCmd *RootCmd) {
if cmdOpts.loggerPrefixName == "" { if cmdOpts.loggerPrefixName == "" {
cmdOpts.loggerPrefixName = "OpenIM.log.all" cmdOpts.loggerPrefixName = "OpenIM.log.all"
} }
if err := log.InitFromConfig(cmdOpts.loggerPrefixName, name, config.Config.Log.RemainLogLevel, config.Config.Log.IsStdout, config.Config.Log.IsJson, config.Config.Log.StorageLocation, config.Config.Log.RemainRotationCount); err != nil { if err := log.InitFromConfig(cmdOpts.loggerPrefixName, name, config.Config.Log.RemainLogLevel, config.Config.Log.IsStdout, config.Config.Log.IsJSON, config.Config.Log.StorageLocation, config.Config.Log.RemainRotationCount); err != nil {
panic(err) panic(err)
} }
return nil return nil

@ -64,7 +64,7 @@ type config struct {
} `yaml:"mysql"` } `yaml:"mysql"`
Mongo struct { Mongo struct {
Uri string `yaml:"uri"` URI string `yaml:"uri"`
Address []string `yaml:"address"` Address []string `yaml:"address"`
Database string `yaml:"database"` Database string `yaml:"database"`
Username string `yaml:"username"` Username string `yaml:"username"`
@ -94,7 +94,7 @@ type config struct {
ConsumerGroupID struct { ConsumerGroupID struct {
MsgToRedis string `yaml:"msgToRedis"` MsgToRedis string `yaml:"msgToRedis"`
MsgToMongo string `yaml:"msgToMongo"` MsgToMongo string `yaml:"msgToMongo"`
MsgToMySql string `yaml:"msgToMySql"` MsgToMySQL string `yaml:"msgToMySql"`
MsgToPush string `yaml:"msgToPush"` MsgToPush string `yaml:"msgToPush"`
} `yaml:"consumerGroupID"` } `yaml:"consumerGroupID"`
} `yaml:"kafka"` } `yaml:"kafka"`
@ -105,7 +105,7 @@ type config struct {
} `yaml:"rpc"` } `yaml:"rpc"`
Api struct { Api struct {
OpenImApiPort []int `yaml:"openImApiPort"` OpenImAPIPort []int `yaml:"openImApiPort"`
ListenIP string `yaml:"listenIP"` ListenIP string `yaml:"listenIP"`
} `yaml:"api"` } `yaml:"api"`
@ -135,7 +135,7 @@ type config struct {
} `yaml:"oss"` } `yaml:"oss"`
} `yaml:"object"` } `yaml:"object"`
RpcPort struct { RPCPort struct {
OpenImUserPort []int `yaml:"openImUserPort"` OpenImUserPort []int `yaml:"openImUserPort"`
OpenImFriendPort []int `yaml:"openImFriendPort"` OpenImFriendPort []int `yaml:"openImFriendPort"`
OpenImMessagePort []int `yaml:"openImMessagePort"` OpenImMessagePort []int `yaml:"openImMessagePort"`
@ -148,7 +148,7 @@ type config struct {
OpenImThirdPort []int `yaml:"openImThirdPort"` OpenImThirdPort []int `yaml:"openImThirdPort"`
} `yaml:"rpcPort"` } `yaml:"rpcPort"`
RpcRegisterName struct { RPCRegisterName struct {
OpenImUserName string `yaml:"openImUserName"` OpenImUserName string `yaml:"openImUserName"`
OpenImFriendName string `yaml:"openImFriendName"` OpenImFriendName string `yaml:"openImFriendName"`
OpenImMsgName string `yaml:"openImMsgName"` OpenImMsgName string `yaml:"openImMsgName"`
@ -166,7 +166,7 @@ type config struct {
RemainRotationCount uint `yaml:"remainRotationCount"` RemainRotationCount uint `yaml:"remainRotationCount"`
RemainLogLevel int `yaml:"remainLogLevel"` RemainLogLevel int `yaml:"remainLogLevel"`
IsStdout bool `yaml:"isStdout"` IsStdout bool `yaml:"isStdout"`
IsJson bool `yaml:"isJson"` IsJSON bool `yaml:"isJson"`
WithStack bool `yaml:"withStack"` WithStack bool `yaml:"withStack"`
} `yaml:"log"` } `yaml:"log"`
@ -180,7 +180,7 @@ type config struct {
Push struct { Push struct {
Enable string `yaml:"enable"` Enable string `yaml:"enable"`
GeTui struct { GeTui struct {
PushUrl string `yaml:"pushUrl"` PushURL string `yaml:"pushUrl"`
AppKey string `yaml:"appKey"` AppKey string `yaml:"appKey"`
Intent string `yaml:"intent"` Intent string `yaml:"intent"`
MasterSecret string `yaml:"masterSecret"` MasterSecret string `yaml:"masterSecret"`
@ -193,7 +193,7 @@ type config struct {
Jpns struct { Jpns struct {
AppKey string `yaml:"appKey"` AppKey string `yaml:"appKey"`
MasterSecret string `yaml:"masterSecret"` MasterSecret string `yaml:"masterSecret"`
PushUrl string `yaml:"pushUrl"` PushURL string `yaml:"pushUrl"`
PushIntent string `yaml:"pushIntent"` PushIntent string `yaml:"pushIntent"`
} `yaml:"jpns"` } `yaml:"jpns"`
} }
@ -224,7 +224,7 @@ type config struct {
Production bool `yaml:"production"` Production bool `yaml:"production"`
} `yaml:"iosPush"` } `yaml:"iosPush"`
Callback struct { Callback struct {
CallbackUrl string `yaml:"url"` CallbackURL string `yaml:"url"`
CallbackBeforeSendSingleMsg CallBackConfig `yaml:"beforeSendSingleMsg"` CallbackBeforeSendSingleMsg CallBackConfig `yaml:"beforeSendSingleMsg"`
CallbackAfterSendSingleMsg CallBackConfig `yaml:"afterSendSingleMsg"` CallbackAfterSendSingleMsg CallBackConfig `yaml:"afterSendSingleMsg"`
CallbackBeforeSendGroupMsg CallBackConfig `yaml:"beforeSendGroupMsg"` CallbackBeforeSendGroupMsg CallBackConfig `yaml:"beforeSendGroupMsg"`
@ -280,9 +280,9 @@ type notification struct {
GroupMemberSetToOrdinary NotificationConf `yaml:"groupMemberSetToOrdinaryUser"` GroupMemberSetToOrdinary NotificationConf `yaml:"groupMemberSetToOrdinaryUser"`
GroupInfoSetAnnouncement NotificationConf `yaml:"groupInfoSetAnnouncement"` GroupInfoSetAnnouncement NotificationConf `yaml:"groupInfoSetAnnouncement"`
GroupInfoSetName NotificationConf `yaml:"groupInfoSetName"` GroupInfoSetName NotificationConf `yaml:"groupInfoSetName"`
////////////////////////user/////////////////////// // //////////////////////user///////////////////////
UserInfoUpdated NotificationConf `yaml:"userInfoUpdated"` UserInfoUpdated NotificationConf `yaml:"userInfoUpdated"`
//////////////////////friend/////////////////////// // ////////////////////friend///////////////////////
FriendApplicationAdded NotificationConf `yaml:"friendApplicationAdded"` FriendApplicationAdded NotificationConf `yaml:"friendApplicationAdded"`
FriendApplicationApproved NotificationConf `yaml:"friendApplicationApproved"` FriendApplicationApproved NotificationConf `yaml:"friendApplicationApproved"`
FriendApplicationRejected NotificationConf `yaml:"friendApplicationRejected"` FriendApplicationRejected NotificationConf `yaml:"friendApplicationRejected"`
@ -292,21 +292,21 @@ type notification struct {
BlackAdded NotificationConf `yaml:"blackAdded"` BlackAdded NotificationConf `yaml:"blackAdded"`
BlackDeleted NotificationConf `yaml:"blackDeleted"` BlackDeleted NotificationConf `yaml:"blackDeleted"`
FriendInfoUpdated NotificationConf `yaml:"friendInfoUpdated"` FriendInfoUpdated NotificationConf `yaml:"friendInfoUpdated"`
//////////////////////conversation/////////////////////// // ////////////////////conversation///////////////////////
ConversationChanged NotificationConf `yaml:"conversationChanged"` ConversationChanged NotificationConf `yaml:"conversationChanged"`
ConversationSetPrivate NotificationConf `yaml:"conversationSetPrivate"` ConversationSetPrivate NotificationConf `yaml:"conversationSetPrivate"`
} }
func GetServiceNames() []string { func GetServiceNames() []string {
return []string{ return []string{
Config.RpcRegisterName.OpenImUserName, Config.RPCRegisterName.OpenImUserName,
Config.RpcRegisterName.OpenImFriendName, Config.RPCRegisterName.OpenImFriendName,
Config.RpcRegisterName.OpenImMsgName, Config.RPCRegisterName.OpenImMsgName,
Config.RpcRegisterName.OpenImPushName, Config.RPCRegisterName.OpenImPushName,
Config.RpcRegisterName.OpenImMessageGatewayName, Config.RPCRegisterName.OpenImMessageGatewayName,
Config.RpcRegisterName.OpenImGroupName, Config.RPCRegisterName.OpenImGroupName,
Config.RpcRegisterName.OpenImAuthName, Config.RPCRegisterName.OpenImAuthName,
Config.RpcRegisterName.OpenImConversationName, Config.RPCRegisterName.OpenImConversationName,
Config.RpcRegisterName.OpenImThirdName, Config.RPCRegisterName.OpenImThirdName,
} }
} }

@ -100,8 +100,8 @@ type MsgModel interface {
thirdCache thirdCache
AddTokenFlag(ctx context.Context, userID string, platformID int, token string, flag int) error AddTokenFlag(ctx context.Context, userID string, platformID int, token string, flag int) error
GetTokensWithoutError(ctx context.Context, userID string, platformID int) (map[string]int, error) GetTokensWithoutError(ctx context.Context, userID string, platformID int) (map[string]int, error)
SetTokenMapByUidPid(ctx context.Context, userID string, platformID int, m map[string]int) error SetTokenMapByUIDPid(ctx context.Context, userID string, platformID int, m map[string]int) error
DeleteTokenByUidPid(ctx context.Context, userID string, platformID int, fields []string) error DeleteTokenByUIDPid(ctx context.Context, userID string, platformID int, fields []string) error
GetMessagesBySeq( GetMessagesBySeq(
ctx context.Context, ctx context.Context,
conversationID string, conversationID string,
@ -330,7 +330,7 @@ func (c *msgCache) GetTokensWithoutError(ctx context.Context, userID string, pla
return mm, nil return mm, nil
} }
func (c *msgCache) SetTokenMapByUidPid(ctx context.Context, userID string, platform int, m map[string]int) error { func (c *msgCache) SetTokenMapByUIDPid(ctx context.Context, userID string, platform int, m map[string]int) error {
key := uidPidToken + userID + ":" + constant.PlatformIDToName(platform) key := uidPidToken + userID + ":" + constant.PlatformIDToName(platform)
mm := make(map[string]interface{}) mm := make(map[string]interface{})
for k, v := range m { for k, v := range m {
@ -339,7 +339,7 @@ func (c *msgCache) SetTokenMapByUidPid(ctx context.Context, userID string, platf
return errs.Wrap(c.rdb.HSet(ctx, key, mm).Err()) return errs.Wrap(c.rdb.HSet(ctx, key, mm).Err())
} }
func (c *msgCache) DeleteTokenByUidPid(ctx context.Context, userID string, platform int, fields []string) error { func (c *msgCache) DeleteTokenByUIDPid(ctx context.Context, userID string, platform int, fields []string) error {
key := uidPidToken + userID + ":" + constant.PlatformIDToName(platform) key := uidPidToken + userID + ":" + constant.PlatformIDToName(platform)
return errs.Wrap(c.rdb.HDel(ctx, key, fields...).Err()) return errs.Wrap(c.rdb.HDel(ctx, key, fields...).Err())
} }
@ -359,7 +359,7 @@ func (c *msgCache) GetMessagesBySeq(
) (seqMsgs []*sdkws.MsgData, failedSeqs []int64, err error) { ) (seqMsgs []*sdkws.MsgData, failedSeqs []int64, err error) {
pipe := c.rdb.Pipeline() pipe := c.rdb.Pipeline()
for _, v := range seqs { for _, v := range seqs {
//MESSAGE_CACHE:169.254.225.224_reliability1653387820_0_1 // MESSAGE_CACHE:169.254.225.224_reliability1653387820_0_1
key := c.getMessageCacheKey(conversationID, v) key := c.getMessageCacheKey(conversationID, v)
if err := pipe.Get(ctx, key).Err(); err != nil && err != redis.Nil { if err := pipe.Get(ctx, key).Err(); err != nil && err != redis.Nil {
return nil, nil, err return nil, nil, err

@ -26,9 +26,9 @@ import (
) )
type AuthDatabase interface { type AuthDatabase interface {
//结果为空 不返回错误 // 结果为空 不返回错误
GetTokensWithoutError(ctx context.Context, userID string, platformID int) (map[string]int, error) GetTokensWithoutError(ctx context.Context, userID string, platformID int) (map[string]int, error)
//创建token // 创建token
CreateToken(ctx context.Context, userID string, platformID int) (string, error) CreateToken(ctx context.Context, userID string, platformID int) (string, error)
} }
@ -66,7 +66,7 @@ func (a *authDatabase) CreateToken(ctx context.Context, userID string, platformI
} }
} }
if len(deleteTokenKey) != 0 { if len(deleteTokenKey) != 0 {
err := a.cache.DeleteTokenByUidPid(ctx, userID, platformID, deleteTokenKey) err := a.cache.DeleteTokenByUIDPid(ctx, userID, platformID, deleteTokenKey)
if err != nil { if err != nil {
return "", err return "", err
} }

@ -26,7 +26,7 @@ type ConversationLocalCache struct {
lock sync.Mutex lock sync.Mutex
superGroupRecvMsgNotNotifyUserIDs map[string]Hash superGroupRecvMsgNotNotifyUserIDs map[string]Hash
conversationIDs map[string]Hash conversationIDs map[string]Hash
client *rpcclient.ConversationRpcClient client *rpcclient.ConversationRPCClient
} }
type Hash struct { type Hash struct {
@ -34,7 +34,7 @@ type Hash struct {
ids []string ids []string
} }
func NewConversationLocalCache(client *rpcclient.ConversationRpcClient) *ConversationLocalCache { func NewConversationLocalCache(client *rpcclient.ConversationRPCClient) *ConversationLocalCache {
return &ConversationLocalCache{ return &ConversationLocalCache{
superGroupRecvMsgNotNotifyUserIDs: make(map[string]Hash), superGroupRecvMsgNotNotifyUserIDs: make(map[string]Hash),
conversationIDs: make(map[string]Hash), conversationIDs: make(map[string]Hash),

@ -26,7 +26,7 @@ import (
type GroupLocalCache struct { type GroupLocalCache struct {
lock sync.Mutex lock sync.Mutex
cache map[string]GroupMemberIDsHash cache map[string]GroupMemberIDsHash
client *rpcclient.GroupRpcClient client *rpcclient.GroupRPCClient
} }
type GroupMemberIDsHash struct { type GroupMemberIDsHash struct {
@ -34,7 +34,7 @@ type GroupMemberIDsHash struct {
userIDs []string userIDs []string
} }
func NewGroupLocalCache(client *rpcclient.GroupRpcClient) *GroupLocalCache { func NewGroupLocalCache(client *rpcclient.GroupRPCClient) *GroupLocalCache {
return &GroupLocalCache{ return &GroupLocalCache{
cache: make(map[string]GroupMemberIDsHash, 0), cache: make(map[string]GroupMemberIDsHash, 0),
client: client, client: client,

@ -38,12 +38,12 @@ type Mongo struct {
func NewMongo() (*Mongo, error) { func NewMongo() (*Mongo, error) {
specialerror.AddReplace(mongo.ErrNoDocuments, errs.ErrRecordNotFound) specialerror.AddReplace(mongo.ErrNoDocuments, errs.ErrRecordNotFound)
uri := "mongodb://sample.host:27017/?maxPoolSize=20&w=majority" uri := "mongodb://sample.host:27017/?maxPoolSize=20&w=majority"
if config.Config.Mongo.Uri != "" { if config.Config.Mongo.URI != "" {
// example: // example:
// mongodb://$user:$password@mongo1.mongo:27017,mongo2.mongo:27017,mongo3.mongo:27017/$DBDatabase/?replicaSet=rs0&readPreference=secondary&authSource=admin&maxPoolSize=$DBMaxPoolSize // mongodb://$user:$password@mongo1.mongo:27017,mongo2.mongo:27017,mongo3.mongo:27017/$DBDatabase/?replicaSet=rs0&readPreference=secondary&authSource=admin&maxPoolSize=$DBMaxPoolSize
uri = config.Config.Mongo.Uri uri = config.Config.Mongo.URI
} else { } else {
//mongodb://mongodb1.example.com:27317,mongodb2.example.com:27017/?replicaSet=mySet&authSource=authDB // mongodb://mongodb1.example.com:27317,mongodb2.example.com:27017/?replicaSet=mySet&authSource=authDB
mongodbHosts := "" mongodbHosts := ""
for i, v := range config.Config.Mongo.Address { for i, v := range config.Config.Mongo.Address {
if i == len(config.Config.Mongo.Address)-1 { if i == len(config.Config.Mongo.Address)-1 {

@ -50,16 +50,16 @@ func InitFromConfig(
loggerPrefixName, moduleName string, loggerPrefixName, moduleName string,
logLevel int, logLevel int,
isStdout bool, isStdout bool,
isJson bool, isJSON bool,
logLocation string, logLocation string,
rotateCount uint, rotateCount uint,
) error { ) error {
l, err := NewZapLogger(loggerPrefixName, moduleName, logLevel, isStdout, isJson, logLocation, rotateCount) l, err := NewZapLogger(loggerPrefixName, moduleName, logLevel, isStdout, isJSON, logLocation, rotateCount)
if err != nil { if err != nil {
return err return err
} }
pkgLogger = l.WithCallDepth(2) pkgLogger = l.WithCallDepth(2)
if isJson { if isJSON {
pkgLogger = pkgLogger.WithName(moduleName) pkgLogger = pkgLogger.WithName(moduleName)
} }
return nil return nil
@ -104,7 +104,7 @@ func NewZapLogger(
loggerPrefixName, loggerName string, loggerPrefixName, loggerName string,
logLevel int, logLevel int,
isStdout bool, isStdout bool,
isJson bool, isJSON bool,
logLocation string, logLocation string,
rotateCount uint, rotateCount uint,
) (*ZapLogger, error) { ) (*ZapLogger, error) {
@ -114,7 +114,7 @@ func NewZapLogger(
// InitialFields: map[string]interface{}{"PID": os.Getegid()}, // InitialFields: map[string]interface{}{"PID": os.Getegid()},
DisableStacktrace: true, DisableStacktrace: true,
} }
if isJson { if isJSON {
zapConfig.Encoding = "json" zapConfig.Encoding = "json"
} else { } else {
zapConfig.Encoding = "console" zapConfig.Encoding = "console"
@ -123,7 +123,7 @@ func NewZapLogger(
// zapConfig.OutputPaths = append(zapConfig.OutputPaths, "stdout", "stderr") // zapConfig.OutputPaths = append(zapConfig.OutputPaths, "stdout", "stderr")
// } // }
zl := &ZapLogger{level: logLevelMap[logLevel], loggerName: loggerName, loggerPrefixName: loggerPrefixName} zl := &ZapLogger{level: logLevelMap[logLevel], loggerName: loggerName, loggerPrefixName: loggerPrefixName}
opts, err := zl.cores(isStdout, isJson, logLocation, rotateCount) opts, err := zl.cores(isStdout, isJSON, logLocation, rotateCount)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -135,7 +135,7 @@ func NewZapLogger(
return zl, nil return zl, nil
} }
func (l *ZapLogger) cores(isStdout bool, isJson bool, logLocation string, rotateCount uint) (zap.Option, error) { func (l *ZapLogger) cores(isStdout bool, isJSON bool, logLocation string, rotateCount uint) (zap.Option, error) {
c := zap.NewProductionEncoderConfig() c := zap.NewProductionEncoderConfig()
c.EncodeTime = l.timeEncoder c.EncodeTime = l.timeEncoder
c.EncodeDuration = zapcore.SecondsDurationEncoder c.EncodeDuration = zapcore.SecondsDurationEncoder
@ -145,7 +145,7 @@ func (l *ZapLogger) cores(isStdout bool, isJson bool, logLocation string, rotate
c.CallerKey = "caller" c.CallerKey = "caller"
c.NameKey = "logger" c.NameKey = "logger"
var fileEncoder zapcore.Encoder var fileEncoder zapcore.Encoder
if isJson { if isJSON {
c.EncodeLevel = zapcore.CapitalLevelEncoder c.EncodeLevel = zapcore.CapitalLevelEncoder
fileEncoder = zapcore.NewJSONEncoder(c) fileEncoder = zapcore.NewJSONEncoder(c)
fileEncoder.AddInt("PID", os.Getpid()) fileEncoder.AddInt("PID", os.Getpid())

@ -45,7 +45,7 @@ func RpcClientInterceptor(
if ctx == nil { if ctx == nil {
return errs.ErrInternalServer.Wrap("call rpc request context is nil") return errs.ErrInternalServer.Wrap("call rpc request context is nil")
} }
ctx, err = getRpcContext(ctx, method) ctx, err = getRPCContext(ctx, method)
if err != nil { if err != nil {
return err return err
} }
@ -74,7 +74,7 @@ func RpcClientInterceptor(
return errs.NewCodeError(int(sta.Code()), sta.Message()).Wrap() return errs.NewCodeError(int(sta.Code()), sta.Message()).Wrap()
} }
func getRpcContext(ctx context.Context, method string) (context.Context, error) { func getRPCContext(ctx context.Context, method string) (context.Context, error) {
// ctx, _ = context.WithTimeout(ctx, time.Second*5) // ctx, _ = context.WithTimeout(ctx, time.Second*5)
md := metadata.Pairs() md := metadata.Pairs()
if keys, _ := ctx.Value(constant.RpcCustomHeader).([]string); len(keys) > 0 { if keys, _ := ctx.Value(constant.RpcCustomHeader).([]string); len(keys) > 0 {

@ -20,17 +20,17 @@ import (
) )
var ( var (
//auth rpc // auth rpc
UserLoginCounter prometheus.Counter UserLoginCounter prometheus.Counter
UserRegisterCounter prometheus.Counter UserRegisterCounter prometheus.Counter
//seg // seg
SeqGetSuccessCounter prometheus.Counter SeqGetSuccessCounter prometheus.Counter
SeqGetFailedCounter prometheus.Counter SeqGetFailedCounter prometheus.Counter
SeqSetSuccessCounter prometheus.Counter SeqSetSuccessCounter prometheus.Counter
SeqSetFailedCounter prometheus.Counter SeqSetFailedCounter prometheus.Counter
//msg-db // msg-db
MsgInsertRedisSuccessCounter prometheus.Counter MsgInsertRedisSuccessCounter prometheus.Counter
MsgInsertRedisFailedCounter prometheus.Counter MsgInsertRedisFailedCounter prometheus.Counter
MsgInsertMongoSuccessCounter prometheus.Counter MsgInsertMongoSuccessCounter prometheus.Counter
@ -40,7 +40,7 @@ var (
MsgPullFromMongoSuccessCounter prometheus.Counter MsgPullFromMongoSuccessCounter prometheus.Counter
MsgPullFromMongoFailedCounter prometheus.Counter MsgPullFromMongoFailedCounter prometheus.Counter
//msg-ws // msg-ws
MsgRecvTotalCounter prometheus.Counter MsgRecvTotalCounter prometheus.Counter
GetNewestSeqTotalCounter prometheus.Counter GetNewestSeqTotalCounter prometheus.Counter
PullMsgBySeqListTotalCounter prometheus.Counter PullMsgBySeqListTotalCounter prometheus.Counter
@ -50,7 +50,7 @@ var (
WorkSuperGroupChatMsgRecvSuccessCounter prometheus.Counter WorkSuperGroupChatMsgRecvSuccessCounter prometheus.Counter
OnlineUserGauge prometheus.Gauge OnlineUserGauge prometheus.Gauge
//msg-msg // msg-msg
SingleChatMsgProcessSuccessCounter prometheus.Counter SingleChatMsgProcessSuccessCounter prometheus.Counter
SingleChatMsgProcessFailedCounter prometheus.Counter SingleChatMsgProcessFailedCounter prometheus.Counter
GroupChatMsgProcessSuccessCounter prometheus.Counter GroupChatMsgProcessSuccessCounter prometheus.Counter
@ -58,14 +58,14 @@ var (
WorkSuperGroupChatMsgProcessSuccessCounter prometheus.Counter WorkSuperGroupChatMsgProcessSuccessCounter prometheus.Counter
WorkSuperGroupChatMsgProcessFailedCounter prometheus.Counter WorkSuperGroupChatMsgProcessFailedCounter prometheus.Counter
//msg-push // msg-push
MsgOnlinePushSuccessCounter prometheus.Counter MsgOnlinePushSuccessCounter prometheus.Counter
MsgOfflinePushSuccessCounter prometheus.Counter MsgOfflinePushSuccessCounter prometheus.Counter
MsgOfflinePushFailedCounter prometheus.Counter MsgOfflinePushFailedCounter prometheus.Counter
// api // api
ApiRequestCounter prometheus.Counter APIRequestCounter prometheus.Counter
ApiRequestSuccessCounter prometheus.Counter APIRequestSuccessCounter prometheus.Counter
ApiRequestFailedCounter prometheus.Counter APIRequestFailedCounter prometheus.Counter
// grpc // grpc
GrpcRequestCounter prometheus.Counter GrpcRequestCounter prometheus.Counter
@ -136,31 +136,31 @@ func NewSeqSetFailedCounter() {
}) })
} }
func NewApiRequestCounter() { func NewAPIRequestCounter() {
if ApiRequestCounter != nil { if APIRequestCounter != nil {
return return
} }
ApiRequestCounter = promauto.NewCounter(prometheus.CounterOpts{ APIRequestCounter = promauto.NewCounter(prometheus.CounterOpts{
Name: "api_request", Name: "api_request",
Help: "The number of api request", Help: "The number of api request",
}) })
} }
func NewApiRequestSuccessCounter() { func NewAPIRequestSuccessCounter() {
if ApiRequestSuccessCounter != nil { if APIRequestFailedCounter != nil {
return return
} }
ApiRequestSuccessCounter = promauto.NewCounter(prometheus.CounterOpts{ APIRequestFailedCounter = promauto.NewCounter(prometheus.CounterOpts{
Name: "api_request_success", Name: "api_request_success",
Help: "The number of api request success", Help: "The number of api request success",
}) })
} }
func NewApiRequestFailedCounter() { func NewAPIRequestFailedCounter() {
if ApiRequestFailedCounter != nil { if APIRequestFailedCounter != nil {
return return
} }
ApiRequestFailedCounter = promauto.NewCounter(prometheus.CounterOpts{ APIRequestFailedCounter = promauto.NewCounter(prometheus.CounterOpts{
Name: "api_request_failed", Name: "api_request_failed",
Help: "The number of api request failed", Help: "The number of api request failed",
}) })

@ -29,7 +29,7 @@ import (
type Claims struct { type Claims struct {
UserID string UserID string
PlatformID int //login platform PlatformID int // login platform
jwt.RegisteredClaims jwt.RegisteredClaims
} }
@ -40,9 +40,9 @@ func BuildClaims(uid string, platformID int, ttl int64) Claims {
UserID: uid, UserID: uid,
PlatformID: platformID, PlatformID: platformID,
RegisteredClaims: jwt.RegisteredClaims{ RegisteredClaims: jwt.RegisteredClaims{
ExpiresAt: jwt.NewNumericDate(now.Add(time.Duration(ttl*24) * time.Hour)), //Expiration time ExpiresAt: jwt.NewNumericDate(now.Add(time.Duration(ttl*24) * time.Hour)), // Expiration time
IssuedAt: jwt.NewNumericDate(now), //Issuing time IssuedAt: jwt.NewNumericDate(now), // Issuing time
NotBefore: jwt.NewNumericDate(before), //Begin Effective time NotBefore: jwt.NewNumericDate(before), // Begin Effective time
}} }}
} }
@ -87,7 +87,7 @@ func CheckAccessV3(ctx context.Context, ownerUserID string) (err error) {
return errs.ErrNoPermission.Wrap(utils.GetSelfFuncName()) return errs.ErrNoPermission.Wrap(utils.GetSelfFuncName())
} }
func IsAppManagerUid(ctx context.Context) bool { func IsAppManagerUID(ctx context.Context) bool {
return utils.IsContain(mcontext.GetOpUserID(ctx), config.Config.Manager.UserID) return utils.IsContain(mcontext.GetOpUserID(ctx), config.Config.Manager.UserID)
} }

@ -25,7 +25,7 @@ import (
) )
func NewAuth(discov discoveryregistry.SvcDiscoveryRegistry) *Auth { func NewAuth(discov discoveryregistry.SvcDiscoveryRegistry) *Auth {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImAuthName) conn, err := discov.GetConn(context.Background(), config.Config.RPCRegisterName.OpenImAuthName)
if err != nil { if err != nil {
panic(err) panic(err)
} }

@ -18,7 +18,7 @@ type Conversation struct {
} }
func NewConversation(discov discoveryregistry.SvcDiscoveryRegistry) *Conversation { func NewConversation(discov discoveryregistry.SvcDiscoveryRegistry) *Conversation {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImConversationName) conn, err := discov.GetConn(context.Background(), config.Config.RPCRegisterName.OpenImConversationName)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -26,13 +26,13 @@ func NewConversation(discov discoveryregistry.SvcDiscoveryRegistry) *Conversatio
return &Conversation{discov: discov, conn: conn, Client: client} return &Conversation{discov: discov, conn: conn, Client: client}
} }
type ConversationRpcClient Conversation type ConversationRPCClient Conversation
func NewConversationRpcClient(discov discoveryregistry.SvcDiscoveryRegistry) ConversationRpcClient { func NewConversationRPCClient(discov discoveryregistry.SvcDiscoveryRegistry) ConversationRPCClient {
return ConversationRpcClient(*NewConversation(discov)) return ConversationRPCClient(*NewConversation(discov))
} }
func (c *ConversationRpcClient) GetSingleConversationRecvMsgOpt(ctx context.Context, userID, conversationID string) (int32, error) { func (c *ConversationRPCClient) GetSingleConversationRecvMsgOpt(ctx context.Context, userID, conversationID string) (int32, error) {
var req pbConversation.GetConversationReq var req pbConversation.GetConversationReq
req.OwnerUserID = userID req.OwnerUserID = userID
req.ConversationID = conversationID req.ConversationID = conversationID
@ -43,26 +43,26 @@ func (c *ConversationRpcClient) GetSingleConversationRecvMsgOpt(ctx context.Cont
return conversation.GetConversation().RecvMsgOpt, err return conversation.GetConversation().RecvMsgOpt, err
} }
func (c *ConversationRpcClient) SingleChatFirstCreateConversation(ctx context.Context, recvID, sendID string) error { func (c *ConversationRPCClient) SingleChatFirstCreateConversation(ctx context.Context, recvID, sendID string) error {
_, err := c.Client.CreateSingleChatConversations(ctx, &pbConversation.CreateSingleChatConversationsReq{RecvID: recvID, SendID: sendID}) _, err := c.Client.CreateSingleChatConversations(ctx, &pbConversation.CreateSingleChatConversationsReq{RecvID: recvID, SendID: sendID})
return err return err
} }
func (c *ConversationRpcClient) GroupChatFirstCreateConversation(ctx context.Context, groupID string, userIDs []string) error { func (c *ConversationRPCClient) GroupChatFirstCreateConversation(ctx context.Context, groupID string, userIDs []string) error {
_, err := c.Client.CreateGroupChatConversations(ctx, &pbConversation.CreateGroupChatConversationsReq{UserIDs: userIDs, GroupID: groupID}) _, err := c.Client.CreateGroupChatConversations(ctx, &pbConversation.CreateGroupChatConversationsReq{UserIDs: userIDs, GroupID: groupID})
return err return err
} }
func (c *ConversationRpcClient) SetConversationMaxSeq(ctx context.Context, ownerUserIDs []string, conversationID string, maxSeq int64) error { func (c *ConversationRPCClient) SetConversationMaxSeq(ctx context.Context, ownerUserIDs []string, conversationID string, maxSeq int64) error {
_, err := c.Client.SetConversationMaxSeq(ctx, &pbConversation.SetConversationMaxSeqReq{OwnerUserID: ownerUserIDs, ConversationID: conversationID, MaxSeq: maxSeq}) _, err := c.Client.SetConversationMaxSeq(ctx, &pbConversation.SetConversationMaxSeqReq{OwnerUserID: ownerUserIDs, ConversationID: conversationID, MaxSeq: maxSeq})
return err return err
} }
func (c *ConversationRpcClient) SetConversations(ctx context.Context, userIDs []string, conversation *pbConversation.ConversationReq) error { func (c *ConversationRPCClient) SetConversations(ctx context.Context, userIDs []string, conversation *pbConversation.ConversationReq) error {
_, err := c.Client.SetConversations(ctx, &pbConversation.SetConversationsReq{UserIDs: userIDs, Conversation: conversation}) _, err := c.Client.SetConversations(ctx, &pbConversation.SetConversationsReq{UserIDs: userIDs, Conversation: conversation})
return err return err
} }
func (c *ConversationRpcClient) GetConversationIDs(ctx context.Context, ownerUserID string) ([]string, error) { func (c *ConversationRPCClient) GetConversationIDs(ctx context.Context, ownerUserID string) ([]string, error) {
resp, err := c.Client.GetConversationIDs(ctx, &pbConversation.GetConversationIDsReq{UserID: ownerUserID}) resp, err := c.Client.GetConversationIDs(ctx, &pbConversation.GetConversationIDsReq{UserID: ownerUserID})
if err != nil { if err != nil {
return nil, err return nil, err
@ -70,7 +70,7 @@ func (c *ConversationRpcClient) GetConversationIDs(ctx context.Context, ownerUse
return resp.ConversationIDs, nil return resp.ConversationIDs, nil
} }
func (c *ConversationRpcClient) GetConversation(ctx context.Context, ownerUserID, conversationID string) (*pbConversation.Conversation, error) { func (c *ConversationRPCClient) GetConversation(ctx context.Context, ownerUserID, conversationID string) (*pbConversation.Conversation, error) {
resp, err := c.Client.GetConversation(ctx, &pbConversation.GetConversationReq{OwnerUserID: ownerUserID, ConversationID: conversationID}) resp, err := c.Client.GetConversation(ctx, &pbConversation.GetConversationReq{OwnerUserID: ownerUserID, ConversationID: conversationID})
if err != nil { if err != nil {
return nil, err return nil, err
@ -78,7 +78,7 @@ func (c *ConversationRpcClient) GetConversation(ctx context.Context, ownerUserID
return resp.Conversation, nil return resp.Conversation, nil
} }
func (c *ConversationRpcClient) GetConversationsByConversationID(ctx context.Context, conversationIDs []string) ([]*pbConversation.Conversation, error) { func (c *ConversationRPCClient) GetConversationsByConversationID(ctx context.Context, conversationIDs []string) ([]*pbConversation.Conversation, error) {
resp, err := c.Client.GetConversationsByConversationID(ctx, &pbConversation.GetConversationsByConversationIDReq{ConversationIDs: conversationIDs}) resp, err := c.Client.GetConversationsByConversationID(ctx, &pbConversation.GetConversationsByConversationIDReq{ConversationIDs: conversationIDs})
if err != nil { if err != nil {
return nil, err return nil, err
@ -89,7 +89,7 @@ func (c *ConversationRpcClient) GetConversationsByConversationID(ctx context.Con
return resp.Conversations, nil return resp.Conversations, nil
} }
func (c *ConversationRpcClient) GetConversations(ctx context.Context, ownerUserID string, conversationIDs []string) ([]*pbConversation.Conversation, error) { func (c *ConversationRPCClient) GetConversations(ctx context.Context, ownerUserID string, conversationIDs []string) ([]*pbConversation.Conversation, error) {
resp, err := c.Client.GetConversations(ctx, &pbConversation.GetConversationsReq{OwnerUserID: ownerUserID, ConversationIDs: conversationIDs}) resp, err := c.Client.GetConversations(ctx, &pbConversation.GetConversationsReq{OwnerUserID: ownerUserID, ConversationIDs: conversationIDs})
if err != nil { if err != nil {
return nil, err return nil, err

@ -32,7 +32,7 @@ type Friend struct {
} }
func NewFriend(discov discoveryregistry.SvcDiscoveryRegistry) *Friend { func NewFriend(discov discoveryregistry.SvcDiscoveryRegistry) *Friend {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImFriendName) conn, err := discov.GetConn(context.Background(), config.Config.RPCRegisterName.OpenImFriendName)
if err != nil { if err != nil {
panic(err) panic(err)
} }

@ -36,7 +36,7 @@ type Group struct {
} }
func NewGroup(discov discoveryregistry.SvcDiscoveryRegistry) *Group { func NewGroup(discov discoveryregistry.SvcDiscoveryRegistry) *Group {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImGroupName) conn, err := discov.GetConn(context.Background(), config.Config.RPCRegisterName.OpenImGroupName)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -44,13 +44,13 @@ func NewGroup(discov discoveryregistry.SvcDiscoveryRegistry) *Group {
return &Group{discov: discov, conn: conn, Client: client} return &Group{discov: discov, conn: conn, Client: client}
} }
type GroupRpcClient Group type GroupRPCClient Group
func NewGroupRpcClient(discov discoveryregistry.SvcDiscoveryRegistry) GroupRpcClient { func NewGroupRPCClient(discov discoveryregistry.SvcDiscoveryRegistry) GroupRPCClient {
return GroupRpcClient(*NewGroup(discov)) return GroupRPCClient(*NewGroup(discov))
} }
func (g *GroupRpcClient) GetGroupInfos( func (g *GroupRPCClient) GetGroupInfos(
ctx context.Context, ctx context.Context,
groupIDs []string, groupIDs []string,
complete bool, complete bool,
@ -71,7 +71,7 @@ func (g *GroupRpcClient) GetGroupInfos(
return resp.GroupInfos, nil return resp.GroupInfos, nil
} }
func (g *GroupRpcClient) GetGroupInfo(ctx context.Context, groupID string) (*sdkws.GroupInfo, error) { func (g *GroupRPCClient) GetGroupInfo(ctx context.Context, groupID string) (*sdkws.GroupInfo, error) {
groups, err := g.GetGroupInfos(ctx, []string{groupID}, true) groups, err := g.GetGroupInfos(ctx, []string{groupID}, true)
if err != nil { if err != nil {
return nil, err return nil, err
@ -79,7 +79,7 @@ func (g *GroupRpcClient) GetGroupInfo(ctx context.Context, groupID string) (*sdk
return groups[0], nil return groups[0], nil
} }
func (g *GroupRpcClient) GetGroupInfoMap( func (g *GroupRPCClient) GetGroupInfoMap(
ctx context.Context, ctx context.Context,
groupIDs []string, groupIDs []string,
complete bool, complete bool,
@ -93,7 +93,7 @@ func (g *GroupRpcClient) GetGroupInfoMap(
}), nil }), nil
} }
func (g *GroupRpcClient) GetGroupMemberInfos( func (g *GroupRPCClient) GetGroupMemberInfos(
ctx context.Context, ctx context.Context,
groupID string, groupID string,
userIDs []string, userIDs []string,
@ -116,7 +116,7 @@ func (g *GroupRpcClient) GetGroupMemberInfos(
return resp.Members, nil return resp.Members, nil
} }
func (g *GroupRpcClient) GetGroupMemberInfo( func (g *GroupRPCClient) GetGroupMemberInfo(
ctx context.Context, ctx context.Context,
groupID string, groupID string,
userID string, userID string,
@ -128,7 +128,7 @@ func (g *GroupRpcClient) GetGroupMemberInfo(
return members[0], nil return members[0], nil
} }
func (g *GroupRpcClient) GetGroupMemberInfoMap( func (g *GroupRPCClient) GetGroupMemberInfoMap(
ctx context.Context, ctx context.Context,
groupID string, groupID string,
userIDs []string, userIDs []string,
@ -143,7 +143,7 @@ func (g *GroupRpcClient) GetGroupMemberInfoMap(
}), nil }), nil
} }
func (g *GroupRpcClient) GetOwnerAndAdminInfos( func (g *GroupRPCClient) GetOwnerAndAdminInfos(
ctx context.Context, ctx context.Context,
groupID string, groupID string,
) ([]*sdkws.GroupMemberFullInfo, error) { ) ([]*sdkws.GroupMemberFullInfo, error) {
@ -157,7 +157,7 @@ func (g *GroupRpcClient) GetOwnerAndAdminInfos(
return resp.Members, nil return resp.Members, nil
} }
func (g *GroupRpcClient) GetOwnerInfo(ctx context.Context, groupID string) (*sdkws.GroupMemberFullInfo, error) { func (g *GroupRPCClient) GetOwnerInfo(ctx context.Context, groupID string) (*sdkws.GroupMemberFullInfo, error) {
resp, err := g.Client.GetGroupMemberRoleLevel(ctx, &group.GetGroupMemberRoleLevelReq{ resp, err := g.Client.GetGroupMemberRoleLevel(ctx, &group.GetGroupMemberRoleLevelReq{
GroupID: groupID, GroupID: groupID,
RoleLevels: []int32{constant.GroupOwner}, RoleLevels: []int32{constant.GroupOwner},
@ -165,7 +165,7 @@ func (g *GroupRpcClient) GetOwnerInfo(ctx context.Context, groupID string) (*sdk
return resp.Members[0], err return resp.Members[0], err
} }
func (g *GroupRpcClient) GetGroupMemberIDs(ctx context.Context, groupID string) ([]string, error) { func (g *GroupRPCClient) GetGroupMemberIDs(ctx context.Context, groupID string) ([]string, error) {
resp, err := g.Client.GetGroupMemberUserIDs(ctx, &group.GetGroupMemberUserIDsReq{ resp, err := g.Client.GetGroupMemberUserIDs(ctx, &group.GetGroupMemberUserIDsReq{
GroupID: groupID, GroupID: groupID,
}) })
@ -175,7 +175,7 @@ func (g *GroupRpcClient) GetGroupMemberIDs(ctx context.Context, groupID string)
return resp.UserIDs, nil return resp.UserIDs, nil
} }
func (g *GroupRpcClient) GetGroupInfoCache(ctx context.Context, groupID string) (*sdkws.GroupInfo, error) { func (g *GroupRPCClient) GetGroupInfoCache(ctx context.Context, groupID string) (*sdkws.GroupInfo, error) {
resp, err := g.Client.GetGroupInfoCache(ctx, &group.GetGroupInfoCacheReq{ resp, err := g.Client.GetGroupInfoCache(ctx, &group.GetGroupInfoCacheReq{
GroupID: groupID, GroupID: groupID,
}) })
@ -185,7 +185,7 @@ func (g *GroupRpcClient) GetGroupInfoCache(ctx context.Context, groupID string)
return resp.GroupInfo, nil return resp.GroupInfo, nil
} }
func (g *GroupRpcClient) GetGroupMemberCache( func (g *GroupRPCClient) GetGroupMemberCache(
ctx context.Context, ctx context.Context,
groupID string, groupID string,
groupMemberID string, groupMemberID string,
@ -200,7 +200,7 @@ func (g *GroupRpcClient) GetGroupMemberCache(
return resp.Member, nil return resp.Member, nil
} }
func (g *GroupRpcClient) DismissGroup(ctx context.Context, groupID string) error { func (g *GroupRPCClient) DismissGroup(ctx context.Context, groupID string) error {
_, err := g.Client.DismissGroup(ctx, &group.DismissGroupReq{ _, err := g.Client.DismissGroup(ctx, &group.DismissGroupReq{
GroupID: groupID, GroupID: groupID,
DeleteMember: true, DeleteMember: true,

@ -112,7 +112,7 @@ type Message struct {
} }
func NewMessage(discov discoveryregistry.SvcDiscoveryRegistry) *Message { func NewMessage(discov discoveryregistry.SvcDiscoveryRegistry) *Message {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImMsgName) conn, err := discov.GetConn(context.Background(), config.Config.RPCRegisterName.OpenImMsgName)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -164,15 +164,15 @@ func WithLocalSendMsg(sendMsg func(ctx context.Context, req *msg.SendMsgReq) (*m
} }
} }
func WithRpcClient(msgRpcClient *MessageRpcClient) NotificationSenderOptions { func WithRPCClient(msgRpcClient *MessageRpcClient) NotificationSenderOptions {
return func(s *NotificationSender) { return func(s *NotificationSender) {
s.sendMsg = msgRpcClient.SendMsg s.sendMsg = msgRpcClient.SendMsg
} }
} }
func WithUserRpcClient(userRpcClient *UserRpcClient) NotificationSenderOptions { func WithUserRPCClient(userRPCClient *UserRPCClient) NotificationSenderOptions {
return func(s *NotificationSender) { return func(s *NotificationSender) {
s.getUserInfo = userRpcClient.GetUserInfo s.getUserInfo = userRPCClient.GetUserInfo
} }
} }
@ -185,18 +185,17 @@ func NewNotificationSender(opts ...NotificationSenderOptions) *NotificationSende
} }
type notificationOpt struct { type notificationOpt struct {
WithRpcGetUsername bool WithRPCGetUsername bool
} }
type NotificationOptions func(*notificationOpt) type NotificationOptions func(*notificationOpt)
func WithRpcGetUserName() NotificationOptions { func WithRPCGetUserName() NotificationOptions {
return func(opt *notificationOpt) { return func(opt *notificationOpt) {
opt.WithRpcGetUsername = true opt.WithRPCGetUsername = true
} }
} }
func (s *NotificationSender) NotificationWithSessionType(ctx context.Context, sendID, recvID string, contentType, sesstionType int32, m proto.Message, opts ...NotificationOptions) (err error) {
func (s *NotificationSender) NotificationWithSesstionType(ctx context.Context, sendID, recvID string, contentType, sesstionType int32, m proto.Message, opts ...NotificationOptions) (err error) {
n := sdkws.NotificationElem{Detail: utils.StructToJsonString(m)} n := sdkws.NotificationElem{Detail: utils.StructToJsonString(m)}
content, err := json.Marshal(&n) content, err := json.Marshal(&n)
if err != nil { if err != nil {
@ -209,7 +208,7 @@ func (s *NotificationSender) NotificationWithSesstionType(ctx context.Context, s
} }
var req msg.SendMsgReq var req msg.SendMsgReq
var msg sdkws.MsgData var msg sdkws.MsgData
if notificationOpt.WithRpcGetUsername && s.getUserInfo != nil { if notificationOpt.WithRPCGetUsername && s.getUserInfo != nil {
userInfo, err := s.getUserInfo(ctx, sendID) userInfo, err := s.getUserInfo(ctx, sendID)
if err != nil { if err != nil {
log.ZWarn(ctx, "getUserInfo failed", err, "sendID", sendID) log.ZWarn(ctx, "getUserInfo failed", err, "sendID", sendID)
@ -248,5 +247,5 @@ func (s *NotificationSender) NotificationWithSesstionType(ctx context.Context, s
} }
func (s *NotificationSender) Notification(ctx context.Context, sendID, recvID string, contentType int32, m proto.Message, opts ...NotificationOptions) error { func (s *NotificationSender) Notification(ctx context.Context, sendID, recvID string, contentType int32, m proto.Message, opts ...NotificationOptions) error {
return s.NotificationWithSesstionType(ctx, sendID, recvID, contentType, s.sessionTypeConf[contentType], m, opts...) return s.NotificationWithSessionType(ctx, sendID, recvID, contentType, s.sessionTypeConf[contentType], m, opts...)
} }

@ -27,7 +27,7 @@ type ConversationNotificationSender struct {
} }
func NewConversationNotificationSender(msgRpcClient *rpcclient.MessageRpcClient) *ConversationNotificationSender { func NewConversationNotificationSender(msgRpcClient *rpcclient.MessageRpcClient) *ConversationNotificationSender {
return &ConversationNotificationSender{rpcclient.NewNotificationSender(rpcclient.WithRpcClient(msgRpcClient))} return &ConversationNotificationSender{rpcclient.NewNotificationSender(rpcclient.WithRPCClient(msgRpcClient))}
} }
// SetPrivate调用 // SetPrivate调用

@ -85,7 +85,7 @@ func NewFriendNotificationSender(
opts ...friendNotificationSenderOptions, opts ...friendNotificationSenderOptions,
) *FriendNotificationSender { ) *FriendNotificationSender {
f := &FriendNotificationSender{ f := &FriendNotificationSender{
NotificationSender: rpcclient.NewNotificationSender(rpcclient.WithRpcClient(msgRpcClient)), NotificationSender: rpcclient.NewNotificationSender(rpcclient.WithRPCClient(msgRpcClient)),
} }
for _, opt := range opts { for _, opt := range opts {
opt(f) opt(f)

@ -16,9 +16,9 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils" "github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
) )
func NewGroupNotificationSender(db controller.GroupDatabase, msgRpcClient *rpcclient.MessageRpcClient, userRpcClient *rpcclient.UserRpcClient, fn func(ctx context.Context, userIDs []string) ([]CommonUser, error)) *GroupNotificationSender { func NewGroupNotificationSender(db controller.GroupDatabase, msgRpcClient *rpcclient.MessageRpcClient, userRPCClient *rpcclient.UserRPCClient, fn func(ctx context.Context, userIDs []string) ([]CommonUser, error)) *GroupNotificationSender {
return &GroupNotificationSender{ return &GroupNotificationSender{
NotificationSender: rpcclient.NewNotificationSender(rpcclient.WithRpcClient(msgRpcClient), rpcclient.WithUserRpcClient(userRpcClient)), NotificationSender: rpcclient.NewNotificationSender(rpcclient.WithRPCClient(msgRpcClient), rpcclient.WithUserRPCClient(userRPCClient)),
getUsersInfo: fn, getUsersInfo: fn,
db: db, db: db,
} }
@ -103,7 +103,7 @@ func (g *GroupNotificationSender) getGroupMembers(ctx context.Context, groupID s
res = append(res, g.groupMemberDB2PB(member, user.AppMangerLevel)) res = append(res, g.groupMemberDB2PB(member, user.AppMangerLevel))
delete(users, member.UserID) delete(users, member.UserID)
} }
//for userID, info := range users { // for userID, info := range users {
// if info.AppMangerLevel == constant.AppAdmin { // if info.AppMangerLevel == constant.AppAdmin {
// res = append(res, &sdkws.GroupMemberFullInfo{ // res = append(res, &sdkws.GroupMemberFullInfo{
// GroupID: groupID, // GroupID: groupID,
@ -113,7 +113,7 @@ func (g *GroupNotificationSender) getGroupMembers(ctx context.Context, groupID s
// AppMangerLevel: info.AppMangerLevel, // AppMangerLevel: info.AppMangerLevel,
// }) // })
// } // }
//} // }
return res, nil return res, nil
} }
@ -250,7 +250,7 @@ func (g *GroupNotificationSender) GroupInfoSetNotification(ctx context.Context,
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err return err
} }
return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupInfoSetNotification, tips, rpcclient.WithRpcGetUserName()) return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupInfoSetNotification, tips, rpcclient.WithRPCGetUserName())
} }
func (g *GroupNotificationSender) GroupInfoSetNameNotification(ctx context.Context, tips *sdkws.GroupInfoSetNameTips) (err error) { func (g *GroupNotificationSender) GroupInfoSetNameNotification(ctx context.Context, tips *sdkws.GroupInfoSetNameTips) (err error) {
@ -264,7 +264,7 @@ func (g *GroupNotificationSender) GroupInfoSetAnnouncementNotification(ctx conte
if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil { if err := g.fillOpUser(ctx, &tips.OpUser, tips.Group.GroupID); err != nil {
return err return err
} }
return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupInfoSetAnnouncementNotification, tips, rpcclient.WithRpcGetUserName()) return g.Notification(ctx, mcontext.GetOpUserID(ctx), tips.Group.GroupID, constant.GroupInfoSetAnnouncementNotification, tips, rpcclient.WithRPCGetUserName())
} }
func (g *GroupNotificationSender) JoinGroupApplicationNotification(ctx context.Context, req *pbGroup.JoinGroupReq) (err error) { func (g *GroupNotificationSender) JoinGroupApplicationNotification(ctx context.Context, req *pbGroup.JoinGroupReq) (err error) {

@ -32,5 +32,5 @@ func (m *MsgNotificationSender) MarkAsReadNotification(ctx context.Context, conv
Seqs: seqs, Seqs: seqs,
HasReadSeq: hasReadSeq, HasReadSeq: hasReadSeq,
} }
return m.NotificationWithSesstionType(ctx, sendID, recvID, constant.HasReadReceipt, sesstionType, tips) return m.NotificationWithSessionType(ctx, sendID, recvID, constant.HasReadReceipt, sesstionType, tips)
} }

@ -31,7 +31,7 @@ type Push struct {
} }
func NewPush(discov discoveryregistry.SvcDiscoveryRegistry) *Push { func NewPush(discov discoveryregistry.SvcDiscoveryRegistry) *Push {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImPushName) conn, err := discov.GetConn(context.Background(), config.Config.RPCRegisterName.OpenImPushName)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -42,13 +42,13 @@ func NewPush(discov discoveryregistry.SvcDiscoveryRegistry) *Push {
} }
} }
type PushRpcClient Push type PushRPCClient Push
func NewPushRpcClient(discov discoveryregistry.SvcDiscoveryRegistry) PushRpcClient { func NewPushRPCClient(discov discoveryregistry.SvcDiscoveryRegistry) PushRPCClient {
return PushRpcClient(*NewPush(discov)) return PushRPCClient(*NewPush(discov))
} }
func (p *PushRpcClient) DelUserPushToken( func (p *PushRPCClient) DelUserPushToken(
ctx context.Context, ctx context.Context,
req *push.DelUserPushTokenReq, req *push.DelUserPushTokenReq,
) (*push.DelUserPushTokenResp, error) { ) (*push.DelUserPushTokenResp, error) {

@ -31,7 +31,7 @@ type Third struct {
} }
func NewThird(discov discoveryregistry.SvcDiscoveryRegistry) *Third { func NewThird(discov discoveryregistry.SvcDiscoveryRegistry) *Third {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImThirdName) conn, err := discov.GetConn(context.Background(), config.Config.RPCRegisterName.OpenImThirdName)
if err != nil { if err != nil {
panic(err) panic(err)
} }

@ -36,7 +36,7 @@ type User struct {
} }
func NewUser(discov discoveryregistry.SvcDiscoveryRegistry) *User { func NewUser(discov discoveryregistry.SvcDiscoveryRegistry) *User {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImUserName) conn, err := discov.GetConn(context.Background(), config.Config.RPCRegisterName.OpenImUserName)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -44,13 +44,13 @@ func NewUser(discov discoveryregistry.SvcDiscoveryRegistry) *User {
return &User{Discov: discov, Client: client, conn: conn} return &User{Discov: discov, Client: client, conn: conn}
} }
type UserRpcClient User type UserRPCClient User
func NewUserRpcClient(client discoveryregistry.SvcDiscoveryRegistry) UserRpcClient { func NewUserRPCClient(client discoveryregistry.SvcDiscoveryRegistry) UserRPCClient {
return UserRpcClient(*NewUser(client)) return UserRPCClient(*NewUser(client))
} }
func (u *UserRpcClient) GetUsersInfo(ctx context.Context, userIDs []string) ([]*sdkws.UserInfo, error) { func (u *UserRPCClient) GetUsersInfo(ctx context.Context, userIDs []string) ([]*sdkws.UserInfo, error) {
resp, err := u.Client.GetDesignateUsers(ctx, &user.GetDesignateUsersReq{ resp, err := u.Client.GetDesignateUsers(ctx, &user.GetDesignateUsersReq{
UserIDs: userIDs, UserIDs: userIDs,
}) })
@ -65,7 +65,7 @@ func (u *UserRpcClient) GetUsersInfo(ctx context.Context, userIDs []string) ([]*
return resp.UsersInfo, nil return resp.UsersInfo, nil
} }
func (u *UserRpcClient) GetUserInfo(ctx context.Context, userID string) (*sdkws.UserInfo, error) { func (u *UserRPCClient) GetUserInfo(ctx context.Context, userID string) (*sdkws.UserInfo, error) {
users, err := u.GetUsersInfo(ctx, []string{userID}) users, err := u.GetUsersInfo(ctx, []string{userID})
if err != nil { if err != nil {
return nil, err return nil, err
@ -73,7 +73,7 @@ func (u *UserRpcClient) GetUserInfo(ctx context.Context, userID string) (*sdkws.
return users[0], nil return users[0], nil
} }
func (u *UserRpcClient) GetUsersInfoMap(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error) { func (u *UserRPCClient) GetUsersInfoMap(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error) {
users, err := u.GetUsersInfo(ctx, userIDs) users, err := u.GetUsersInfo(ctx, userIDs)
if err != nil { if err != nil {
return nil, err return nil, err
@ -83,7 +83,7 @@ func (u *UserRpcClient) GetUsersInfoMap(ctx context.Context, userIDs []string) (
}), nil }), nil
} }
func (u *UserRpcClient) GetPublicUserInfos( func (u *UserRPCClient) GetPublicUserInfos(
ctx context.Context, ctx context.Context,
userIDs []string, userIDs []string,
complete bool, complete bool,
@ -102,7 +102,7 @@ func (u *UserRpcClient) GetPublicUserInfos(
}), nil }), nil
} }
func (u *UserRpcClient) GetPublicUserInfo(ctx context.Context, userID string) (*sdkws.PublicUserInfo, error) { func (u *UserRPCClient) GetPublicUserInfo(ctx context.Context, userID string) (*sdkws.PublicUserInfo, error) {
users, err := u.GetPublicUserInfos(ctx, []string{userID}, true) users, err := u.GetPublicUserInfos(ctx, []string{userID}, true)
if err != nil { if err != nil {
return nil, err return nil, err
@ -110,7 +110,7 @@ func (u *UserRpcClient) GetPublicUserInfo(ctx context.Context, userID string) (*
return users[0], nil return users[0], nil
} }
func (u *UserRpcClient) GetPublicUserInfoMap( func (u *UserRPCClient) GetPublicUserInfoMap(
ctx context.Context, ctx context.Context,
userIDs []string, userIDs []string,
complete bool, complete bool,
@ -124,7 +124,7 @@ func (u *UserRpcClient) GetPublicUserInfoMap(
}), nil }), nil
} }
func (u *UserRpcClient) GetUserGlobalMsgRecvOpt(ctx context.Context, userID string) (int32, error) { func (u *UserRPCClient) GetUserGlobalMsgRecvOpt(ctx context.Context, userID string) (int32, error) {
resp, err := u.Client.GetGlobalRecvMessageOpt(ctx, &user.GetGlobalRecvMessageOptReq{ resp, err := u.Client.GetGlobalRecvMessageOpt(ctx, &user.GetGlobalRecvMessageOptReq{
UserID: userID, UserID: userID,
}) })
@ -134,7 +134,7 @@ func (u *UserRpcClient) GetUserGlobalMsgRecvOpt(ctx context.Context, userID stri
return resp.GlobalRecvMsgOpt, err return resp.GlobalRecvMsgOpt, err
} }
func (u *UserRpcClient) Access(ctx context.Context, ownerUserID string) error { func (u *UserRPCClient) Access(ctx context.Context, ownerUserID string) error {
_, err := u.GetUserInfo(ctx, ownerUserID) _, err := u.GetUserInfo(ctx, ownerUserID)
if err != nil { if err != nil {
return err return err

@ -88,7 +88,7 @@ func StructToJsonBytes(param interface{}) []byte {
} }
// The incoming parameter must be a pointer // The incoming parameter must be a pointer
func JsonStringToStruct(s string, args interface{}) error { func JSONStringToStruct(s string, args interface{}) error {
err := json.Unmarshal([]byte(s), args) err := json.Unmarshal([]byte(s), args)
return err return err
} }

Loading…
Cancel
Save