signal-desktop/ts/backbone/Conversation.ts

43 lines
1.2 KiB
TypeScript
Raw Normal View History

/**
* @prettier
*/
import is from '@sindresorhus/is';
import { Collection as BackboneCollection } from '../types/backbone/Collection';
2018-04-15 00:09:52 +00:00
import { deferredToPromise } from '../../js/modules/deferred_to_promise';
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: {
name: 'hasVisualMediaAttachments',
lower: [conversationId, lowerReceivedAt, hasVisualMediaAttachments],
upper: [conversationId, upperReceivedAt, hasVisualMediaAttachments],
order: 'desc',
},
2018-04-15 01:08:16 +00:00
limit: 50,
})
);
return collection.models.map(model => model.toJSON());
};