Ensure deleting conversation deletes story replies
This commit is contained in:
parent
00a720faa9
commit
67c706a7ef
10 changed files with 219 additions and 163 deletions
|
@ -1457,11 +1457,9 @@ export class ConversationModel extends window.Backbone
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const metrics = await getMessageMetricsForConversation(
|
const metrics = await getMessageMetricsForConversation(conversationId, {
|
||||||
conversationId,
|
includeStoryReplies: !isGroup(this.attributes),
|
||||||
undefined,
|
});
|
||||||
isGroup(this.attributes)
|
|
||||||
);
|
|
||||||
|
|
||||||
// If this is a message request that has not yet been accepted, we always show the
|
// If this is a message request that has not yet been accepted, we always show the
|
||||||
// oldest messages, to ensure that the ConversationHero is shown. We don't want to
|
// oldest messages, to ensure that the ConversationHero is shown. We don't want to
|
||||||
|
@ -1480,7 +1478,7 @@ export class ConversationModel extends window.Backbone
|
||||||
}
|
}
|
||||||
|
|
||||||
const messages = await getOlderMessagesByConversation(conversationId, {
|
const messages = await getOlderMessagesByConversation(conversationId, {
|
||||||
isGroup: isGroup(this.attributes),
|
includeStoryReplies: !isGroup(this.attributes),
|
||||||
limit: MESSAGE_LOAD_CHUNK_SIZE,
|
limit: MESSAGE_LOAD_CHUNK_SIZE,
|
||||||
storyId: undefined,
|
storyId: undefined,
|
||||||
});
|
});
|
||||||
|
@ -1533,7 +1531,7 @@ export class ConversationModel extends window.Backbone
|
||||||
const receivedAt = message.received_at;
|
const receivedAt = message.received_at;
|
||||||
const sentAt = message.sent_at;
|
const sentAt = message.sent_at;
|
||||||
const models = await getOlderMessagesByConversation(conversationId, {
|
const models = await getOlderMessagesByConversation(conversationId, {
|
||||||
isGroup: isGroup(this.attributes),
|
includeStoryReplies: !isGroup(this.attributes),
|
||||||
limit: MESSAGE_LOAD_CHUNK_SIZE,
|
limit: MESSAGE_LOAD_CHUNK_SIZE,
|
||||||
messageId: oldestMessageId,
|
messageId: oldestMessageId,
|
||||||
receivedAt,
|
receivedAt,
|
||||||
|
@ -1588,7 +1586,7 @@ export class ConversationModel extends window.Backbone
|
||||||
const receivedAt = message.received_at;
|
const receivedAt = message.received_at;
|
||||||
const sentAt = message.sent_at;
|
const sentAt = message.sent_at;
|
||||||
const models = await getNewerMessagesByConversation(conversationId, {
|
const models = await getNewerMessagesByConversation(conversationId, {
|
||||||
isGroup: isGroup(this.attributes),
|
includeStoryReplies: !isGroup(this.attributes),
|
||||||
limit: MESSAGE_LOAD_CHUNK_SIZE,
|
limit: MESSAGE_LOAD_CHUNK_SIZE,
|
||||||
receivedAt,
|
receivedAt,
|
||||||
sentAt,
|
sentAt,
|
||||||
|
@ -1646,7 +1644,7 @@ export class ConversationModel extends window.Backbone
|
||||||
const { older, newer, metrics } =
|
const { older, newer, metrics } =
|
||||||
await getConversationRangeCenteredOnMessage({
|
await getConversationRangeCenteredOnMessage({
|
||||||
conversationId,
|
conversationId,
|
||||||
isGroup: isGroup(this.attributes),
|
includeStoryReplies: !isGroup(this.attributes),
|
||||||
limit: MESSAGE_LOAD_CHUNK_SIZE,
|
limit: MESSAGE_LOAD_CHUNK_SIZE,
|
||||||
messageId,
|
messageId,
|
||||||
receivedAt,
|
receivedAt,
|
||||||
|
@ -2067,7 +2065,7 @@ export class ConversationModel extends window.Backbone
|
||||||
messages = await window.Signal.Data.getOlderMessagesByConversation(
|
messages = await window.Signal.Data.getOlderMessagesByConversation(
|
||||||
this.get('id'),
|
this.get('id'),
|
||||||
{
|
{
|
||||||
isGroup: isGroup(this.attributes),
|
includeStoryReplies: !isGroup(this.attributes),
|
||||||
limit: 100,
|
limit: 100,
|
||||||
messageId: first ? first.id : undefined,
|
messageId: first ? first.id : undefined,
|
||||||
receivedAt: first ? first.received_at : undefined,
|
receivedAt: first ? first.received_at : undefined,
|
||||||
|
@ -4134,7 +4132,7 @@ export class ConversationModel extends window.Backbone
|
||||||
const ourUuid = window.textsecure.storage.user.getCheckedUuid().toString();
|
const ourUuid = window.textsecure.storage.user.getCheckedUuid().toString();
|
||||||
const stats = await window.Signal.Data.getConversationMessageStats({
|
const stats = await window.Signal.Data.getConversationMessageStats({
|
||||||
conversationId,
|
conversationId,
|
||||||
isGroup: isGroup(this.attributes),
|
includeStoryReplies: !isGroup(this.attributes),
|
||||||
ourUuid,
|
ourUuid,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -4621,7 +4619,7 @@ export class ConversationModel extends window.Backbone
|
||||||
this.id,
|
this.id,
|
||||||
{
|
{
|
||||||
storyId: undefined,
|
storyId: undefined,
|
||||||
isGroup: isGroup(this.attributes),
|
includeStoryReplies: !isGroup(this.attributes),
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1259,7 +1259,7 @@ async function getTotalUnreadForConversation(
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
options: {
|
options: {
|
||||||
storyId: UUIDStringType | undefined;
|
storyId: UUIDStringType | undefined;
|
||||||
isGroup: boolean;
|
includeStoryReplies: boolean;
|
||||||
}
|
}
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
return channels.getTotalUnreadForConversation(conversationId, options);
|
return channels.getTotalUnreadForConversation(conversationId, options);
|
||||||
|
@ -1267,7 +1267,7 @@ async function getTotalUnreadForConversation(
|
||||||
|
|
||||||
async function getUnreadByConversationAndMarkRead(options: {
|
async function getUnreadByConversationAndMarkRead(options: {
|
||||||
conversationId: string;
|
conversationId: string;
|
||||||
isGroup?: boolean;
|
includeStoryReplies: boolean;
|
||||||
newestUnreadAt: number;
|
newestUnreadAt: number;
|
||||||
now?: number;
|
now?: number;
|
||||||
readAt?: number;
|
readAt?: number;
|
||||||
|
@ -1320,14 +1320,14 @@ function handleMessageJSON(
|
||||||
async function getOlderMessagesByConversation(
|
async function getOlderMessagesByConversation(
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
{
|
{
|
||||||
isGroup,
|
includeStoryReplies,
|
||||||
limit = 100,
|
limit = 100,
|
||||||
messageId,
|
messageId,
|
||||||
receivedAt = Number.MAX_VALUE,
|
receivedAt = Number.MAX_VALUE,
|
||||||
sentAt = Number.MAX_VALUE,
|
sentAt = Number.MAX_VALUE,
|
||||||
storyId,
|
storyId,
|
||||||
}: {
|
}: {
|
||||||
isGroup: boolean;
|
includeStoryReplies: boolean;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
messageId?: string;
|
messageId?: string;
|
||||||
receivedAt?: number;
|
receivedAt?: number;
|
||||||
|
@ -1338,7 +1338,7 @@ async function getOlderMessagesByConversation(
|
||||||
const messages = await channels.getOlderMessagesByConversation(
|
const messages = await channels.getOlderMessagesByConversation(
|
||||||
conversationId,
|
conversationId,
|
||||||
{
|
{
|
||||||
isGroup,
|
includeStoryReplies,
|
||||||
limit,
|
limit,
|
||||||
receivedAt,
|
receivedAt,
|
||||||
sentAt,
|
sentAt,
|
||||||
|
@ -1362,13 +1362,13 @@ async function getOlderStories(options: {
|
||||||
async function getNewerMessagesByConversation(
|
async function getNewerMessagesByConversation(
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
{
|
{
|
||||||
isGroup,
|
includeStoryReplies,
|
||||||
limit = 100,
|
limit = 100,
|
||||||
receivedAt = 0,
|
receivedAt = 0,
|
||||||
sentAt = 0,
|
sentAt = 0,
|
||||||
storyId,
|
storyId,
|
||||||
}: {
|
}: {
|
||||||
isGroup: boolean;
|
includeStoryReplies: boolean;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
receivedAt?: number;
|
receivedAt?: number;
|
||||||
sentAt?: number;
|
sentAt?: number;
|
||||||
|
@ -1378,7 +1378,7 @@ async function getNewerMessagesByConversation(
|
||||||
const messages = await channels.getNewerMessagesByConversation(
|
const messages = await channels.getNewerMessagesByConversation(
|
||||||
conversationId,
|
conversationId,
|
||||||
{
|
{
|
||||||
isGroup,
|
includeStoryReplies,
|
||||||
limit,
|
limit,
|
||||||
receivedAt,
|
receivedAt,
|
||||||
sentAt,
|
sentAt,
|
||||||
|
@ -1390,17 +1390,17 @@ async function getNewerMessagesByConversation(
|
||||||
}
|
}
|
||||||
async function getConversationMessageStats({
|
async function getConversationMessageStats({
|
||||||
conversationId,
|
conversationId,
|
||||||
isGroup,
|
includeStoryReplies,
|
||||||
ourUuid,
|
ourUuid,
|
||||||
}: {
|
}: {
|
||||||
conversationId: string;
|
conversationId: string;
|
||||||
isGroup?: boolean;
|
includeStoryReplies: boolean;
|
||||||
ourUuid: UUIDStringType;
|
ourUuid: UUIDStringType;
|
||||||
}): Promise<ConversationMessageStatsType> {
|
}): Promise<ConversationMessageStatsType> {
|
||||||
const { preview, activity, hasUserInitiatedMessages } =
|
const { preview, activity, hasUserInitiatedMessages } =
|
||||||
await channels.getConversationMessageStats({
|
await channels.getConversationMessageStats({
|
||||||
conversationId,
|
conversationId,
|
||||||
isGroup,
|
includeStoryReplies,
|
||||||
ourUuid,
|
ourUuid,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1419,20 +1419,21 @@ async function getLastConversationMessage({
|
||||||
}
|
}
|
||||||
async function getMessageMetricsForConversation(
|
async function getMessageMetricsForConversation(
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
storyId?: UUIDStringType,
|
options: {
|
||||||
isGroup?: boolean
|
storyId?: UUIDStringType;
|
||||||
|
includeStoryReplies: boolean;
|
||||||
|
}
|
||||||
): Promise<ConversationMetricsType> {
|
): Promise<ConversationMetricsType> {
|
||||||
const result = await channels.getMessageMetricsForConversation(
|
const result = await channels.getMessageMetricsForConversation(
|
||||||
conversationId,
|
conversationId,
|
||||||
storyId,
|
options
|
||||||
isGroup
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
async function getConversationRangeCenteredOnMessage(options: {
|
async function getConversationRangeCenteredOnMessage(options: {
|
||||||
conversationId: string;
|
conversationId: string;
|
||||||
isGroup: boolean;
|
includeStoryReplies: boolean;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
messageId: string;
|
messageId: string;
|
||||||
receivedAt: number;
|
receivedAt: number;
|
||||||
|
@ -1479,7 +1480,7 @@ async function removeAllMessagesInConversation(
|
||||||
// time so we don't use too much memory.
|
// time so we don't use too much memory.
|
||||||
messages = await getOlderMessagesByConversation(conversationId, {
|
messages = await getOlderMessagesByConversation(conversationId, {
|
||||||
limit: chunkSize,
|
limit: chunkSize,
|
||||||
isGroup: true,
|
includeStoryReplies: true,
|
||||||
storyId: undefined,
|
storyId: undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -458,12 +458,12 @@ export type DataInterface = {
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
options: {
|
options: {
|
||||||
storyId: UUIDStringType | undefined;
|
storyId: UUIDStringType | undefined;
|
||||||
isGroup: boolean;
|
includeStoryReplies: boolean;
|
||||||
}
|
}
|
||||||
) => Promise<number>;
|
) => Promise<number>;
|
||||||
getUnreadByConversationAndMarkRead: (options: {
|
getUnreadByConversationAndMarkRead: (options: {
|
||||||
conversationId: string;
|
conversationId: string;
|
||||||
isGroup?: boolean;
|
includeStoryReplies: boolean;
|
||||||
newestUnreadAt: number;
|
newestUnreadAt: number;
|
||||||
now?: number;
|
now?: number;
|
||||||
readAt?: number;
|
readAt?: number;
|
||||||
|
@ -517,13 +517,15 @@ export type DataInterface = {
|
||||||
// getNewerMessagesByConversation is JSON on server, full message on Client
|
// getNewerMessagesByConversation is JSON on server, full message on Client
|
||||||
getMessageMetricsForConversation: (
|
getMessageMetricsForConversation: (
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
storyId?: UUIDStringType,
|
options: {
|
||||||
isGroup?: boolean
|
storyId?: UUIDStringType;
|
||||||
|
includeStoryReplies: boolean;
|
||||||
|
}
|
||||||
) => Promise<ConversationMetricsType>;
|
) => Promise<ConversationMetricsType>;
|
||||||
// getConversationRangeCenteredOnMessage is JSON on server, full message on client
|
// getConversationRangeCenteredOnMessage is JSON on server, full message on client
|
||||||
getConversationMessageStats: (options: {
|
getConversationMessageStats: (options: {
|
||||||
conversationId: string;
|
conversationId: string;
|
||||||
isGroup?: boolean;
|
includeStoryReplies: boolean;
|
||||||
ourUuid: UUIDStringType;
|
ourUuid: UUIDStringType;
|
||||||
}) => Promise<ConversationMessageStatsType>;
|
}) => Promise<ConversationMessageStatsType>;
|
||||||
getLastConversationMessage(options: {
|
getLastConversationMessage(options: {
|
||||||
|
@ -706,7 +708,7 @@ export type ServerInterface = DataInterface & {
|
||||||
getOlderMessagesByConversation: (
|
getOlderMessagesByConversation: (
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
options: {
|
options: {
|
||||||
isGroup: boolean;
|
includeStoryReplies: boolean;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
messageId?: string;
|
messageId?: string;
|
||||||
receivedAt?: number;
|
receivedAt?: number;
|
||||||
|
@ -717,7 +719,7 @@ export type ServerInterface = DataInterface & {
|
||||||
getNewerMessagesByConversation: (
|
getNewerMessagesByConversation: (
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
options: {
|
options: {
|
||||||
isGroup: boolean;
|
includeStoryReplies: boolean;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
receivedAt?: number;
|
receivedAt?: number;
|
||||||
sentAt?: number;
|
sentAt?: number;
|
||||||
|
@ -726,7 +728,7 @@ export type ServerInterface = DataInterface & {
|
||||||
) => Promise<Array<MessageTypeUnhydrated>>;
|
) => Promise<Array<MessageTypeUnhydrated>>;
|
||||||
getConversationRangeCenteredOnMessage: (options: {
|
getConversationRangeCenteredOnMessage: (options: {
|
||||||
conversationId: string;
|
conversationId: string;
|
||||||
isGroup: boolean;
|
includeStoryReplies: boolean;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
messageId: string;
|
messageId: string;
|
||||||
receivedAt: number;
|
receivedAt: number;
|
||||||
|
@ -804,7 +806,7 @@ export type ClientInterface = DataInterface & {
|
||||||
getOlderMessagesByConversation: (
|
getOlderMessagesByConversation: (
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
options: {
|
options: {
|
||||||
isGroup: boolean;
|
includeStoryReplies: boolean;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
messageId?: string;
|
messageId?: string;
|
||||||
receivedAt?: number;
|
receivedAt?: number;
|
||||||
|
@ -815,7 +817,7 @@ export type ClientInterface = DataInterface & {
|
||||||
getNewerMessagesByConversation: (
|
getNewerMessagesByConversation: (
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
options: {
|
options: {
|
||||||
isGroup: boolean;
|
includeStoryReplies: boolean;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
receivedAt?: number;
|
receivedAt?: number;
|
||||||
sentAt?: number;
|
sentAt?: number;
|
||||||
|
@ -824,7 +826,7 @@ export type ClientInterface = DataInterface & {
|
||||||
) => Promise<Array<MessageAttributesType>>;
|
) => Promise<Array<MessageAttributesType>>;
|
||||||
getConversationRangeCenteredOnMessage: (options: {
|
getConversationRangeCenteredOnMessage: (options: {
|
||||||
conversationId: string;
|
conversationId: string;
|
||||||
isGroup: boolean;
|
includeStoryReplies: boolean;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
messageId: string;
|
messageId: string;
|
||||||
receivedAt: number;
|
receivedAt: number;
|
||||||
|
|
161
ts/sql/Server.ts
161
ts/sql/Server.ts
|
@ -1757,6 +1757,8 @@ async function getMessageCount(conversationId?: string): Promise<number> {
|
||||||
return getMessageCountSync(conversationId);
|
return getMessageCountSync(conversationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note: we really only use this in 1:1 conversations, where story replies are always
|
||||||
|
// shown, so this has no need to be story-aware.
|
||||||
function hasUserInitiatedMessages(conversationId: string): boolean {
|
function hasUserInitiatedMessages(conversationId: string): boolean {
|
||||||
const db = getInstance();
|
const db = getInstance();
|
||||||
|
|
||||||
|
@ -2151,27 +2153,30 @@ async function getMessageBySender({
|
||||||
|
|
||||||
export function _storyIdPredicate(
|
export function _storyIdPredicate(
|
||||||
storyId: string | undefined,
|
storyId: string | undefined,
|
||||||
isGroup?: boolean
|
includeStoryReplies: boolean
|
||||||
): string {
|
): string {
|
||||||
if (!isGroup && storyId === undefined) {
|
// This is unintuitive, but 'including story replies' means that we need replies to
|
||||||
// We could use 'TRUE' here, but it is better to require `$storyId`
|
// lots of different stories. So, we remove the storyId check with a clause that will
|
||||||
// parameter
|
// always be true. We don't just return TRUE because we want to use our passed-in
|
||||||
|
// $storyId parameter.
|
||||||
|
if (includeStoryReplies && storyId === undefined) {
|
||||||
return '$storyId IS NULL';
|
return '$storyId IS NULL';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// In constrast to: replies to a specific story
|
||||||
return 'storyId IS $storyId';
|
return 'storyId IS $storyId';
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getUnreadByConversationAndMarkRead({
|
async function getUnreadByConversationAndMarkRead({
|
||||||
conversationId,
|
conversationId,
|
||||||
isGroup,
|
includeStoryReplies,
|
||||||
newestUnreadAt,
|
newestUnreadAt,
|
||||||
storyId,
|
storyId,
|
||||||
readAt,
|
readAt,
|
||||||
now = Date.now(),
|
now = Date.now(),
|
||||||
}: {
|
}: {
|
||||||
conversationId: string;
|
conversationId: string;
|
||||||
isGroup?: boolean;
|
includeStoryReplies: boolean;
|
||||||
newestUnreadAt: number;
|
newestUnreadAt: number;
|
||||||
storyId?: UUIDStringType;
|
storyId?: UUIDStringType;
|
||||||
readAt?: number;
|
readAt?: number;
|
||||||
|
@ -2189,7 +2194,7 @@ async function getUnreadByConversationAndMarkRead({
|
||||||
json = json_patch(json, $jsonPatch)
|
json = json_patch(json, $jsonPatch)
|
||||||
WHERE
|
WHERE
|
||||||
conversationId = $conversationId AND
|
conversationId = $conversationId AND
|
||||||
(${_storyIdPredicate(storyId, isGroup)}) AND
|
(${_storyIdPredicate(storyId, includeStoryReplies)}) AND
|
||||||
isStory IS 0 AND
|
isStory IS 0 AND
|
||||||
type IS 'incoming' AND
|
type IS 'incoming' AND
|
||||||
(
|
(
|
||||||
|
@ -2215,7 +2220,7 @@ async function getUnreadByConversationAndMarkRead({
|
||||||
conversationId = $conversationId AND
|
conversationId = $conversationId AND
|
||||||
seenStatus = ${SeenStatus.Unseen} AND
|
seenStatus = ${SeenStatus.Unseen} AND
|
||||||
isStory = 0 AND
|
isStory = 0 AND
|
||||||
(${_storyIdPredicate(storyId, isGroup)}) AND
|
(${_storyIdPredicate(storyId, includeStoryReplies)}) AND
|
||||||
received_at <= $newestUnreadAt
|
received_at <= $newestUnreadAt
|
||||||
ORDER BY received_at DESC, sent_at DESC;
|
ORDER BY received_at DESC, sent_at DESC;
|
||||||
`
|
`
|
||||||
|
@ -2237,7 +2242,7 @@ async function getUnreadByConversationAndMarkRead({
|
||||||
conversationId = $conversationId AND
|
conversationId = $conversationId AND
|
||||||
seenStatus = ${SeenStatus.Unseen} AND
|
seenStatus = ${SeenStatus.Unseen} AND
|
||||||
isStory = 0 AND
|
isStory = 0 AND
|
||||||
(${_storyIdPredicate(storyId, isGroup)}) AND
|
(${_storyIdPredicate(storyId, includeStoryReplies)}) AND
|
||||||
received_at <= $newestUnreadAt;
|
received_at <= $newestUnreadAt;
|
||||||
`
|
`
|
||||||
).run({
|
).run({
|
||||||
|
@ -2439,7 +2444,7 @@ async function _removeAllReactions(): Promise<void> {
|
||||||
async function getOlderMessagesByConversation(
|
async function getOlderMessagesByConversation(
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
options: {
|
options: {
|
||||||
isGroup: boolean;
|
includeStoryReplies: boolean;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
messageId?: string;
|
messageId?: string;
|
||||||
receivedAt?: number;
|
receivedAt?: number;
|
||||||
|
@ -2452,14 +2457,14 @@ async function getOlderMessagesByConversation(
|
||||||
function getOlderMessagesByConversationSync(
|
function getOlderMessagesByConversationSync(
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
{
|
{
|
||||||
isGroup,
|
includeStoryReplies,
|
||||||
limit = 100,
|
limit = 100,
|
||||||
messageId,
|
messageId,
|
||||||
receivedAt = Number.MAX_VALUE,
|
receivedAt = Number.MAX_VALUE,
|
||||||
sentAt = Number.MAX_VALUE,
|
sentAt = Number.MAX_VALUE,
|
||||||
storyId,
|
storyId,
|
||||||
}: {
|
}: {
|
||||||
isGroup: boolean;
|
includeStoryReplies: boolean;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
messageId?: string;
|
messageId?: string;
|
||||||
receivedAt?: number;
|
receivedAt?: number;
|
||||||
|
@ -2476,7 +2481,7 @@ function getOlderMessagesByConversationSync(
|
||||||
conversationId = $conversationId AND
|
conversationId = $conversationId AND
|
||||||
($messageId IS NULL OR id IS NOT $messageId) AND
|
($messageId IS NULL OR id IS NOT $messageId) AND
|
||||||
isStory IS 0 AND
|
isStory IS 0 AND
|
||||||
(${_storyIdPredicate(storyId, isGroup)}) AND
|
(${_storyIdPredicate(storyId, includeStoryReplies)}) AND
|
||||||
(
|
(
|
||||||
(received_at = $received_at AND sent_at < $sent_at) OR
|
(received_at = $received_at AND sent_at < $sent_at) OR
|
||||||
received_at < $received_at
|
received_at < $received_at
|
||||||
|
@ -2540,7 +2545,7 @@ async function getOlderStories({
|
||||||
async function getNewerMessagesByConversation(
|
async function getNewerMessagesByConversation(
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
options: {
|
options: {
|
||||||
isGroup: boolean;
|
includeStoryReplies: boolean;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
receivedAt?: number;
|
receivedAt?: number;
|
||||||
sentAt?: number;
|
sentAt?: number;
|
||||||
|
@ -2552,13 +2557,13 @@ async function getNewerMessagesByConversation(
|
||||||
function getNewerMessagesByConversationSync(
|
function getNewerMessagesByConversationSync(
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
{
|
{
|
||||||
isGroup,
|
includeStoryReplies,
|
||||||
limit = 100,
|
limit = 100,
|
||||||
receivedAt = 0,
|
receivedAt = 0,
|
||||||
sentAt = 0,
|
sentAt = 0,
|
||||||
storyId,
|
storyId,
|
||||||
}: {
|
}: {
|
||||||
isGroup: boolean;
|
includeStoryReplies: boolean;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
receivedAt?: number;
|
receivedAt?: number;
|
||||||
sentAt?: number;
|
sentAt?: number;
|
||||||
|
@ -2572,7 +2577,7 @@ function getNewerMessagesByConversationSync(
|
||||||
SELECT json FROM messages WHERE
|
SELECT json FROM messages WHERE
|
||||||
conversationId = $conversationId AND
|
conversationId = $conversationId AND
|
||||||
isStory IS 0 AND
|
isStory IS 0 AND
|
||||||
(${_storyIdPredicate(storyId, isGroup)}) AND
|
(${_storyIdPredicate(storyId, includeStoryReplies)}) AND
|
||||||
(
|
(
|
||||||
(received_at = $received_at AND sent_at > $sent_at) OR
|
(received_at = $received_at AND sent_at > $sent_at) OR
|
||||||
received_at > $received_at
|
received_at > $received_at
|
||||||
|
@ -2593,8 +2598,13 @@ function getNewerMessagesByConversationSync(
|
||||||
}
|
}
|
||||||
function getOldestMessageForConversation(
|
function getOldestMessageForConversation(
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
storyId?: UUIDStringType,
|
{
|
||||||
isGroup?: boolean
|
storyId,
|
||||||
|
includeStoryReplies,
|
||||||
|
}: {
|
||||||
|
storyId?: UUIDStringType;
|
||||||
|
includeStoryReplies: boolean;
|
||||||
|
}
|
||||||
): MessageMetricsType | undefined {
|
): MessageMetricsType | undefined {
|
||||||
const db = getInstance();
|
const db = getInstance();
|
||||||
const row = db
|
const row = db
|
||||||
|
@ -2603,7 +2613,7 @@ function getOldestMessageForConversation(
|
||||||
SELECT * FROM messages WHERE
|
SELECT * FROM messages WHERE
|
||||||
conversationId = $conversationId AND
|
conversationId = $conversationId AND
|
||||||
isStory IS 0 AND
|
isStory IS 0 AND
|
||||||
(${_storyIdPredicate(storyId, isGroup)})
|
(${_storyIdPredicate(storyId, includeStoryReplies)})
|
||||||
ORDER BY received_at ASC, sent_at ASC
|
ORDER BY received_at ASC, sent_at ASC
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
`
|
`
|
||||||
|
@ -2621,8 +2631,13 @@ function getOldestMessageForConversation(
|
||||||
}
|
}
|
||||||
function getNewestMessageForConversation(
|
function getNewestMessageForConversation(
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
storyId?: UUIDStringType,
|
{
|
||||||
isGroup?: boolean
|
storyId,
|
||||||
|
includeStoryReplies,
|
||||||
|
}: {
|
||||||
|
storyId?: UUIDStringType;
|
||||||
|
includeStoryReplies: boolean;
|
||||||
|
}
|
||||||
): MessageMetricsType | undefined {
|
): MessageMetricsType | undefined {
|
||||||
const db = getInstance();
|
const db = getInstance();
|
||||||
const row = db
|
const row = db
|
||||||
|
@ -2631,7 +2646,7 @@ function getNewestMessageForConversation(
|
||||||
SELECT * FROM messages WHERE
|
SELECT * FROM messages WHERE
|
||||||
conversationId = $conversationId AND
|
conversationId = $conversationId AND
|
||||||
isStory IS 0 AND
|
isStory IS 0 AND
|
||||||
(${_storyIdPredicate(storyId, isGroup)})
|
(${_storyIdPredicate(storyId, includeStoryReplies)})
|
||||||
ORDER BY received_at DESC, sent_at DESC
|
ORDER BY received_at DESC, sent_at DESC
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
`
|
`
|
||||||
|
@ -2650,11 +2665,11 @@ function getNewestMessageForConversation(
|
||||||
|
|
||||||
function getLastConversationActivity({
|
function getLastConversationActivity({
|
||||||
conversationId,
|
conversationId,
|
||||||
isGroup,
|
includeStoryReplies,
|
||||||
ourUuid,
|
ourUuid,
|
||||||
}: {
|
}: {
|
||||||
conversationId: string;
|
conversationId: string;
|
||||||
isGroup?: boolean;
|
includeStoryReplies: boolean;
|
||||||
ourUuid: UUIDStringType;
|
ourUuid: UUIDStringType;
|
||||||
}): MessageType | undefined {
|
}): MessageType | undefined {
|
||||||
const db = getInstance();
|
const db = getInstance();
|
||||||
|
@ -2666,7 +2681,7 @@ function getLastConversationActivity({
|
||||||
conversationId = $conversationId AND
|
conversationId = $conversationId AND
|
||||||
shouldAffectActivity IS 1 AND
|
shouldAffectActivity IS 1 AND
|
||||||
isTimerChangeFromSync IS 0 AND
|
isTimerChangeFromSync IS 0 AND
|
||||||
${isGroup ? 'storyId IS NULL AND' : ''}
|
${includeStoryReplies ? '' : 'storyId IS NULL AND'}
|
||||||
isGroupLeaveEventFromOther IS 0
|
isGroupLeaveEventFromOther IS 0
|
||||||
ORDER BY received_at DESC, sent_at DESC
|
ORDER BY received_at DESC, sent_at DESC
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
|
@ -2684,10 +2699,10 @@ function getLastConversationActivity({
|
||||||
}
|
}
|
||||||
function getLastConversationPreview({
|
function getLastConversationPreview({
|
||||||
conversationId,
|
conversationId,
|
||||||
isGroup,
|
includeStoryReplies,
|
||||||
}: {
|
}: {
|
||||||
conversationId: string;
|
conversationId: string;
|
||||||
isGroup?: boolean;
|
includeStoryReplies: boolean;
|
||||||
}): MessageType | undefined {
|
}): MessageType | undefined {
|
||||||
const db = getInstance();
|
const db = getInstance();
|
||||||
const row = prepare(
|
const row = prepare(
|
||||||
|
@ -2698,7 +2713,7 @@ function getLastConversationPreview({
|
||||||
conversationId = $conversationId AND
|
conversationId = $conversationId AND
|
||||||
shouldAffectPreview IS 1 AND
|
shouldAffectPreview IS 1 AND
|
||||||
isGroupLeaveEventFromOther IS 0 AND
|
isGroupLeaveEventFromOther IS 0 AND
|
||||||
${isGroup ? 'storyId IS NULL AND' : ''}
|
${includeStoryReplies ? '' : 'storyId IS NULL AND'}
|
||||||
(
|
(
|
||||||
expiresAt IS NULL
|
expiresAt IS NULL
|
||||||
OR
|
OR
|
||||||
|
@ -2721,11 +2736,11 @@ function getLastConversationPreview({
|
||||||
|
|
||||||
async function getConversationMessageStats({
|
async function getConversationMessageStats({
|
||||||
conversationId,
|
conversationId,
|
||||||
isGroup,
|
includeStoryReplies,
|
||||||
ourUuid,
|
ourUuid,
|
||||||
}: {
|
}: {
|
||||||
conversationId: string;
|
conversationId: string;
|
||||||
isGroup?: boolean;
|
includeStoryReplies: boolean;
|
||||||
ourUuid: UUIDStringType;
|
ourUuid: UUIDStringType;
|
||||||
}): Promise<ConversationMessageStatsType> {
|
}): Promise<ConversationMessageStatsType> {
|
||||||
const db = getInstance();
|
const db = getInstance();
|
||||||
|
@ -2734,10 +2749,13 @@ async function getConversationMessageStats({
|
||||||
return {
|
return {
|
||||||
activity: getLastConversationActivity({
|
activity: getLastConversationActivity({
|
||||||
conversationId,
|
conversationId,
|
||||||
isGroup,
|
includeStoryReplies,
|
||||||
ourUuid,
|
ourUuid,
|
||||||
}),
|
}),
|
||||||
preview: getLastConversationPreview({ conversationId, isGroup }),
|
preview: getLastConversationPreview({
|
||||||
|
conversationId,
|
||||||
|
includeStoryReplies,
|
||||||
|
}),
|
||||||
hasUserInitiatedMessages: hasUserInitiatedMessages(conversationId),
|
hasUserInitiatedMessages: hasUserInitiatedMessages(conversationId),
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
@ -2771,8 +2789,13 @@ async function getLastConversationMessage({
|
||||||
|
|
||||||
function getOldestUnseenMessageForConversation(
|
function getOldestUnseenMessageForConversation(
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
storyId?: UUIDStringType,
|
{
|
||||||
isGroup?: boolean
|
storyId,
|
||||||
|
includeStoryReplies,
|
||||||
|
}: {
|
||||||
|
storyId?: UUIDStringType;
|
||||||
|
includeStoryReplies: boolean;
|
||||||
|
}
|
||||||
): MessageMetricsType | undefined {
|
): MessageMetricsType | undefined {
|
||||||
const db = getInstance();
|
const db = getInstance();
|
||||||
const row = db
|
const row = db
|
||||||
|
@ -2782,7 +2805,7 @@ function getOldestUnseenMessageForConversation(
|
||||||
conversationId = $conversationId AND
|
conversationId = $conversationId AND
|
||||||
seenStatus = ${SeenStatus.Unseen} AND
|
seenStatus = ${SeenStatus.Unseen} AND
|
||||||
isStory IS 0 AND
|
isStory IS 0 AND
|
||||||
(${_storyIdPredicate(storyId, isGroup)})
|
(${_storyIdPredicate(storyId, includeStoryReplies)})
|
||||||
ORDER BY received_at ASC, sent_at ASC
|
ORDER BY received_at ASC, sent_at ASC
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
`
|
`
|
||||||
|
@ -2803,7 +2826,7 @@ async function getTotalUnreadForConversation(
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
options: {
|
options: {
|
||||||
storyId: UUIDStringType | undefined;
|
storyId: UUIDStringType | undefined;
|
||||||
isGroup: boolean;
|
includeStoryReplies: boolean;
|
||||||
}
|
}
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
return getTotalUnreadForConversationSync(conversationId, options);
|
return getTotalUnreadForConversationSync(conversationId, options);
|
||||||
|
@ -2812,10 +2835,10 @@ function getTotalUnreadForConversationSync(
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
{
|
{
|
||||||
storyId,
|
storyId,
|
||||||
isGroup,
|
includeStoryReplies,
|
||||||
}: {
|
}: {
|
||||||
storyId: UUIDStringType | undefined;
|
storyId: UUIDStringType | undefined;
|
||||||
isGroup: boolean;
|
includeStoryReplies: boolean;
|
||||||
}
|
}
|
||||||
): number {
|
): number {
|
||||||
const db = getInstance();
|
const db = getInstance();
|
||||||
|
@ -2828,7 +2851,7 @@ function getTotalUnreadForConversationSync(
|
||||||
conversationId = $conversationId AND
|
conversationId = $conversationId AND
|
||||||
readStatus = ${ReadStatus.Unread} AND
|
readStatus = ${ReadStatus.Unread} AND
|
||||||
isStory IS 0 AND
|
isStory IS 0 AND
|
||||||
(${_storyIdPredicate(storyId, isGroup)})
|
(${_storyIdPredicate(storyId, includeStoryReplies)})
|
||||||
`
|
`
|
||||||
)
|
)
|
||||||
.get({
|
.get({
|
||||||
|
@ -2844,8 +2867,13 @@ function getTotalUnreadForConversationSync(
|
||||||
}
|
}
|
||||||
function getTotalUnseenForConversationSync(
|
function getTotalUnseenForConversationSync(
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
storyId?: UUIDStringType,
|
{
|
||||||
isGroup?: boolean
|
storyId,
|
||||||
|
includeStoryReplies,
|
||||||
|
}: {
|
||||||
|
storyId?: UUIDStringType;
|
||||||
|
includeStoryReplies: boolean;
|
||||||
|
}
|
||||||
): number {
|
): number {
|
||||||
const db = getInstance();
|
const db = getInstance();
|
||||||
const row = db
|
const row = db
|
||||||
|
@ -2857,7 +2885,7 @@ function getTotalUnseenForConversationSync(
|
||||||
conversationId = $conversationId AND
|
conversationId = $conversationId AND
|
||||||
seenStatus = ${SeenStatus.Unseen} AND
|
seenStatus = ${SeenStatus.Unseen} AND
|
||||||
isStory IS 0 AND
|
isStory IS 0 AND
|
||||||
(${_storyIdPredicate(storyId, isGroup)})
|
(${_storyIdPredicate(storyId, includeStoryReplies)})
|
||||||
`
|
`
|
||||||
)
|
)
|
||||||
.get({
|
.get({
|
||||||
|
@ -2874,35 +2902,29 @@ function getTotalUnseenForConversationSync(
|
||||||
|
|
||||||
async function getMessageMetricsForConversation(
|
async function getMessageMetricsForConversation(
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
storyId?: UUIDStringType,
|
options: {
|
||||||
isGroup?: boolean
|
storyId?: UUIDStringType;
|
||||||
|
includeStoryReplies: boolean;
|
||||||
|
}
|
||||||
): Promise<ConversationMetricsType> {
|
): Promise<ConversationMetricsType> {
|
||||||
return getMessageMetricsForConversationSync(conversationId, storyId, isGroup);
|
return getMessageMetricsForConversationSync(conversationId, options);
|
||||||
}
|
}
|
||||||
function getMessageMetricsForConversationSync(
|
function getMessageMetricsForConversationSync(
|
||||||
conversationId: string,
|
conversationId: string,
|
||||||
storyId?: UUIDStringType,
|
options: {
|
||||||
isGroup?: boolean
|
storyId?: UUIDStringType;
|
||||||
|
includeStoryReplies: boolean;
|
||||||
|
}
|
||||||
): ConversationMetricsType {
|
): ConversationMetricsType {
|
||||||
const oldest = getOldestMessageForConversation(
|
const oldest = getOldestMessageForConversation(conversationId, options);
|
||||||
conversationId,
|
const newest = getNewestMessageForConversation(conversationId, options);
|
||||||
storyId,
|
|
||||||
isGroup
|
|
||||||
);
|
|
||||||
const newest = getNewestMessageForConversation(
|
|
||||||
conversationId,
|
|
||||||
storyId,
|
|
||||||
isGroup
|
|
||||||
);
|
|
||||||
const oldestUnseen = getOldestUnseenMessageForConversation(
|
const oldestUnseen = getOldestUnseenMessageForConversation(
|
||||||
conversationId,
|
conversationId,
|
||||||
storyId,
|
options
|
||||||
isGroup
|
|
||||||
);
|
);
|
||||||
const totalUnseen = getTotalUnseenForConversationSync(
|
const totalUnseen = getTotalUnseenForConversationSync(
|
||||||
conversationId,
|
conversationId,
|
||||||
storyId,
|
options
|
||||||
isGroup
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -2917,7 +2939,7 @@ function getMessageMetricsForConversationSync(
|
||||||
|
|
||||||
async function getConversationRangeCenteredOnMessage({
|
async function getConversationRangeCenteredOnMessage({
|
||||||
conversationId,
|
conversationId,
|
||||||
isGroup,
|
includeStoryReplies,
|
||||||
limit,
|
limit,
|
||||||
messageId,
|
messageId,
|
||||||
receivedAt,
|
receivedAt,
|
||||||
|
@ -2925,7 +2947,7 @@ async function getConversationRangeCenteredOnMessage({
|
||||||
storyId,
|
storyId,
|
||||||
}: {
|
}: {
|
||||||
conversationId: string;
|
conversationId: string;
|
||||||
isGroup: boolean;
|
includeStoryReplies: boolean;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
messageId: string;
|
messageId: string;
|
||||||
receivedAt: number;
|
receivedAt: number;
|
||||||
|
@ -2939,7 +2961,7 @@ async function getConversationRangeCenteredOnMessage({
|
||||||
return db.transaction(() => {
|
return db.transaction(() => {
|
||||||
return {
|
return {
|
||||||
older: getOlderMessagesByConversationSync(conversationId, {
|
older: getOlderMessagesByConversationSync(conversationId, {
|
||||||
isGroup,
|
includeStoryReplies,
|
||||||
limit,
|
limit,
|
||||||
messageId,
|
messageId,
|
||||||
receivedAt,
|
receivedAt,
|
||||||
|
@ -2947,17 +2969,16 @@ async function getConversationRangeCenteredOnMessage({
|
||||||
storyId,
|
storyId,
|
||||||
}),
|
}),
|
||||||
newer: getNewerMessagesByConversationSync(conversationId, {
|
newer: getNewerMessagesByConversationSync(conversationId, {
|
||||||
isGroup,
|
includeStoryReplies,
|
||||||
limit,
|
limit,
|
||||||
receivedAt,
|
receivedAt,
|
||||||
sentAt,
|
sentAt,
|
||||||
storyId,
|
storyId,
|
||||||
}),
|
}),
|
||||||
metrics: getMessageMetricsForConversationSync(
|
metrics: getMessageMetricsForConversationSync(conversationId, {
|
||||||
conversationId,
|
|
||||||
storyId,
|
storyId,
|
||||||
isGroup
|
includeStoryReplies,
|
||||||
),
|
}),
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|
|
@ -392,7 +392,11 @@ function loadStoryReplies(
|
||||||
const conversation = getConversationSelector(getState())(conversationId);
|
const conversation = getConversationSelector(getState())(conversationId);
|
||||||
const replies = await dataInterface.getOlderMessagesByConversation(
|
const replies = await dataInterface.getOlderMessagesByConversation(
|
||||||
conversationId,
|
conversationId,
|
||||||
{ limit: 9000, storyId: messageId, isGroup: isGroup(conversation) }
|
{
|
||||||
|
limit: 9000,
|
||||||
|
storyId: messageId,
|
||||||
|
includeStoryReplies: !isGroup(conversation),
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
|
|
|
@ -70,6 +70,7 @@ describe('sql/conversationSummary', () => {
|
||||||
const messages = await getConversationMessageStats({
|
const messages = await getConversationMessageStats({
|
||||||
conversationId,
|
conversationId,
|
||||||
ourUuid,
|
ourUuid,
|
||||||
|
includeStoryReplies: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.strictEqual(messages.activity?.body, message2.body, 'activity');
|
assert.strictEqual(messages.activity?.body, message2.body, 'activity');
|
||||||
|
@ -122,7 +123,7 @@ describe('sql/conversationSummary', () => {
|
||||||
|
|
||||||
const messages = await getConversationMessageStats({
|
const messages = await getConversationMessageStats({
|
||||||
conversationId,
|
conversationId,
|
||||||
isGroup: true,
|
includeStoryReplies: false,
|
||||||
ourUuid,
|
ourUuid,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -215,6 +216,7 @@ describe('sql/conversationSummary', () => {
|
||||||
const messages = await getConversationMessageStats({
|
const messages = await getConversationMessageStats({
|
||||||
conversationId,
|
conversationId,
|
||||||
ourUuid,
|
ourUuid,
|
||||||
|
includeStoryReplies: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.strictEqual(messages.preview?.body, message1.body);
|
assert.strictEqual(messages.preview?.body, message1.body);
|
||||||
|
@ -322,6 +324,7 @@ describe('sql/conversationSummary', () => {
|
||||||
const messages = await getConversationMessageStats({
|
const messages = await getConversationMessageStats({
|
||||||
conversationId,
|
conversationId,
|
||||||
ourUuid,
|
ourUuid,
|
||||||
|
includeStoryReplies: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.strictEqual(messages.activity?.body, message1.body);
|
assert.strictEqual(messages.activity?.body, message1.body);
|
||||||
|
@ -370,6 +373,7 @@ describe('sql/conversationSummary', () => {
|
||||||
const messages = await getConversationMessageStats({
|
const messages = await getConversationMessageStats({
|
||||||
conversationId,
|
conversationId,
|
||||||
ourUuid,
|
ourUuid,
|
||||||
|
includeStoryReplies: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.strictEqual(messages.activity?.body, message1.body);
|
assert.strictEqual(messages.activity?.body, message1.body);
|
||||||
|
@ -419,6 +423,7 @@ describe('sql/conversationSummary', () => {
|
||||||
const messages = await getConversationMessageStats({
|
const messages = await getConversationMessageStats({
|
||||||
conversationId,
|
conversationId,
|
||||||
ourUuid,
|
ourUuid,
|
||||||
|
includeStoryReplies: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.strictEqual(messages.activity?.body, message1.body);
|
assert.strictEqual(messages.activity?.body, message1.body);
|
||||||
|
@ -461,6 +466,7 @@ describe('sql/conversationSummary', () => {
|
||||||
const messages = await getConversationMessageStats({
|
const messages = await getConversationMessageStats({
|
||||||
conversationId,
|
conversationId,
|
||||||
ourUuid,
|
ourUuid,
|
||||||
|
includeStoryReplies: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.strictEqual(messages.preview?.body, message1.body);
|
assert.strictEqual(messages.preview?.body, message1.body);
|
||||||
|
@ -505,6 +511,7 @@ describe('sql/conversationSummary', () => {
|
||||||
const messages = await getConversationMessageStats({
|
const messages = await getConversationMessageStats({
|
||||||
conversationId,
|
conversationId,
|
||||||
ourUuid,
|
ourUuid,
|
||||||
|
includeStoryReplies: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.strictEqual(messages.preview?.body, message1.body);
|
assert.strictEqual(messages.preview?.body, message1.body);
|
||||||
|
@ -564,6 +571,7 @@ describe('sql/conversationSummary', () => {
|
||||||
const messages = await getConversationMessageStats({
|
const messages = await getConversationMessageStats({
|
||||||
conversationId,
|
conversationId,
|
||||||
ourUuid,
|
ourUuid,
|
||||||
|
includeStoryReplies: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.strictEqual(messages.activity?.body, message1.body, 'activity');
|
assert.strictEqual(messages.activity?.body, message1.body, 'activity');
|
||||||
|
|
|
@ -41,7 +41,7 @@ describe('sql/markRead', () => {
|
||||||
const conversationId = getUuid();
|
const conversationId = getUuid();
|
||||||
const ourUuid = getUuid();
|
const ourUuid = getUuid();
|
||||||
|
|
||||||
const message1: MessageAttributesType = {
|
const oldest: MessageAttributesType = {
|
||||||
id: getUuid(),
|
id: getUuid(),
|
||||||
body: 'message 1',
|
body: 'message 1',
|
||||||
type: 'incoming',
|
type: 'incoming',
|
||||||
|
@ -51,7 +51,7 @@ describe('sql/markRead', () => {
|
||||||
timestamp: start + 1,
|
timestamp: start + 1,
|
||||||
readStatus: ReadStatus.Read,
|
readStatus: ReadStatus.Read,
|
||||||
};
|
};
|
||||||
const message2: MessageAttributesType = {
|
const oldestUnread: MessageAttributesType = {
|
||||||
id: getUuid(),
|
id: getUuid(),
|
||||||
body: 'message 2',
|
body: 'message 2',
|
||||||
type: 'incoming',
|
type: 'incoming',
|
||||||
|
@ -61,7 +61,7 @@ describe('sql/markRead', () => {
|
||||||
timestamp: start + 2,
|
timestamp: start + 2,
|
||||||
readStatus: ReadStatus.Unread,
|
readStatus: ReadStatus.Unread,
|
||||||
};
|
};
|
||||||
const message3: MessageAttributesType = {
|
const unreadInAnotherConvo: MessageAttributesType = {
|
||||||
id: getUuid(),
|
id: getUuid(),
|
||||||
body: 'message 3',
|
body: 'message 3',
|
||||||
type: 'incoming',
|
type: 'incoming',
|
||||||
|
@ -71,7 +71,7 @@ describe('sql/markRead', () => {
|
||||||
timestamp: start + 3,
|
timestamp: start + 3,
|
||||||
readStatus: ReadStatus.Unread,
|
readStatus: ReadStatus.Unread,
|
||||||
};
|
};
|
||||||
const message4: MessageAttributesType = {
|
const unread: MessageAttributesType = {
|
||||||
id: getUuid(),
|
id: getUuid(),
|
||||||
body: 'message 4',
|
body: 'message 4',
|
||||||
type: 'incoming',
|
type: 'incoming',
|
||||||
|
@ -81,7 +81,7 @@ describe('sql/markRead', () => {
|
||||||
timestamp: start + 4,
|
timestamp: start + 4,
|
||||||
readStatus: ReadStatus.Unread,
|
readStatus: ReadStatus.Unread,
|
||||||
};
|
};
|
||||||
const message5: MessageAttributesType = {
|
const unreadStory: MessageAttributesType = {
|
||||||
id: getUuid(),
|
id: getUuid(),
|
||||||
body: 'message 5',
|
body: 'message 5',
|
||||||
type: 'story',
|
type: 'story',
|
||||||
|
@ -92,7 +92,7 @@ describe('sql/markRead', () => {
|
||||||
readStatus: ReadStatus.Unread,
|
readStatus: ReadStatus.Unread,
|
||||||
storyId: getUuid(),
|
storyId: getUuid(),
|
||||||
};
|
};
|
||||||
const message6: MessageAttributesType = {
|
const unreadStoryReply: MessageAttributesType = {
|
||||||
id: getUuid(),
|
id: getUuid(),
|
||||||
body: 'message 6',
|
body: 'message 6',
|
||||||
type: 'incoming',
|
type: 'incoming',
|
||||||
|
@ -103,7 +103,7 @@ describe('sql/markRead', () => {
|
||||||
readStatus: ReadStatus.Unread,
|
readStatus: ReadStatus.Unread,
|
||||||
storyId: getUuid(),
|
storyId: getUuid(),
|
||||||
};
|
};
|
||||||
const message7: MessageAttributesType = {
|
const newestUnread: MessageAttributesType = {
|
||||||
id: getUuid(),
|
id: getUuid(),
|
||||||
body: 'message 7',
|
body: 'message 7',
|
||||||
type: 'incoming',
|
type: 'incoming',
|
||||||
|
@ -115,7 +115,15 @@ describe('sql/markRead', () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
await saveMessages(
|
await saveMessages(
|
||||||
[message1, message2, message3, message4, message5, message6, message7],
|
[
|
||||||
|
oldest,
|
||||||
|
oldestUnread,
|
||||||
|
unreadInAnotherConvo,
|
||||||
|
unread,
|
||||||
|
unreadStory,
|
||||||
|
unreadStoryReply,
|
||||||
|
newestUnread,
|
||||||
|
],
|
||||||
{
|
{
|
||||||
forceSave: true,
|
forceSave: true,
|
||||||
ourUuid,
|
ourUuid,
|
||||||
|
@ -126,56 +134,68 @@ describe('sql/markRead', () => {
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
await getTotalUnreadForConversation(conversationId, {
|
await getTotalUnreadForConversation(conversationId, {
|
||||||
storyId: undefined,
|
storyId: undefined,
|
||||||
isGroup: false,
|
includeStoryReplies: false,
|
||||||
}),
|
}),
|
||||||
4,
|
3,
|
||||||
'unread count'
|
'no stories/unread count - before'
|
||||||
);
|
);
|
||||||
|
|
||||||
const markedRead = await getUnreadByConversationAndMarkRead({
|
const markedRead = await getUnreadByConversationAndMarkRead({
|
||||||
conversationId,
|
conversationId,
|
||||||
newestUnreadAt: message4.received_at,
|
newestUnreadAt: unreadStoryReply.received_at,
|
||||||
readAt,
|
readAt,
|
||||||
|
includeStoryReplies: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.lengthOf(markedRead, 2, 'two messages marked read');
|
assert.lengthOf(markedRead, 2, 'no stories/two messages marked read');
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
await getTotalUnreadForConversation(conversationId, {
|
await getTotalUnreadForConversation(conversationId, {
|
||||||
storyId: undefined,
|
storyId: undefined,
|
||||||
isGroup: false,
|
includeStoryReplies: false,
|
||||||
}),
|
}),
|
||||||
2,
|
1,
|
||||||
'unread count'
|
'no stories/unread count - after'
|
||||||
);
|
);
|
||||||
|
|
||||||
// Sorted in descending order
|
// Sorted in descending order
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
markedRead[0].id,
|
markedRead[0].id,
|
||||||
message4.id,
|
unread.id,
|
||||||
'first should be message4'
|
'no stories/first should be "unread" message'
|
||||||
);
|
);
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
markedRead[1].id,
|
markedRead[1].id,
|
||||||
message2.id,
|
oldestUnread.id,
|
||||||
'second should be message2'
|
'no stories/second should be oldestUnread'
|
||||||
);
|
);
|
||||||
|
|
||||||
const markedRead2 = await getUnreadByConversationAndMarkRead({
|
const markedRead2 = await getUnreadByConversationAndMarkRead({
|
||||||
conversationId,
|
conversationId,
|
||||||
newestUnreadAt: message7.received_at,
|
newestUnreadAt: newestUnread.received_at,
|
||||||
readAt,
|
readAt,
|
||||||
|
includeStoryReplies: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.lengthOf(markedRead2, 2, 'two messages marked read');
|
assert.lengthOf(markedRead2, 2, 'with stories/two messages marked read');
|
||||||
assert.strictEqual(markedRead2[0].id, message7.id, 'should be message7');
|
|
||||||
|
assert.strictEqual(
|
||||||
|
markedRead2[0].id,
|
||||||
|
newestUnread.id,
|
||||||
|
'with stories/should be newestUnread'
|
||||||
|
);
|
||||||
|
assert.strictEqual(
|
||||||
|
markedRead2[1].id,
|
||||||
|
unreadStoryReply.id,
|
||||||
|
'with stories/should be unreadStoryReply'
|
||||||
|
);
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
await getTotalUnreadForConversation(conversationId, {
|
await getTotalUnreadForConversation(conversationId, {
|
||||||
storyId: undefined,
|
storyId: undefined,
|
||||||
isGroup: false,
|
includeStoryReplies: true,
|
||||||
}),
|
}),
|
||||||
0,
|
0,
|
||||||
'unread count'
|
'with stories/unread count'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -281,6 +301,7 @@ describe('sql/markRead', () => {
|
||||||
newestUnreadAt: message7.received_at,
|
newestUnreadAt: message7.received_at,
|
||||||
readAt,
|
readAt,
|
||||||
storyId,
|
storyId,
|
||||||
|
includeStoryReplies: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.lengthOf(markedRead, 3, 'three messages marked read');
|
assert.lengthOf(markedRead, 3, 'three messages marked read');
|
||||||
|
@ -377,7 +398,7 @@ describe('sql/markRead', () => {
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
await getTotalUnreadForConversation(conversationId, {
|
await getTotalUnreadForConversation(conversationId, {
|
||||||
storyId: undefined,
|
storyId: undefined,
|
||||||
isGroup: false,
|
includeStoryReplies: true,
|
||||||
}),
|
}),
|
||||||
2,
|
2,
|
||||||
'unread count'
|
'unread count'
|
||||||
|
@ -388,6 +409,7 @@ describe('sql/markRead', () => {
|
||||||
conversationId,
|
conversationId,
|
||||||
newestUnreadAt: message4.received_at,
|
newestUnreadAt: message4.received_at,
|
||||||
readAt,
|
readAt,
|
||||||
|
includeStoryReplies: false,
|
||||||
now,
|
now,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -400,7 +422,7 @@ describe('sql/markRead', () => {
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
await getTotalUnreadForConversation(conversationId, {
|
await getTotalUnreadForConversation(conversationId, {
|
||||||
storyId: undefined,
|
storyId: undefined,
|
||||||
isGroup: false,
|
includeStoryReplies: true,
|
||||||
}),
|
}),
|
||||||
1,
|
1,
|
||||||
'unread count'
|
'unread count'
|
||||||
|
@ -798,7 +820,7 @@ describe('sql/markRead', () => {
|
||||||
|
|
||||||
const markedRead = await getUnreadByConversationAndMarkRead({
|
const markedRead = await getUnreadByConversationAndMarkRead({
|
||||||
conversationId,
|
conversationId,
|
||||||
isGroup: true,
|
includeStoryReplies: false,
|
||||||
newestUnreadAt: message4.received_at,
|
newestUnreadAt: message4.received_at,
|
||||||
readAt,
|
readAt,
|
||||||
});
|
});
|
||||||
|
|
|
@ -93,7 +93,7 @@ describe('sql/timelineFetches', () => {
|
||||||
assert.lengthOf(await _getAllMessages(), 5);
|
assert.lengthOf(await _getAllMessages(), 5);
|
||||||
|
|
||||||
const messages = await getOlderMessagesByConversation(conversationId, {
|
const messages = await getOlderMessagesByConversation(conversationId, {
|
||||||
isGroup: false,
|
includeStoryReplies: true,
|
||||||
limit: 5,
|
limit: 5,
|
||||||
storyId: undefined,
|
storyId: undefined,
|
||||||
});
|
});
|
||||||
|
@ -150,7 +150,7 @@ describe('sql/timelineFetches', () => {
|
||||||
assert.lengthOf(await _getAllMessages(), 3);
|
assert.lengthOf(await _getAllMessages(), 3);
|
||||||
|
|
||||||
const messages = await getOlderMessagesByConversation(conversationId, {
|
const messages = await getOlderMessagesByConversation(conversationId, {
|
||||||
isGroup: true,
|
includeStoryReplies: false,
|
||||||
limit: 5,
|
limit: 5,
|
||||||
storyId,
|
storyId,
|
||||||
});
|
});
|
||||||
|
@ -204,7 +204,7 @@ describe('sql/timelineFetches', () => {
|
||||||
assert.lengthOf(await _getAllMessages(), 3);
|
assert.lengthOf(await _getAllMessages(), 3);
|
||||||
|
|
||||||
const messages = await getOlderMessagesByConversation(conversationId, {
|
const messages = await getOlderMessagesByConversation(conversationId, {
|
||||||
isGroup: true,
|
includeStoryReplies: false,
|
||||||
limit: 5,
|
limit: 5,
|
||||||
storyId: undefined,
|
storyId: undefined,
|
||||||
});
|
});
|
||||||
|
@ -255,7 +255,7 @@ describe('sql/timelineFetches', () => {
|
||||||
assert.lengthOf(await _getAllMessages(), 3);
|
assert.lengthOf(await _getAllMessages(), 3);
|
||||||
|
|
||||||
const messages = await getOlderMessagesByConversation(conversationId, {
|
const messages = await getOlderMessagesByConversation(conversationId, {
|
||||||
isGroup: true,
|
includeStoryReplies: false,
|
||||||
limit: 5,
|
limit: 5,
|
||||||
receivedAt: target,
|
receivedAt: target,
|
||||||
sentAt: target,
|
sentAt: target,
|
||||||
|
@ -308,7 +308,7 @@ describe('sql/timelineFetches', () => {
|
||||||
assert.lengthOf(await _getAllMessages(), 3);
|
assert.lengthOf(await _getAllMessages(), 3);
|
||||||
|
|
||||||
const messages = await getOlderMessagesByConversation(conversationId, {
|
const messages = await getOlderMessagesByConversation(conversationId, {
|
||||||
isGroup: true,
|
includeStoryReplies: false,
|
||||||
limit: 5,
|
limit: 5,
|
||||||
receivedAt: target,
|
receivedAt: target,
|
||||||
sentAt: target,
|
sentAt: target,
|
||||||
|
@ -365,7 +365,7 @@ describe('sql/timelineFetches', () => {
|
||||||
assert.lengthOf(await _getAllMessages(), 3);
|
assert.lengthOf(await _getAllMessages(), 3);
|
||||||
|
|
||||||
const messages = await getOlderMessagesByConversation(conversationId, {
|
const messages = await getOlderMessagesByConversation(conversationId, {
|
||||||
isGroup: true,
|
includeStoryReplies: false,
|
||||||
limit: 5,
|
limit: 5,
|
||||||
messageId: message2.id,
|
messageId: message2.id,
|
||||||
receivedAt: target,
|
receivedAt: target,
|
||||||
|
@ -443,7 +443,7 @@ describe('sql/timelineFetches', () => {
|
||||||
assert.lengthOf(await _getAllMessages(), 5);
|
assert.lengthOf(await _getAllMessages(), 5);
|
||||||
|
|
||||||
const messages = await getNewerMessagesByConversation(conversationId, {
|
const messages = await getNewerMessagesByConversation(conversationId, {
|
||||||
isGroup: false,
|
includeStoryReplies: true,
|
||||||
limit: 5,
|
limit: 5,
|
||||||
storyId: undefined,
|
storyId: undefined,
|
||||||
});
|
});
|
||||||
|
@ -499,7 +499,7 @@ describe('sql/timelineFetches', () => {
|
||||||
assert.lengthOf(await _getAllMessages(), 3);
|
assert.lengthOf(await _getAllMessages(), 3);
|
||||||
|
|
||||||
const messages = await getNewerMessagesByConversation(conversationId, {
|
const messages = await getNewerMessagesByConversation(conversationId, {
|
||||||
isGroup: true,
|
includeStoryReplies: false,
|
||||||
limit: 5,
|
limit: 5,
|
||||||
storyId,
|
storyId,
|
||||||
});
|
});
|
||||||
|
@ -551,7 +551,7 @@ describe('sql/timelineFetches', () => {
|
||||||
assert.lengthOf(await _getAllMessages(), 3);
|
assert.lengthOf(await _getAllMessages(), 3);
|
||||||
|
|
||||||
const messages = await getNewerMessagesByConversation(conversationId, {
|
const messages = await getNewerMessagesByConversation(conversationId, {
|
||||||
isGroup: true,
|
includeStoryReplies: false,
|
||||||
limit: 5,
|
limit: 5,
|
||||||
receivedAt: target,
|
receivedAt: target,
|
||||||
sentAt: target,
|
sentAt: target,
|
||||||
|
@ -606,7 +606,7 @@ describe('sql/timelineFetches', () => {
|
||||||
assert.lengthOf(await _getAllMessages(), 3);
|
assert.lengthOf(await _getAllMessages(), 3);
|
||||||
|
|
||||||
const messages = await getNewerMessagesByConversation(conversationId, {
|
const messages = await getNewerMessagesByConversation(conversationId, {
|
||||||
isGroup: true,
|
includeStoryReplies: false,
|
||||||
limit: 5,
|
limit: 5,
|
||||||
storyId: undefined,
|
storyId: undefined,
|
||||||
receivedAt: target,
|
receivedAt: target,
|
||||||
|
@ -659,7 +659,7 @@ describe('sql/timelineFetches', () => {
|
||||||
assert.lengthOf(await _getAllMessages(), 3);
|
assert.lengthOf(await _getAllMessages(), 3);
|
||||||
|
|
||||||
const messages = await getNewerMessagesByConversation(conversationId, {
|
const messages = await getNewerMessagesByConversation(conversationId, {
|
||||||
isGroup: true,
|
includeStoryReplies: false,
|
||||||
limit: 5,
|
limit: 5,
|
||||||
receivedAt: target,
|
receivedAt: target,
|
||||||
sentAt: target,
|
sentAt: target,
|
||||||
|
@ -778,24 +778,23 @@ describe('sql/timelineFetches', () => {
|
||||||
assert.lengthOf(await _getAllMessages(), 8);
|
assert.lengthOf(await _getAllMessages(), 8);
|
||||||
|
|
||||||
const metricsInTimeline = await getMessageMetricsForConversation(
|
const metricsInTimeline = await getMessageMetricsForConversation(
|
||||||
conversationId
|
conversationId,
|
||||||
);
|
{
|
||||||
assert.strictEqual(
|
includeStoryReplies: false,
|
||||||
metricsInTimeline?.oldest?.id,
|
}
|
||||||
oldestInStory.id,
|
|
||||||
'oldest'
|
|
||||||
);
|
);
|
||||||
|
assert.strictEqual(metricsInTimeline?.oldest?.id, oldest.id, 'oldest');
|
||||||
assert.strictEqual(metricsInTimeline?.newest?.id, newest.id, 'newest');
|
assert.strictEqual(metricsInTimeline?.newest?.id, newest.id, 'newest');
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
metricsInTimeline?.oldestUnseen?.id,
|
metricsInTimeline?.oldestUnseen?.id,
|
||||||
oldestUnseen.id,
|
oldestUnseen.id,
|
||||||
'oldestUnseen'
|
'oldestUnseen'
|
||||||
);
|
);
|
||||||
assert.strictEqual(metricsInTimeline?.totalUnseen, 3, 'totalUnseen');
|
assert.strictEqual(metricsInTimeline?.totalUnseen, 2, 'totalUnseen');
|
||||||
|
|
||||||
const metricsInStory = await getMessageMetricsForConversation(
|
const metricsInStory = await getMessageMetricsForConversation(
|
||||||
conversationId,
|
conversationId,
|
||||||
storyId
|
{ storyId, includeStoryReplies: true }
|
||||||
);
|
);
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
metricsInStory?.oldest?.id,
|
metricsInStory?.oldest?.id,
|
||||||
|
|
|
@ -1643,11 +1643,12 @@ describe('SQL migrations test', () => {
|
||||||
|
|
||||||
function insertPredicate(
|
function insertPredicate(
|
||||||
query: string,
|
query: string,
|
||||||
storyId: string | undefined
|
storyId: string | undefined,
|
||||||
|
includeStoryReplies: boolean
|
||||||
): string {
|
): string {
|
||||||
return query.replaceAll(
|
return query.replaceAll(
|
||||||
':story_id_predicate:',
|
':story_id_predicate:',
|
||||||
_storyIdPredicate(storyId)
|
_storyIdPredicate(storyId, includeStoryReplies)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1657,7 +1658,7 @@ describe('SQL migrations test', () => {
|
||||||
for (const storyId of ['123', undefined]) {
|
for (const storyId of ['123', undefined]) {
|
||||||
for (const { query, index } of queries) {
|
for (const { query, index } of queries) {
|
||||||
const details = db
|
const details = db
|
||||||
.prepare(insertPredicate(query, storyId))
|
.prepare(insertPredicate(query, storyId, true))
|
||||||
.all({ storyId })
|
.all({ storyId })
|
||||||
.map(({ detail }) => detail)
|
.map(({ detail }) => detail)
|
||||||
.join('\n');
|
.join('\n');
|
||||||
|
|
|
@ -33,7 +33,7 @@ export async function markConversationRead(
|
||||||
conversationId,
|
conversationId,
|
||||||
newestUnreadAt,
|
newestUnreadAt,
|
||||||
readAt: options.readAt,
|
readAt: options.readAt,
|
||||||
isGroup: isGroup(conversationAttrs),
|
includeStoryReplies: !isGroup(conversationAttrs),
|
||||||
}),
|
}),
|
||||||
window.Signal.Data.getUnreadReactionsAndMarkRead({
|
window.Signal.Data.getUnreadReactionsAndMarkRead({
|
||||||
conversationId,
|
conversationId,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue