mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-01-11 06:56:59 +08:00
fix: changing naming irregularities under pkg and internal packages, #520
This commit is contained in:
parent
b59366fd60
commit
d352dd2859
@ -147,7 +147,7 @@ func (m *msgServer) sendMsgSingleChat(ctx context.Context, req *pbMsg.SendMsgReq
|
||||
if err := m.messageVerification(ctx, req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var isSend bool = true
|
||||
isSend := true
|
||||
isNotification := utils.IsNotificationByMsg(req.MsgData)
|
||||
if !isNotification {
|
||||
isSend, err = m.modifyMessageByUserMessageReceiveOpt(
|
||||
|
||||
@ -53,14 +53,14 @@ func (r responseBodyWriter) Write(b []byte) (int, error) {
|
||||
}
|
||||
|
||||
func PrometheusMiddleware(c *gin.Context) {
|
||||
Inc(ApiRequestCounter)
|
||||
Inc(APIRequestCounter)
|
||||
w := &responseBodyWriter{body: &bytes.Buffer{}, ResponseWriter: c.Writer}
|
||||
c.Writer = w
|
||||
c.Next()
|
||||
if c.Writer.Status() == http.StatusOK {
|
||||
Inc(ApiRequestSuccessCounter)
|
||||
Inc(APIRequestSuccessCounter)
|
||||
} else {
|
||||
Inc(ApiRequestFailedCounter)
|
||||
Inc(APIRequestFailedCounter)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -195,7 +195,7 @@ func WithRPCGetUserName() NotificationOptions {
|
||||
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) NotificationWithSessionType(ctx context.Context, sendID, recvID string, contentType, sessionType int32, m proto.Message, opts ...NotificationOptions) (err error) {
|
||||
n := sdkws.NotificationElem{Detail: utils.StructToJsonString(m)}
|
||||
content, err := json.Marshal(&n)
|
||||
if err != nil {
|
||||
@ -217,14 +217,14 @@ func (s *NotificationSender) NotificationWithSessionType(ctx context.Context, se
|
||||
msg.SenderFaceURL = userInfo.FaceURL
|
||||
}
|
||||
}
|
||||
var offlineInfo sdkws.OfflinePushInfo
|
||||
|
||||
var title, desc, ex string
|
||||
msg.SendID = sendID
|
||||
msg.RecvID = recvID
|
||||
msg.Content = content
|
||||
msg.MsgFrom = constant.SysMsgType
|
||||
msg.ContentType = contentType
|
||||
msg.SessionType = sesstionType
|
||||
msg.SessionType = sessionType
|
||||
if msg.SessionType == constant.SuperGroupChatType {
|
||||
msg.GroupID = recvID
|
||||
}
|
||||
@ -232,9 +232,12 @@ func (s *NotificationSender) NotificationWithSessionType(ctx context.Context, se
|
||||
msg.ClientMsgID = utils.GetMsgID(sendID)
|
||||
options := config.GetOptionsByNotification(s.contentTypeConf[contentType])
|
||||
msg.Options = options
|
||||
offlineInfo.Title = title
|
||||
offlineInfo.Desc = desc
|
||||
offlineInfo.Ex = ex
|
||||
|
||||
offlineInfo := sdkws.OfflinePushInfo{
|
||||
Title: title,
|
||||
Desc: desc,
|
||||
Ex: ex,
|
||||
}
|
||||
msg.OfflinePushInfo = &offlineInfo
|
||||
req.MsgData = &msg
|
||||
_, err = s.sendMsg(ctx, &req)
|
||||
|
||||
@ -25,6 +25,7 @@ func (m *MsgNotificationSender) UserDeleteMsgsNotification(ctx context.Context,
|
||||
return m.Notification(ctx, userID, userID, constant.MsgDeleteNotification, &tips)
|
||||
}
|
||||
|
||||
// MarkAsReadNotification 标记已读通知
|
||||
func (m *MsgNotificationSender) MarkAsReadNotification(ctx context.Context, conversationID string, sesstionType int32, sendID, recvID string, seqs []int64, hasReadSeq int64) error {
|
||||
tips := &sdkws.MarkAsReadTips{
|
||||
MarkAsReadUserID: sendID,
|
||||
@ -32,5 +33,6 @@ func (m *MsgNotificationSender) MarkAsReadNotification(ctx context.Context, conv
|
||||
Seqs: seqs,
|
||||
HasReadSeq: hasReadSeq,
|
||||
}
|
||||
|
||||
return m.NotificationWithSessionType(ctx, sendID, recvID, constant.HasReadReceipt, sesstionType, tips)
|
||||
}
|
||||
|
||||
@ -24,17 +24,20 @@ import (
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/push"
|
||||
)
|
||||
|
||||
// Push 推送结构体
|
||||
type Push struct {
|
||||
conn grpc.ClientConnInterface
|
||||
Client push.PushMsgServiceClient
|
||||
discov discoveryregistry.SvcDiscoveryRegistry
|
||||
}
|
||||
|
||||
// NewPush 连接发送服务
|
||||
func NewPush(discov discoveryregistry.SvcDiscoveryRegistry) *Push {
|
||||
conn, err := discov.GetConn(context.Background(), config.Config.RPCRegisterName.OpenImPushName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return &Push{
|
||||
discov: discov,
|
||||
conn: conn,
|
||||
@ -44,10 +47,12 @@ func NewPush(discov discoveryregistry.SvcDiscoveryRegistry) *Push {
|
||||
|
||||
type PushRPCClient Push
|
||||
|
||||
// NewPushRPCClient 连接发送 RPC 客户端
|
||||
func NewPushRPCClient(discov discoveryregistry.SvcDiscoveryRegistry) PushRPCClient {
|
||||
return PushRPCClient(*NewPush(discov))
|
||||
}
|
||||
|
||||
// DelUserPushToken 删除用户发送消息 token 权限
|
||||
func (p *PushRPCClient) DelUserPushToken(
|
||||
ctx context.Context,
|
||||
req *push.DelUserPushTokenReq,
|
||||
|
||||
@ -30,11 +30,13 @@ type Third struct {
|
||||
discov discoveryregistry.SvcDiscoveryRegistry
|
||||
}
|
||||
|
||||
// NewThird 连接第三方服务
|
||||
func NewThird(discov discoveryregistry.SvcDiscoveryRegistry) *Third {
|
||||
conn, err := discov.GetConn(context.Background(), config.Config.RPCRegisterName.OpenImThirdName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
client := third.NewThirdClient(conn)
|
||||
|
||||
return &Third{discov: discov, Client: client, conn: conn}
|
||||
}
|
||||
|
||||
@ -35,17 +35,20 @@ type User struct {
|
||||
Discov discoveryregistry.SvcDiscoveryRegistry
|
||||
}
|
||||
|
||||
// NewUser 新建用户
|
||||
func NewUser(discov discoveryregistry.SvcDiscoveryRegistry) *User {
|
||||
conn, err := discov.GetConn(context.Background(), config.Config.RPCRegisterName.OpenImUserName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
client := user.NewUserClient(conn)
|
||||
|
||||
return &User{Discov: discov, Client: client, conn: conn}
|
||||
}
|
||||
|
||||
type UserRPCClient User
|
||||
|
||||
// NewUserRPCClient 新建用户 RPC 客户端
|
||||
func NewUserRPCClient(client discoveryregistry.SvcDiscoveryRegistry) UserRPCClient {
|
||||
return UserRPCClient(*NewUser(client))
|
||||
}
|
||||
@ -65,24 +68,29 @@ func (u *UserRPCClient) GetUsersInfo(ctx context.Context, userIDs []string) ([]*
|
||||
return resp.UsersInfo, nil
|
||||
}
|
||||
|
||||
// GetUserInfo 获取指定用户信息
|
||||
func (u *UserRPCClient) GetUserInfo(ctx context.Context, userID string) (*sdkws.UserInfo, error) {
|
||||
users, err := u.GetUsersInfo(ctx, []string{userID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return users[0], nil
|
||||
}
|
||||
|
||||
// GetUsersInfoMap 获取用户信息集合
|
||||
func (u *UserRPCClient) GetUsersInfoMap(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error) {
|
||||
users, err := u.GetUsersInfo(ctx, userIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return utils.SliceToMap(users, func(e *sdkws.UserInfo) string {
|
||||
return e.UserID
|
||||
}), nil
|
||||
}
|
||||
|
||||
// 获取公有用户信息
|
||||
func (u *UserRPCClient) GetPublicUserInfos(
|
||||
ctx context.Context,
|
||||
userIDs []string,
|
||||
@ -102,14 +110,17 @@ func (u *UserRPCClient) GetPublicUserInfos(
|
||||
}), nil
|
||||
}
|
||||
|
||||
// GetPublicUserInfo 获取用户信息
|
||||
func (u *UserRPCClient) GetPublicUserInfo(ctx context.Context, userID string) (*sdkws.PublicUserInfo, error) {
|
||||
users, err := u.GetPublicUserInfos(ctx, []string{userID}, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return users[0], nil
|
||||
}
|
||||
|
||||
// GetPublicUserInfoMap 获取用户信息集合
|
||||
func (u *UserRPCClient) GetPublicUserInfoMap(
|
||||
ctx context.Context,
|
||||
userIDs []string,
|
||||
@ -119,11 +130,13 @@ func (u *UserRPCClient) GetPublicUserInfoMap(
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return utils.SliceToMap(users, func(e *sdkws.PublicUserInfo) string {
|
||||
return e.UserID
|
||||
}), nil
|
||||
}
|
||||
|
||||
// GetUserGlobalMsgRecvOpt 获取用户消息接收选项
|
||||
func (u *UserRPCClient) GetUserGlobalMsgRecvOpt(ctx context.Context, userID string) (int32, error) {
|
||||
resp, err := u.Client.GetGlobalRecvMessageOpt(ctx, &user.GetGlobalRecvMessageOptReq{
|
||||
UserID: userID,
|
||||
@ -131,13 +144,16 @@ func (u *UserRPCClient) GetUserGlobalMsgRecvOpt(ctx context.Context, userID stri
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return resp.GlobalRecvMsgOpt, err
|
||||
}
|
||||
|
||||
// Access token 验签
|
||||
func (u *UserRPCClient) Access(ctx context.Context, ownerUserID string) error {
|
||||
_, err := u.GetUserInfo(ctx, ownerUserID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tokenverify.CheckAccessV3(ctx, ownerUserID)
|
||||
}
|
||||
|
||||
@ -108,5 +108,6 @@ func Start(
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return utils.Wrap1(srv.Serve(listener))
|
||||
}
|
||||
|
||||
@ -63,8 +63,10 @@ func (s *Statistics) output() {
|
||||
}
|
||||
}
|
||||
|
||||
// NewStatistics 新建数据
|
||||
func NewStatistics(allCount *uint64, moduleName, printArgs string, sleepTime int) *Statistics {
|
||||
p := &Statistics{AllCount: allCount, ModuleName: moduleName, SleepTime: uint64(sleepTime), PrintArgs: printArgs}
|
||||
go p.output()
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user