Allow fetching conversation messages by a specific type.

pull/33/head
Mikunj 7 years ago
parent 4b7a94c7d0
commit 1150f0f915

@ -1310,21 +1310,42 @@ async function getUnreadByConversation(conversationId) {
async function getMessagesByConversation(
conversationId,
{ limit = 100, receivedAt = Number.MAX_VALUE } = {}
{ limit = 100, receivedAt = Number.MAX_VALUE, type = null } = {}
) {
const rows = await db.all(
`SELECT json FROM messages WHERE
conversationId = $conversationId AND
received_at < $received_at
ORDER BY received_at DESC
LIMIT $limit;`,
{
$conversationId: conversationId,
$received_at: receivedAt,
$limit: limit,
}
);
let rows = [];
// Filter by a specific type of message
if (type) {
rows = await db.all(`
SELECT json FROM messages WHERE
conversationId = $conversationId AND
received_at < $received_at AND
type = $type
ORDER BY received_at DESC
LIMIT $limit;
`,
{
$conversationId: conversationId,
$received_at: receivedAt,
$limit: limit,
$type: type,
}
);
} else {
rows = await db.all(`
SELECT json FROM messages WHERE
conversationId = $conversationId AND
received_at < $received_at
ORDER BY received_at DESC
LIMIT $limit;
`,
{
$conversationId: conversationId,
$received_at: receivedAt,
$limit: limit,
}
);
}
return map(rows, row => jsonToObject(row.json));
}

@ -237,7 +237,10 @@
// Go through the messages and check for any pending friend requests
const messages = await window.Signal.Data.getMessagesByConversation(
this.id,
{ MessageCollection: Whisper.MessageCollection }
{
type: 'friend-request',
MessageCollection: Whisper.MessageCollection,
}
);
for (const message of messages.models) {
@ -250,7 +253,10 @@
// Theoretically all ouur messages could be friend requests, thus we have to unfortunately go through each one :(
const messages = await window.Signal.Data.getMessagesByConversation(
this.id,
{ MessageCollection: Whisper.MessageCollection }
{
type: 'friend-request',
MessageCollection: Whisper.MessageCollection,
}
);
// We are most likely to find the friend request in the more recent conversations first

@ -776,11 +776,12 @@ async function getUnreadByConversation(conversationId, { MessageCollection }) {
async function getMessagesByConversation(
conversationId,
{ limit = 100, receivedAt = Number.MAX_VALUE, MessageCollection }
{ limit = 100, receivedAt = Number.MAX_VALUE, MessageCollection, type = null }
) {
const messages = await channels.getMessagesByConversation(conversationId, {
limit,
receivedAt,
type,
});
return new MessageCollection(messages);

Loading…
Cancel
Save