mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-09 17:44:59 +09:00
GO-4727 ReadMessages: get the last added msg before orderId and lastDbState
This commit is contained in:
parent
d2ee7ba8ef
commit
f35c0527e5
5 changed files with 1267 additions and 1250 deletions
|
@ -231,7 +231,7 @@ func (s *storeObject) MarkReadMessages(ctx context.Context, beforeOrderId string
|
|||
// 3. update the MarkSeenHeads
|
||||
// 2. mark messages as read in the DB
|
||||
|
||||
msg, err := s.GetMessageByOrderId(ctx, beforeOrderId)
|
||||
msg, err := s.GetLastAddedMessageBeforeOrderIdAndAddedTime(ctx, beforeOrderId, lastDbState)
|
||||
if err != nil {
|
||||
return fmt.Errorf("get message: %w", err)
|
||||
}
|
||||
|
@ -241,13 +241,20 @@ func (s *storeObject) MarkReadMessages(ctx context.Context, beforeOrderId string
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *storeObject) GetMessageByOrderId(ctx context.Context, orderId string) (*model.ChatMessage, error) {
|
||||
func (s *storeObject) GetLastAddedMessageBeforeOrderIdAndAddedTime(ctx context.Context, orderId string, addedTime int64) (*model.ChatMessage, error) {
|
||||
coll, err := s.store.Collection(ctx, collectionName)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("get collection: %w", err)
|
||||
}
|
||||
|
||||
iter, err := coll.Find(query.Key{Path: []string{orderKey, "id"}, Filter: query.NewComp(query.CompOpEq, orderId)}).Limit(1).Iter(ctx)
|
||||
iter, err := coll.Find(
|
||||
query.And{
|
||||
query.Key{Path: []string{orderKey, "id"}, Filter: query.NewComp(query.CompOpLte, orderId)},
|
||||
query.Key{Path: []string{addedKey}, Filter: query.NewComp(query.CompOpLte, addedTime)},
|
||||
},
|
||||
).
|
||||
Limit(1).
|
||||
Iter(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("find id: %w", err)
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ package core
|
|||
import (
|
||||
"context"
|
||||
|
||||
anystore "github.com/anyproto/any-store"
|
||||
|
||||
"github.com/anyproto/anytype-heart/core/block/chats"
|
||||
"github.com/anyproto/anytype-heart/core/block/editor/chatobject"
|
||||
"github.com/anyproto/anytype-heart/pb"
|
||||
|
@ -127,7 +129,9 @@ func (mw *Middleware) ChatUnsubscribe(cctx context.Context, req *pb.RpcChatUnsub
|
|||
func (mw *Middleware) ChatReadMessages(ctx context.Context, request *pb.RpcChatReadRequest) *pb.RpcChatReadResponse {
|
||||
chatService := mustService[chats.Service](mw)
|
||||
err := chatService.ChatReadMessages(request.ChatObjectId, request.BeforeOrderId, request.LastDbState)
|
||||
code := mapErrorCode[pb.RpcChatReadResponseErrorCode](err)
|
||||
code := mapErrorCode(err,
|
||||
errToCode(anystore.ErrDocNotFound, pb.RpcChatReadResponseError_MESSAGES_NOT_FOUND),
|
||||
)
|
||||
return &pb.RpcChatReadResponse{
|
||||
Error: &pb.RpcChatReadResponseError{
|
||||
Code: code,
|
||||
|
|
|
@ -22668,7 +22668,8 @@ Middleware-to-front-end response, that can contain a NULL error or a non-NULL er
|
|||
| ---- | ------ | ----------- |
|
||||
| NULL | 0 | |
|
||||
| UNKNOWN_ERROR | 1 | |
|
||||
| BAD_INPUT | 2 | ... |
|
||||
| BAD_INPUT | 2 | |
|
||||
| MESSAGES_NOT_FOUND | 100 | chat is empty or invalid beforeOrderId/lastDbState |
|
||||
|
||||
|
||||
|
||||
|
|
2493
pb/commands.pb.go
2493
pb/commands.pb.go
File diff suppressed because it is too large
Load diff
|
@ -7949,6 +7949,8 @@ message Rpc {
|
|||
NULL = 0;
|
||||
UNKNOWN_ERROR = 1;
|
||||
BAD_INPUT = 2;
|
||||
|
||||
MESSAGES_NOT_FOUND = 100; // chat is empty or invalid beforeOrderId/lastDbState
|
||||
// ...
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue