Introduce new 'Block request' button in timeline

This commit is contained in:
Scott Nonnenberg 2022-03-15 17:11:28 -07:00 committed by GitHub
parent 536dd0c7b0
commit 703bb8a3a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 1088 additions and 157 deletions

View file

@ -56,7 +56,7 @@ import type {
IdentityKeyType,
ItemKeyType,
ItemType,
LastConversationMessagesType,
ConversationMessageStatsType,
MessageType,
MessageTypeUnhydrated,
PreKeyIdType,
@ -241,7 +241,8 @@ const dataInterface: ClientInterface = {
getNewerMessagesByConversation,
getMessageMetricsForConversation,
getConversationRangeCenteredOnMessage,
getLastConversationMessages,
getConversationMessageStats,
getLastConversationMessage,
hasGroupCallHistoryMessage,
migrateConversationMessages,
@ -1097,7 +1098,7 @@ async function saveMessage(
}
async function saveMessages(
arrayOfMessages: Array<MessageType>,
arrayOfMessages: ReadonlyArray<MessageType>,
options: { forceSave?: boolean; ourUuid: UUIDStringType }
) {
await channels.saveMessages(
@ -1291,15 +1292,15 @@ async function getNewerMessagesByConversation(
return handleMessageJSON(messages);
}
async function getLastConversationMessages({
async function getConversationMessageStats({
conversationId,
ourUuid,
}: {
conversationId: string;
ourUuid: UUIDStringType;
}): Promise<LastConversationMessagesType> {
}): Promise<ConversationMessageStatsType> {
const { preview, activity, hasUserInitiatedMessages } =
await channels.getLastConversationMessages({
await channels.getConversationMessageStats({
conversationId,
ourUuid,
});
@ -1310,6 +1311,13 @@ async function getLastConversationMessages({
hasUserInitiatedMessages,
};
}
async function getLastConversationMessage({
conversationId,
}: {
conversationId: string;
}) {
return channels.getLastConversationMessage({ conversationId });
}
async function getMessageMetricsForConversation(
conversationId: string,
storyId?: UUIDStringType

View file

@ -218,7 +218,7 @@ export type UnprocessedUpdateType = {
decrypted?: string;
};
export type LastConversationMessagesType = {
export type ConversationMessageStatsType = {
activity?: MessageType;
preview?: MessageType;
hasUserInitiatedMessages: boolean;
@ -379,7 +379,7 @@ export type DataInterface = {
}
) => Promise<string>;
saveMessages: (
arrayOfMessages: Array<MessageType>,
arrayOfMessages: ReadonlyArray<MessageType>,
options: { forceSave?: boolean; ourUuid: UUIDStringType }
) => Promise<void>;
removeMessage: (id: string) => Promise<void>;
@ -453,10 +453,13 @@ export type DataInterface = {
storyId?: UUIDStringType
) => Promise<ConversationMetricsType>;
// getConversationRangeCenteredOnMessage is JSON on server, full message on client
getLastConversationMessages: (options: {
getConversationMessageStats: (options: {
conversationId: string;
ourUuid: UUIDStringType;
}) => Promise<LastConversationMessagesType>;
}) => Promise<ConversationMessageStatsType>;
getLastConversationMessage(options: {
conversationId: string;
}): Promise<MessageType | undefined>;
hasGroupCallHistoryMessage: (
conversationId: string,
eraId: string

View file

@ -80,7 +80,7 @@ import type {
IdentityKeyType,
ItemKeyType,
ItemType,
LastConversationMessagesType,
ConversationMessageStatsType,
MessageMetricsType,
MessageType,
MessageTypeUnhydrated,
@ -237,7 +237,8 @@ const dataInterface: ServerInterface = {
getTotalUnreadForConversation,
getMessageMetricsForConversation,
getConversationRangeCenteredOnMessage,
getLastConversationMessages,
getConversationMessageStats,
getLastConversationMessage,
hasGroupCallHistoryMessage,
migrateConversationMessages,
@ -1912,7 +1913,7 @@ async function saveMessage(
}
async function saveMessages(
arrayOfMessages: Array<MessageType>,
arrayOfMessages: ReadonlyArray<MessageType>,
options: { forceSave?: boolean; ourUuid: UUIDStringType }
): Promise<void> {
const db = getInstance();
@ -2591,13 +2592,13 @@ function getLastConversationPreview({
return jsonToObject(row.json);
}
async function getLastConversationMessages({
async function getConversationMessageStats({
conversationId,
ourUuid,
}: {
conversationId: string;
ourUuid: UUIDStringType;
}): Promise<LastConversationMessagesType> {
}): Promise<ConversationMessageStatsType> {
const db = getInstance();
return db.transaction(() => {
@ -2612,6 +2613,32 @@ async function getLastConversationMessages({
})();
}
async function getLastConversationMessage({
conversationId,
}: {
conversationId: string;
}): Promise<MessageType | undefined> {
const db = getInstance();
const row = db
.prepare<Query>(
`
SELECT * FROM messages WHERE
conversationId = $conversationId
ORDER BY received_at DESC, sent_at DESC
LIMIT 1;
`
)
.get({
conversationId,
});
if (!row) {
return undefined;
}
return jsonToObject(row.json);
}
function getOldestUnreadMessageForConversation(
conversationId: string,
storyId?: UUIDStringType