Adds logic around downloading stories
This commit is contained in:
parent
9d3f0072a5
commit
3b5cc26fec
29 changed files with 645 additions and 149 deletions
|
@ -212,6 +212,7 @@ const dataInterface: ClientInterface = {
|
|||
searchMessagesInConversation,
|
||||
|
||||
getMessageCount,
|
||||
getStoryCount,
|
||||
saveMessage,
|
||||
saveMessages,
|
||||
removeMessage,
|
||||
|
@ -295,6 +296,7 @@ const dataInterface: ClientInterface = {
|
|||
_deleteAllStoryReads,
|
||||
addNewStoryRead,
|
||||
getLastStoryReadsForAuthor,
|
||||
countStoryReadsByConversation,
|
||||
|
||||
removeAll,
|
||||
removeAllConfiguration,
|
||||
|
@ -1078,6 +1080,10 @@ async function getMessageCount(conversationId?: string) {
|
|||
return channels.getMessageCount(conversationId);
|
||||
}
|
||||
|
||||
async function getStoryCount(conversationId: string) {
|
||||
return channels.getStoryCount(conversationId);
|
||||
}
|
||||
|
||||
async function saveMessage(
|
||||
data: MessageType,
|
||||
options: {
|
||||
|
@ -1633,6 +1639,11 @@ async function getLastStoryReadsForAuthor(options: {
|
|||
}): Promise<Array<StoryReadType>> {
|
||||
return channels.getLastStoryReadsForAuthor(options);
|
||||
}
|
||||
async function countStoryReadsByConversation(
|
||||
conversationId: string
|
||||
): Promise<number> {
|
||||
return channels.countStoryReadsByConversation(conversationId);
|
||||
}
|
||||
|
||||
// Other
|
||||
|
||||
|
|
|
@ -371,6 +371,7 @@ export type DataInterface = {
|
|||
// searchMessagesInConversation is JSON on server, full message on Client
|
||||
|
||||
getMessageCount: (conversationId?: string) => Promise<number>;
|
||||
getStoryCount: (conversationId: string) => Promise<number>;
|
||||
saveMessage: (
|
||||
data: MessageType,
|
||||
options: {
|
||||
|
@ -561,6 +562,7 @@ export type DataInterface = {
|
|||
conversationId?: UUIDStringType;
|
||||
limit?: number;
|
||||
}): Promise<Array<StoryReadType>>;
|
||||
countStoryReadsByConversation(conversationId: string): Promise<number>;
|
||||
|
||||
removeAll: () => Promise<void>;
|
||||
removeAllConfiguration: (type?: RemoveAllConfiguration) => Promise<void>;
|
||||
|
|
|
@ -208,6 +208,7 @@ const dataInterface: ServerInterface = {
|
|||
searchMessagesInConversation,
|
||||
|
||||
getMessageCount,
|
||||
getStoryCount,
|
||||
saveMessage,
|
||||
saveMessages,
|
||||
removeMessage,
|
||||
|
@ -291,6 +292,7 @@ const dataInterface: ServerInterface = {
|
|||
_deleteAllStoryReads,
|
||||
addNewStoryRead,
|
||||
getLastStoryReadsForAuthor,
|
||||
countStoryReadsByConversation,
|
||||
|
||||
removeAll,
|
||||
removeAllConfiguration,
|
||||
|
@ -1686,6 +1688,20 @@ function getMessageCountSync(
|
|||
return count;
|
||||
}
|
||||
|
||||
async function getStoryCount(conversationId: string): Promise<number> {
|
||||
const db = getInstance();
|
||||
return db
|
||||
.prepare<Query>(
|
||||
`
|
||||
SELECT count(*)
|
||||
FROM messages
|
||||
WHERE conversationId = $conversationId AND isStory = 1;
|
||||
`
|
||||
)
|
||||
.pluck()
|
||||
.get({ conversationId });
|
||||
}
|
||||
|
||||
async function getMessageCount(conversationId?: string): Promise<number> {
|
||||
return getMessageCountSync(conversationId);
|
||||
}
|
||||
|
@ -2392,7 +2408,7 @@ function getOlderMessagesByConversationSync(
|
|||
|
||||
async function getOlderStories({
|
||||
conversationId,
|
||||
limit = 10,
|
||||
limit = 9999,
|
||||
receivedAt = Number.MAX_VALUE,
|
||||
sentAt,
|
||||
sourceUuid,
|
||||
|
@ -2416,7 +2432,7 @@ async function getOlderStories({
|
|||
(received_at < $receivedAt
|
||||
OR (received_at IS $receivedAt AND sent_at < $sentAt)
|
||||
)
|
||||
ORDER BY received_at DESC, sent_at DESC
|
||||
ORDER BY received_at ASC, sent_at ASC
|
||||
LIMIT $limit;
|
||||
`
|
||||
)
|
||||
|
@ -4157,6 +4173,21 @@ async function getLastStoryReadsForAuthor({
|
|||
});
|
||||
}
|
||||
|
||||
async function countStoryReadsByConversation(
|
||||
conversationId: string
|
||||
): Promise<number> {
|
||||
const db = getInstance();
|
||||
return db
|
||||
.prepare<Query>(
|
||||
`
|
||||
SELECT COUNT(storyId) FROM storyReads
|
||||
WHERE conversationId = $conversationId;
|
||||
`
|
||||
)
|
||||
.pluck()
|
||||
.get({ conversationId });
|
||||
}
|
||||
|
||||
// All data in database
|
||||
async function removeAll(): Promise<void> {
|
||||
const db = getInstance();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue