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

Feat/attachments extra attrs #535

Merged
merged 24 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
994c885
feat(api): add attachment extra attributes
marrouchi Jan 8, 2025
7be6115
feat(frontend): apply frontend updates (context)
marrouchi Jan 8, 2025
6783103
fix(api): unit test
marrouchi Jan 8, 2025
9e96055
feat: update migration to populate subscriber avatar attachments
marrouchi Jan 8, 2025
65fad2f
feat: update migration to populate user avatar attachments
marrouchi Jan 8, 2025
e8c917a
feat: migrate setting attachments
marrouchi Jan 9, 2025
e859cf1
feat: add migration to populate block attachment new attributes
marrouchi Jan 9, 2025
39213e8
refactor: channels design to allow attachment ownership
marrouchi Jan 15, 2025
90aad93
fix: update migration to populate the message attachments with extra …
marrouchi Jan 15, 2025
bdf1763
refactor: rename owner to createdBy
marrouchi Jan 15, 2025
0b4a108
fix: minor
marrouchi Jan 15, 2025
505cd24
feat: add the access attribute
marrouchi Jan 16, 2025
3f9dd69
refactor: rename context to resourceRef
marrouchi Jan 16, 2025
c27f37a
feat: rename enum instead of string
marrouchi Jan 16, 2025
4fac5d4
feat: enforce security to access own attachment
marrouchi Jan 16, 2025
359049f
refactor: use enums
marrouchi Jan 16, 2025
a355ef0
fix: console channel session.web
marrouchi Jan 16, 2025
36b0544
fix: media library
marrouchi Jan 17, 2025
f736356
fix: carousel display + refactor attachment url
marrouchi Jan 17, 2025
8d1bb47
feat: enhance attachment display in inbox
marrouchi Jan 17, 2025
356b16a
fix: rename payload to ensure consistency
marrouchi Jan 17, 2025
b74c4a4
fix: migration
marrouchi Jan 17, 2025
3ed8bbc
feat: make storage mode configurable env var
MohamedAliBouhaouala Jan 17, 2025
bb2d0d4
Merge pull request #583 from Hexastack/feat/storage-mode-env-var
marrouchi Jan 17, 2025
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
1 change: 1 addition & 0 deletions frontend/src/components/contents/ContentDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const ContentFieldInput: React.FC<ContentFieldInput> = ({
value={field.value?.payload?.id}
accept={MIME_TYPES["images"].join(",")}
format="full"
size={256}
resourceRef={AttachmentResourceRef.ContentAttachment}
/>
);
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/components/inbox/components/AttachmentViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { Button, Dialog, DialogContent } from "@mui/material";
import { FC } from "react";

import { DialogTitle } from "@/app-components/dialogs";
import { useConfig } from "@/hooks/useConfig";
import { useDialog } from "@/hooks/useDialog";
import { useGetAttachmentUrl } from "@/hooks/useGetAttachmentUrl";
import { useTranslate } from "@/hooks/useTranslate";
import {
FileType,
Expand Down Expand Up @@ -95,19 +95,19 @@ export const AttachmentViewer = (props: {
message: StdIncomingAttachmentMessage | StdOutgoingAttachmentMessage;
}) => {
const message = props.message;
const { apiUrl } = useConfig();
const getUrl = useGetAttachmentUrl();

// if the attachment is an array show a 4x4 grid with a +{number of remaining attachment} and open a modal to show the list of attachments
// Remark: Messenger doesn't send multiple attachments when user sends multiple at once, it only relays the first one to Hexabot
// TODO: Implenent this
if (Array.isArray(message.attachment)) {
if (!message.attachment) {
return <>No attachment to display</>;
} else if (Array.isArray(message.attachment)) {
return <>Not yet Implemented</>;
}

const AttachmentViewerForType = componentMap[message.attachment.type];
const url =
"id" in message.attachment?.payload && message.attachment?.payload.id
? `${apiUrl}attachment/download/${message.attachment?.payload.id}`
: message.attachment?.payload?.url;
const url = getUrl(message.attachment?.payload);

return <AttachmentViewerForType url={url} />;
};
10 changes: 7 additions & 3 deletions frontend/src/components/inbox/components/Carousel.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
* Copyright © 2025 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/


import ArrowBackIosNewIcon from "@mui/icons-material/ArrowBackIosNew";
import ArrowForwardIosIcon from "@mui/icons-material/ArrowForwardIos";
import {
Expand All @@ -18,8 +19,9 @@ import {
styled,
Typography,
} from "@mui/material";
import { forwardRef, useEffect, useRef, useState, useCallback } from "react";
import { forwardRef, useCallback, useEffect, useRef, useState } from "react";

import { useGetAttachmentUrl } from "@/hooks/useGetAttachmentUrl";
import {
AnyButton as ButtonType,
OutgoingPopulatedListMessage,
Expand Down Expand Up @@ -188,6 +190,8 @@ const ListCard = forwardRef<
buttons: ButtonType[];
}
>(function ListCardRef(props, ref) {
const getUrl = useGetAttachmentUrl();

return (
<Card
style={{
Expand All @@ -203,7 +207,7 @@ const ListCard = forwardRef<
>
{props.content.image_url ? (
<CardMedia
image={props.content.image_url?.payload?.url as string}
image={getUrl(props.content.image_url.payload)}
sx={{ height: "185px" }}
title={props.content.title}
/>
Expand Down
12 changes: 10 additions & 2 deletions frontend/src/components/media-library/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
* Copyright © 2025 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/


import DriveFolderUploadIcon from "@mui/icons-material/DriveFolderUpload";
import { Box, Grid, Paper } from "@mui/material";
import { GridColDef, GridEventListener } from "@mui/x-data-grid";
Expand All @@ -32,7 +33,10 @@ import { PermissionAction } from "@/types/permission.types";
import { TFilterStringFields } from "@/types/search.types";
import { getDateTimeFormatter } from "@/utils/date";

import { IAttachment } from "../../types/attachment.types";
import {
AttachmentResourceRef,
IAttachment,
} from "../../types/attachment.types";

type MediaLibraryProps = {
showTitle?: boolean;
Expand All @@ -53,6 +57,10 @@ export const MediaLibrary = ({ onSelect, accept }: MediaLibraryProps) => {
{
params: {
where: {
resourceRef: [
AttachmentResourceRef.BlockAttachment,
AttachmentResourceRef.ContentAttachment,
],
...searchPayload.where,
or: {
...searchPayload.where.or,
Expand Down
20 changes: 20 additions & 0 deletions frontend/src/hooks/useGetAttachmentUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright © 2025 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/

import { AttachmentForeignKey } from "@/types/message.types";
import { getAttachmentDownloadUrl } from "@/utils/attachment";

import { useConfig } from "./useConfig";

export const useGetAttachmentUrl = () => {
const { apiUrl } = useConfig();

return (attachment: AttachmentForeignKey) => {
return getAttachmentDownloadUrl(apiUrl, attachment);
};
};
16 changes: 14 additions & 2 deletions frontend/src/utils/attachment.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
* Copyright © 2025 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/

import { FileType } from "@/types/message.types";

import { AttachmentForeignKey, FileType } from "@/types/message.types";

import { buildURL } from "./URL";

export const MIME_TYPES = {
marrouchi marked this conversation as resolved.
Show resolved Hide resolved
images: ["image/jpeg", "image/png", "image/gif", "image/webp"],
Expand Down Expand Up @@ -34,3 +37,12 @@ export function getFileType(mimeType: string): FileType {
return FileType.file;
}
}

export function getAttachmentDownloadUrl(
baseUrl: string,
attachment: AttachmentForeignKey,
) {
return "id" in attachment && attachment.id
? buildURL(baseUrl, `/attachment/download/${attachment.id}`)
: attachment.url;
}
Loading