Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { FastifyRequest } from "fastify";
import { PublicFile } from "../../../../../services/files/entities/file";
import { ListResult } from "../../../../../core/platform/framework/api/crud-service";
import { Pagination } from "../../../../../core/platform/framework/api/crud-service";
import { ListResult, Pagination } from "../../../../../core/platform/framework/api/crud-service";
import { MessageFile } from "../../../../../services/messages/entities/message-files";
import { Message } from "../../../../../services/messages/entities/messages";
import { ChannelViewExecutionContext } from "../../../../../services/messages/types";
Expand All @@ -11,6 +9,7 @@ import { formatUser } from "../../../../../utils/users";
import gr from "../../../../global-resolver";
import { MessageFileRef } from "../../../../../services/messages/entities/message-file-refs";
import recentFiles from "./recent-files";
import { isEmpty } from "lodash";

interface MessageViewSearchFilesQueryParameters extends PaginationQueryParameters {
q: string;
Expand Down Expand Up @@ -41,7 +40,7 @@ export default async (
}>,
context: ChannelViewExecutionContext,
): Promise<ResourceListResponse<MessageFile>> => {
if (request.query.q.length < 1) {
if (isEmpty(request)) {
return recentFiles(request);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ const emoji = require('emoji-name-map');
type PropsType = {
channel: ChannelType;
showLabel: boolean;
collapseToOne?: boolean;
};

export default ({ channel, showLabel }: PropsType): JSX.Element => {
export default ({ channel, showLabel, collapseToOne }: PropsType): JSX.Element => {
if (channel.visibility === 'direct') {
let channelMembers = (channel.members || []).filter(e => e !== UsersService.getCurrentUserId());
channelMembers = channelMembers.filter((e, i) => channelMembers.indexOf(e) === i);
Expand All @@ -29,12 +30,14 @@ export default ({ channel, showLabel }: PropsType): JSX.Element => {

users.forEach(member => {
channelName.push(UserService.getFullName(member));
icons.push(getThumbnail(member));
if (!(collapseToOne && icons.length > 0)) {
icons.push(getThumbnail(member));
}
});

let width = 64;

if (channelMembers.length > 1) {
if (!collapseToOne && channelMembers.length > 1) {
const shift = 64 - (64 * 2) / 5;
width = 64 + (channelMembers.length - 1) * shift;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default ({ channel, highlight, onClick }: PropsType): JSX.Element => {

return (
<div className="result-item" onClick={onItemClick}>
<ChannelAvatar channel={channel} showLabel={false} />
<ChannelAvatar channel={channel} showLabel={false} collapseToOne={true} />
<div className="result-item-content">
<div
className="channel-title"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ export default ({ message, highlight, onClick }: PropsType): JSX.Element => {

return (
<div className="result-item" onClick={onItemClick}>
{channel ? <ChannelAvatar channel={channel} showLabel={false} /> : <div />}
{channel ? (
<ChannelAvatar channel={channel} showLabel={false} collapseToOne={true} />
) : (
<div />
)}
{/*<div className="result-item-icon">*/}
{/* <div>*/}
{/* <img className="result-item-icon-back" src={thumbnail} />*/}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default (): JSX.Element => {
Search.recent.channels.slice(0, 14).map(channel => (
<ChannelItem
channel={channel}
key={channel.id}
key={channel.id || '' + Math.random()}
onClick={() => {
onClick(channel);
}}
Expand All @@ -43,7 +43,7 @@ export default (): JSX.Element => {

const ChannelItem = ({ channel, onClick }: { channel: ChannelType; onClick: any }): JSX.Element => {
assert(channel.workspace_id, 'No workspace_id in channel object');
const avatar = ChannelAvatar({ channel, showLabel: true });
const avatar = ChannelAvatar({ channel, showLabel: true, collapseToOne: true });
return (
<div className="result-item" onClick={onClick}>
<div className="result-item-icon">{avatar}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ input:focus {
//position: absolute;

width: 100vw;
height: 90vh;
height: 100vh;

max-width: 1000px;

Expand Down Expand Up @@ -456,7 +456,7 @@ input:focus {
mask-image: linear-gradient(to right, black 92%, transparent 100%);

.result-item {
margin-right: 5px;
margin-right: 4px;
cursor: pointer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default (): JSX.Element => {
<div>
<div className="results-group-title ">Channels and contacts</div>

{Search.results.channels.length && (
{(Search.results.channels.length && (
<div className="result-items">
{Search.results.channels.map(channel => (
<ChannelsResult
Expand All @@ -36,9 +36,9 @@ export default (): JSX.Element => {
/>
))}
</div>
)}
)) || <div />}

{Search.results.users.length && (
{(Search.results.users.length && (
<div className="result-items">
{Search.results.users.map(user => (
<UsersResult
Expand All @@ -49,7 +49,7 @@ export default (): JSX.Element => {
/>
))}
</div>
)}
)) || <div />}
</div>
)) || <div />}
{(Search.results.messages.length && (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useEffect, useState } from 'react';
import Search from 'features/global/services/search-service';
import FilesResult from 'components/search-popup/parts/recent/files-result';
import PerfectScrollbar from 'react-perfect-scrollbar';
import { FileType } from 'features/files/types/file';
import DriveService from 'deprecated/Apps/Drive/Drive';
import FileUploadService from 'features/files/services/file-upload-service';
import PerfectScrollbar from 'react-perfect-scrollbar';
import FilesResult from 'components/search-popup/parts/recent/files-result';

export default (): JSX.Element => {
const [pageReady, setPageReady] = useState(false);
Expand Down Expand Up @@ -85,6 +85,6 @@ export default (): JSX.Element => {
</PerfectScrollbar>
</div>
</div>
)) || <div />
)) || <div></div>
);
};
43 changes: 34 additions & 9 deletions twake/frontend/src/app/features/global/services/search-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,43 @@ class SearchService extends Observable {
this.notify();

const promises = [
ChannelAPIClient.recent(Workspaces.currentGroupId, 12).then(a => {
ChannelAPIClient.recent(Workspaces.currentGroupId, 14).then(a => {
this.recent.channels = a;
this.notify();
}),
FileAPIClient.recent(Workspaces.currentGroupId, 'file', 10).then(a => {
this.recent.files = a;
this.notify();
}),
FileAPIClient.recent(Workspaces.currentGroupId, 'media', 10).then(a => {
this.recent.media = a;
this.notify();
}),

MessageAPIClient.searchFile(null, {
limit: 10,
is_file: true,
})
.then(a => {
this.recent.files = a.resources;
this.notify();
})
.catch(e => {
this.logger.error(e);
}),

MessageAPIClient.searchFile(null, {
limit: 10,
is_media: true,
})
.then(a => {
this.recent.media = a.resources;
this.notify();
})
.catch(e => {
this.logger.error(e);
}),

// FileAPIClient.recent(Workspaces.currentGroupId, 'file', 10).then(a => {
// this.recent.files = a;
// this.notify();
// }),
// FileAPIClient.recent(Workspaces.currentGroupId, 'media', 10).then(a => {
// this.recent.media = a;
// this.notify();
// }),
];

Promise.any(promises).then(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class MessageAPIClient {

/**
* Delete a link preview from a message
*
*
* @param {String} companyId - The company id
* @param {String} threadId - The thread id
* @param {String} messageId - The message id
Expand All @@ -156,7 +156,7 @@ class MessageAPIClient {

return response.resource;
}

async search(searchString: string, options?: BaseSearchOptions) {
let companyId = options?.company_id ? options.company_id : Workspace.currentGroupId;
let query = `/internal/services/messages/v1/companies/${companyId}/search?q=${searchString}`;
Expand All @@ -170,9 +170,12 @@ class MessageAPIClient {
return res;
}

async searchFile(searchString: string, options?: FileSearchOptions) {
async searchFile(searchString: string | null, options?: FileSearchOptions) {
let companyId = options?.company_id ? options.company_id : Workspace.currentGroupId;
let query = `/internal/services/messages/v1/companies/${companyId}/files/search?q=${searchString}`;
let query = `/internal/services/messages/v1/companies/${companyId}/files/search`;
if (searchString) {
query += `q=${searchString}`;
}
const res = await Api.getWithParams<{ resources: FileType[] }>(query, options);
this.logger.debug(
`FileSearch by name "${searchString}" with options`,
Expand Down