Skip to content

Commit

Permalink
Also use sent_at whenever we query database with received_at
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Jan 20, 2021
1 parent f32a0b5 commit 9f81b41
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 134 deletions.
3 changes: 3 additions & 0 deletions js/modules/backup.js
Expand Up @@ -673,6 +673,7 @@ async function exportConversation(conversation, options = {}) {

// We're looping from the most recent to the oldest
let lastReceivedAt = Number.MAX_VALUE;
let lastSentAt = Number.MAX_VALUE;

while (!complete) {
// eslint-disable-next-line no-await-in-loop
Expand All @@ -681,6 +682,7 @@ async function exportConversation(conversation, options = {}) {
{
limit: CHUNK_SIZE,
receivedAt: lastReceivedAt,
sentAt: lastSentAt,
MessageCollection: Whisper.MessageCollection,
}
);
Expand Down Expand Up @@ -771,6 +773,7 @@ async function exportConversation(conversation, options = {}) {
const last = messages.length > 0 ? messages[messages.length - 1] : null;
if (last) {
lastReceivedAt = last.received_at;
lastSentAt = last.sent_at;
}

if (messages.length < CHUNK_SIZE) {
Expand Down
1 change: 1 addition & 0 deletions test/backup_test.js
Expand Up @@ -457,6 +457,7 @@ describe('Backup', () => {
body: 'Totally!',
source: OUR_NUMBER,
received_at: 1524185933350,
sent_at: 1524185933350,
timestamp: 1524185933350,
errors: [],
attachments: [
Expand Down
1 change: 1 addition & 0 deletions ts/models/conversations.ts
Expand Up @@ -1314,6 +1314,7 @@ export class ConversationModel extends window.Backbone.Model<
MessageCollection: window.Whisper.MessageCollection,
limit: 100,
receivedAt: first ? first.get('received_at') : undefined,
sentAt: first ? first.get('sent_at') : undefined,
messageId: first ? first.id : undefined,
}
);
Expand Down
6 changes: 6 additions & 0 deletions ts/sql/Client.ts
Expand Up @@ -983,11 +983,13 @@ async function getOlderMessagesByConversation(
{
limit = 100,
receivedAt = Number.MAX_VALUE,
sentAt = Number.MAX_VALUE,
messageId,
MessageCollection,
}: {
limit?: number;
receivedAt?: number;
sentAt?: number;
messageId?: string;
MessageCollection: typeof MessageModelCollectionType;
}
Expand All @@ -997,6 +999,7 @@ async function getOlderMessagesByConversation(
{
limit,
receivedAt,
sentAt,
messageId,
}
);
Expand All @@ -1008,10 +1011,12 @@ async function getNewerMessagesByConversation(
{
limit = 100,
receivedAt = 0,
sentAt = 0,
MessageCollection,
}: {
limit?: number;
receivedAt?: number;
sentAt?: number;
MessageCollection: typeof MessageModelCollectionType;
}
) {
Expand All @@ -1020,6 +1025,7 @@ async function getNewerMessagesByConversation(
{
limit,
receivedAt,
sentAt,
}
);

Expand Down
5 changes: 4 additions & 1 deletion ts/sql/Interface.ts
Expand Up @@ -217,12 +217,13 @@ export type ServerInterface = DataInterface & {
options?: {
limit?: number;
receivedAt?: number;
sentAt?: number;
messageId?: string;
}
) => Promise<Array<MessageTypeUnhydrated>>;
getNewerMessagesByConversation: (
conversationId: string,
options?: { limit?: number; receivedAt?: number }
options?: { limit?: number; receivedAt?: number; sentAt?: number }
) => Promise<Array<MessageTypeUnhydrated>>;
getLastConversationActivity: (
conversationId: string
Expand Down Expand Up @@ -309,6 +310,7 @@ export type ClientInterface = DataInterface & {
limit?: number;
messageId?: string;
receivedAt?: number;
sentAt?: number;
MessageCollection: typeof MessageModelCollectionType;
}
) => Promise<MessageModelCollectionType>;
Expand All @@ -317,6 +319,7 @@ export type ClientInterface = DataInterface & {
options: {
limit?: number;
receivedAt?: number;
sentAt?: number;
MessageCollection: typeof MessageModelCollectionType;
}
) => Promise<MessageModelCollectionType>;
Expand Down

0 comments on commit 9f81b41

Please sign in to comment.