Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(chat): Fixed delete 'shared with me' attachments (Issue #2005) #2010

Merged
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
2 changes: 1 addition & 1 deletion apps/chat/src/components/Chatbar/ChatFolders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ const ChatFolderTemplate = ({
if (folder.sharedWithMe) {
dispatch(
ShareActions.discardSharedWithMe({
resourceId: folder.id,
resourceIds: [folder.id],
isFolder: true,
featureType: FeatureType.Chat,
}),
Expand Down
2 changes: 1 addition & 1 deletion apps/chat/src/components/Chatbar/Conversation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ export const ConversationComponent = ({
if (conversation.sharedWithMe) {
dispatch(
ShareActions.discardSharedWithMe({
resourceId: conversation.id,
resourceIds: [conversation.id],
featureType: FeatureType.Chat,
}),
);
Expand Down
27 changes: 24 additions & 3 deletions apps/chat/src/components/Files/FileManagerModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -544,11 +544,11 @@ export const FileManagerModal = ({
[canAttachFiles, dispatch, forceShowSelectCheckBox],
);

const handleDeleteFolder = useCallback(
const handleDiscardSharedWithMeFolder = useCallback(
(folderId: string) => {
dispatch(
ShareActions.discardSharedWithMe({
resourceId: folderId,
resourceIds: [folderId],
featureType: FeatureType.File,
isFolder: true,
}),
Expand All @@ -562,6 +562,16 @@ export const FileManagerModal = ({
return;
}
if (deletingFileIds.length) {
const sharedWithMeFilesIds = sharedWithMeRootFiles
.filter(({ id }) => deletingFileIds.includes(id))
.map(({ id }) => id);

dispatch(
ShareActions.discardSharedWithMe({
resourceIds: sharedWithMeFilesIds,
featureType: FeatureType.File,
}),
);
dispatch(FilesActions.deleteFilesList({ fileIds: deletingFileIds }));
if (selectedFilesIds === deletingFileIds) {
setSelectedFilesIds([]);
Expand All @@ -570,6 +580,15 @@ export const FileManagerModal = ({
if (deletingFolderIds.length) {
// TODO: implement
// dispatch(FilesActions.deleteFolderList({ folderIds: deletingFolderIds }));
const sharedWithMeFoldersIds = sharedWithMeRootFolders
.filter(({ id }) => deletingFolderIds.includes(id))
.map(({ id }) => id);
dispatch(
ShareActions.discardSharedWithMe({
resourceIds: sharedWithMeFoldersIds,
featureType: FeatureType.File,
}),
);
if (selectedFolderIds === deletingFolderIds) {
setSelectedFolderIds([]);
}
Expand All @@ -580,6 +599,8 @@ export const FileManagerModal = ({
dispatch,
selectedFilesIds,
selectedFolderIds,
sharedWithMeRootFiles,
sharedWithMeRootFolders,
]);

const handleDownloadMultipleFiles = useCallback(() => {
Expand Down Expand Up @@ -759,7 +780,7 @@ export const FileManagerModal = ({
canSelectFolders={canAttachFolders}
showTooltip={showTooltip}
onSelectFolder={handleFolderToggle}
onDeleteFolder={handleDeleteFolder}
onDeleteFolder={handleDiscardSharedWithMeFolder}
/>
);
})}
Expand Down
2 changes: 1 addition & 1 deletion apps/chat/src/components/Promptbar/components/Prompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export const PromptComponent = ({
if (prompt.sharedWithMe) {
dispatch(
ShareActions.discardSharedWithMe({
resourceId: prompt.id,
resourceIds: [prompt.id],
featureType: FeatureType.Prompt,
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ const PromptFolderTemplate = ({
if (folder.sharedWithMe) {
dispatch(
ShareActions.discardSharedWithMe({
resourceId: folder.id,
resourceIds: [folder.id],
isFolder: true,
featureType: FeatureType.Prompt,
}),
Expand Down
10 changes: 0 additions & 10 deletions apps/chat/src/store/files/files.epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { FeatureType, UploadStatus } from '@/src/types/common';
import { AppEpic } from '@/src/types/store';

import { PublicationActions } from '../publication/publication.reducers';
import { ShareActions } from '../share/share.reducers';
import { UIActions, UISelectors } from '../ui/ui.reducers';
import { FilesActions, FilesSelectors } from './files.reducers';

Expand Down Expand Up @@ -169,15 +168,6 @@ const deleteFileEpic: AppEpic = (action$, state$) =>
(file) => file.id === payload.fileId,
);

if (file && file.sharedWithMe) {
return of(
ShareActions.discardSharedWithMe({
resourceId: file.id,
featureType: FeatureType.File,
}),
);
}

if (!file?.serverSynced) {
return concat(
of(
Expand Down
37 changes: 24 additions & 13 deletions apps/chat/src/store/share/share.epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -853,12 +853,31 @@ const discardSharedWithMeEpic: AppEpic = (action$) =>
action$.pipe(
filter(ShareActions.discardSharedWithMe.match),
switchMap(({ payload }) => {
const resourceUrl = payload.isFolder
? ApiUtils.encodeApiUrl(payload.resourceId) + '/'
: ApiUtils.encodeApiUrl(payload.resourceId);
const resourceUrls = payload.isFolder
? payload.resourceIds.map(
(resourceId) => ApiUtils.encodeApiUrl(resourceId) + '/',
)
: payload.resourceIds.map((resourceId) =>
ApiUtils.encodeApiUrl(resourceId),
);

return ShareService.shareDiscard([resourceUrl]).pipe(
map(() => ShareActions.discardSharedWithMeSuccess(payload)),
return ShareService.shareDiscard(resourceUrls).pipe(
switchMap(() => {
if (!payload.isFolder && payload.featureType === FeatureType.File) {
return EMPTY;
}
const actions: Observable<AnyAction>[] = payload.resourceIds.map(
(resourceId) =>
of(
ShareActions.discardSharedWithMeSuccess({
resourceId,
featureType: payload.featureType,
isFolder: payload.isFolder,
}),
),
);
return concat(...actions);
}),
catchError(() => of(ShareActions.discardSharedWithMeFail())),
);
}),
Expand Down Expand Up @@ -970,14 +989,6 @@ const discardSharedWithMeSuccessEpic: AppEpic = (action$, state$) =>
}

if (payload.featureType === FeatureType.File) {
if (!payload.isFolder) {
return of(
FilesActions.deleteFileSuccess({
fileId: payload.resourceId,
}),
);
}

const folders = FilesSelectors.selectFolders(state$.value);
return concat(
of(
Expand Down
2 changes: 1 addition & 1 deletion apps/chat/src/store/share/share.reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const shareSlice = createSlice({
discardSharedWithMe: (
state,
_action: PayloadAction<{
resourceId: string;
resourceIds: string[];
featureType: FeatureType;
isFolder?: boolean;
}>,
Expand Down