|
4 | 4 | /* eslint-disable max-lines */ |
5 | 5 |
|
6 | 6 | import {processReceivedThreads} from '@actions/local/thread'; |
7 | | -import {Config, Preferences, Screens} from '@constants'; |
| 7 | +import {ActionType, Config, Preferences, Screens} from '@constants'; |
8 | 8 | import {SYSTEM_IDENTIFIERS} from '@constants/database'; |
9 | 9 | import DatabaseManager from '@database/manager'; |
10 | 10 | import TestHelper from '@test/test_helper'; |
@@ -1219,6 +1219,146 @@ describe('Team Queries', () => { |
1219 | 1219 | await TestHelper.wait(waitTime); |
1220 | 1220 | expect(subscriptionNext).not.toHaveBeenCalled(); |
1221 | 1221 | }); |
| 1222 | + |
| 1223 | + it('should not consider the team unread when a gm or a dm are unread', async () => { |
| 1224 | + const subscriptionNext = jest.fn(); |
| 1225 | + const notify_props = {mark_unread: 'all' as const}; |
| 1226 | + const result = observeIsTeamUnread(database, teamId); |
| 1227 | + |
| 1228 | + result.subscribe({next: subscriptionNext}); |
| 1229 | + await TestHelper.wait(waitTime); |
| 1230 | + |
| 1231 | + // The subscription always return the first value |
| 1232 | + expect(subscriptionNext).toHaveBeenCalledWith(false); |
| 1233 | + subscriptionNext.mockClear(); |
| 1234 | + |
| 1235 | + // Setup DM channel with unreads |
| 1236 | + let channelModels = (await Promise.all((await prepareAllMyChannels( |
| 1237 | + operator, |
| 1238 | + [TestHelper.fakeChannel({id: 'dm1', team_id: '', type: 'D', total_msg_count: 30})], |
| 1239 | + [TestHelper.fakeMyChannel({ |
| 1240 | + channel_id: 'dm1', |
| 1241 | + user_id: userId, |
| 1242 | + notify_props, |
| 1243 | + msg_count: 20, |
| 1244 | + })], |
| 1245 | + false, |
| 1246 | + )))).flat(); |
| 1247 | + await operator.batchRecords([...channelModels], 'test'); |
| 1248 | + |
| 1249 | + await TestHelper.wait(waitTime); |
| 1250 | + expect(subscriptionNext).not.toHaveBeenCalled(); |
| 1251 | + |
| 1252 | + // Setup GM channel with unreads |
| 1253 | + channelModels = (await Promise.all((await prepareAllMyChannels( |
| 1254 | + operator, |
| 1255 | + [TestHelper.fakeChannel({id: 'gm1', team_id: '', type: 'G', total_msg_count: 30})], |
| 1256 | + [TestHelper.fakeMyChannel({ |
| 1257 | + channel_id: 'gm1', |
| 1258 | + user_id: userId, |
| 1259 | + notify_props, |
| 1260 | + msg_count: 20, |
| 1261 | + })], |
| 1262 | + false, |
| 1263 | + )))).flat(); |
| 1264 | + await operator.batchRecords([...channelModels], 'test'); |
| 1265 | + |
| 1266 | + await TestHelper.wait(waitTime); |
| 1267 | + expect(subscriptionNext).not.toHaveBeenCalled(); |
| 1268 | + }); |
| 1269 | + |
| 1270 | + it('should not consider the team unread if a thread in a dm or a gm has unread messages', async () => { |
| 1271 | + const subscriptionNext = jest.fn(); |
| 1272 | + const notify_props = {mark_unread: 'all' as const}; |
| 1273 | + const result = observeIsTeamUnread(database, teamId); |
| 1274 | + |
| 1275 | + result.subscribe({next: subscriptionNext}); |
| 1276 | + await TestHelper.wait(waitTime); |
| 1277 | + |
| 1278 | + // The subscription always return the first value |
| 1279 | + expect(subscriptionNext).toHaveBeenCalledWith(false); |
| 1280 | + subscriptionNext.mockClear(); |
| 1281 | + |
| 1282 | + // Setup DM channel with thread |
| 1283 | + let channelModels = (await Promise.all((await prepareAllMyChannels( |
| 1284 | + operator, |
| 1285 | + [TestHelper.fakeChannel({id: 'dm1', team_id: '', type: 'D', total_msg_count: 20})], |
| 1286 | + [TestHelper.fakeMyChannel({ |
| 1287 | + channel_id: 'dm1', |
| 1288 | + user_id: userId, |
| 1289 | + notify_props, |
| 1290 | + msg_count: 20, |
| 1291 | + })], |
| 1292 | + false, |
| 1293 | + )))).flat(); |
| 1294 | + |
| 1295 | + const dmPost = TestHelper.fakePost({id: 'dm_thread', channel_id: 'dm1'}); |
| 1296 | + |
| 1297 | + const dmThreads = [{ |
| 1298 | + ...TestHelper.fakeThread({ |
| 1299 | + id: 'dm_thread', |
| 1300 | + participants: undefined, |
| 1301 | + reply_count: 2, |
| 1302 | + last_reply_at: 123, |
| 1303 | + is_following: true, |
| 1304 | + unread_replies: 2, |
| 1305 | + unread_mentions: 1, |
| 1306 | + }), |
| 1307 | + lastFetchedAt: 0, |
| 1308 | + }]; |
| 1309 | + |
| 1310 | + const dmModels = await operator.handleThreads({threads: dmThreads, prepareRecordsOnly: false}); |
| 1311 | + let postModels = await operator.handlePosts({ |
| 1312 | + actionType: ActionType.POSTS.RECEIVED_IN_CHANNEL, |
| 1313 | + order: [], |
| 1314 | + posts: [dmPost], |
| 1315 | + prepareRecordsOnly: true, |
| 1316 | + }); |
| 1317 | + await operator.batchRecords([...channelModels, ...dmModels, ...postModels], 'test'); |
| 1318 | + |
| 1319 | + await TestHelper.wait(waitTime); |
| 1320 | + expect(subscriptionNext).not.toHaveBeenCalled(); |
| 1321 | + |
| 1322 | + // Setup GM channel with thread |
| 1323 | + channelModels = (await Promise.all((await prepareAllMyChannels( |
| 1324 | + operator, |
| 1325 | + [TestHelper.fakeChannel({id: 'gm1', team_id: '', type: 'G', total_msg_count: 20})], |
| 1326 | + [TestHelper.fakeMyChannel({ |
| 1327 | + channel_id: 'gm1', |
| 1328 | + user_id: userId, |
| 1329 | + notify_props, |
| 1330 | + msg_count: 20, |
| 1331 | + })], |
| 1332 | + false, |
| 1333 | + )))).flat(); |
| 1334 | + |
| 1335 | + const gmPost = TestHelper.fakePost({id: 'gm_thread', channel_id: 'gm1'}); |
| 1336 | + |
| 1337 | + const gmThreads = [{ |
| 1338 | + ...TestHelper.fakeThread({ |
| 1339 | + id: 'gm_thread', |
| 1340 | + participants: undefined, |
| 1341 | + reply_count: 3, |
| 1342 | + last_reply_at: 123, |
| 1343 | + is_following: true, |
| 1344 | + unread_replies: 3, |
| 1345 | + unread_mentions: 2, |
| 1346 | + }), |
| 1347 | + lastFetchedAt: 123, |
| 1348 | + }]; |
| 1349 | + |
| 1350 | + const gmModels = await operator.handleThreads({threads: gmThreads, prepareRecordsOnly: false}); |
| 1351 | + postModels = await operator.handlePosts({ |
| 1352 | + actionType: ActionType.POSTS.RECEIVED_IN_CHANNEL, |
| 1353 | + order: [], |
| 1354 | + posts: [gmPost], |
| 1355 | + prepareRecordsOnly: true, |
| 1356 | + }); |
| 1357 | + await operator.batchRecords([...channelModels, ...gmModels, ...postModels], 'test'); |
| 1358 | + |
| 1359 | + await TestHelper.wait(waitTime); |
| 1360 | + expect(subscriptionNext).not.toHaveBeenCalled(); |
| 1361 | + }); |
1222 | 1362 | }); |
1223 | 1363 |
|
1224 | 1364 | describe('observeSortedJoinedTeams', () => { |
|
0 commit comments