Always provide isGroup/storyId to message-fetching functions
This commit is contained in:
@@ -1490,6 +1490,7 @@ export class ConversationModel extends window.Backbone
|
||||
const messages = await getOlderMessagesByConversation(conversationId, {
|
||||
isGroup: isGroup(this.attributes),
|
||||
limit: MESSAGE_LOAD_CHUNK_SIZE,
|
||||
storyId: undefined,
|
||||
});
|
||||
|
||||
const cleaned: Array<MessageModel> = await this.cleanModels(messages);
|
||||
@@ -1541,10 +1542,11 @@ export class ConversationModel extends window.Backbone
|
||||
const sentAt = message.sent_at;
|
||||
const models = await getOlderMessagesByConversation(conversationId, {
|
||||
isGroup: isGroup(this.attributes),
|
||||
limit: MESSAGE_LOAD_CHUNK_SIZE,
|
||||
messageId: oldestMessageId,
|
||||
receivedAt,
|
||||
sentAt,
|
||||
messageId: oldestMessageId,
|
||||
limit: MESSAGE_LOAD_CHUNK_SIZE,
|
||||
storyId: undefined,
|
||||
});
|
||||
|
||||
if (models.length < 1) {
|
||||
@@ -1595,9 +1597,10 @@ export class ConversationModel extends window.Backbone
|
||||
const sentAt = message.sent_at;
|
||||
const models = await getNewerMessagesByConversation(conversationId, {
|
||||
isGroup: isGroup(this.attributes),
|
||||
limit: MESSAGE_LOAD_CHUNK_SIZE,
|
||||
receivedAt,
|
||||
sentAt,
|
||||
limit: MESSAGE_LOAD_CHUNK_SIZE,
|
||||
storyId: undefined,
|
||||
});
|
||||
|
||||
if (models.length < 1) {
|
||||
@@ -1651,10 +1654,12 @@ export class ConversationModel extends window.Backbone
|
||||
const { older, newer, metrics } =
|
||||
await getConversationRangeCenteredOnMessage({
|
||||
conversationId,
|
||||
isGroup: isGroup(this.attributes),
|
||||
limit: MESSAGE_LOAD_CHUNK_SIZE,
|
||||
messageId,
|
||||
receivedAt,
|
||||
sentAt,
|
||||
messageId,
|
||||
storyId: undefined,
|
||||
});
|
||||
const all = [...older, message, ...newer];
|
||||
|
||||
@@ -2035,9 +2040,10 @@ export class ConversationModel extends window.Backbone
|
||||
{
|
||||
isGroup: isGroup(this.attributes),
|
||||
limit: 100,
|
||||
messageId: first ? first.id : undefined,
|
||||
receivedAt: first ? first.received_at : undefined,
|
||||
sentAt: first ? first.sent_at : undefined,
|
||||
messageId: first ? first.id : undefined,
|
||||
storyId: undefined,
|
||||
}
|
||||
);
|
||||
|
||||
|
@@ -1239,12 +1239,12 @@ async function getOlderMessagesByConversation(
|
||||
sentAt = Number.MAX_VALUE,
|
||||
storyId,
|
||||
}: {
|
||||
isGroup?: boolean;
|
||||
isGroup: boolean;
|
||||
limit?: number;
|
||||
messageId?: string;
|
||||
receivedAt?: number;
|
||||
sentAt?: number;
|
||||
storyId?: string;
|
||||
storyId: string | undefined;
|
||||
}
|
||||
) {
|
||||
const messages = await channels.getOlderMessagesByConversation(
|
||||
@@ -1280,11 +1280,11 @@ async function getNewerMessagesByConversation(
|
||||
sentAt = 0,
|
||||
storyId,
|
||||
}: {
|
||||
isGroup?: boolean;
|
||||
isGroup: boolean;
|
||||
limit?: number;
|
||||
receivedAt?: number;
|
||||
sentAt?: number;
|
||||
storyId?: UUIDStringType;
|
||||
storyId: UUIDStringType | undefined;
|
||||
}
|
||||
) {
|
||||
const messages = await channels.getNewerMessagesByConversation(
|
||||
@@ -1344,11 +1344,12 @@ async function getMessageMetricsForConversation(
|
||||
}
|
||||
async function getConversationRangeCenteredOnMessage(options: {
|
||||
conversationId: string;
|
||||
isGroup: boolean;
|
||||
limit?: number;
|
||||
messageId: string;
|
||||
receivedAt: number;
|
||||
sentAt?: number;
|
||||
storyId?: UUIDStringType;
|
||||
storyId: UUIDStringType | undefined;
|
||||
}) {
|
||||
const result = await channels.getConversationRangeCenteredOnMessage(options);
|
||||
|
||||
@@ -1390,6 +1391,8 @@ async function removeAllMessagesInConversation(
|
||||
// time so we don't use too much memory.
|
||||
messages = await getOlderMessagesByConversation(conversationId, {
|
||||
limit: chunkSize,
|
||||
isGroup: true,
|
||||
storyId: undefined,
|
||||
});
|
||||
|
||||
if (!messages.length) {
|
||||
|
@@ -628,32 +628,33 @@ export type ServerInterface = DataInterface & {
|
||||
|
||||
getOlderMessagesByConversation: (
|
||||
conversationId: string,
|
||||
options?: {
|
||||
isGroup?: boolean;
|
||||
options: {
|
||||
isGroup: boolean;
|
||||
limit?: number;
|
||||
messageId?: string;
|
||||
receivedAt?: number;
|
||||
sentAt?: number;
|
||||
storyId?: string;
|
||||
storyId: string | undefined;
|
||||
}
|
||||
) => Promise<Array<MessageTypeUnhydrated>>;
|
||||
getNewerMessagesByConversation: (
|
||||
conversationId: string,
|
||||
options?: {
|
||||
isGroup?: boolean;
|
||||
options: {
|
||||
isGroup: boolean;
|
||||
limit?: number;
|
||||
receivedAt?: number;
|
||||
sentAt?: number;
|
||||
storyId?: UUIDStringType;
|
||||
storyId: UUIDStringType | undefined;
|
||||
}
|
||||
) => Promise<Array<MessageTypeUnhydrated>>;
|
||||
getConversationRangeCenteredOnMessage: (options: {
|
||||
conversationId: string;
|
||||
isGroup: boolean;
|
||||
limit?: number;
|
||||
messageId: string;
|
||||
receivedAt: number;
|
||||
sentAt?: number;
|
||||
storyId?: UUIDStringType;
|
||||
storyId: UUIDStringType | undefined;
|
||||
}) => Promise<{
|
||||
older: Array<MessageTypeUnhydrated>;
|
||||
newer: Array<MessageTypeUnhydrated>;
|
||||
@@ -701,31 +702,32 @@ export type ClientInterface = DataInterface & {
|
||||
getOlderMessagesByConversation: (
|
||||
conversationId: string,
|
||||
options: {
|
||||
isGroup?: boolean;
|
||||
isGroup: boolean;
|
||||
limit?: number;
|
||||
messageId?: string;
|
||||
receivedAt?: number;
|
||||
sentAt?: number;
|
||||
storyId?: string;
|
||||
storyId: string | undefined;
|
||||
}
|
||||
) => Promise<Array<MessageAttributesType>>;
|
||||
getNewerMessagesByConversation: (
|
||||
conversationId: string,
|
||||
options: {
|
||||
isGroup?: boolean;
|
||||
isGroup: boolean;
|
||||
limit?: number;
|
||||
receivedAt?: number;
|
||||
sentAt?: number;
|
||||
storyId?: UUIDStringType;
|
||||
storyId: UUIDStringType | undefined;
|
||||
}
|
||||
) => Promise<Array<MessageAttributesType>>;
|
||||
getConversationRangeCenteredOnMessage: (options: {
|
||||
conversationId: string;
|
||||
isGroup: boolean;
|
||||
limit?: number;
|
||||
messageId: string;
|
||||
receivedAt: number;
|
||||
sentAt?: number;
|
||||
storyId?: UUIDStringType;
|
||||
storyId: UUIDStringType | undefined;
|
||||
}) => Promise<{
|
||||
older: Array<MessageAttributesType>;
|
||||
newer: Array<MessageAttributesType>;
|
||||
|
@@ -2352,13 +2352,13 @@ async function _removeAllReactions(): Promise<void> {
|
||||
|
||||
async function getOlderMessagesByConversation(
|
||||
conversationId: string,
|
||||
options?: {
|
||||
isGroup?: boolean;
|
||||
options: {
|
||||
isGroup: boolean;
|
||||
limit?: number;
|
||||
messageId?: string;
|
||||
receivedAt?: number;
|
||||
sentAt?: number;
|
||||
storyId?: string;
|
||||
storyId: string | undefined;
|
||||
}
|
||||
): Promise<Array<MessageTypeUnhydrated>> {
|
||||
return getOlderMessagesByConversationSync(conversationId, options);
|
||||
@@ -2373,13 +2373,13 @@ function getOlderMessagesByConversationSync(
|
||||
sentAt = Number.MAX_VALUE,
|
||||
storyId,
|
||||
}: {
|
||||
isGroup?: boolean;
|
||||
isGroup: boolean;
|
||||
limit?: number;
|
||||
messageId?: string;
|
||||
receivedAt?: number;
|
||||
sentAt?: number;
|
||||
storyId?: string;
|
||||
} = {}
|
||||
storyId: string | undefined;
|
||||
}
|
||||
): Array<MessageTypeUnhydrated> {
|
||||
const db = getInstance();
|
||||
|
||||
@@ -2453,11 +2453,12 @@ async function getOlderStories({
|
||||
|
||||
async function getNewerMessagesByConversation(
|
||||
conversationId: string,
|
||||
options?: {
|
||||
options: {
|
||||
isGroup: boolean;
|
||||
limit?: number;
|
||||
receivedAt?: number;
|
||||
sentAt?: number;
|
||||
storyId?: UUIDStringType;
|
||||
storyId: UUIDStringType | undefined;
|
||||
}
|
||||
): Promise<Array<MessageTypeUnhydrated>> {
|
||||
return getNewerMessagesByConversationSync(conversationId, options);
|
||||
@@ -2471,12 +2472,12 @@ function getNewerMessagesByConversationSync(
|
||||
sentAt = 0,
|
||||
storyId,
|
||||
}: {
|
||||
isGroup?: boolean;
|
||||
isGroup: boolean;
|
||||
limit?: number;
|
||||
receivedAt?: number;
|
||||
sentAt?: number;
|
||||
storyId?: UUIDStringType;
|
||||
} = {}
|
||||
storyId: UUIDStringType | undefined;
|
||||
}
|
||||
): Array<MessageTypeUnhydrated> {
|
||||
const db = getInstance();
|
||||
const rows: JSONRows = db
|
||||
@@ -2830,6 +2831,7 @@ function getMessageMetricsForConversationSync(
|
||||
|
||||
async function getConversationRangeCenteredOnMessage({
|
||||
conversationId,
|
||||
isGroup,
|
||||
limit,
|
||||
messageId,
|
||||
receivedAt,
|
||||
@@ -2837,11 +2839,12 @@ async function getConversationRangeCenteredOnMessage({
|
||||
storyId,
|
||||
}: {
|
||||
conversationId: string;
|
||||
isGroup: boolean;
|
||||
limit?: number;
|
||||
messageId: string;
|
||||
receivedAt: number;
|
||||
sentAt?: number;
|
||||
storyId?: UUIDStringType;
|
||||
storyId: UUIDStringType | undefined;
|
||||
}): Promise<{
|
||||
older: Array<MessageTypeUnhydrated>;
|
||||
newer: Array<MessageTypeUnhydrated>;
|
||||
@@ -2852,6 +2855,7 @@ async function getConversationRangeCenteredOnMessage({
|
||||
return db.transaction(() => {
|
||||
return {
|
||||
older: getOlderMessagesByConversationSync(conversationId, {
|
||||
isGroup,
|
||||
limit,
|
||||
messageId,
|
||||
receivedAt,
|
||||
@@ -2859,6 +2863,7 @@ async function getConversationRangeCenteredOnMessage({
|
||||
storyId,
|
||||
}),
|
||||
newer: getNewerMessagesByConversationSync(conversationId, {
|
||||
isGroup,
|
||||
limit,
|
||||
receivedAt,
|
||||
sentAt,
|
||||
|
@@ -33,6 +33,8 @@ import {
|
||||
import { useBoundActions } from '../../hooks/useBoundActions';
|
||||
import { viewSyncJobQueue } from '../../jobs/viewSyncJobQueue';
|
||||
import { viewedReceiptsJobQueue } from '../../jobs/viewedReceiptsJobQueue';
|
||||
import { isGroup } from '../../util/whatTypeOfConversation';
|
||||
import { getConversationSelector } from '../selectors/conversations';
|
||||
|
||||
export type StoryDataType = {
|
||||
attachment?: AttachmentType;
|
||||
@@ -133,10 +135,11 @@ function loadStoryReplies(
|
||||
conversationId: string,
|
||||
messageId: string
|
||||
): ThunkAction<void, RootStateType, unknown, LoadStoryRepliesActionType> {
|
||||
return async dispatch => {
|
||||
return async (dispatch, getState) => {
|
||||
const conversation = getConversationSelector(getState())(conversationId);
|
||||
const replies = await dataInterface.getOlderMessagesByConversation(
|
||||
conversationId,
|
||||
{ limit: 9000, storyId: messageId }
|
||||
{ limit: 9000, storyId: messageId, isGroup: isGroup(conversation) }
|
||||
);
|
||||
|
||||
dispatch({
|
||||
|
@@ -93,7 +93,9 @@ describe('sql/timelineFetches', () => {
|
||||
assert.lengthOf(await _getAllMessages(), 5);
|
||||
|
||||
const messages = await getOlderMessagesByConversation(conversationId, {
|
||||
isGroup: false,
|
||||
limit: 5,
|
||||
storyId: undefined,
|
||||
});
|
||||
assert.lengthOf(messages, 3);
|
||||
|
||||
@@ -148,6 +150,7 @@ describe('sql/timelineFetches', () => {
|
||||
assert.lengthOf(await _getAllMessages(), 3);
|
||||
|
||||
const messages = await getOlderMessagesByConversation(conversationId, {
|
||||
isGroup: true,
|
||||
limit: 5,
|
||||
storyId,
|
||||
});
|
||||
@@ -203,6 +206,7 @@ describe('sql/timelineFetches', () => {
|
||||
const messages = await getOlderMessagesByConversation(conversationId, {
|
||||
isGroup: true,
|
||||
limit: 5,
|
||||
storyId: undefined,
|
||||
});
|
||||
assert.lengthOf(messages, 1);
|
||||
assert.strictEqual(messages[0].id, message3.id);
|
||||
@@ -251,9 +255,11 @@ describe('sql/timelineFetches', () => {
|
||||
assert.lengthOf(await _getAllMessages(), 3);
|
||||
|
||||
const messages = await getOlderMessagesByConversation(conversationId, {
|
||||
isGroup: true,
|
||||
limit: 5,
|
||||
receivedAt: target,
|
||||
sentAt: target,
|
||||
storyId: undefined,
|
||||
});
|
||||
assert.lengthOf(messages, 1);
|
||||
assert.strictEqual(messages[0].id, message1.id);
|
||||
@@ -302,9 +308,11 @@ describe('sql/timelineFetches', () => {
|
||||
assert.lengthOf(await _getAllMessages(), 3);
|
||||
|
||||
const messages = await getOlderMessagesByConversation(conversationId, {
|
||||
isGroup: true,
|
||||
limit: 5,
|
||||
receivedAt: target,
|
||||
sentAt: target,
|
||||
storyId: undefined,
|
||||
});
|
||||
|
||||
assert.lengthOf(messages, 2);
|
||||
@@ -357,10 +365,12 @@ describe('sql/timelineFetches', () => {
|
||||
assert.lengthOf(await _getAllMessages(), 3);
|
||||
|
||||
const messages = await getOlderMessagesByConversation(conversationId, {
|
||||
isGroup: true,
|
||||
limit: 5,
|
||||
messageId: message2.id,
|
||||
receivedAt: target,
|
||||
sentAt: target,
|
||||
messageId: message2.id,
|
||||
storyId: undefined,
|
||||
});
|
||||
|
||||
assert.lengthOf(messages, 1);
|
||||
@@ -433,7 +443,9 @@ describe('sql/timelineFetches', () => {
|
||||
assert.lengthOf(await _getAllMessages(), 5);
|
||||
|
||||
const messages = await getNewerMessagesByConversation(conversationId, {
|
||||
isGroup: false,
|
||||
limit: 5,
|
||||
storyId: undefined,
|
||||
});
|
||||
|
||||
assert.lengthOf(messages, 3);
|
||||
@@ -487,6 +499,7 @@ describe('sql/timelineFetches', () => {
|
||||
assert.lengthOf(await _getAllMessages(), 3);
|
||||
|
||||
const messages = await getNewerMessagesByConversation(conversationId, {
|
||||
isGroup: true,
|
||||
limit: 5,
|
||||
storyId,
|
||||
});
|
||||
@@ -538,9 +551,11 @@ describe('sql/timelineFetches', () => {
|
||||
assert.lengthOf(await _getAllMessages(), 3);
|
||||
|
||||
const messages = await getNewerMessagesByConversation(conversationId, {
|
||||
isGroup: true,
|
||||
limit: 5,
|
||||
receivedAt: target,
|
||||
sentAt: target,
|
||||
storyId: undefined,
|
||||
});
|
||||
assert.lengthOf(messages, 1);
|
||||
assert.strictEqual(messages[0].id, message3.id);
|
||||
@@ -593,6 +608,7 @@ describe('sql/timelineFetches', () => {
|
||||
const messages = await getNewerMessagesByConversation(conversationId, {
|
||||
isGroup: true,
|
||||
limit: 5,
|
||||
storyId: undefined,
|
||||
receivedAt: target,
|
||||
sentAt: target,
|
||||
});
|
||||
@@ -643,9 +659,11 @@ describe('sql/timelineFetches', () => {
|
||||
assert.lengthOf(await _getAllMessages(), 3);
|
||||
|
||||
const messages = await getNewerMessagesByConversation(conversationId, {
|
||||
isGroup: true,
|
||||
limit: 5,
|
||||
receivedAt: target,
|
||||
sentAt: target,
|
||||
storyId: undefined,
|
||||
});
|
||||
|
||||
assert.lengthOf(messages, 2);
|
||||
|
Reference in New Issue
Block a user