Message Requests improvements

This commit is contained in:
Scott Nonnenberg 2020-08-06 17:50:54 -07:00 committed by GitHub
parent b63291507a
commit 81cb7730a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 302 additions and 263 deletions

View file

@ -156,6 +156,8 @@ const dataInterface: ClientInterface = {
getTapToViewMessagesNeedingErase,
getOlderMessagesByConversation,
getNewerMessagesByConversation,
getLastConversationActivity,
getLastConversationPreview,
getMessageMetricsForConversation,
migrateConversationMessages,
@ -1022,6 +1024,32 @@ async function getNewerMessagesByConversation(
return new MessageCollection(handleMessageJSON(messages));
}
async function getLastConversationActivity(
conversationId: string,
options: {
Message: typeof MessageModelType;
}
): Promise<MessageModelType | undefined> {
const { Message } = options;
const result = await channels.getLastConversationActivity(conversationId);
if (result) {
return new Message(result);
}
return;
}
async function getLastConversationPreview(
conversationId: string,
options: {
Message: typeof MessageModelType;
}
): Promise<MessageModelType | undefined> {
const { Message } = options;
const result = await channels.getLastConversationPreview(conversationId);
if (result) {
return new Message(result);
}
return;
}
async function getMessageMetricsForConversation(conversationId: string) {
const result = await channels.getMessageMetricsForConversation(
conversationId

View file

@ -210,6 +210,12 @@ export type ServerInterface = DataInterface & {
conversationId: string,
options?: { limit?: number; receivedAt?: number }
) => Promise<Array<MessageTypeUnhydrated>>;
getLastConversationActivity: (
conversationId: string
) => Promise<MessageType | undefined>;
getLastConversationPreview: (
conversationId: string
) => Promise<MessageType | undefined>;
getNextExpiringMessage: () => Promise<MessageType>;
getNextTapToViewMessageToAgeOut: () => Promise<MessageType>;
getOutgoingWithoutExpiresAt: () => Promise<Array<MessageType>>;
@ -308,6 +314,18 @@ export type ClientInterface = DataInterface & {
MessageCollection: typeof MessageModelCollectionType;
}
) => Promise<MessageModelCollectionType>;
getLastConversationActivity: (
conversationId: string,
options: {
Message: typeof MessageModelType;
}
) => Promise<MessageModelType | undefined>;
getLastConversationPreview: (
conversationId: string,
options: {
Message: typeof MessageModelType;
}
) => Promise<MessageModelType | undefined>;
getNextExpiringMessage: ({
Message,
}: {

View file

@ -132,6 +132,8 @@ const dataInterface: ServerInterface = {
getOlderMessagesByConversation,
getNewerMessagesByConversation,
getMessageMetricsForConversation,
getLastConversationActivity,
getLastConversationPreview,
migrateConversationMessages,
getUnprocessedCount,
@ -2749,6 +2751,50 @@ async function getNewestMessageForConversation(conversationId: string) {
return row;
}
async function getLastConversationActivity(
conversationId: string
): Promise<MessageType | null> {
const db = getInstance();
const row = await db.get(
`SELECT * FROM messages WHERE
conversationId = $conversationId AND
type NOT IN ('profile-change', 'verified-change', 'message-history-unsynced') AND
json_extract(json, '$.expirationTimerUpdate.fromSync') != true
ORDER BY received_at DESC
LIMIT 1;`,
{
$conversationId: conversationId,
}
);
if (!row) {
return null;
}
return jsonToObject(row.json);
}
async function getLastConversationPreview(
conversationId: string
): Promise<MessageType | null> {
const db = getInstance();
const row = await db.get(
`SELECT * FROM messages WHERE
conversationId = $conversationId AND
type NOT IN ('profile-change', 'verified-change', 'message-history-unsynced')
ORDER BY received_at DESC
LIMIT 1;`,
{
$conversationId: conversationId,
}
);
if (!row) {
return null;
}
return jsonToObject(row.json);
}
async function getOldestUnreadMessageForConversation(conversationId: string) {
const db = getInstance();
const row = await db.get(