mark as read and modify pb

This commit is contained in:
wangchuxiao 2023-06-12 18:52:35 +08:00
parent 2e457d5a74
commit 6cc801ed06
7 changed files with 560 additions and 326 deletions

View File

@ -62,6 +62,35 @@ func (m *msgServer) MarkMsgsAsRead(ctx context.Context, req *msg.MarkMsgsAsReadR
return &msg.MarkMsgsAsReadResp{}, nil return &msg.MarkMsgsAsReadResp{}, nil
} }
func (m *msgServer) MarkConversationAsRead(ctx context.Context, req *msg.MarkConversationAsReadReq) (resp *msg.MarkConversationAsReadResp, err error) {
hasReadSeq, err := m.MsgDatabase.GetHasReadSeq(ctx, req.UserID, req.ConversationID)
if err != nil {
return
}
var seqs []int64
for i := hasReadSeq + 1; i <= req.HasReadSeq; i++ {
seqs = append(seqs, i)
}
conversations, err := m.Conversation.GetConversationsByConversationID(ctx, []string{req.ConversationID})
if err != nil {
return
}
if err = m.MsgDatabase.MarkSingleChatMsgsAsRead(ctx, req.ConversationID, req.UserID, seqs); err != nil {
return
}
if req.HasReadSeq > hasReadSeq {
err = m.MsgDatabase.SetHasReadSeq(ctx, req.UserID, req.ConversationID, req.HasReadSeq)
if err != nil {
return
}
hasReadSeq = req.HasReadSeq
}
if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, conversations[0].ConversationType, req.UserID, m.conversationAndGetRecvID(conversations[0], req.UserID), seqs, hasReadSeq); err != nil {
return
}
return &msg.MarkConversationAsReadResp{}, nil
}
func (m *msgServer) sendMarkAsReadNotification(ctx context.Context, conversationID string, sesstionType int32, sendID, recvID string, seqs []int64, hasReadSeq int64) error { func (m *msgServer) sendMarkAsReadNotification(ctx context.Context, conversationID string, sesstionType int32, sendID, recvID string, seqs []int64, hasReadSeq int64) error {
tips := &sdkws.MarkAsReadTips{ tips := &sdkws.MarkAsReadTips{
MarkAsReadUserID: sendID, MarkAsReadUserID: sendID,

View File

@ -68,6 +68,7 @@ type CommonMsgDatabase interface {
SetUserConversationsMinSeqs(ctx context.Context, userID string, seqs map[string]int64) (err error) SetUserConversationsMinSeqs(ctx context.Context, userID string, seqs map[string]int64) (err error)
SetHasReadSeq(ctx context.Context, userID string, conversationID string, hasReadSeq int64) error SetHasReadSeq(ctx context.Context, userID string, conversationID string, hasReadSeq int64) error
GetHasReadSeqs(ctx context.Context, userID string, conversationIDs []string) (map[string]int64, error) GetHasReadSeqs(ctx context.Context, userID string, conversationIDs []string) (map[string]int64, error)
GetHasReadSeq(ctx context.Context, userID string, conversationID string) (int64, error)
GetMongoMaxAndMinSeq(ctx context.Context, conversationID string) (maxSeq, minSeq int64, err error) GetMongoMaxAndMinSeq(ctx context.Context, conversationID string) (maxSeq, minSeq int64, err error)
GetConversationMinMaxSeqInMongoAndCache(ctx context.Context, conversationID string) (minSeqMongo, maxSeqMongo, minSeqCache, maxSeqCache int64, err error) GetConversationMinMaxSeqInMongoAndCache(ctx context.Context, conversationID string) (minSeqMongo, maxSeqMongo, minSeqCache, maxSeqCache int64, err error)
@ -474,7 +475,6 @@ func (db *commonMsgDatabase) GetMsgBySeqsRange(ctx context.Context, userID strin
maxSeq = userMaxSeq maxSeq = userMaxSeq
} }
} }
if begin < minSeq { if begin < minSeq {
begin = minSeq begin = minSeq
} }
@ -810,6 +810,10 @@ func (db *commonMsgDatabase) GetHasReadSeqs(ctx context.Context, userID string,
return db.cache.GetHasReadSeqs(ctx, userID, conversationIDs) return db.cache.GetHasReadSeqs(ctx, userID, conversationIDs)
} }
func (db *commonMsgDatabase) GetHasReadSeq(ctx context.Context, userID string, conversationID string) (int64, error) {
return db.cache.GetHasReadSeq(ctx, userID, conversationID)
}
func (db *commonMsgDatabase) SetSendMsgStatus(ctx context.Context, id string, status int32) error { func (db *commonMsgDatabase) SetSendMsgStatus(ctx context.Context, id string, status int32) error {
return db.cache.SetSendMsgStatus(ctx, id, status) return db.cache.SetSendMsgStatus(ctx, id, status)
} }

View File

@ -281,16 +281,25 @@ func (m *MsgMongoDriver) IsExistDocID(ctx context.Context, docID string) (bool,
} }
func (m *MsgMongoDriver) MarkSingleChatMsgsAsRead(ctx context.Context, userID string, docID string, indexes []int64) error { func (m *MsgMongoDriver) MarkSingleChatMsgsAsRead(ctx context.Context, userID string, docID string, indexes []int64) error {
updates := bson.M{ updates := []mongo.WriteModel{}
"$set": bson.M{},
}
for _, index := range indexes { for _, index := range indexes {
updates["$set"].(bson.M)[fmt.Sprintf("msgs.%d.is_read", index)] = true filter := bson.M{
"doc_id": docID,
fmt.Sprintf("msgs.%d.msg.send_id", index): bson.M{
"$ne": userID,
},
}
update := bson.M{
"$set": bson.M{
fmt.Sprintf("msgs.%d.msg.is_read", index): true,
},
}
updateModel := mongo.NewUpdateManyModel().
SetFilter(filter).
SetUpdate(update)
updates = append(updates, updateModel)
} }
filter := bson.M{"doc_id": docID} _, err := m.MsgCollection.BulkWrite(ctx, updates)
_, err := m.MsgCollection.UpdateMany(ctx, filter, updates) return err
if err != nil {
return utils.Wrap(err, "")
}
return nil
} }

