Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added MaxTimestampNanos to GetMessagesStatelessRequest #378

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions routes/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ type GetMessagesStatelessRequest struct {
// SortAlgorithm determines how the messages should be returned. Currently
// it support time, deso, and followers based sorting.
SortAlgorithm string `safeForLogging:"true"`

// ---------------------------------------------------------
// DB Message Pagination Fields
// ---------------------------------------------------------

// MaxTimestampNanos specifies the max timestamp to start retrieving messages from.
// Defaults to math.MaxUint64 unless otherwise specified.
MaxTimestampNanos uint64 `safeForLogging:"true"`
}

// GetMessagesResponse ...
Expand All @@ -71,7 +79,7 @@ type GetMessagesResponse struct {
}

func (fes *APIServer) getMessagesStateless(publicKeyBytes []byte,
fetchAfterPublicKeyBytes []byte, numToFetch uint64, holdersOnly bool,
fetchAfterPublicKeyBytes []byte, numToFetch uint64, maxTimestampNanos uint64, holdersOnly bool,
holdingsOnly bool, followersOnly bool, followingOnly bool, sortAlgorithm string) (
_publicKeyToProfileEntry map[string]*ProfileEntryResponse,
_orderedContactsWithMessages []*MessageContactResponse,
Expand All @@ -94,7 +102,7 @@ func (fes *APIServer) getMessagesStateless(publicKeyBytes []byte,
// for more insight on this.

// Get user's messaging groups and up to lib.MessagesToFetchPerInboxCall messages.
messageEntries, messagingGroups, err := utxoView.GetLimitedMessagesForUser(publicKeyBytes, uint64(lib.MessagesToFetchPerInboxCall))
messageEntries, messagingGroups, err := utxoView.GetLimitedMessagesForUser(publicKeyBytes, maxTimestampNanos, uint64(lib.MessagesToFetchPerInboxCall))
if err != nil {
return nil, nil, nil, 0, nil, errors.Wrapf(
err, "getMessagesStateless: Problem fetching MessageEntries and MessagingGroupEntries from augmented UtxoView: ")
Expand Down Expand Up @@ -506,7 +514,7 @@ func (fes *APIServer) GetMessagesStateless(ww http.ResponseWriter, rr *http.Requ
// Get all contacts profile entries, messages, and group messaging keys.
publicKeyToProfileEntry, orderedContactsWithMessages,
unreadStateByContact, numOfUnreadThreads, messagingGroups, err := fes.getMessagesStateless(publicKeyBytes, fetchAfterPublicKeyBytes,
getMessagesRequest.NumToFetch, getMessagesRequest.HoldersOnly, getMessagesRequest.HoldingsOnly,
getMessagesRequest.NumToFetch, getMessagesRequest.MaxTimestampNanos, getMessagesRequest.HoldersOnly, getMessagesRequest.HoldingsOnly,
getMessagesRequest.FollowersOnly, getMessagesRequest.FollowingOnly, getMessagesRequest.SortAlgorithm)
if err != nil {
_AddBadRequestError(ww, fmt.Sprintf("GetMessagesStateless: Problem fetching and decrypting messages: %v", err))
Expand Down