Skip to content

Commit

Permalink
Attachment list in view info for DMs and GMs mobile (#8120)
Browse files Browse the repository at this point in the history
* Attachment list in view info for DMs and GMs mobile

* refactor: only get currentID for DMs and GMs

* used typing
  • Loading branch information
Rajat-Dabade authored Aug 13, 2024
1 parent 4e4bd8f commit 8f536f7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions app/actions/remote/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
// See LICENSE.txt for license information.

import {getPosts} from '@actions/local/post';
import {General} from '@app/constants';
import {SYSTEM_IDENTIFIERS} from '@constants/database';
import DatabaseManager from '@database/manager';
import NetworkManager from '@managers/network_manager';
import {prepareMissingChannelsForAllTeams} from '@queries/servers/channel';
import {getConfigValue} from '@queries/servers/system';
import {getConfigValue, getCurrentTeamId} from '@queries/servers/system';
import {getIsCRTEnabled, prepareThreadsFromReceivedPosts} from '@queries/servers/thread';
import {getCurrentUser} from '@queries/servers/user';
import {getFullErrorMessage} from '@utils/errors';
Expand All @@ -18,6 +19,7 @@ import {fetchPostAuthors, fetchMissingChannelsFromPosts} from './post';
import {forceLogoutIfNecessary} from './session';

import type Model from '@nozbe/watermelondb/Model';
import type ChannelModel from '@typings/database/models/servers/channel';
import type PostModel from '@typings/database/models/servers/post';

export async function fetchRecentMentions(serverUrl: string): Promise<PostSearchRequest> {
Expand Down Expand Up @@ -129,10 +131,15 @@ export const searchPosts = async (serverUrl: string, teamId: string, params: Pos
}
};

export const searchFiles = async (serverUrl: string, teamId: string, params: FileSearchParams): Promise<{files?: FileInfo[]; channels?: string[]; error?: unknown}> => {
export const searchFiles = async (serverUrl: string, teamId: string, params: FileSearchParams, channel?: ChannelModel): Promise<{files?: FileInfo[]; channels?: string[]; error?: unknown}> => {
try {
let currentTeamId = teamId;
if (channel && (channel.type === General.DM_CHANNEL || channel.type === General.GM_CHANNEL)) {
const {database} = DatabaseManager.getServerDatabaseAndOperator(serverUrl);
currentTeamId = await getCurrentTeamId(database);
}
const client = NetworkManager.getClient(serverUrl);
const result = await client.searchFiles(teamId, params.terms);
const result = await client.searchFiles(currentTeamId, params.terms);
const files = result?.file_infos ? Object.values(result.file_infos) : [];
const [allChannelIds, allPostIds] = files.reduce<[Set<string>, Set<string>]>((acc, f) => {
if (f.channel_id) {
Expand Down
2 changes: 1 addition & 1 deletion app/screens/channel_files/channel_files.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function ChannelFiles({
const t = Date.now();
lastSearchRequest.current = t;
const searchParams = getSearchParams(channel.id, searchTerm, ftr);
const {files} = await searchFiles(serverUrl, channel.teamId, searchParams);
const {files} = await searchFiles(serverUrl, channel.teamId, searchParams, channel);
if (lastSearchRequest.current !== t) {
return;
}
Expand Down

0 comments on commit 8f536f7

Please sign in to comment.