Skip to content

Commit

Permalink
getTotalUnreadForConversation: Add missing isGroup parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
automated-signal committed Apr 28, 2022
1 parent 075b968 commit 00f770c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 17 deletions.
3 changes: 2 additions & 1 deletion ts/models/conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4672,7 +4672,8 @@ export class ConversationModel extends window.Backbone
await markConversationRead(this.attributes, newestUnreadAt, options);

const unreadCount = await window.Signal.Data.getTotalUnreadForConversation(
this.id
this.id,
{ storyId: undefined, isGroup: isGroup(this.attributes) }
);

const prevUnreadCount = this.get('unreadCount');
Expand Down
7 changes: 5 additions & 2 deletions ts/sql/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1170,9 +1170,12 @@ async function getMessageBySender({

async function getTotalUnreadForConversation(
conversationId: string,
storyId?: UUIDStringType
options: {
storyId: UUIDStringType | undefined;
isGroup: boolean;
}
) {
return channels.getTotalUnreadForConversation(conversationId, storyId);
return channels.getTotalUnreadForConversation(conversationId, options);
}

async function getUnreadByConversationAndMarkRead(options: {
Expand Down
5 changes: 4 additions & 1 deletion ts/sql/Interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,10 @@ export type DataInterface = {
removeMessages: (ids: Array<string>) => Promise<void>;
getTotalUnreadForConversation: (
conversationId: string,
storyId?: UUIDStringType
options: {
storyId: UUIDStringType | undefined;
isGroup: boolean;
}
) => Promise<number>;
getUnreadByConversationAndMarkRead: (options: {
conversationId: string;
Expand Down
23 changes: 15 additions & 8 deletions ts/sql/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2676,14 +2676,22 @@ function getOldestUnreadMessageForConversation(

async function getTotalUnreadForConversation(
conversationId: string,
storyId?: UUIDStringType
options: {
storyId: UUIDStringType | undefined;
isGroup: boolean;
}
): Promise<number> {
return getTotalUnreadForConversationSync(conversationId, storyId);
return getTotalUnreadForConversationSync(conversationId, options);
}
function getTotalUnreadForConversationSync(
conversationId: string,
storyId?: UUIDStringType,
isGroup?: boolean
{
storyId,
isGroup,
}: {
storyId: UUIDStringType | undefined;
isGroup: boolean;
}
): number {
const db = getInstance();
const row = db
Expand Down Expand Up @@ -2737,11 +2745,10 @@ function getMessageMetricsForConversationSync(
storyId,
isGroup
);
const totalUnread = getTotalUnreadForConversationSync(
conversationId,
const totalUnread = getTotalUnreadForConversationSync(conversationId, {
storyId,
isGroup
);
isGroup: Boolean(isGroup),
});

return {
oldest: oldest ? pick(oldest, ['received_at', 'sent_at', 'id']) : undefined,
Expand Down
25 changes: 20 additions & 5 deletions ts/test-electron/sql/markRead_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ describe('sql/markRead', () => {

assert.lengthOf(await _getAllMessages(), 7);
assert.strictEqual(
await getTotalUnreadForConversation(conversationId),
await getTotalUnreadForConversation(conversationId, {
storyId: undefined,
isGroup: false,
}),
4,
'unread count'
);
Expand All @@ -137,7 +140,10 @@ describe('sql/markRead', () => {

assert.lengthOf(markedRead, 2, 'two messages marked read');
assert.strictEqual(
await getTotalUnreadForConversation(conversationId),
await getTotalUnreadForConversation(conversationId, {
storyId: undefined,
isGroup: false,
}),
2,
'unread count'
);
Expand All @@ -164,7 +170,10 @@ describe('sql/markRead', () => {
assert.strictEqual(markedRead2[0].id, message7.id, 'should be message7');

assert.strictEqual(
await getTotalUnreadForConversation(conversationId),
await getTotalUnreadForConversation(conversationId, {
storyId: undefined,
isGroup: false,
}),
0,
'unread count'
);
Expand Down Expand Up @@ -365,7 +374,10 @@ describe('sql/markRead', () => {
});

assert.strictEqual(
await getTotalUnreadForConversation(conversationId),
await getTotalUnreadForConversation(conversationId, {
storyId: undefined,
isGroup: false,
}),
2,
'unread count'
);
Expand All @@ -384,7 +396,10 @@ describe('sql/markRead', () => {
'first should be message4'
);
assert.strictEqual(
await getTotalUnreadForConversation(conversationId),
await getTotalUnreadForConversation(conversationId, {
storyId: undefined,
isGroup: false,
}),
1,
'unread count'
);
Expand Down

0 comments on commit 00f770c

Please sign in to comment.