Get the correct unread count for a conversation
This commit is contained in:
parent
c68d65ea0b
commit
887b2c1db1
5 changed files with 47 additions and 14 deletions
|
@ -167,6 +167,7 @@ const dataInterface: ClientInterface = {
|
|||
saveMessages,
|
||||
removeMessage,
|
||||
removeMessages,
|
||||
getUnreadCountForConversation,
|
||||
getUnreadByConversationAndMarkRead,
|
||||
getUnreadReactionsAndMarkRead,
|
||||
markReactionAsRead,
|
||||
|
@ -1046,6 +1047,10 @@ async function getMessageBySender(
|
|||
return new Message(messages[0]);
|
||||
}
|
||||
|
||||
async function getUnreadCountForConversation(conversationId: string) {
|
||||
return channels.getUnreadCountForConversation(conversationId);
|
||||
}
|
||||
|
||||
async function getUnreadByConversationAndMarkRead(
|
||||
conversationId: string,
|
||||
newestUnreadId: number,
|
||||
|
|
|
@ -343,6 +343,7 @@ export type ServerInterface = DataInterface & {
|
|||
getNextTapToViewMessageToAgeOut: () => Promise<MessageType | undefined>;
|
||||
getOutgoingWithoutExpiresAt: () => Promise<Array<MessageType>>;
|
||||
getTapToViewMessagesNeedingErase: () => Promise<Array<MessageType>>;
|
||||
getUnreadCountForConversation: (conversationId: string) => Promise<number>;
|
||||
getUnreadByConversationAndMarkRead: (
|
||||
conversationId: string,
|
||||
newestUnreadId: number,
|
||||
|
@ -486,6 +487,7 @@ export type ClientInterface = DataInterface & {
|
|||
getTapToViewMessagesNeedingErase: (options: {
|
||||
MessageCollection: typeof MessageModelCollectionType;
|
||||
}) => Promise<MessageModelCollectionType>;
|
||||
getUnreadCountForConversation: (conversationId: string) => Promise<number>;
|
||||
getUnreadByConversationAndMarkRead: (
|
||||
conversationId: string,
|
||||
newestUnreadId: number,
|
||||
|
|
|
@ -157,6 +157,7 @@ const dataInterface: ServerInterface = {
|
|||
saveMessages,
|
||||
removeMessage,
|
||||
removeMessages,
|
||||
getUnreadCountForConversation,
|
||||
getUnreadByConversationAndMarkRead,
|
||||
getUnreadReactionsAndMarkRead,
|
||||
markReactionAsRead,
|
||||
|
@ -3092,6 +3093,24 @@ function updateExpirationTimers(
|
|||
);
|
||||
}
|
||||
|
||||
async function getUnreadCountForConversation(
|
||||
conversationId: string
|
||||
): Promise<number> {
|
||||
const db = getInstance();
|
||||
const row = db
|
||||
.prepare<Query>(
|
||||
`
|
||||
SELECT COUNT(*) AS unreadCount FROM messages
|
||||
WHERE unread = 1 AND
|
||||
conversationId = $conversationId
|
||||
`
|
||||
)
|
||||
.get({
|
||||
conversationId,
|
||||
});
|
||||
return row.unreadCount;
|
||||
}
|
||||
|
||||
async function getUnreadByConversationAndMarkRead(
|
||||
conversationId: string,
|
||||
newestUnreadId: number,
|
||||
|
@ -3118,6 +3137,10 @@ async function getUnreadByConversationAndMarkRead(
|
|||
newestUnreadId,
|
||||
});
|
||||
|
||||
if (!rows.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const messagesWithExpireTimer: Map<
|
||||
string,
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue