Skip to content

Commit

Permalink
Fix team sidebar not showing thread unreads
Browse files Browse the repository at this point in the history
  • Loading branch information
larkox committed Feb 21, 2025
1 parent 8e854a8 commit 498f1c9
Show file tree
Hide file tree
Showing 20 changed files with 792 additions and 168 deletions.
19 changes: 9 additions & 10 deletions app/actions/local/post.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe('sendEphemeralPost', () => {
});

describe('removePost', () => {
const post = {...TestHelper.fakePost(channelId), id: 'postid'};
const post = TestHelper.fakePost({id: 'postid', channel_id: channelId});

it('handle not found database', async () => {
const {post: rPost, error} = await removePost('foo', post);
Expand Down Expand Up @@ -139,12 +139,12 @@ describe('removePost', () => {
});

it('base case - system message', async () => {
const systemPost = {...TestHelper.fakePost(channelId), id: `${COMBINED_USER_ACTIVITY}id1_id2`, type: Post.POST_TYPES.COMBINED_USER_ACTIVITY as PostType, props: {system_post_ids: ['id1']}};
const systemPost = TestHelper.fakePost({channel_id: channelId, id: `${COMBINED_USER_ACTIVITY}id1_id2`, type: Post.POST_TYPES.COMBINED_USER_ACTIVITY as PostType, props: {system_post_ids: ['id1']}});

await operator.handlePosts({
actionType: ActionType.POSTS.RECEIVED_IN_CHANNEL,
order: [post.id, 'id1'],
posts: [systemPost, {...TestHelper.fakePost(channelId), id: 'id1'}],
posts: [systemPost, TestHelper.fakePost({id: 'id1', channel_id: channelId})],
prepareRecordsOnly: false,
});

Expand All @@ -155,7 +155,7 @@ describe('removePost', () => {
});

describe('markPostAsDeleted', () => {
const post = TestHelper.fakePost(channelId);
const post = TestHelper.fakePost({channel_id: channelId});

it('handle not found database', async () => {
const {model, error} = await markPostAsDeleted('foo', post);
Expand Down Expand Up @@ -185,8 +185,7 @@ describe('markPostAsDeleted', () => {
});

describe('storePostsForChannel', () => {
const post = TestHelper.fakePost(channelId);
post.user_id = user.id;
const post = TestHelper.fakePost({channel_id: channelId, user_id: user.id});
const teamId = 'tId1';
const channel: Channel = {
id: channelId,
Expand Down Expand Up @@ -226,7 +225,7 @@ describe('storePostsForChannel', () => {
});

describe('getPosts', () => {
const post = TestHelper.fakePost(channelId);
const post = TestHelper.fakePost({channel_id: channelId});

it('handle not found database', async () => {
const posts = await getPosts('foo', [post.id]);
Expand All @@ -249,7 +248,7 @@ describe('getPosts', () => {
});

describe('addPostAcknowledgement', () => {
const post = TestHelper.fakePost(channelId);
const post = TestHelper.fakePost({channel_id: channelId});

it('handle not found database', async () => {
const {model, error} = await addPostAcknowledgement('foo', post.id, user.id, 123, false);
Expand Down Expand Up @@ -292,7 +291,7 @@ describe('addPostAcknowledgement', () => {
});

describe('removePostAcknowledgement', () => {
const post = TestHelper.fakePost(channelId);
const post = TestHelper.fakePost({channel_id: channelId});

it('handle not found database', async () => {
const {model, error} = await removePostAcknowledgement('foo', post.id, user.id, false);
Expand Down Expand Up @@ -321,7 +320,7 @@ describe('removePostAcknowledgement', () => {
});

describe('deletePosts', () => {
const post = TestHelper.fakePost(channelId);
const post = TestHelper.fakePost({channel_id: channelId});

it('handle not found database', async () => {
const {error} = await deletePosts('foo', [post.id]);
Expand Down
2 changes: 1 addition & 1 deletion app/actions/local/systems.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe('dataRetention', () => {
});

it('rentention off - dataRetentionCleanup', async () => {
const post = {...TestHelper.fakePost('channelid1'), id: 'postid', create_at: 1};
const post = TestHelper.fakePost({channel_id: 'channelid1', id: 'postid', create_at: 1});
await operator.handlePosts({
actionType: ActionType.POSTS.RECEIVED_IN_CHANNEL,
order: [post.id],
Expand Down
14 changes: 7 additions & 7 deletions app/actions/local/thread.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const user2: UserProfile = {
roles: '',
} as UserProfile;

const rootPost = {...TestHelper.fakePost(channelId, user.id), id: 'rootpostid', create_at: 1};
const rootPost = TestHelper.fakePost({channel_id: channelId, user_id: user.id, id: 'rootpostid', create_at: 1});
const threads = [
{
id: rootPost.id,
Expand Down Expand Up @@ -147,7 +147,7 @@ describe('switchToThread', () => {
it('handle no channel', async () => {
await operator.handleUsers({users: [user], prepareRecordsOnly: false});
await operator.handleSystem({systems: [{id: SYSTEM_IDENTIFIERS.CURRENT_USER_ID, value: user.id}], prepareRecordsOnly: false});
const post = {...TestHelper.fakePost(channelId, user2.id), id: 'postid', create_at: 1};
const post = TestHelper.fakePost({channel_id: channelId, user_id: user2.id, id: 'postid', create_at: 1});
await operator.handlePosts({
actionType: ActionType.POSTS.RECEIVED_IN_CHANNEL,
order: [post.id],
Expand All @@ -165,7 +165,7 @@ describe('switchToThread', () => {
await operator.handleTeam({teams: [team], prepareRecordsOnly: false});
await operator.handleSystem({systems: [{id: SYSTEM_IDENTIFIERS.CURRENT_TEAM_ID, value: 'teamid2'}, {id: SYSTEM_IDENTIFIERS.CURRENT_USER_ID, value: user.id}], prepareRecordsOnly: false});
await operator.handleChannel({channels: [channel], prepareRecordsOnly: false});
const post = {...TestHelper.fakePost(channelId, user2.id), id: 'postid', create_at: 1};
const post = TestHelper.fakePost({channel_id: channelId, user_id: user2.id, id: 'postid', create_at: 1});
await operator.handlePosts({
actionType: ActionType.POSTS.RECEIVED_IN_CHANNEL,
order: [post.id],
Expand All @@ -183,7 +183,7 @@ describe('switchToThread', () => {
await operator.handleTeam({teams: [team], prepareRecordsOnly: false});
await operator.handleSystem({systems: [{id: SYSTEM_IDENTIFIERS.CURRENT_TEAM_ID, value: 'teamid2'}, {id: SYSTEM_IDENTIFIERS.CURRENT_USER_ID, value: user.id}], prepareRecordsOnly: false});
await operator.handleChannel({channels: [channel], prepareRecordsOnly: false});
const post = {...TestHelper.fakePost(channelId, user2.id), id: 'postid', create_at: 1};
const post = TestHelper.fakePost({channel_id: channelId, user_id: user2.id, id: 'postid', create_at: 1});
await operator.handlePosts({
actionType: ActionType.POSTS.RECEIVED_IN_CHANNEL,
order: [post.id],
Expand All @@ -201,7 +201,7 @@ describe('switchToThread', () => {
await operator.handleTeam({teams: [team], prepareRecordsOnly: false});
await operator.handleSystem({systems: [{id: SYSTEM_IDENTIFIERS.CURRENT_TEAM_ID, value: 'teamid2'}, {id: SYSTEM_IDENTIFIERS.CURRENT_USER_ID, value: user.id}], prepareRecordsOnly: false});
await operator.handleChannel({channels: [{...channel, team_id: '', type: 'D', display_name: 'user1-user2'}], prepareRecordsOnly: false});
const post = {...TestHelper.fakePost(channelId, user2.id), id: 'postid', create_at: 1};
const post = TestHelper.fakePost({channel_id: channelId, user_id: user2.id, id: 'postid', create_at: 1});
await operator.handlePosts({
actionType: ActionType.POSTS.RECEIVED_IN_CHANNEL,
order: [post.id],
Expand All @@ -224,7 +224,7 @@ describe('createThreadFromNewPost', () => {
it('base case', async () => {
await operator.handleUsers({users: [user, user2], prepareRecordsOnly: false});
await operator.handleThreads({threads, prepareRecordsOnly: false, teamId: team.id});
const post = {...TestHelper.fakePost(channelId, user2.id), id: 'postid', create_at: 1, root_id: rootPost.id};
const post = TestHelper.fakePost({channel_id: channelId, user_id: user2.id, id: 'postid', create_at: 1, root_id: rootPost.id});

const {models, error} = await createThreadFromNewPost(serverUrl, post, false);
expect(error).toBeUndefined();
Expand All @@ -234,7 +234,7 @@ describe('createThreadFromNewPost', () => {

it('base case - no root post', async () => {
await operator.handleUsers({users: [user2], prepareRecordsOnly: false});
const post = {...TestHelper.fakePost(channelId, user2.id), id: 'postid', create_at: 1};
const post = TestHelper.fakePost({channel_id: channelId, user_id: user2.id, id: 'postid', create_at: 1});

const {models, error} = await createThreadFromNewPost(serverUrl, post);
expect(error).toBeUndefined();
Expand Down
11 changes: 4 additions & 7 deletions app/actions/remote/entry/notification.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('Performance metrics are set correctly', () => {
expect(client).toBeTruthy();
operator = (await TestHelper.setupServerDatabase(serverUrl)).operator;
await DatabaseManager.setActiveServerDatabase(serverUrl);
post = TestHelper.fakePost(TestHelper.basicChannel!.id);
post = TestHelper.fakePost({channel_id: TestHelper.basicChannel!.id});
await operator.handlePosts({
actionType: ActionType.POSTS.RECEIVED_NEW,
order: [post.id],
Expand Down Expand Up @@ -101,8 +101,7 @@ describe('Performance metrics are set correctly', () => {
});

it('thread notification', async () => {
const commentPost = TestHelper.fakePost(TestHelper.basicChannel!.id);
commentPost.root_id = post.id;
const commentPost = TestHelper.fakePost({channel_id: TestHelper.basicChannel!.id, root_id: post.id});
await operator.handlePosts({
actionType: ActionType.POSTS.RECEIVED_NEW,
order: [commentPost.id],
Expand Down Expand Up @@ -134,8 +133,7 @@ describe('Performance metrics are set correctly', () => {
});

it('thread notification with wrong root id', async () => {
const commentPost = TestHelper.fakePost(TestHelper.basicChannel!.id);
commentPost.root_id = post.id;
const commentPost = TestHelper.fakePost({channel_id: TestHelper.basicChannel!.id, root_id: post.id});
await operator.handlePosts({
actionType: ActionType.POSTS.RECEIVED_NEW,
order: [commentPost.id],
Expand Down Expand Up @@ -167,8 +165,7 @@ describe('Performance metrics are set correctly', () => {
});

it('thread notification with non crt', async () => {
const commentPost = TestHelper.fakePost(TestHelper.basicChannel!.id);
commentPost.root_id = post.id;
const commentPost = TestHelper.fakePost({channel_id: TestHelper.basicChannel!.id, root_id: post.id});
await operator.handlePosts({
actionType: ActionType.POSTS.RECEIVED_NEW,
order: [commentPost.id],
Expand Down
2 changes: 1 addition & 1 deletion app/actions/remote/notifications.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const channel: Channel = {

const user1 = {id: 'userid1', username: 'user1', email: 'user1@mattermost.com', roles: ''} as UserProfile;

const post1 = {...TestHelper.fakePost(channelId), id: 'postid1'};
const post1 = TestHelper.fakePost({channel_id: channelId, id: 'postid1'});

const notificationExtraData = {
channel,
Expand Down
6 changes: 3 additions & 3 deletions app/actions/remote/post.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ const teamId = 'teamid1';
const user1 = {id: 'userid1', username: 'user1', email: 'user1@mattermost.com', roles: ''} as UserProfile;
const user2 = {id: 'userid2', username: 'user2', email: 'user2@mattermost.com', roles: ''} as UserProfile;

const post1 = {...TestHelper.fakePost(channelId), id: 'postid1', user_id: user1.id};
const post2 = {...TestHelper.fakePost(channelId), id: 'postid2', user_id: user2.id};
const reply1 = {...TestHelper.fakePost(channelId), id: 'replyid1', root_id: post1.id, user_id: user2.id};
const post1 = TestHelper.fakePost({channel_id: channelId, id: 'postid1', user_id: user1.id});
const post2 = TestHelper.fakePost({channel_id: channelId, id: 'postid2', user_id: user2.id});
const reply1 = TestHelper.fakePost({channel_id: channelId, id: 'replyid1', root_id: post1.id, user_id: user2.id});

const channel1 = {
id: channelId,
Expand Down
2 changes: 1 addition & 1 deletion app/actions/remote/preference.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const channel: Channel = {
const user1 = {id: 'userid1', username: 'user1', email: 'user1@mattermost.com', roles: ''} as UserProfile;

const preference1 = {category: 'category1', name: 'name1', user_id: user1.id, value: 'value1'} as PreferenceType;
const post1 = {...TestHelper.fakePost(channelId), id: 'postid1'};
const post1 = TestHelper.fakePost({channel_id: channelId, id: 'postid1'});

const throwFunc = () => {
throw Error('error');
Expand Down
4 changes: 2 additions & 2 deletions app/actions/remote/reactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ const team: Team = {

const user1 = {id: 'userid1', username: 'user1', email: 'user1@mattermost.com', roles: ''} as UserProfile;

const post1 = {...TestHelper.fakePost(channelId), id: 'postid1'};
const post2 = {...TestHelper.fakePost(channelId), id: 'postid2', root_id: post1.id};
const post1 = TestHelper.fakePost({channel_id: channelId, id: 'postid1'});
const post2 = TestHelper.fakePost({channel_id: channelId, id: 'postid2', root_id: post1.id});

const thread1: Thread = {id: 'postid1',
reply_count: 1,
Expand Down
2 changes: 1 addition & 1 deletion app/actions/remote/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const channel: Channel = {
} as Channel;

const user1 = {id: 'userid1', username: 'user1', email: 'user1@mattermost.com', roles: ''} as UserProfile;
const post1 = {...TestHelper.fakePost(channelId), id: 'postid1'};
const post1 = TestHelper.fakePost({channel_id: channelId, id: 'postid1'});

const fileInfo1: FileInfo = {
id: 'fileid1',
Expand Down
2 changes: 1 addition & 1 deletion app/actions/remote/thread.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const team: Team = {

const user1 = {id: 'userid1', username: 'user1', email: 'user1@mattermost.com', roles: ''} as UserProfile;

const post1 = {...TestHelper.fakePost(channelId), id: 'postid1'};
const post1 = TestHelper.fakePost({channel_id: channelId, id: 'postid1'});

const thread1: Thread = {id: 'postid1',
reply_count: 1,
Expand Down
Loading

0 comments on commit 498f1c9

Please sign in to comment.