Add Collection.fetchVisualMediaAttachments
This commit is contained in:
parent
cad5e417f3
commit
825980fbd1
1 changed files with 44 additions and 0 deletions
44
ts/backbone/Conversation.ts
Normal file
44
ts/backbone/Conversation.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
* @prettier
|
||||
*/
|
||||
import is from '@sindresorhus/is';
|
||||
|
||||
import { deferredToPromise } from '../../js/modules/deferred_to_promise';
|
||||
import { Collection as BackboneCollection } from '../types/backbone/Collection';
|
||||
import { Message } from '../types/Message';
|
||||
|
||||
export const fetchVisualMediaAttachments = async ({
|
||||
conversationId,
|
||||
WhisperMessageCollection,
|
||||
}: {
|
||||
conversationId: string;
|
||||
WhisperMessageCollection: BackboneCollection<Message>;
|
||||
}): Promise<Array<Message>> => {
|
||||
if (!is.string(conversationId)) {
|
||||
throw new TypeError("'conversationId' is required");
|
||||
}
|
||||
|
||||
if (!is.object(WhisperMessageCollection)) {
|
||||
throw new TypeError("'WhisperMessageCollection' is required");
|
||||
}
|
||||
|
||||
const collection = new WhisperMessageCollection();
|
||||
const lowerReceivedAt = 0;
|
||||
const upperReceivedAt = Number.MAX_VALUE;
|
||||
const hasVisualMediaAttachments = 1;
|
||||
await deferredToPromise(
|
||||
collection.fetch({
|
||||
index: {
|
||||
// 'hasVisualMediaAttachments' index on
|
||||
// [conversationId, hasVisualMediaAttachments, received_at]
|
||||
name: 'hasVisualMediaAttachments',
|
||||
lower: [conversationId, hasVisualMediaAttachments, lowerReceivedAt],
|
||||
upper: [conversationId, hasVisualMediaAttachments, upperReceivedAt],
|
||||
order: 'desc',
|
||||
},
|
||||
limit: 10,
|
||||
})
|
||||
);
|
||||
|
||||
return collection.models.map(model => model.toJSON());
|
||||
};
|
Loading…
Add table
Reference in a new issue