View File

@ -85,7 +85,7 @@ type GetPaginationFriendsResp struct {
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
FriendsInfo []*sdkws.FriendInfo `protobuf:"bytes,1,rep,name=FriendsInfo,proto3" json:"FriendsInfo"` FriendsInfo []*sdkws.FriendInfo `protobuf:"bytes,1,rep,name=friendsInfo,proto3" json:"friendsInfo"`
Total int32 `protobuf:"varint,2,opt,name=total,proto3" json:"total"` Total int32 `protobuf:"varint,2,opt,name=total,proto3" json:"total"`
} }
@ -1589,10 +1589,10 @@ var file_friend_friend_proto_rawDesc = []byte{
0x16, 0x0a, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x44, 0x22, 0x72, 0x0a, 0x18, 0x67, 0x65, 0x74, 0x50, 0x61, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x44, 0x22, 0x72, 0x0a, 0x18, 0x67, 0x65, 0x74, 0x50, 0x61,
0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x73, 0x52, 0x67, 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x73, 0x52,
0x65, 0x73, 0x70, 0x12, 0x40, 0x0a, 0x0b, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x73, 0x49, 0x6e, 0x65, 0x73, 0x70, 0x12, 0x40, 0x0a, 0x0b, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x73, 0x49, 0x6e,
0x66, 0x6f, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x4f, 0x70, 0x65, 0x6e, 0x49, 0x66, 0x6f, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x4f, 0x70, 0x65, 0x6e, 0x49,
0x4d, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x73, 0x64, 0x6b, 0x77, 0x73, 0x2e, 0x46, 0x72, 0x4d, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x73, 0x64, 0x6b, 0x77, 0x73, 0x2e, 0x46, 0x72,
0x69, 0x65, 0x6e, 0x64, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x0b, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x69, 0x65, 0x6e, 0x64, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x0b, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64,
0x73, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x18, 0x02, 0x73, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x18, 0x02,
0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x22, 0x79, 0x0a, 0x13, 0x61, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x22, 0x79, 0x0a, 0x13, 0x61,
0x70, 0x70, 0x6c, 0x79, 0x54, 0x6f, 0x41, 0x64, 0x64, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x52, 0x70, 0x70, 0x6c, 0x79, 0x54, 0x6f, 0x41, 0x64, 0x64, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x52,
@ -1891,7 +1891,7 @@ var file_friend_friend_proto_goTypes = []interface{}{
} }
var file_friend_friend_proto_depIdxs = []int32{ var file_friend_friend_proto_depIdxs = []int32{
30, // 0: OpenIMServer.friend.getPaginationFriendsReq.pagination:type_name -> OpenIMServer.sdkws.RequestPagination 30, // 0: OpenIMServer.friend.getPaginationFriendsReq.pagination:type_name -> OpenIMServer.sdkws.RequestPagination
31, // 1: OpenIMServer.friend.getPaginationFriendsResp.FriendsInfo:type_name -> OpenIMServer.sdkws.FriendInfo 31, // 1: OpenIMServer.friend.getPaginationFriendsResp.friendsInfo:type_name -> OpenIMServer.sdkws.FriendInfo
30, // 2: OpenIMServer.friend.getPaginationFriendsApplyToReq.pagination:type_name -> OpenIMServer.sdkws.RequestPagination 30, // 2: OpenIMServer.friend.getPaginationFriendsApplyToReq.pagination:type_name -> OpenIMServer.sdkws.RequestPagination
32, // 3: OpenIMServer.friend.getPaginationFriendsApplyToResp.FriendRequests:type_name -> OpenIMServer.sdkws.FriendRequest 32, // 3: OpenIMServer.friend.getPaginationFriendsApplyToResp.FriendRequests:type_name -> OpenIMServer.sdkws.FriendRequest
31, // 4: OpenIMServer.friend.getDesignatedFriendsResp.friendsInfo:type_name -> OpenIMServer.sdkws.FriendInfo 31, // 4: OpenIMServer.friend.getDesignatedFriendsResp.friendsInfo:type_name -> OpenIMServer.sdkws.FriendInfo

View File

@ -8,11 +8,8 @@ message getPaginationFriendsReq{
string userID = 2; string userID = 2;
} }
message getPaginationFriendsResp{ message getPaginationFriendsResp{
repeated sdkws.FriendInfo FriendsInfo = 1; repeated sdkws.FriendInfo friendsInfo = 1;
int32 total = 2; int32 total = 2;
} }

File diff suppressed because it is too large Load Diff

View File

@ -176,6 +176,15 @@ message MarkMsgsAsReadReq {
message MarkMsgsAsReadResp { message MarkMsgsAsReadResp {
} }
message MarkConversationAsReadReq {
string conversationID = 1;
string userID = 2;
int64 hasReadSeq = 3;
}
message MarkConversationAsReadResp {
}
message DeleteSyncOpt { message DeleteSyncOpt {
bool IsSyncSelf = 3; bool IsSyncSelf = 3;
bool IsSyncOther = 4; bool IsSyncOther = 4;
@ -272,7 +281,9 @@ service msg {
// //
rpc GetSendMsgStatus(GetSendMsgStatusReq) returns(GetSendMsgStatusResp); rpc GetSendMsgStatus(GetSendMsgStatusReq) returns(GetSendMsgStatusResp);
rpc RevokeMsg(RevokeMsgReq) returns(RevokeMsgResp); rpc RevokeMsg(RevokeMsgReq) returns(RevokeMsgResp);
// mark as read
rpc MarkMsgsAsRead(MarkMsgsAsReadReq) returns(MarkMsgsAsReadResp); rpc MarkMsgsAsRead(MarkMsgsAsReadReq) returns(MarkMsgsAsReadResp);
rpc MarkConversationAsRead(MarkConversationAsReadReq) returns(MarkConversationAsReadResp);
// //
rpc SetMessageReactionExtensions(SetMessageReactionExtensionsReq) returns(SetMessageReactionExtensionsResp); rpc SetMessageReactionExtensions(SetMessageReactionExtensionsReq) returns(SetMessageReactionExtensionsResp);
rpc GetMessagesReactionExtensions(GetMessagesReactionExtensionsReq) returns(GetMessagesReactionExtensionsResp); rpc GetMessagesReactionExtensions(GetMessagesReactionExtensionsReq) returns(GetMessagesReactionExtensionsResp);