Drop story replies from group timeline
This commit is contained in:
parent
e5ba00b798
commit
774246b6e2
10 changed files with 358 additions and 33 deletions
|
@ -85,6 +85,7 @@ import * as universalExpireTimer from '../util/universalExpireTimer';
|
|||
import type { GroupNameCollisionsWithIdsByTitle } from '../util/groupMemberNameCollisions';
|
||||
import {
|
||||
isDirectConversation,
|
||||
isGroup,
|
||||
isGroupV1,
|
||||
isGroupV2,
|
||||
isMe,
|
||||
|
@ -1375,10 +1376,16 @@ export class ConversationModel extends window.Backbone
|
|||
// Clear typing indicator for a given contact if we receive a message from them
|
||||
this.clearContactTypingTimer(typingToken);
|
||||
|
||||
if (!isStory(message.attributes)) {
|
||||
this.addSingleMessage(message);
|
||||
// If it's a group story reply or a story message, we don't want to update
|
||||
// the last message or add new messages to redux.
|
||||
const isGroupStoryReply =
|
||||
isGroup(this.attributes) && message.get('storyId');
|
||||
if (isGroupStoryReply || isStory(message.attributes)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.addSingleMessage(message);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
this.debouncedUpdateLastMessage!();
|
||||
}
|
||||
|
@ -1486,7 +1493,11 @@ export class ConversationModel extends window.Backbone
|
|||
}
|
||||
}
|
||||
|
||||
const metrics = await getMessageMetricsForConversation(conversationId);
|
||||
const metrics = await getMessageMetricsForConversation(
|
||||
conversationId,
|
||||
undefined,
|
||||
isGroup(this.attributes)
|
||||
);
|
||||
|
||||
// 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
|
||||
|
@ -1505,6 +1516,7 @@ export class ConversationModel extends window.Backbone
|
|||
}
|
||||
|
||||
const messages = await getOlderMessagesByConversation(conversationId, {
|
||||
isGroup: isGroup(this.attributes),
|
||||
limit: MESSAGE_LOAD_CHUNK_SIZE,
|
||||
});
|
||||
|
||||
|
@ -1556,6 +1568,7 @@ export class ConversationModel extends window.Backbone
|
|||
const receivedAt = message.received_at;
|
||||
const sentAt = message.sent_at;
|
||||
const models = await getOlderMessagesByConversation(conversationId, {
|
||||
isGroup: isGroup(this.attributes),
|
||||
receivedAt,
|
||||
sentAt,
|
||||
messageId: oldestMessageId,
|
||||
|
@ -1609,6 +1622,7 @@ export class ConversationModel extends window.Backbone
|
|||
const receivedAt = message.received_at;
|
||||
const sentAt = message.sent_at;
|
||||
const models = await getNewerMessagesByConversation(conversationId, {
|
||||
isGroup: isGroup(this.attributes),
|
||||
receivedAt,
|
||||
sentAt,
|
||||
limit: MESSAGE_LOAD_CHUNK_SIZE,
|
||||
|
@ -2047,6 +2061,7 @@ export class ConversationModel extends window.Backbone
|
|||
messages = await window.Signal.Data.getOlderMessagesByConversation(
|
||||
this.get('id'),
|
||||
{
|
||||
isGroup: isGroup(this.attributes),
|
||||
limit: 100,
|
||||
receivedAt: first ? first.received_at : undefined,
|
||||
sentAt: first ? first.sent_at : undefined,
|
||||
|
@ -4186,6 +4201,7 @@ export class ConversationModel extends window.Backbone
|
|||
const ourUuid = window.textsecure.storage.user.getCheckedUuid().toString();
|
||||
const stats = await window.Signal.Data.getConversationMessageStats({
|
||||
conversationId,
|
||||
isGroup: isGroup(this.attributes),
|
||||
ourUuid,
|
||||
});
|
||||
|
||||
|
|
|
@ -2542,9 +2542,12 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
}
|
||||
|
||||
const conversationTimestamp = conversation.get('timestamp');
|
||||
const isGroupStoryReply =
|
||||
isGroup(conversation.attributes) && message.get('storyId');
|
||||
if (
|
||||
!conversationTimestamp ||
|
||||
message.get('sent_at') > conversationTimestamp
|
||||
!isGroupStoryReply &&
|
||||
(!conversationTimestamp ||
|
||||
message.get('sent_at') > conversationTimestamp)
|
||||
) {
|
||||
conversation.set({
|
||||
lastMessage: message.getNotificationText(),
|
||||
|
@ -2626,7 +2629,10 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
const isFirstRun = false;
|
||||
await this.modifyTargetMessage(conversation, isFirstRun);
|
||||
|
||||
if (isMessageUnread(this.attributes)) {
|
||||
const isGroupStoryReply =
|
||||
isGroup(conversation.attributes) && this.get('storyId');
|
||||
|
||||
if (isMessageUnread(this.attributes) && !isGroupStoryReply) {
|
||||
await conversation.notify(this);
|
||||
}
|
||||
|
||||
|
@ -2722,6 +2728,9 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
|
||||
const viewSyncs = ViewSyncs.getSingleton().forMessage(message);
|
||||
|
||||
const isGroupStoryReply =
|
||||
isGroup(conversation.attributes) && message.get('storyId');
|
||||
|
||||
if (readSyncs.length !== 0 || viewSyncs.length !== 0) {
|
||||
const markReadAt = Math.min(
|
||||
Date.now(),
|
||||
|
@ -2758,7 +2767,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
this.pendingMarkRead ?? Date.now(),
|
||||
markReadAt
|
||||
);
|
||||
} else if (isFirstRun) {
|
||||
} else if (isFirstRun && !isGroupStoryReply) {
|
||||
conversation.set({
|
||||
unreadCount: (conversation.get('unreadCount') || 0) + 1,
|
||||
isArchived: false,
|
||||
|
|
|
@ -1177,6 +1177,7 @@ async function getTotalUnreadForConversation(
|
|||
|
||||
async function getUnreadByConversationAndMarkRead(options: {
|
||||
conversationId: string;
|
||||
isGroup?: boolean;
|
||||
newestUnreadAt: number;
|
||||
readAt?: number;
|
||||
storyId?: UUIDStringType;
|
||||
|
@ -1228,12 +1229,14 @@ function handleMessageJSON(
|
|||
async function getOlderMessagesByConversation(
|
||||
conversationId: string,
|
||||
{
|
||||
isGroup,
|
||||
limit = 100,
|
||||
messageId,
|
||||
receivedAt = Number.MAX_VALUE,
|
||||
sentAt = Number.MAX_VALUE,
|
||||
storyId,
|
||||
}: {
|
||||
isGroup?: boolean;
|
||||
limit?: number;
|
||||
messageId?: string;
|
||||
receivedAt?: number;
|
||||
|
@ -1244,6 +1247,7 @@ async function getOlderMessagesByConversation(
|
|||
const messages = await channels.getOlderMessagesByConversation(
|
||||
conversationId,
|
||||
{
|
||||
isGroup,
|
||||
limit,
|
||||
receivedAt,
|
||||
sentAt,
|
||||
|
@ -1267,11 +1271,13 @@ async function getOlderStories(options: {
|
|||
async function getNewerMessagesByConversation(
|
||||
conversationId: string,
|
||||
{
|
||||
isGroup,
|
||||
limit = 100,
|
||||
receivedAt = 0,
|
||||
sentAt = 0,
|
||||
storyId,
|
||||
}: {
|
||||
isGroup?: boolean;
|
||||
limit?: number;
|
||||
receivedAt?: number;
|
||||
sentAt?: number;
|
||||
|
@ -1281,6 +1287,7 @@ async function getNewerMessagesByConversation(
|
|||
const messages = await channels.getNewerMessagesByConversation(
|
||||
conversationId,
|
||||
{
|
||||
isGroup,
|
||||
limit,
|
||||
receivedAt,
|
||||
sentAt,
|
||||
|
@ -1292,14 +1299,17 @@ async function getNewerMessagesByConversation(
|
|||
}
|
||||
async function getConversationMessageStats({
|
||||
conversationId,
|
||||
isGroup,
|
||||
ourUuid,
|
||||
}: {
|
||||
conversationId: string;
|
||||
isGroup?: boolean;
|
||||
ourUuid: UUIDStringType;
|
||||
}): Promise<ConversationMessageStatsType> {
|
||||
const { preview, activity, hasUserInitiatedMessages } =
|
||||
await channels.getConversationMessageStats({
|
||||
conversationId,
|
||||
isGroup,
|
||||
ourUuid,
|
||||
});
|
||||
|
||||
|
@ -1318,11 +1328,13 @@ async function getLastConversationMessage({
|
|||
}
|
||||
async function getMessageMetricsForConversation(
|
||||
conversationId: string,
|
||||
storyId?: UUIDStringType
|
||||
storyId?: UUIDStringType,
|
||||
isGroup?: boolean
|
||||
) {
|
||||
const result = await channels.getMessageMetricsForConversation(
|
||||
conversationId,
|
||||
storyId
|
||||
storyId,
|
||||
isGroup
|
||||
);
|
||||
|
||||
return result;
|
||||
|
|
|
@ -388,6 +388,7 @@ export type DataInterface = {
|
|||
) => Promise<number>;
|
||||
getUnreadByConversationAndMarkRead: (options: {
|
||||
conversationId: string;
|
||||
isGroup?: boolean;
|
||||
newestUnreadAt: number;
|
||||
readAt?: number;
|
||||
storyId?: UUIDStringType;
|
||||
|
@ -448,11 +449,13 @@ export type DataInterface = {
|
|||
// getNewerMessagesByConversation is JSON on server, full message on Client
|
||||
getMessageMetricsForConversation: (
|
||||
conversationId: string,
|
||||
storyId?: UUIDStringType
|
||||
storyId?: UUIDStringType,
|
||||
isGroup?: boolean
|
||||
) => Promise<ConversationMetricsType>;
|
||||
// getConversationRangeCenteredOnMessage is JSON on server, full message on client
|
||||
getConversationMessageStats: (options: {
|
||||
conversationId: string;
|
||||
isGroup?: boolean;
|
||||
ourUuid: UUIDStringType;
|
||||
}) => Promise<ConversationMessageStatsType>;
|
||||
getLastConversationMessage(options: {
|
||||
|
@ -613,6 +616,7 @@ export type ServerInterface = DataInterface & {
|
|||
getOlderMessagesByConversation: (
|
||||
conversationId: string,
|
||||
options?: {
|
||||
isGroup?: boolean;
|
||||
limit?: number;
|
||||
messageId?: string;
|
||||
receivedAt?: number;
|
||||
|
@ -623,6 +627,7 @@ export type ServerInterface = DataInterface & {
|
|||
getNewerMessagesByConversation: (
|
||||
conversationId: string,
|
||||
options?: {
|
||||
isGroup?: boolean;
|
||||
limit?: number;
|
||||
receivedAt?: number;
|
||||
sentAt?: number;
|
||||
|
@ -683,6 +688,7 @@ export type ClientInterface = DataInterface & {
|
|||
getOlderMessagesByConversation: (
|
||||
conversationId: string,
|
||||
options: {
|
||||
isGroup?: boolean;
|
||||
limit?: number;
|
||||
messageId?: string;
|
||||
receivedAt?: number;
|
||||
|
@ -693,6 +699,7 @@ export type ClientInterface = DataInterface & {
|
|||
getNewerMessagesByConversation: (
|
||||
conversationId: string,
|
||||
options: {
|
||||
isGroup?: boolean;
|
||||
limit?: number;
|
||||
receivedAt?: number;
|
||||
sentAt?: number;
|
||||
|
|
|
@ -2030,8 +2030,11 @@ async function getMessageBySender({
|
|||
return jsonToObject(rows[0].json);
|
||||
}
|
||||
|
||||
export function _storyIdPredicate(storyId: string | undefined): string {
|
||||
if (storyId === undefined) {
|
||||
export function _storyIdPredicate(
|
||||
storyId: string | undefined,
|
||||
isGroup?: boolean
|
||||
): string {
|
||||
if (!isGroup && storyId === undefined) {
|
||||
// We could use 'TRUE' here, but it is better to require `$storyId`
|
||||
// parameter
|
||||
return '$storyId IS NULL';
|
||||
|
@ -2042,11 +2045,13 @@ export function _storyIdPredicate(storyId: string | undefined): string {
|
|||
|
||||
async function getUnreadByConversationAndMarkRead({
|
||||
conversationId,
|
||||
isGroup,
|
||||
newestUnreadAt,
|
||||
storyId,
|
||||
readAt,
|
||||
}: {
|
||||
conversationId: string;
|
||||
isGroup?: boolean;
|
||||
newestUnreadAt: number;
|
||||
storyId?: UUIDStringType;
|
||||
readAt?: number;
|
||||
|
@ -2070,7 +2075,7 @@ async function getUnreadByConversationAndMarkRead({
|
|||
) AND
|
||||
expireTimer > 0 AND
|
||||
conversationId = $conversationId AND
|
||||
(${_storyIdPredicate(storyId)}) AND
|
||||
(${_storyIdPredicate(storyId, isGroup)}) AND
|
||||
received_at <= $newestUnreadAt;
|
||||
`
|
||||
).run({
|
||||
|
@ -2089,7 +2094,7 @@ async function getUnreadByConversationAndMarkRead({
|
|||
WHERE
|
||||
readStatus = ${ReadStatus.Unread} AND
|
||||
conversationId = $conversationId AND
|
||||
(${_storyIdPredicate(storyId)}) AND
|
||||
(${_storyIdPredicate(storyId, isGroup)}) AND
|
||||
received_at <= $newestUnreadAt
|
||||
ORDER BY received_at DESC, sent_at DESC;
|
||||
`
|
||||
|
@ -2109,7 +2114,7 @@ async function getUnreadByConversationAndMarkRead({
|
|||
WHERE
|
||||
readStatus = ${ReadStatus.Unread} AND
|
||||
conversationId = $conversationId AND
|
||||
(${_storyIdPredicate(storyId)}) AND
|
||||
(${_storyIdPredicate(storyId, isGroup)}) AND
|
||||
received_at <= $newestUnreadAt;
|
||||
`
|
||||
).run({
|
||||
|
@ -2310,6 +2315,7 @@ async function _removeAllReactions(): Promise<void> {
|
|||
async function getOlderMessagesByConversation(
|
||||
conversationId: string,
|
||||
options?: {
|
||||
isGroup?: boolean;
|
||||
limit?: number;
|
||||
messageId?: string;
|
||||
receivedAt?: number;
|
||||
|
@ -2322,12 +2328,14 @@ async function getOlderMessagesByConversation(
|
|||
function getOlderMessagesByConversationSync(
|
||||
conversationId: string,
|
||||
{
|
||||
isGroup,
|
||||
limit = 100,
|
||||
messageId,
|
||||
receivedAt = Number.MAX_VALUE,
|
||||
sentAt = Number.MAX_VALUE,
|
||||
storyId,
|
||||
}: {
|
||||
isGroup?: boolean;
|
||||
limit?: number;
|
||||
messageId?: string;
|
||||
receivedAt?: number;
|
||||
|
@ -2344,7 +2352,7 @@ function getOlderMessagesByConversationSync(
|
|||
conversationId = $conversationId AND
|
||||
($messageId IS NULL OR id IS NOT $messageId) AND
|
||||
isStory IS 0 AND
|
||||
(${_storyIdPredicate(storyId)}) AND
|
||||
(${_storyIdPredicate(storyId, isGroup)}) AND
|
||||
(
|
||||
(received_at = $received_at AND sent_at < $sent_at) OR
|
||||
received_at < $received_at
|
||||
|
@ -2419,11 +2427,13 @@ async function getNewerMessagesByConversation(
|
|||
function getNewerMessagesByConversationSync(
|
||||
conversationId: string,
|
||||
{
|
||||
isGroup,
|
||||
limit = 100,
|
||||
receivedAt = 0,
|
||||
sentAt = 0,
|
||||
storyId,
|
||||
}: {
|
||||
isGroup?: boolean;
|
||||
limit?: number;
|
||||
receivedAt?: number;
|
||||
sentAt?: number;
|
||||
|
@ -2437,7 +2447,7 @@ function getNewerMessagesByConversationSync(
|
|||
SELECT json FROM messages WHERE
|
||||
conversationId = $conversationId AND
|
||||
isStory IS 0 AND
|
||||
(${_storyIdPredicate(storyId)}) AND
|
||||
(${_storyIdPredicate(storyId, isGroup)}) AND
|
||||
(
|
||||
(received_at = $received_at AND sent_at > $sent_at) OR
|
||||
received_at > $received_at
|
||||
|
@ -2458,7 +2468,8 @@ function getNewerMessagesByConversationSync(
|
|||
}
|
||||
function getOldestMessageForConversation(
|
||||
conversationId: string,
|
||||
storyId?: UUIDStringType
|
||||
storyId?: UUIDStringType,
|
||||
isGroup?: boolean
|
||||
): MessageMetricsType | undefined {
|
||||
const db = getInstance();
|
||||
const row = db
|
||||
|
@ -2467,7 +2478,7 @@ function getOldestMessageForConversation(
|
|||
SELECT * FROM messages WHERE
|
||||
conversationId = $conversationId AND
|
||||
isStory IS 0 AND
|
||||
(${_storyIdPredicate(storyId)})
|
||||
(${_storyIdPredicate(storyId, isGroup)})
|
||||
ORDER BY received_at ASC, sent_at ASC
|
||||
LIMIT 1;
|
||||
`
|
||||
|
@ -2485,7 +2496,8 @@ function getOldestMessageForConversation(
|
|||
}
|
||||
function getNewestMessageForConversation(
|
||||
conversationId: string,
|
||||
storyId?: UUIDStringType
|
||||
storyId?: UUIDStringType,
|
||||
isGroup?: boolean
|
||||
): MessageMetricsType | undefined {
|
||||
const db = getInstance();
|
||||
const row = db
|
||||
|
@ -2494,7 +2506,7 @@ function getNewestMessageForConversation(
|
|||
SELECT * FROM messages WHERE
|
||||
conversationId = $conversationId AND
|
||||
isStory IS 0 AND
|
||||
(${_storyIdPredicate(storyId)})
|
||||
(${_storyIdPredicate(storyId, isGroup)})
|
||||
ORDER BY received_at DESC, sent_at DESC
|
||||
LIMIT 1;
|
||||
`
|
||||
|
@ -2513,9 +2525,11 @@ function getNewestMessageForConversation(
|
|||
|
||||
function getLastConversationActivity({
|
||||
conversationId,
|
||||
isGroup,
|
||||
ourUuid,
|
||||
}: {
|
||||
conversationId: string;
|
||||
isGroup?: boolean;
|
||||
ourUuid: UUIDStringType;
|
||||
}): MessageType | undefined {
|
||||
const db = getInstance();
|
||||
|
@ -2527,6 +2541,7 @@ function getLastConversationActivity({
|
|||
conversationId = $conversationId AND
|
||||
shouldAffectActivity IS 1 AND
|
||||
isTimerChangeFromSync IS 0 AND
|
||||
${isGroup ? 'storyId IS NULL AND' : ''}
|
||||
isGroupLeaveEventFromOther IS 0
|
||||
ORDER BY received_at DESC, sent_at DESC
|
||||
LIMIT 1;
|
||||
|
@ -2544,8 +2559,10 @@ function getLastConversationActivity({
|
|||
}
|
||||
function getLastConversationPreview({
|
||||
conversationId,
|
||||
isGroup,
|
||||
}: {
|
||||
conversationId: string;
|
||||
isGroup?: boolean;
|
||||
}): MessageType | undefined {
|
||||
const db = getInstance();
|
||||
const row = prepare(
|
||||
|
@ -2556,6 +2573,7 @@ function getLastConversationPreview({
|
|||
conversationId = $conversationId AND
|
||||
shouldAffectPreview IS 1 AND
|
||||
isGroupLeaveEventFromOther IS 0 AND
|
||||
${isGroup ? 'storyId IS NULL AND' : ''}
|
||||
(
|
||||
expiresAt IS NULL
|
||||
OR
|
||||
|
@ -2578,9 +2596,11 @@ function getLastConversationPreview({
|
|||
|
||||
async function getConversationMessageStats({
|
||||
conversationId,
|
||||
isGroup,
|
||||
ourUuid,
|
||||
}: {
|
||||
conversationId: string;
|
||||
isGroup?: boolean;
|
||||
ourUuid: UUIDStringType;
|
||||
}): Promise<ConversationMessageStatsType> {
|
||||
const db = getInstance();
|
||||
|
@ -2589,9 +2609,10 @@ async function getConversationMessageStats({
|
|||
return {
|
||||
activity: getLastConversationActivity({
|
||||
conversationId,
|
||||
isGroup,
|
||||
ourUuid,
|
||||
}),
|
||||
preview: getLastConversationPreview({ conversationId }),
|
||||
preview: getLastConversationPreview({ conversationId, isGroup }),
|
||||
hasUserInitiatedMessages: hasUserInitiatedMessages(conversationId),
|
||||
};
|
||||
})();
|
||||
|
@ -2625,7 +2646,8 @@ async function getLastConversationMessage({
|
|||
|
||||
function getOldestUnreadMessageForConversation(
|
||||
conversationId: string,
|
||||
storyId?: UUIDStringType
|
||||
storyId?: UUIDStringType,
|
||||
isGroup?: boolean
|
||||
): MessageMetricsType | undefined {
|
||||
const db = getInstance();
|
||||
const row = db
|
||||
|
@ -2635,7 +2657,7 @@ function getOldestUnreadMessageForConversation(
|
|||
conversationId = $conversationId AND
|
||||
readStatus = ${ReadStatus.Unread} AND
|
||||
isStory IS 0 AND
|
||||
(${_storyIdPredicate(storyId)})
|
||||
(${_storyIdPredicate(storyId, isGroup)})
|
||||
ORDER BY received_at ASC, sent_at ASC
|
||||
LIMIT 1;
|
||||
`
|
||||
|
@ -2660,7 +2682,8 @@ async function getTotalUnreadForConversation(
|
|||
}
|
||||
function getTotalUnreadForConversationSync(
|
||||
conversationId: string,
|
||||
storyId?: UUIDStringType
|
||||
storyId?: UUIDStringType,
|
||||
isGroup?: boolean
|
||||
): number {
|
||||
const db = getInstance();
|
||||
const row = db
|
||||
|
@ -2672,7 +2695,7 @@ function getTotalUnreadForConversationSync(
|
|||
conversationId = $conversationId AND
|
||||
readStatus = ${ReadStatus.Unread} AND
|
||||
isStory IS 0 AND
|
||||
(${_storyIdPredicate(storyId)})
|
||||
(${_storyIdPredicate(storyId, isGroup)})
|
||||
`
|
||||
)
|
||||
.get({
|
||||
|
@ -2689,23 +2712,35 @@ function getTotalUnreadForConversationSync(
|
|||
|
||||
async function getMessageMetricsForConversation(
|
||||
conversationId: string,
|
||||
storyId?: UUIDStringType
|
||||
storyId?: UUIDStringType,
|
||||
isGroup?: boolean
|
||||
): Promise<ConversationMetricsType> {
|
||||
return getMessageMetricsForConversationSync(conversationId, storyId);
|
||||
return getMessageMetricsForConversationSync(conversationId, storyId, isGroup);
|
||||
}
|
||||
function getMessageMetricsForConversationSync(
|
||||
conversationId: string,
|
||||
storyId?: UUIDStringType
|
||||
storyId?: UUIDStringType,
|
||||
isGroup?: boolean
|
||||
): ConversationMetricsType {
|
||||
const oldest = getOldestMessageForConversation(conversationId, storyId);
|
||||
const newest = getNewestMessageForConversation(conversationId, storyId);
|
||||
const oldest = getOldestMessageForConversation(
|
||||
conversationId,
|
||||
storyId,
|
||||
isGroup
|
||||
);
|
||||
const newest = getNewestMessageForConversation(
|
||||
conversationId,
|
||||
storyId,
|
||||
isGroup
|
||||
);
|
||||
const oldestUnread = getOldestUnreadMessageForConversation(
|
||||
conversationId,
|
||||
storyId
|
||||
storyId,
|
||||
isGroup
|
||||
);
|
||||
const totalUnread = getTotalUnreadForConversationSync(
|
||||
conversationId,
|
||||
storyId
|
||||
storyId,
|
||||
isGroup
|
||||
);
|
||||
|
||||
return {
|
||||
|
|
|
@ -79,6 +79,7 @@ import { useBoundActions } from '../../hooks/useBoundActions';
|
|||
import type { NoopActionType } from './noop';
|
||||
import { conversationJobQueue } from '../../jobs/conversationJobQueue';
|
||||
import type { TimelineMessageLoadingState } from '../../util/timelineUtil';
|
||||
import { isGroup } from '../../util/whatTypeOfConversation';
|
||||
|
||||
// State
|
||||
|
||||
|
@ -2453,6 +2454,12 @@ export function reducer(
|
|||
return state;
|
||||
}
|
||||
|
||||
const conversationAttrs = state.conversationLookup[conversationId];
|
||||
const isGroupStoryReply = isGroup(conversationAttrs) && data.storyId;
|
||||
if (isGroupStoryReply) {
|
||||
return state;
|
||||
}
|
||||
|
||||
return {
|
||||
...state,
|
||||
messagesLookup: {
|
||||
|
|
|
@ -77,6 +77,60 @@ describe('sql/conversationSummary', () => {
|
|||
assert.isTrue(messages.hasUserInitiatedMessages);
|
||||
});
|
||||
|
||||
it('returns the latest message in current conversation excluding group story replies', async () => {
|
||||
assert.lengthOf(await _getAllMessages(), 0);
|
||||
|
||||
const now = Date.now();
|
||||
const conversationId = getUuid();
|
||||
const ourUuid = getUuid();
|
||||
const message1: MessageAttributesType = {
|
||||
id: getUuid(),
|
||||
body: 'message 1',
|
||||
type: 'outgoing',
|
||||
conversationId,
|
||||
sent_at: now + 1,
|
||||
received_at: now + 1,
|
||||
timestamp: now + 1,
|
||||
};
|
||||
const message2: MessageAttributesType = {
|
||||
id: getUuid(),
|
||||
body: 'message 2',
|
||||
type: 'outgoing',
|
||||
conversationId,
|
||||
sent_at: now + 2,
|
||||
received_at: now + 2,
|
||||
timestamp: now + 2,
|
||||
storyId: getUuid(),
|
||||
};
|
||||
const message3: MessageAttributesType = {
|
||||
id: getUuid(),
|
||||
body: 'message 3',
|
||||
type: 'incoming',
|
||||
conversationId,
|
||||
sent_at: now + 3,
|
||||
received_at: now + 3,
|
||||
timestamp: now + 3,
|
||||
storyId: getUuid(),
|
||||
};
|
||||
|
||||
await saveMessages([message1, message2, message3], {
|
||||
forceSave: true,
|
||||
ourUuid,
|
||||
});
|
||||
|
||||
assert.lengthOf(await _getAllMessages(), 3);
|
||||
|
||||
const messages = await getConversationMessageStats({
|
||||
conversationId,
|
||||
isGroup: true,
|
||||
ourUuid,
|
||||
});
|
||||
|
||||
assert.strictEqual(messages.activity?.body, message1.body, 'activity');
|
||||
assert.strictEqual(messages.preview?.body, message1.body, 'preview');
|
||||
assert.isTrue(messages.hasUserInitiatedMessages);
|
||||
});
|
||||
|
||||
it('preview excludes several message types, allows type = NULL', async () => {
|
||||
assert.lengthOf(await _getAllMessages(), 0);
|
||||
|
||||
|
|
|
@ -719,4 +719,80 @@ describe('sql/markRead', () => {
|
|||
'should be reaction5'
|
||||
);
|
||||
});
|
||||
|
||||
it('does not include group story replies', async () => {
|
||||
assert.lengthOf(await _getAllMessages(), 0);
|
||||
|
||||
const start = Date.now();
|
||||
const readAt = start + 20;
|
||||
const conversationId = getUuid();
|
||||
const storyId = getUuid();
|
||||
const ourUuid = getUuid();
|
||||
|
||||
const message1: MessageAttributesType = {
|
||||
id: getUuid(),
|
||||
body: 'message 1',
|
||||
type: 'story',
|
||||
conversationId,
|
||||
sent_at: start + 1,
|
||||
received_at: start + 1,
|
||||
timestamp: start + 1,
|
||||
readStatus: ReadStatus.Read,
|
||||
};
|
||||
const message2: MessageAttributesType = {
|
||||
id: getUuid(),
|
||||
body: 'message 2',
|
||||
type: 'incoming',
|
||||
conversationId,
|
||||
sent_at: start + 2,
|
||||
received_at: start + 2,
|
||||
timestamp: start + 2,
|
||||
readStatus: ReadStatus.Unread,
|
||||
storyId,
|
||||
};
|
||||
const message3: MessageAttributesType = {
|
||||
id: getUuid(),
|
||||
body: 'message 3',
|
||||
type: 'incoming',
|
||||
conversationId,
|
||||
sent_at: start + 3,
|
||||
received_at: start + 3,
|
||||
timestamp: start + 3,
|
||||
readStatus: ReadStatus.Unread,
|
||||
};
|
||||
const message4: MessageAttributesType = {
|
||||
id: getUuid(),
|
||||
body: 'message 4',
|
||||
type: 'incoming',
|
||||
conversationId,
|
||||
sent_at: start + 4,
|
||||
received_at: start + 4,
|
||||
timestamp: start + 4,
|
||||
readStatus: ReadStatus.Unread,
|
||||
storyId,
|
||||
};
|
||||
|
||||
await saveMessages([message1, message2, message3, message4], {
|
||||
forceSave: true,
|
||||
ourUuid,
|
||||
});
|
||||
|
||||
assert.lengthOf(await _getAllMessages(), 4);
|
||||
|
||||
const markedRead = await getUnreadByConversationAndMarkRead({
|
||||
conversationId,
|
||||
isGroup: true,
|
||||
newestUnreadAt: message4.received_at,
|
||||
readAt,
|
||||
});
|
||||
|
||||
assert.lengthOf(markedRead, 1, '1 message marked read');
|
||||
|
||||
// Sorted in descending order
|
||||
assert.strictEqual(
|
||||
markedRead[0].id,
|
||||
message3.id,
|
||||
'first should be message3'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -155,6 +155,59 @@ describe('sql/timelineFetches', () => {
|
|||
assert.strictEqual(messages[0].id, message2.id);
|
||||
});
|
||||
|
||||
it('returns N most recent messages excluding group story replies', async () => {
|
||||
assert.lengthOf(await _getAllMessages(), 0);
|
||||
|
||||
const now = Date.now();
|
||||
const conversationId = getUuid();
|
||||
const storyId = getUuid();
|
||||
const ourUuid = getUuid();
|
||||
|
||||
const message1: MessageAttributesType = {
|
||||
id: getUuid(),
|
||||
body: 'story',
|
||||
type: 'incoming',
|
||||
conversationId,
|
||||
sent_at: now - 20,
|
||||
received_at: now - 20,
|
||||
timestamp: now - 20,
|
||||
storyId,
|
||||
};
|
||||
const message2: MessageAttributesType = {
|
||||
id: getUuid(),
|
||||
body: 'story reply 1',
|
||||
type: 'outgoing',
|
||||
conversationId,
|
||||
sent_at: now - 10,
|
||||
received_at: now - 10,
|
||||
timestamp: now - 10,
|
||||
storyId,
|
||||
};
|
||||
const message3: MessageAttributesType = {
|
||||
id: getUuid(),
|
||||
body: 'normal message',
|
||||
type: 'outgoing',
|
||||
conversationId,
|
||||
sent_at: now,
|
||||
received_at: now,
|
||||
timestamp: now,
|
||||
};
|
||||
|
||||
await saveMessages([message1, message2, message3], {
|
||||
forceSave: true,
|
||||
ourUuid,
|
||||
});
|
||||
|
||||
assert.lengthOf(await _getAllMessages(), 3);
|
||||
|
||||
const messages = await getOlderMessagesByConversation(conversationId, {
|
||||
isGroup: true,
|
||||
limit: 5,
|
||||
});
|
||||
assert.lengthOf(messages, 1);
|
||||
assert.strictEqual(messages[0].id, message3.id);
|
||||
});
|
||||
|
||||
it('returns N messages older than provided received_at', async () => {
|
||||
assert.lengthOf(await _getAllMessages(), 0);
|
||||
|
||||
|
@ -493,6 +546,60 @@ describe('sql/timelineFetches', () => {
|
|||
assert.strictEqual(messages[0].id, message3.id);
|
||||
});
|
||||
|
||||
it('returns N messages excluding group story replies', async () => {
|
||||
assert.lengthOf(await _getAllMessages(), 0);
|
||||
|
||||
const target = Date.now();
|
||||
const conversationId = getUuid();
|
||||
const ourUuid = getUuid();
|
||||
|
||||
const message1: MessageAttributesType = {
|
||||
id: getUuid(),
|
||||
body: 'message 1',
|
||||
type: 'outgoing',
|
||||
conversationId,
|
||||
sent_at: target - 10,
|
||||
received_at: target - 10,
|
||||
timestamp: target - 10,
|
||||
storyId: getUuid(),
|
||||
};
|
||||
const message2: MessageAttributesType = {
|
||||
id: getUuid(),
|
||||
body: 'message 2',
|
||||
type: 'outgoing',
|
||||
conversationId,
|
||||
sent_at: target + 20,
|
||||
received_at: target + 20,
|
||||
timestamp: target + 20,
|
||||
};
|
||||
const message3: MessageAttributesType = {
|
||||
id: getUuid(),
|
||||
body: 'message 3',
|
||||
type: 'outgoing',
|
||||
conversationId,
|
||||
sent_at: target + 10,
|
||||
received_at: target + 10,
|
||||
timestamp: target + 10,
|
||||
storyId: getUuid(),
|
||||
};
|
||||
|
||||
await saveMessages([message1, message2, message3], {
|
||||
forceSave: true,
|
||||
ourUuid,
|
||||
});
|
||||
|
||||
assert.lengthOf(await _getAllMessages(), 3);
|
||||
|
||||
const messages = await getNewerMessagesByConversation(conversationId, {
|
||||
isGroup: true,
|
||||
limit: 5,
|
||||
receivedAt: target,
|
||||
sentAt: target,
|
||||
});
|
||||
assert.lengthOf(messages, 1);
|
||||
assert.strictEqual(messages[0].id, message2.id);
|
||||
});
|
||||
|
||||
it('returns N newer messages with same received_at, greater sent_at', async () => {
|
||||
assert.lengthOf(await _getAllMessages(), 0);
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import { hasErrors } from '../state/selectors/message';
|
|||
import { readReceiptsJobQueue } from '../jobs/readReceiptsJobQueue';
|
||||
import { readSyncJobQueue } from '../jobs/readSyncJobQueue';
|
||||
import { notificationService } from '../services/notifications';
|
||||
import { isGroup } from './whatTypeOfConversation';
|
||||
import * as log from '../logging/log';
|
||||
|
||||
export async function markConversationRead(
|
||||
|
@ -22,6 +23,7 @@ export async function markConversationRead(
|
|||
conversationId,
|
||||
newestUnreadAt,
|
||||
readAt: options.readAt,
|
||||
isGroup: isGroup(conversationAttrs),
|
||||
}),
|
||||
window.Signal.Data.getUnreadReactionsAndMarkRead({
|
||||
conversationId,
|
||||
|
|
Loading…
Reference in a new issue