Show mentioned badges & enable scrolling to mentions in conversations
This commit is contained in:
parent
caaeda8abe
commit
d012779e87
21 changed files with 694 additions and 184 deletions
|
@ -514,6 +514,20 @@ export type DataInterface = {
|
|||
includeStoryReplies: boolean;
|
||||
}
|
||||
) => Promise<number>;
|
||||
getTotalUnreadMentionsOfMeForConversation: (
|
||||
conversationId: string,
|
||||
options: {
|
||||
storyId?: string;
|
||||
includeStoryReplies: boolean;
|
||||
}
|
||||
) => Promise<number>;
|
||||
getOldestUnreadMentionOfMeForConversation(
|
||||
conversationId: string,
|
||||
options: {
|
||||
storyId?: string;
|
||||
includeStoryReplies: boolean;
|
||||
}
|
||||
): Promise<MessageMetricsType | undefined>;
|
||||
getUnreadByConversationAndMarkRead: (options: {
|
||||
conversationId: string;
|
||||
includeStoryReplies: boolean;
|
||||
|
|
|
@ -266,7 +266,9 @@ const dataInterface: ServerInterface = {
|
|||
getOlderMessagesByConversation,
|
||||
getAllStories,
|
||||
getNewerMessagesByConversation,
|
||||
getOldestUnreadMentionOfMeForConversation,
|
||||
getTotalUnreadForConversation,
|
||||
getTotalUnreadMentionsOfMeForConversation,
|
||||
getMessageMetricsForConversation,
|
||||
getConversationRangeCenteredOnMessage,
|
||||
getConversationMessageStats,
|
||||
|
@ -1800,6 +1802,7 @@ function saveMessageSync(
|
|||
id,
|
||||
isErased,
|
||||
isViewOnce,
|
||||
mentionsMe,
|
||||
received_at,
|
||||
schemaVersion,
|
||||
sent_at,
|
||||
|
@ -1850,6 +1853,7 @@ function saveMessageSync(
|
|||
isChangeCreatedByUs: groupV2Change?.from === ourUuid ? 1 : 0,
|
||||
isErased: isErased ? 1 : 0,
|
||||
isViewOnce: isViewOnce ? 1 : 0,
|
||||
mentionsMe: mentionsMe ? 1 : 0,
|
||||
received_at: received_at || null,
|
||||
schemaVersion: schemaVersion || 0,
|
||||
serverGuid: serverGuid || null,
|
||||
|
@ -1881,6 +1885,7 @@ function saveMessageSync(
|
|||
isChangeCreatedByUs = $isChangeCreatedByUs,
|
||||
isErased = $isErased,
|
||||
isViewOnce = $isViewOnce,
|
||||
mentionsMe = $mentionsMe,
|
||||
received_at = $received_at,
|
||||
schemaVersion = $schemaVersion,
|
||||
serverGuid = $serverGuid,
|
||||
|
@ -1925,6 +1930,7 @@ function saveMessageSync(
|
|||
isChangeCreatedByUs,
|
||||
isErased,
|
||||
isViewOnce,
|
||||
mentionsMe,
|
||||
received_at,
|
||||
schemaVersion,
|
||||
serverGuid,
|
||||
|
@ -1950,6 +1956,7 @@ function saveMessageSync(
|
|||
$isChangeCreatedByUs,
|
||||
$isErased,
|
||||
$isViewOnce,
|
||||
$mentionsMe,
|
||||
$received_at,
|
||||
$schemaVersion,
|
||||
$serverGuid,
|
||||
|
@ -2885,6 +2892,38 @@ function getOldestUnseenMessageForConversation(
|
|||
return row;
|
||||
}
|
||||
|
||||
async function getOldestUnreadMentionOfMeForConversation(
|
||||
conversationId: string,
|
||||
options: {
|
||||
storyId?: string;
|
||||
includeStoryReplies: boolean;
|
||||
}
|
||||
): Promise<MessageMetricsType | undefined> {
|
||||
return getOldestUnreadMentionOfMeForConversationSync(conversationId, options);
|
||||
}
|
||||
|
||||
export function getOldestUnreadMentionOfMeForConversationSync(
|
||||
conversationId: string,
|
||||
options: {
|
||||
storyId?: string;
|
||||
includeStoryReplies: boolean;
|
||||
}
|
||||
): MessageMetricsType | undefined {
|
||||
const db = getInstance();
|
||||
const [query, params] = sql`
|
||||
SELECT received_at, sent_at, id FROM messages WHERE
|
||||
conversationId = ${conversationId} AND
|
||||
readStatus = ${ReadStatus.Unread} AND
|
||||
mentionsMe IS 1 AND
|
||||
isStory IS 0 AND
|
||||
(${_storyIdPredicate(options.storyId, options.includeStoryReplies)})
|
||||
ORDER BY received_at ASC, sent_at ASC
|
||||
LIMIT 1;
|
||||
`;
|
||||
|
||||
return db.prepare(query).get(params);
|
||||
}
|
||||
|
||||
async function getTotalUnreadForConversation(
|
||||
conversationId: string,
|
||||
options: {
|
||||
|
@ -2918,6 +2957,40 @@ function getTotalUnreadForConversationSync(
|
|||
|
||||
return row;
|
||||
}
|
||||
async function getTotalUnreadMentionsOfMeForConversation(
|
||||
conversationId: string,
|
||||
options: {
|
||||
storyId?: string;
|
||||
includeStoryReplies: boolean;
|
||||
}
|
||||
): Promise<number> {
|
||||
return getTotalUnreadMentionsOfMeForConversationSync(conversationId, options);
|
||||
}
|
||||
function getTotalUnreadMentionsOfMeForConversationSync(
|
||||
conversationId: string,
|
||||
{
|
||||
storyId,
|
||||
includeStoryReplies,
|
||||
}: {
|
||||
storyId?: string;
|
||||
includeStoryReplies: boolean;
|
||||
}
|
||||
): number {
|
||||
const db = getInstance();
|
||||
const [query, params] = sql`
|
||||
SELECT count(1)
|
||||
FROM messages
|
||||
WHERE
|
||||
conversationId = ${conversationId} AND
|
||||
readStatus = ${ReadStatus.Unread} AND
|
||||
mentionsMe IS 1 AND
|
||||
isStory IS 0 AND
|
||||
(${_storyIdPredicate(storyId, includeStoryReplies)})
|
||||
`;
|
||||
const row = db.prepare(query).pluck().get(params);
|
||||
|
||||
return row;
|
||||
}
|
||||
function getTotalUnseenForConversationSync(
|
||||
conversationId: string,
|
||||
{
|
||||
|
|
38
ts/sql/migrations/83-mentions.ts
Normal file
38
ts/sql/migrations/83-mentions.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { Database } from '@signalapp/better-sqlite3';
|
||||
import type { LoggerType } from '../../types/Logging';
|
||||
|
||||
export default function updateToSchemaVersion83(
|
||||
currentVersion: number,
|
||||
db: Database,
|
||||
logger: LoggerType
|
||||
): void {
|
||||
if (currentVersion >= 83) {
|
||||
return;
|
||||
}
|
||||
|
||||
db.transaction(() => {
|
||||
db.exec(
|
||||
`
|
||||
ALTER TABLE messages
|
||||
ADD COLUMN mentionsMe INTEGER NOT NULL DEFAULT 0;
|
||||
|
||||
-- one which includes story data...
|
||||
CREATE INDEX messages_unread_mentions ON messages
|
||||
(conversationId, readStatus, mentionsMe, isStory, storyId, received_at, sent_at)
|
||||
WHERE readStatus IS NOT NULL;
|
||||
|
||||
-- ...and one which doesn't, so storyPredicate works as expected
|
||||
CREATE INDEX messages_unread_mentions_no_story_id ON messages
|
||||
(conversationId, readStatus, mentionsMe, isStory, received_at, sent_at)
|
||||
WHERE isStory IS 0 AND readStatus IS NOT NULL;
|
||||
`
|
||||
);
|
||||
|
||||
db.pragma('user_version = 83');
|
||||
})();
|
||||
|
||||
logger.info('updateToSchemaVersion83: success!');
|
||||
}
|
|
@ -58,6 +58,7 @@ import updateToSchemaVersion79 from './79-paging-lightbox';
|
|||
import updateToSchemaVersion80 from './80-edited-messages';
|
||||
import updateToSchemaVersion81 from './81-contact-removed-notification';
|
||||
import updateToSchemaVersion82 from './82-edited-messages-read-index';
|
||||
import updateToSchemaVersion83 from './83-mentions';
|
||||
|
||||
function updateToSchemaVersion1(
|
||||
currentVersion: number,
|
||||
|
@ -1982,10 +1983,10 @@ export const SCHEMA_VERSIONS = [
|
|||
updateToSchemaVersion77,
|
||||
updateToSchemaVersion78,
|
||||
updateToSchemaVersion79,
|
||||
|
||||
updateToSchemaVersion80,
|
||||
updateToSchemaVersion81,
|
||||
updateToSchemaVersion82,
|
||||
updateToSchemaVersion83,
|
||||
];
|
||||
|
||||
export function updateSchema(db: Database, logger: LoggerType): void {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue