A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
fix(api): include personal notes in dm search scopes (#3486)
Hampus9213a765b1e3
diff --git a/fluxer_api/src/api/channel/services/message/DmScopeUtils.ts b/fluxer_api/src/api/channel/services/message/DmScopeUtils.tsindex bae60de86..2f09ae49a 100644--- a/fluxer_api/src/api/channel/services/message/DmScopeUtils.ts+++ b/fluxer_api/src/api/channel/services/message/DmScopeUtils.ts@@ -1,6 +1,8 @@// SPDX-License-Identifier: AGPL-3.0-or-laterimport type {UserID} from '@app/api/BrandedTypes';+import {userIdToChannelId} from '@app/api/BrandedTypes';+import {isPersonalNotesChannelId} from '@app/api/channel/services/PersonalNotesChannelRepair';import type {Channel} from '@app/api/models/Channel';import type {UserRepository} from '@app/api/user/repositories/UserRepository';import {ChannelTypes} from '@fluxer/constants/src/ChannelConstants';@@ -15,6 +17,9 @@ interface DmScopeOptions {}export function isDmScopeChannelForUser(channel: Channel, userId: UserID): boolean {+ if (channel.type === ChannelTypes.DM_PERSONAL_NOTES) {+ return isPersonalNotesChannelId({userId, channelId: channel.id});+ }const isDm = channel.type === ChannelTypes.DM || channel.type === ChannelTypes.GROUP_DM;return isDm && channel.recipientIds.has(userId);}@@ -26,7 +31,7 @@ export async function getDmChannelIdsForScope({includeChannel,}: DmScopeOptions): Promise<Array<string>> {const summaryResults = await userRepository.listPrivateChannelSummaries(userId);- const channelIdStrings = new Set<string>();+ const channelIdStrings = new Set<string>([userIdToChannelId(userId).toString()]);for (const summary of summaryResults) {const isDm =summary.channelType === ChannelTypes.DM || summary.channelType === ChannelTypes.GROUP_DM || summary.isGroupDm;diff --git a/fluxer_api/src/api/search/tests/MessageSearchEndpoint.test.ts b/fluxer_api/src/api/search/tests/MessageSearchEndpoint.test.tsindex 13f41b8c7..15931dab8 100644--- a/fluxer_api/src/api/search/tests/MessageSearchEndpoint.test.ts+++ b/fluxer_api/src/api/search/tests/MessageSearchEndpoint.test.ts@@ -174,5 +174,39 @@ describe('Message Search Endpoint', () => {}expect(found).toBe(true);});++ test.each(['all_dms', 'open_dms', 'all', 'open_dms_and_all_guilds'] as const)(+ 'finds personal note messages in the %s scope',+ async (scope) => {+ const account = await createTestAccount(harness);+ await ensureSessionStarted(harness, account.token);+ const personalNotesChannelId = account.userId;+ await sendMessage(harness, account.token, personalNotesChannelId, `personal-notes-bootstrap-${Date.now()}`);+ await markChannelAsIndexed(harness, personalNotesChannelId);+ const uniqueContent = `personal-notes-${scope}-${Date.now()}`;+ await sendMessage(harness, account.token, personalNotesChannelId, uniqueContent);+ let foundInScope = false;+ let foundInFilter = false;+ for (let attempt = 0; attempt < 20 && !(foundInScope && foundInFilter); attempt++) {+ const scoped = await createBuilder<MessageSearchResponse>(harness, account.token)+ .post('/search/messages')+ .body({content: uniqueContent, scope, context_channel_id: personalNotesChannelId})+ .expect(HTTP_STATUS.OK)+ .execute();+ foundInScope ||= isSearchResult(scoped) && scoped.messages.some((m) => m.content === uniqueContent);+ const filtered = await createBuilder<MessageSearchResponse>(harness, account.token)+ .post('/search/messages')+ .body({content: uniqueContent, scope, channel_ids: [personalNotesChannelId]})+ .expect(HTTP_STATUS.OK)+ .execute();+ foundInFilter ||= isSearchResult(filtered) && filtered.messages.some((m) => m.content === uniqueContent);+ if (!(foundInScope && foundInFilter)) {+ await wait(TEST_TIMEOUTS.QUICK);+ }+ }+ expect(foundInScope).toBe(true);+ expect(foundInFilter).toBe(true);+ },+ );});});