Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
4rthem committed Jan 6, 2025
1 parent e60edbb commit b731743
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 6 deletions.
32 changes: 32 additions & 0 deletions databox/api/migrations/Version20250106174830.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250106174830 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE message ADD attachments JSON DEFAULT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE SCHEMA public');
$this->addSql('ALTER TABLE message DROP attachments');
}
}
2 changes: 2 additions & 0 deletions databox/api/src/Api/Model/Input/ThreadMessageInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ final class ThreadMessageInput
#[Assert\NotBlank]
public ?string $content = null;

public ?array $attachments = null;

public ?string $threadKey = null;

public ?string $threadId = null;
Expand Down
3 changes: 3 additions & 0 deletions databox/api/src/Api/Model/Output/ThreadMessageOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ class ThreadMessageOutput extends AbstractUuidOutput

#[Groups([Message::GROUP_LIST, Message::GROUP_READ])]
public ?string $content = null;

#[Groups([Message::GROUP_LIST, Message::GROUP_READ])]
public ?array $attachments = null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function transform(object $data, string $outputClass, array &$context = [
$output->setId($data->getId());

$output->content = $data->getContent();
$output->attachments = $data->getAttachments();
$output->thread = $data->getThread();

if ($this->hasGroup([
Expand Down
1 change: 1 addition & 0 deletions databox/api/src/Api/Processor/PostMessageProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function process($data, Operation $operation, array $uriVariables = [], a
$message->setThread($thread);
$message->setAuthorId($user->getId());
$message->setContent($data->content);
$message->setAttachments($data->attachments);
$this->em->persist($message);
$this->em->flush();

Expand Down
13 changes: 13 additions & 0 deletions databox/api/src/Entity/Discussion/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ class Message extends AbstractUuidEntity
#[ORM\Column(type: Types::TEXT, nullable: false)]
private ?string $content = null;

#[ORM\Column(type: Types::JSON, nullable: true)]
private ?array $attachments = null;

public function getThread(): ?Thread
{
return $this->thread;
Expand Down Expand Up @@ -128,4 +131,14 @@ public function setContent(?string $content): void
{
$this->content = $content;
}

public function getAttachments(): ?array
{
return $this->attachments;
}

public function setAttachments(?array $attachments): void
{
$this->attachments = $attachments;
}
}
11 changes: 8 additions & 3 deletions databox/client/src/components/Discussion/DiscussionMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import {ThreadMessage} from "../../types.ts";
import {AssetAnnotation, ThreadMessage} from "../../types.ts";
import {Divider} from "@mui/material";
import moment from "moment";
import {OnAnnotations} from "../Media/Asset/Attribute/Attributes.tsx";

type Props = {
message: ThreadMessage;
onAnnotations?: OnAnnotations | undefined;
};

export default function DiscussionMessage({
message,
onAnnotations,
}: Props) {

const m = moment(message.createdAt);
const annotations: string[] = message.attachments?.filter(a => a.type === 'annotation').map(a => JSON.parse(a.content) as AssetAnnotation) ?? [];

return <>
<div>
<div
onMouseEnter={onAnnotations && annotations.length > 0 ? () => onAnnotations!(annotations) : undefined}
>
<div>
<small>
<strong>
Expand Down
4 changes: 4 additions & 0 deletions databox/client/src/components/Discussion/Thread.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ import MessageForm from "./MessageForm.tsx";
import {CircularProgress} from "@mui/material";
import DiscussionMessage from "./DiscussionMessage.tsx";
import {useChannelRegistration} from "../../lib/pusher.ts";
import {OnAnnotations} from "../Media/Asset/Attribute/Attributes.tsx";

type Props = {
threadKey: string;
threadId?: string;
onAnnotations: OnAnnotations | undefined;
};

export default function Thread({
threadKey,
threadId,
onAnnotations,
}: Props) {
const [messages, setMessages] = React.useState<ApiCollectionResponse<ThreadMessage>>();

Expand Down Expand Up @@ -58,6 +61,7 @@ export default function Thread({
<DiscussionMessage
key={message.id}
message={message}
onAnnotations={onAnnotations}
/>
))}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Props = {
onAnnotations: OnAnnotations | undefined;
};

export default function AssetDiscussion({asset,}: Props) {
export default function AssetDiscussion({asset,onAnnotations}: Props) {
const [expanded, setExpanded] = React.useState(true);
const {t} = useTranslation();

Expand All @@ -34,6 +34,7 @@ export default function AssetDiscussion({asset,}: Props) {
<Thread
threadKey={asset.threadKey}
threadId={asset.thread?.id}
onAnnotations={onAnnotations}
/>
</AccordionDetails>
</Accordion>
Expand Down
44 changes: 42 additions & 2 deletions databox/client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,15 @@ export interface Thread extends Entity {
createdAt: string;
}

type MessageAttachment = {
type: string;
content: string;
}

export interface ThreadMessage extends Entity {
id: string;
content: string;
attachments?: MessageAttachment[];
author: User;
createdAt: string;
updatedAt: string;
Expand Down Expand Up @@ -346,10 +352,44 @@ export enum AnnotationType {
TimeRange = 'time_range',
}

export type AssetAnnotation = {
export interface AssetAnnotation {
type: AnnotationType;
[prop: string]: any;
};
}

export interface PointAnnotation extends AssetAnnotation {
type: AnnotationType.Point;
x: number;
y: number;
page?: number;
}

export interface CircleAnnotation extends AssetAnnotation {
type: AnnotationType.Circle;
x: number;
y: number;
radius: number;
page?: number;
}

export interface RectAnnotation extends AssetAnnotation {
type: AnnotationType.Rect;
x: number;
y: number;
width: number;
height: number;
}

export interface CueAnnotation extends AssetAnnotation {
type: AnnotationType.Cue;
time: number;
}

export interface TimeRangeAnnotation extends AssetAnnotation {
type: AnnotationType.TimeRange;
start: number;
end: number;
}

export interface Entity {
id: string;
Expand Down

0 comments on commit b731743

Please sign in to comment.