Merge remote-tracking branch 'origin/errcode' into errcode

This commit is contained in:
withchao
2023-06-05 15:28:19 +08:00
11 changed files with 1222 additions and 1059 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ import (
func NewThird(discov discoveryregistry.SvcDiscoveryRegistry) *Third {
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImThirdName)
if err != nil {
panic(err)
// panic(err)
}
return &Third{conn: conn, discov: discov}
}
+5 -1
View File
@@ -51,7 +51,11 @@ func (c *ConsumerHandler) handleMs2PsChat(ctx context.Context, msg []byte) {
err = c.pusher.Push2User(ctx, []string{pbData.MsgData.SendID, pbData.MsgData.RecvID}, pbData.MsgData)
}
if err != nil {
log.ZError(ctx, "push failed", err, "msg", pbData.String())
if err == errNoOfflinePusher {
log.ZWarn(ctx, "offline push failed", err, "msg", pbData.String())
} else {
log.ZError(ctx, "push failed", err, "msg", pbData.String())
}
}
}
func (ConsumerHandler) Setup(_ sarama.ConsumerGroupSession) error { return nil }
+6 -1
View File
@@ -8,6 +8,7 @@ import (
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/localcache"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
pbPush "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/push"
"google.golang.org/grpc"
@@ -52,7 +53,11 @@ func (r *pushServer) PushMsg(ctx context.Context, pbData *pbPush.PushMsgReq) (re
err = r.pusher.Push2User(ctx, []string{pbData.MsgData.RecvID, pbData.MsgData.SendID}, pbData.MsgData)
}
if err != nil {
return nil, err
if err != errNoOfflinePusher {
return nil, err
} else {
log.ZWarn(ctx, "offline push failed", err, "msg", pbData.String())
}
}
return &pbPush.PushMsgResp{}, nil
}
+4 -1
View File
@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
"github.com/OpenIMSDK/Open-IM-Server/internal/push/offlinepush"
"github.com/OpenIMSDK/Open-IM-Server/internal/push/offlinepush/fcm"
"github.com/OpenIMSDK/Open-IM-Server/internal/push/offlinepush/getui"
@@ -35,6 +36,8 @@ type Pusher struct {
successCount int
}
var errNoOfflinePusher = errors.New("no offlinePusher is configured")
func NewPusher(client discoveryregistry.SvcDiscoveryRegistry, offlinePusher offlinepush.OfflinePusher, database controller.PushDatabase,
groupLocalCache *localcache.GroupLocalCache, conversationLocalCache *localcache.ConversationLocalCache) *Pusher {
rpcclient.NewGroupClient(client)
@@ -286,7 +289,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) {
if p.offlinePusher == nil {
err = errors.New("no offlinePusher is configured")
err = errNoOfflinePusher
return
}
type AtContent struct {
+33 -1
View File
@@ -3,9 +3,41 @@ package msg
import (
"context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
)
func (m *msgServer) MarkMsgsAsRead(ctx context.Context, req *msg.MarkMsgsAsReadReq) (resp *msg.MarkMsgsAsReadResp, err error) {
return
conversations, err := m.Conversation.GetConversationsByConversationID(ctx, []string{req.ConversationID})
if err != nil {
return
}
var recvID string
if conversations[0].ConversationType == constant.SingleChatType || conversations[0].ConversationType == constant.NotificationChatType {
if req.UserID == conversations[0].OwnerUserID {
recvID = conversations[0].UserID
} else {
recvID = conversations[0].OwnerUserID
}
} else if conversations[0].ConversationType == constant.SuperGroupChatType {
recvID = conversations[0].GroupID
}
err = m.MsgDatabase.MarkSingleChatMsgsAsRead(ctx, req.ConversationID, req.UserID, req.Seqs)
if err != nil {
return
}
if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, req.UserID, recvID, req.Seqs); err != nil {
return
}
return &msg.MarkMsgsAsReadResp{}, nil
}
func (m *msgServer) sendMarkAsReadNotification(ctx context.Context, conversationID string, sendID, recvID string, seqs []int64) error {
// tips := &sdkws.MarkAsReadTips{
// MarkAsReadUserID: sendID,
// ConversationID: conversationID,
// Seqs: seqs,
// }
// m.notificationSender.NotificationWithSesstionType(ctx)
return nil
}