Compare commits
21 Commits
46ffdd809c
...
v1.8.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f0617c8ba5
|
||
|
|
27ea6fa413
|
||
|
|
e2146f4502
|
||
|
|
484b775923
|
||
|
|
5b05a14932
|
||
|
|
2704f7d5c5
|
||
|
|
d271cc215b
|
||
|
|
9eb5a60fb2
|
||
|
|
950646a426
|
||
|
|
a9b80e66cd
|
||
|
|
307655371d
|
||
|
|
8eb0cba050
|
||
|
|
50787c9357
|
||
|
|
0972ed951f
|
||
|
|
f852835c59
|
||
|
|
2c18fd1c1a
|
||
|
|
6d80795e44
|
||
|
|
ace438be6b
|
||
|
|
ea1afa7688
|
||
|
|
0976850c0c
|
||
|
|
ed3ed66cab
|
54
backend/.migrations/0008_bitter_darwin.sql
Normal file
54
backend/.migrations/0008_bitter_darwin.sql
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
CREATE TABLE "comment_likes" (
|
||||||
|
"comment_id" uuid NOT NULL,
|
||||||
|
"user_id" uuid NOT NULL,
|
||||||
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||||
|
CONSTRAINT "comment_likes_comment_id_user_id_pk" PRIMARY KEY("comment_id","user_id")
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE TABLE "comments" (
|
||||||
|
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
||||||
|
"content_id" uuid NOT NULL,
|
||||||
|
"user_id" uuid NOT NULL,
|
||||||
|
"parent_id" uuid,
|
||||||
|
"text" text NOT NULL,
|
||||||
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||||
|
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||||
|
"deleted_at" timestamp with time zone
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE TABLE "conversation_participants" (
|
||||||
|
"conversation_id" uuid NOT NULL,
|
||||||
|
"user_id" uuid NOT NULL,
|
||||||
|
"joined_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||||
|
CONSTRAINT "conversation_participants_conversation_id_user_id_pk" PRIMARY KEY("conversation_id","user_id")
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE TABLE "conversations" (
|
||||||
|
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
||||||
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||||
|
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE TABLE "messages" (
|
||||||
|
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
||||||
|
"conversation_id" uuid NOT NULL,
|
||||||
|
"sender_id" uuid NOT NULL,
|
||||||
|
"text" text NOT NULL,
|
||||||
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||||
|
"read_at" timestamp with time zone
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
ALTER TABLE "comment_likes" ADD CONSTRAINT "comment_likes_comment_id_comments_id_fk" FOREIGN KEY ("comment_id") REFERENCES "public"."comments"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||||
|
ALTER TABLE "comment_likes" ADD CONSTRAINT "comment_likes_user_id_users_uuid_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("uuid") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||||
|
ALTER TABLE "comments" ADD CONSTRAINT "comments_content_id_contents_id_fk" FOREIGN KEY ("content_id") REFERENCES "public"."contents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||||
|
ALTER TABLE "comments" ADD CONSTRAINT "comments_user_id_users_uuid_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("uuid") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||||
|
ALTER TABLE "comments" ADD CONSTRAINT "comments_parent_id_comments_id_fk" FOREIGN KEY ("parent_id") REFERENCES "public"."comments"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||||
|
ALTER TABLE "conversation_participants" ADD CONSTRAINT "conversation_participants_conversation_id_conversations_id_fk" FOREIGN KEY ("conversation_id") REFERENCES "public"."conversations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||||
|
ALTER TABLE "conversation_participants" ADD CONSTRAINT "conversation_participants_user_id_users_uuid_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("uuid") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||||
|
ALTER TABLE "messages" ADD CONSTRAINT "messages_conversation_id_conversations_id_fk" FOREIGN KEY ("conversation_id") REFERENCES "public"."conversations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||||
|
ALTER TABLE "messages" ADD CONSTRAINT "messages_sender_id_users_uuid_fk" FOREIGN KEY ("sender_id") REFERENCES "public"."users"("uuid") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||||
|
CREATE INDEX "comments_content_id_idx" ON "comments" USING btree ("content_id");--> statement-breakpoint
|
||||||
|
CREATE INDEX "comments_user_id_idx" ON "comments" USING btree ("user_id");--> statement-breakpoint
|
||||||
|
CREATE INDEX "comments_parent_id_idx" ON "comments" USING btree ("parent_id");--> statement-breakpoint
|
||||||
|
CREATE INDEX "messages_conversation_id_idx" ON "messages" USING btree ("conversation_id");--> statement-breakpoint
|
||||||
|
CREATE INDEX "messages_sender_id_idx" ON "messages" USING btree ("sender_id");
|
||||||
2080
backend/.migrations/meta/0008_snapshot.json
Normal file
2080
backend/.migrations/meta/0008_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -57,6 +57,13 @@
|
|||||||
"when": 1769605995410,
|
"when": 1769605995410,
|
||||||
"tag": "0007_melodic_synch",
|
"tag": "0007_melodic_synch",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 8,
|
||||||
|
"version": "7",
|
||||||
|
"when": 1769696731978,
|
||||||
|
"tag": "0008_bitter_darwin",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@memegoat/backend",
|
"name": "@memegoat/backend",
|
||||||
"version": "1.8.1",
|
"version": "1.8.3",
|
||||||
"description": "",
|
"description": "",
|
||||||
"author": "",
|
"author": "",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
|||||||
@@ -8,18 +8,45 @@ import {
|
|||||||
Req,
|
Req,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
} from "@nestjs/common";
|
} from "@nestjs/common";
|
||||||
|
import { ConfigService } from "@nestjs/config";
|
||||||
|
import { getIronSession } from "iron-session";
|
||||||
import { AuthGuard } from "../auth/guards/auth.guard";
|
import { AuthGuard } from "../auth/guards/auth.guard";
|
||||||
|
import { getSessionOptions } from "../auth/session.config";
|
||||||
import type { AuthenticatedRequest } from "../common/interfaces/request.interface";
|
import type { AuthenticatedRequest } from "../common/interfaces/request.interface";
|
||||||
|
import { JwtService } from "../crypto/services/jwt.service";
|
||||||
import { CommentsService } from "./comments.service";
|
import { CommentsService } from "./comments.service";
|
||||||
import { CreateCommentDto } from "./dto/create-comment.dto";
|
import { CreateCommentDto } from "./dto/create-comment.dto";
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
export class CommentsController {
|
export class CommentsController {
|
||||||
constructor(private readonly commentsService: CommentsService) {}
|
constructor(
|
||||||
|
private readonly commentsService: CommentsService,
|
||||||
|
private readonly jwtService: JwtService,
|
||||||
|
private readonly configService: ConfigService,
|
||||||
|
) {}
|
||||||
|
|
||||||
@Get("contents/:contentId/comments")
|
@Get("contents/:contentId/comments")
|
||||||
findAllByContentId(@Param("contentId") contentId: string) {
|
async findAllByContentId(
|
||||||
return this.commentsService.findAllByContentId(contentId);
|
@Param("contentId") contentId: string,
|
||||||
|
@Req() req: any,
|
||||||
|
) {
|
||||||
|
// Tentative de récupération de l'utilisateur pour isLiked (optionnel)
|
||||||
|
let userId: string | undefined;
|
||||||
|
try {
|
||||||
|
const session = await getIronSession<any>(
|
||||||
|
req,
|
||||||
|
req.res,
|
||||||
|
getSessionOptions(this.configService.get("SESSION_PASSWORD") as string),
|
||||||
|
);
|
||||||
|
if (session.accessToken) {
|
||||||
|
const payload = await this.jwtService.verifyJwt(session.accessToken);
|
||||||
|
userId = payload.sub;
|
||||||
|
}
|
||||||
|
} catch (_e) {
|
||||||
|
// Ignorer les erreurs de session
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.commentsService.findAllByContentId(contentId, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("contents/:contentId/comments")
|
@Post("contents/:contentId/comments")
|
||||||
@@ -38,4 +65,16 @@ export class CommentsController {
|
|||||||
const isAdmin = req.user.role === "admin" || req.user.role === "moderator";
|
const isAdmin = req.user.role === "admin" || req.user.role === "moderator";
|
||||||
return this.commentsService.remove(req.user.sub, id, isAdmin);
|
return this.commentsService.remove(req.user.sub, id, isAdmin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post("comments/:id/like")
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
|
like(@Req() req: AuthenticatedRequest, @Param("id") id: string) {
|
||||||
|
return this.commentsService.like(req.user.sub, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete("comments/:id/like")
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
|
unlike(@Req() req: AuthenticatedRequest, @Param("id") id: string) {
|
||||||
|
return this.commentsService.unlike(req.user.sub, id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
import { Module } from "@nestjs/common";
|
import { Module } from "@nestjs/common";
|
||||||
import { AuthModule } from "../auth/auth.module";
|
import { AuthModule } from "../auth/auth.module";
|
||||||
|
import { RealtimeModule } from "../realtime/realtime.module";
|
||||||
|
import { S3Module } from "../s3/s3.module";
|
||||||
import { CommentsController } from "./comments.controller";
|
import { CommentsController } from "./comments.controller";
|
||||||
import { CommentsService } from "./comments.service";
|
import { CommentsService } from "./comments.service";
|
||||||
|
import { CommentLikesRepository } from "./repositories/comment-likes.repository";
|
||||||
import { CommentsRepository } from "./repositories/comments.repository";
|
import { CommentsRepository } from "./repositories/comments.repository";
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [AuthModule],
|
imports: [AuthModule, S3Module, RealtimeModule],
|
||||||
controllers: [CommentsController],
|
controllers: [CommentsController],
|
||||||
providers: [CommentsService, CommentsRepository],
|
providers: [CommentsService, CommentsRepository, CommentLikesRepository],
|
||||||
exports: [CommentsService],
|
exports: [CommentsService],
|
||||||
})
|
})
|
||||||
export class CommentsModule {}
|
export class CommentsModule {}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { ForbiddenException, NotFoundException } from "@nestjs/common";
|
import { ForbiddenException, NotFoundException } from "@nestjs/common";
|
||||||
import { Test, TestingModule } from "@nestjs/testing";
|
import { Test, TestingModule } from "@nestjs/testing";
|
||||||
|
import { EventsGateway } from "../realtime/events.gateway";
|
||||||
|
import { S3Service } from "../s3/s3.service";
|
||||||
import { CommentsService } from "./comments.service";
|
import { CommentsService } from "./comments.service";
|
||||||
|
import { CommentLikesRepository } from "./repositories/comment-likes.repository";
|
||||||
import { CommentsRepository } from "./repositories/comments.repository";
|
import { CommentsRepository } from "./repositories/comments.repository";
|
||||||
|
|
||||||
describe("CommentsService", () => {
|
describe("CommentsService", () => {
|
||||||
@@ -11,14 +14,34 @@ describe("CommentsService", () => {
|
|||||||
create: jest.fn(),
|
create: jest.fn(),
|
||||||
findAllByContentId: jest.fn(),
|
findAllByContentId: jest.fn(),
|
||||||
findOne: jest.fn(),
|
findOne: jest.fn(),
|
||||||
|
findOneEnriched: jest.fn(),
|
||||||
delete: jest.fn(),
|
delete: jest.fn(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const mockCommentLikesRepository = {
|
||||||
|
addLike: jest.fn(),
|
||||||
|
removeLike: jest.fn(),
|
||||||
|
countByCommentId: jest.fn(),
|
||||||
|
isLikedByUser: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
|
const mockS3Service = {
|
||||||
|
getPublicUrl: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
|
const mockEventsGateway = {
|
||||||
|
sendToContent: jest.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
jest.clearAllMocks();
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
providers: [
|
providers: [
|
||||||
CommentsService,
|
CommentsService,
|
||||||
{ provide: CommentsRepository, useValue: mockCommentsRepository },
|
{ provide: CommentsRepository, useValue: mockCommentsRepository },
|
||||||
|
{ provide: CommentLikesRepository, useValue: mockCommentLikesRepository },
|
||||||
|
{ provide: S3Service, useValue: mockS3Service },
|
||||||
|
{ provide: EventsGateway, useValue: mockEventsGateway },
|
||||||
],
|
],
|
||||||
}).compile();
|
}).compile();
|
||||||
|
|
||||||
@@ -34,8 +57,12 @@ describe("CommentsService", () => {
|
|||||||
it("should create a comment", async () => {
|
it("should create a comment", async () => {
|
||||||
const userId = "user1";
|
const userId = "user1";
|
||||||
const contentId = "content1";
|
const contentId = "content1";
|
||||||
const dto = { text: "Nice meme" };
|
const dto = { text: "Nice meme", parentId: undefined };
|
||||||
mockCommentsRepository.create.mockResolvedValue({ id: "c1", ...dto });
|
const createdComment = { id: "c1", ...dto, user: { username: "u1" } };
|
||||||
|
mockCommentsRepository.create.mockResolvedValue(createdComment);
|
||||||
|
mockCommentsRepository.findOneEnriched.mockResolvedValue(createdComment);
|
||||||
|
mockCommentLikesRepository.countByCommentId.mockResolvedValue(0);
|
||||||
|
mockCommentLikesRepository.isLikedByUser.mockResolvedValue(false);
|
||||||
|
|
||||||
const result = await service.create(userId, contentId, dto);
|
const result = await service.create(userId, contentId, dto);
|
||||||
expect(result.id).toBe("c1");
|
expect(result.id).toBe("c1");
|
||||||
@@ -43,16 +70,30 @@ describe("CommentsService", () => {
|
|||||||
userId,
|
userId,
|
||||||
contentId,
|
contentId,
|
||||||
text: dto.text,
|
text: dto.text,
|
||||||
|
parentId: undefined,
|
||||||
});
|
});
|
||||||
|
expect(mockEventsGateway.sendToContent).toHaveBeenCalledWith(
|
||||||
|
contentId,
|
||||||
|
"new_comment",
|
||||||
|
expect.any(Object),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("findAllByContentId", () => {
|
describe("findAllByContentId", () => {
|
||||||
it("should return comments for a content", async () => {
|
it("should return comments for a content", async () => {
|
||||||
mockCommentsRepository.findAllByContentId.mockResolvedValue([{ id: "c1" }]);
|
mockCommentsRepository.findAllByContentId.mockResolvedValue([
|
||||||
const result = await service.findAllByContentId("content1");
|
{ id: "c1", user: { avatarUrl: "path" } },
|
||||||
|
]);
|
||||||
|
mockCommentLikesRepository.countByCommentId.mockResolvedValue(5);
|
||||||
|
mockCommentLikesRepository.isLikedByUser.mockResolvedValue(true);
|
||||||
|
mockS3Service.getPublicUrl.mockReturnValue("url");
|
||||||
|
|
||||||
|
const result = await service.findAllByContentId("content1", "u1");
|
||||||
expect(result).toHaveLength(1);
|
expect(result).toHaveLength(1);
|
||||||
expect(repository.findAllByContentId).toHaveBeenCalledWith("content1");
|
expect(result[0].likesCount).toBe(5);
|
||||||
|
expect(result[0].isLiked).toBe(true);
|
||||||
|
expect(result[0].user.avatarUrl).toBe("url");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -81,4 +122,23 @@ describe("CommentsService", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("like", () => {
|
||||||
|
it("should add like", async () => {
|
||||||
|
mockCommentsRepository.findOne.mockResolvedValue({ id: "c1" });
|
||||||
|
await service.like("u1", "c1");
|
||||||
|
expect(mockCommentLikesRepository.addLike).toHaveBeenCalledWith("c1", "u1");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("unlike", () => {
|
||||||
|
it("should remove like", async () => {
|
||||||
|
mockCommentsRepository.findOne.mockResolvedValue({ id: "c1" });
|
||||||
|
await service.unlike("u1", "c1");
|
||||||
|
expect(mockCommentLikesRepository.removeLike).toHaveBeenCalledWith(
|
||||||
|
"c1",
|
||||||
|
"u1",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,23 +3,87 @@ import {
|
|||||||
Injectable,
|
Injectable,
|
||||||
NotFoundException,
|
NotFoundException,
|
||||||
} from "@nestjs/common";
|
} from "@nestjs/common";
|
||||||
|
import { EventsGateway } from "../realtime/events.gateway";
|
||||||
|
import { S3Service } from "../s3/s3.service";
|
||||||
import type { CreateCommentDto } from "./dto/create-comment.dto";
|
import type { CreateCommentDto } from "./dto/create-comment.dto";
|
||||||
|
import { CommentLikesRepository } from "./repositories/comment-likes.repository";
|
||||||
import { CommentsRepository } from "./repositories/comments.repository";
|
import { CommentsRepository } from "./repositories/comments.repository";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CommentsService {
|
export class CommentsService {
|
||||||
constructor(private readonly commentsRepository: CommentsRepository) {}
|
constructor(
|
||||||
|
private readonly commentsRepository: CommentsRepository,
|
||||||
|
private readonly commentLikesRepository: CommentLikesRepository,
|
||||||
|
private readonly s3Service: S3Service,
|
||||||
|
private readonly eventsGateway: EventsGateway,
|
||||||
|
) {}
|
||||||
|
|
||||||
async create(userId: string, contentId: string, dto: CreateCommentDto) {
|
async create(userId: string, contentId: string, dto: CreateCommentDto) {
|
||||||
return this.commentsRepository.create({
|
const comment = await this.commentsRepository.create({
|
||||||
userId,
|
userId,
|
||||||
contentId,
|
contentId,
|
||||||
text: dto.text,
|
text: dto.text,
|
||||||
|
parentId: dto.parentId,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Récupérer le commentaire avec les infos utilisateur pour le WebSocket
|
||||||
|
const enrichedComment = await this.findOneEnriched(comment.id, userId);
|
||||||
|
|
||||||
|
// Notifier les autres utilisateurs sur ce contenu
|
||||||
|
this.eventsGateway.sendToContent(contentId, "new_comment", enrichedComment);
|
||||||
|
|
||||||
|
return enrichedComment;
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAllByContentId(contentId: string) {
|
async findOneEnriched(commentId: string, currentUserId?: string) {
|
||||||
return this.commentsRepository.findAllByContentId(contentId);
|
const comment = await this.commentsRepository.findOneEnriched(commentId);
|
||||||
|
if (!comment) return null;
|
||||||
|
|
||||||
|
const [likesCount, isLiked] = await Promise.all([
|
||||||
|
this.commentLikesRepository.countByCommentId(comment.id),
|
||||||
|
currentUserId
|
||||||
|
? this.commentLikesRepository.isLikedByUser(comment.id, currentUserId)
|
||||||
|
: Promise.resolve(false),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...comment,
|
||||||
|
likesCount,
|
||||||
|
isLiked,
|
||||||
|
user: {
|
||||||
|
...comment.user,
|
||||||
|
avatarUrl: comment.user.avatarUrl
|
||||||
|
? this.s3Service.getPublicUrl(comment.user.avatarUrl)
|
||||||
|
: null,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async findAllByContentId(contentId: string, userId?: string) {
|
||||||
|
const comments = await this.commentsRepository.findAllByContentId(contentId);
|
||||||
|
|
||||||
|
return Promise.all(
|
||||||
|
comments.map(async (comment) => {
|
||||||
|
const [likesCount, isLiked] = await Promise.all([
|
||||||
|
this.commentLikesRepository.countByCommentId(comment.id),
|
||||||
|
userId
|
||||||
|
? this.commentLikesRepository.isLikedByUser(comment.id, userId)
|
||||||
|
: Promise.resolve(false),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...comment,
|
||||||
|
likesCount,
|
||||||
|
isLiked,
|
||||||
|
user: {
|
||||||
|
...comment.user,
|
||||||
|
avatarUrl: comment.user.avatarUrl
|
||||||
|
? this.s3Service.getPublicUrl(comment.user.avatarUrl)
|
||||||
|
: null,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async remove(userId: string, commentId: string, isAdmin = false) {
|
async remove(userId: string, commentId: string, isAdmin = false) {
|
||||||
@@ -34,4 +98,20 @@ export class CommentsService {
|
|||||||
|
|
||||||
await this.commentsRepository.delete(commentId);
|
await this.commentsRepository.delete(commentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async like(userId: string, commentId: string) {
|
||||||
|
const comment = await this.commentsRepository.findOne(commentId);
|
||||||
|
if (!comment) {
|
||||||
|
throw new NotFoundException("Comment not found");
|
||||||
|
}
|
||||||
|
await this.commentLikesRepository.addLike(commentId, userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
async unlike(userId: string, commentId: string) {
|
||||||
|
const comment = await this.commentsRepository.findOne(commentId);
|
||||||
|
if (!comment) {
|
||||||
|
throw new NotFoundException("Comment not found");
|
||||||
|
}
|
||||||
|
await this.commentLikesRepository.removeLike(commentId, userId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,18 @@
|
|||||||
import { IsNotEmpty, IsString, MaxLength } from "class-validator";
|
import {
|
||||||
|
IsNotEmpty,
|
||||||
|
IsOptional,
|
||||||
|
IsString,
|
||||||
|
IsUUID,
|
||||||
|
MaxLength,
|
||||||
|
} from "class-validator";
|
||||||
|
|
||||||
export class CreateCommentDto {
|
export class CreateCommentDto {
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@MaxLength(1000)
|
@MaxLength(1000)
|
||||||
text!: string;
|
text!: string;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsUUID()
|
||||||
|
parentId?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import { Injectable } from "@nestjs/common";
|
||||||
|
import { and, eq, sql } from "drizzle-orm";
|
||||||
|
import { DatabaseService } from "../../database/database.service";
|
||||||
|
import { commentLikes } from "../../database/schemas/comment_likes";
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class CommentLikesRepository {
|
||||||
|
constructor(private readonly databaseService: DatabaseService) {}
|
||||||
|
|
||||||
|
async addLike(commentId: string, userId: string) {
|
||||||
|
await this.databaseService.db
|
||||||
|
.insert(commentLikes)
|
||||||
|
.values({ commentId, userId })
|
||||||
|
.onConflictDoNothing();
|
||||||
|
}
|
||||||
|
|
||||||
|
async removeLike(commentId: string, userId: string) {
|
||||||
|
await this.databaseService.db
|
||||||
|
.delete(commentLikes)
|
||||||
|
.where(
|
||||||
|
and(eq(commentLikes.commentId, commentId), eq(commentLikes.userId, userId)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async countByCommentId(commentId: string) {
|
||||||
|
const results = await this.databaseService.db
|
||||||
|
.select({ count: sql<number>`count(*)` })
|
||||||
|
.from(commentLikes)
|
||||||
|
.where(eq(commentLikes.commentId, commentId));
|
||||||
|
return Number(results[0]?.count || 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
async isLikedByUser(commentId: string, userId: string) {
|
||||||
|
const results = await this.databaseService.db
|
||||||
|
.select()
|
||||||
|
.from(commentLikes)
|
||||||
|
.where(
|
||||||
|
and(eq(commentLikes.commentId, commentId), eq(commentLikes.userId, userId)),
|
||||||
|
);
|
||||||
|
return !!results[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,11 +9,11 @@ export class CommentsRepository {
|
|||||||
constructor(private readonly databaseService: DatabaseService) {}
|
constructor(private readonly databaseService: DatabaseService) {}
|
||||||
|
|
||||||
async create(data: NewCommentInDb) {
|
async create(data: NewCommentInDb) {
|
||||||
const [comment] = await this.databaseService.db
|
const results = await this.databaseService.db
|
||||||
.insert(comments)
|
.insert(comments)
|
||||||
.values(data)
|
.values(data)
|
||||||
.returning();
|
.returning();
|
||||||
return comment;
|
return results[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAllByContentId(contentId: string) {
|
async findAllByContentId(contentId: string) {
|
||||||
@@ -21,6 +21,7 @@ export class CommentsRepository {
|
|||||||
.select({
|
.select({
|
||||||
id: comments.id,
|
id: comments.id,
|
||||||
text: comments.text,
|
text: comments.text,
|
||||||
|
parentId: comments.parentId,
|
||||||
createdAt: comments.createdAt,
|
createdAt: comments.createdAt,
|
||||||
updatedAt: comments.updatedAt,
|
updatedAt: comments.updatedAt,
|
||||||
user: {
|
user: {
|
||||||
@@ -37,11 +38,32 @@ export class CommentsRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findOne(id: string) {
|
async findOne(id: string) {
|
||||||
const [comment] = await this.databaseService.db
|
const results = await this.databaseService.db
|
||||||
.select()
|
.select()
|
||||||
.from(comments)
|
.from(comments)
|
||||||
.where(and(eq(comments.id, id), isNull(comments.deletedAt)));
|
.where(and(eq(comments.id, id), isNull(comments.deletedAt)));
|
||||||
return comment;
|
return results[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
async findOneEnriched(id: string) {
|
||||||
|
const results = await this.databaseService.db
|
||||||
|
.select({
|
||||||
|
id: comments.id,
|
||||||
|
text: comments.text,
|
||||||
|
parentId: comments.parentId,
|
||||||
|
createdAt: comments.createdAt,
|
||||||
|
updatedAt: comments.updatedAt,
|
||||||
|
user: {
|
||||||
|
uuid: users.uuid,
|
||||||
|
username: users.username,
|
||||||
|
displayName: users.displayName,
|
||||||
|
avatarUrl: users.avatarUrl,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.from(comments)
|
||||||
|
.innerJoin(users, eq(comments.userId, users.uuid))
|
||||||
|
.where(and(eq(comments.id, id), isNull(comments.deletedAt)));
|
||||||
|
return results[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
async delete(id: string) {
|
async delete(id: string) {
|
||||||
|
|||||||
21
backend/src/database/schemas/comment_likes.ts
Normal file
21
backend/src/database/schemas/comment_likes.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { pgTable, primaryKey, timestamp, uuid } from "drizzle-orm/pg-core";
|
||||||
|
import { comments } from "./comments";
|
||||||
|
import { users } from "./users";
|
||||||
|
|
||||||
|
export const commentLikes = pgTable(
|
||||||
|
"comment_likes",
|
||||||
|
{
|
||||||
|
commentId: uuid("comment_id")
|
||||||
|
.notNull()
|
||||||
|
.references(() => comments.id, { onDelete: "cascade" }),
|
||||||
|
userId: uuid("user_id")
|
||||||
|
.notNull()
|
||||||
|
.references(() => users.uuid, { onDelete: "cascade" }),
|
||||||
|
createdAt: timestamp("created_at", { withTimezone: true })
|
||||||
|
.notNull()
|
||||||
|
.defaultNow(),
|
||||||
|
},
|
||||||
|
(t) => ({
|
||||||
|
pk: primaryKey({ columns: [t.commentId, t.userId] }),
|
||||||
|
}),
|
||||||
|
);
|
||||||
@@ -12,6 +12,9 @@ export const comments = pgTable(
|
|||||||
userId: uuid("user_id")
|
userId: uuid("user_id")
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => users.uuid, { onDelete: "cascade" }),
|
.references(() => users.uuid, { onDelete: "cascade" }),
|
||||||
|
parentId: uuid("parent_id").references(() => comments.id, {
|
||||||
|
onDelete: "cascade",
|
||||||
|
}),
|
||||||
text: text("text").notNull(),
|
text: text("text").notNull(),
|
||||||
createdAt: timestamp("created_at", { withTimezone: true })
|
createdAt: timestamp("created_at", { withTimezone: true })
|
||||||
.notNull()
|
.notNull()
|
||||||
@@ -24,6 +27,7 @@ export const comments = pgTable(
|
|||||||
(table) => ({
|
(table) => ({
|
||||||
contentIdIdx: index("comments_content_id_idx").on(table.contentId),
|
contentIdIdx: index("comments_content_id_idx").on(table.contentId),
|
||||||
userIdIdx: index("comments_user_id_idx").on(table.userId),
|
userIdIdx: index("comments_user_id_idx").on(table.userId),
|
||||||
|
parentIdIdx: index("comments_parent_id_idx").on(table.parentId),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export * from "./api_keys";
|
export * from "./api_keys";
|
||||||
export * from "./audit_logs";
|
export * from "./audit_logs";
|
||||||
export * from "./categories";
|
export * from "./categories";
|
||||||
|
export * from "./comment_likes";
|
||||||
export * from "./comments";
|
export * from "./comments";
|
||||||
export * from "./content";
|
export * from "./content";
|
||||||
export * from "./favorites";
|
export * from "./favorites";
|
||||||
|
|||||||
@@ -22,6 +22,22 @@ export class MessagesController {
|
|||||||
return this.messagesService.getConversations(req.user.sub);
|
return this.messagesService.getConversations(req.user.sub);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get("unread-count")
|
||||||
|
getUnreadCount(@Req() req: AuthenticatedRequest) {
|
||||||
|
return this.messagesService.getUnreadCount(req.user.sub);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get("conversations/with/:userId")
|
||||||
|
getConversationWithUser(
|
||||||
|
@Req() req: AuthenticatedRequest,
|
||||||
|
@Param("userId") targetUserId: string,
|
||||||
|
) {
|
||||||
|
return this.messagesService.getConversationWithUser(
|
||||||
|
req.user.sub,
|
||||||
|
targetUserId,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Get("conversations/:id")
|
@Get("conversations/:id")
|
||||||
getMessages(
|
getMessages(
|
||||||
@Req() req: AuthenticatedRequest,
|
@Req() req: AuthenticatedRequest,
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ describe("MessagesService", () => {
|
|||||||
findAllConversations: jest.fn(),
|
findAllConversations: jest.fn(),
|
||||||
isParticipant: jest.fn(),
|
isParticipant: jest.fn(),
|
||||||
findMessagesByConversationId: jest.fn(),
|
findMessagesByConversationId: jest.fn(),
|
||||||
|
markAsRead: jest.fn(),
|
||||||
|
countUnreadMessages: jest.fn(),
|
||||||
};
|
};
|
||||||
|
|
||||||
const mockEventsGateway = {
|
const mockEventsGateway = {
|
||||||
|
|||||||
@@ -42,6 +42,17 @@ export class MessagesService {
|
|||||||
return this.messagesRepository.findAllConversations(userId);
|
return this.messagesRepository.findAllConversations(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getUnreadCount(userId: string) {
|
||||||
|
return this.messagesRepository.countUnreadMessages(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getConversationWithUser(userId: string, targetUserId: string) {
|
||||||
|
return this.messagesRepository.findConversationBetweenUsers(
|
||||||
|
userId,
|
||||||
|
targetUserId,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async getMessages(userId: string, conversationId: string) {
|
async getMessages(userId: string, conversationId: string) {
|
||||||
const isParticipant = await this.messagesRepository.isParticipant(
|
const isParticipant = await this.messagesRepository.isParticipant(
|
||||||
conversationId,
|
conversationId,
|
||||||
@@ -51,6 +62,20 @@ export class MessagesService {
|
|||||||
throw new ForbiddenException("You are not part of this conversation");
|
throw new ForbiddenException("You are not part of this conversation");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Marquer comme lus
|
||||||
|
await this.messagesRepository.markAsRead(conversationId, userId);
|
||||||
|
|
||||||
return this.messagesRepository.findMessagesByConversationId(conversationId);
|
return this.messagesRepository.findMessagesByConversationId(conversationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async markAsRead(userId: string, conversationId: string) {
|
||||||
|
const isParticipant = await this.messagesRepository.isParticipant(
|
||||||
|
conversationId,
|
||||||
|
userId,
|
||||||
|
);
|
||||||
|
if (!isParticipant) {
|
||||||
|
throw new ForbiddenException("You are not part of this conversation");
|
||||||
|
}
|
||||||
|
return this.messagesRepository.markAsRead(conversationId, userId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,4 +133,35 @@ export class MessagesRepository {
|
|||||||
.from(conversationParticipants)
|
.from(conversationParticipants)
|
||||||
.where(eq(conversationParticipants.conversationId, conversationId));
|
.where(eq(conversationParticipants.conversationId, conversationId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async markAsRead(conversationId: string, userId: string) {
|
||||||
|
await this.databaseService.db
|
||||||
|
.update(messages)
|
||||||
|
.set({ readAt: new Date() })
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(messages.conversationId, conversationId),
|
||||||
|
sql`${messages.senderId} != ${userId}`,
|
||||||
|
sql`${messages.readAt} IS NULL`,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async countUnreadMessages(userId: string) {
|
||||||
|
const result = await this.databaseService.db
|
||||||
|
.select({ count: sql<number>`count(*)` })
|
||||||
|
.from(messages)
|
||||||
|
.innerJoin(
|
||||||
|
conversationParticipants,
|
||||||
|
eq(messages.conversationId, conversationParticipants.conversationId),
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(conversationParticipants.userId, userId),
|
||||||
|
sql`${messages.senderId} != ${userId}`,
|
||||||
|
sql`${messages.readAt} IS NULL`,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return Number(result[0]?.count || 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
import { Logger } from "@nestjs/common";
|
import { Logger } from "@nestjs/common";
|
||||||
import { ConfigService } from "@nestjs/config";
|
import { ConfigService } from "@nestjs/config";
|
||||||
import {
|
import {
|
||||||
|
ConnectedSocket,
|
||||||
|
MessageBody,
|
||||||
OnGatewayConnection,
|
OnGatewayConnection,
|
||||||
OnGatewayDisconnect,
|
OnGatewayDisconnect,
|
||||||
OnGatewayInit,
|
OnGatewayInit,
|
||||||
|
SubscribeMessage,
|
||||||
WebSocketGateway,
|
WebSocketGateway,
|
||||||
WebSocketServer,
|
WebSocketServer,
|
||||||
} from "@nestjs/websockets";
|
} from "@nestjs/websockets";
|
||||||
@@ -54,6 +57,8 @@ export class EventsGateway
|
|||||||
|
|
||||||
if (!session.accessToken) {
|
if (!session.accessToken) {
|
||||||
this.logger.warn(`Client ${client.id} unauthorized connection`);
|
this.logger.warn(`Client ${client.id} unauthorized connection`);
|
||||||
|
// Permettre les connexions anonymes pour voir les commentaires en temps réel ?
|
||||||
|
// Pour l'instant on déconnecte car le système actuel semble exiger l'auth
|
||||||
client.disconnect();
|
client.disconnect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -75,8 +80,30 @@ export class EventsGateway
|
|||||||
this.logger.log(`Client disconnected: ${client.id}`);
|
this.logger.log(`Client disconnected: ${client.id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SubscribeMessage("join_content")
|
||||||
|
handleJoinContent(
|
||||||
|
@ConnectedSocket() client: Socket,
|
||||||
|
@MessageBody() contentId: string,
|
||||||
|
) {
|
||||||
|
client.join(`content:${contentId}`);
|
||||||
|
this.logger.log(`Client ${client.id} joined content room: ${contentId}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeMessage("leave_content")
|
||||||
|
handleLeaveContent(
|
||||||
|
@ConnectedSocket() client: Socket,
|
||||||
|
@MessageBody() contentId: string,
|
||||||
|
) {
|
||||||
|
client.leave(`content:${contentId}`);
|
||||||
|
this.logger.log(`Client ${client.id} left content room: ${contentId}`);
|
||||||
|
}
|
||||||
|
|
||||||
// Méthode utilitaire pour envoyer des messages à un utilisateur spécifique
|
// Méthode utilitaire pour envoyer des messages à un utilisateur spécifique
|
||||||
sendToUser(userId: string, event: string, data: any) {
|
sendToUser(userId: string, event: string, data: any) {
|
||||||
this.server.to(`user:${userId}`).emit(event, data);
|
this.server.to(`user:${userId}`).emit(event, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sendToContent(contentId: string, event: string, data: any) {
|
||||||
|
this.server.to(`content:${contentId}`).emit(event, data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Injectable } from "@nestjs/common";
|
import { Injectable } from "@nestjs/common";
|
||||||
import { and, eq, lte, sql } from "drizzle-orm";
|
import { and, eq, ilike, lte, or, sql } from "drizzle-orm";
|
||||||
import { DatabaseService } from "../../database/database.service";
|
import { DatabaseService } from "../../database/database.service";
|
||||||
import { contents, favorites, users } from "../../database/schemas";
|
import { contents, favorites, users } from "../../database/schemas";
|
||||||
|
|
||||||
@@ -97,6 +97,24 @@ export class UsersRepository {
|
|||||||
return result[0] || null;
|
return result[0] || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async search(query: string) {
|
||||||
|
return this.databaseService.db
|
||||||
|
.select({
|
||||||
|
uuid: users.uuid,
|
||||||
|
username: users.username,
|
||||||
|
displayName: users.displayName,
|
||||||
|
avatarUrl: users.avatarUrl,
|
||||||
|
})
|
||||||
|
.from(users)
|
||||||
|
.where(
|
||||||
|
or(
|
||||||
|
ilike(users.username, `%${query}%`),
|
||||||
|
ilike(users.displayName, `%${query}%`),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.limit(10);
|
||||||
|
}
|
||||||
|
|
||||||
async findOne(uuid: string) {
|
async findOne(uuid: string) {
|
||||||
const result = await this.databaseService.db
|
const result = await this.databaseService.db
|
||||||
.select()
|
.select()
|
||||||
|
|||||||
@@ -54,6 +54,12 @@ export class UsersController {
|
|||||||
return this.usersService.findPublicProfile(username);
|
return this.usersService.findPublicProfile(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get("search")
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
|
search(@Query("q") query: string) {
|
||||||
|
return this.usersService.search(query);
|
||||||
|
}
|
||||||
|
|
||||||
// Gestion de son propre compte
|
// Gestion de son propre compte
|
||||||
@Get("me")
|
@Get("me")
|
||||||
@UseGuards(AuthGuard)
|
@UseGuards(AuthGuard)
|
||||||
|
|||||||
@@ -106,6 +106,16 @@ export class UsersService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async search(query: string) {
|
||||||
|
const users = await this.usersRepository.search(query);
|
||||||
|
return users.map((user) => ({
|
||||||
|
...user,
|
||||||
|
avatarUrl: user.avatarUrl
|
||||||
|
? this.s3Service.getPublicUrl(user.avatarUrl)
|
||||||
|
: null,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
async findOne(uuid: string) {
|
async findOne(uuid: string) {
|
||||||
const user = await this.usersRepository.findOne(uuid);
|
const user = await this.usersRepository.findOne(uuid);
|
||||||
if (!user) return null;
|
if (!user) return null;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@memegoat/frontend",
|
"name": "@memegoat/frontend",
|
||||||
"version": "1.8.1",
|
"version": "1.8.3",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
import { formatDistanceToNow } from "date-fns";
|
import { formatDistanceToNow } from "date-fns";
|
||||||
import { fr } from "date-fns/locale";
|
import { fr } from "date-fns/locale";
|
||||||
import { Search, Send } from "lucide-react";
|
import { Search, Send, UserPlus, X } from "lucide-react";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { useRouter, useSearchParams } from "next/navigation";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||||
@@ -16,23 +18,54 @@ import {
|
|||||||
type Message,
|
type Message,
|
||||||
MessageService,
|
MessageService,
|
||||||
} from "@/services/message.service";
|
} from "@/services/message.service";
|
||||||
|
import { UserService } from "@/services/user.service";
|
||||||
|
import type { User } from "@/types/user";
|
||||||
|
|
||||||
export default function MessagesPage() {
|
export default function MessagesPage() {
|
||||||
const { user } = useAuth();
|
const { user } = useAuth();
|
||||||
const { socket } = useSocket();
|
const { socket } = useSocket();
|
||||||
|
const _router = useRouter();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
const targetUserId = searchParams.get("user");
|
||||||
|
|
||||||
const [conversations, setConversations] = React.useState<Conversation[]>([]);
|
const [conversations, setConversations] = React.useState<Conversation[]>([]);
|
||||||
const [activeConv, setActiveConv] = React.useState<Conversation | null>(null);
|
const [activeConv, setActiveConv] = React.useState<Conversation | null>(null);
|
||||||
const [messages, setMessages] = React.useState<Message[]>([]);
|
const [messages, setMessages] = React.useState<Message[]>([]);
|
||||||
const [newMessage, setNewMessage] = React.useState("");
|
const [newMessage, setNewMessage] = React.useState("");
|
||||||
const [isLoadingConvs, setIsLoadingConvs] = React.useState(true);
|
const [isLoadingConvs, setIsLoadingConvs] = React.useState(true);
|
||||||
const [isLoadingMsgs, setIsLoadingMsgs] = React.useState(false);
|
const [isLoadingMsgs, setIsLoadingMsgs] = React.useState(false);
|
||||||
|
|
||||||
|
const [searchQuery, setSearchQuery] = React.useState("");
|
||||||
|
const [searchResults, setSearchResults] = React.useState<User[]>([]);
|
||||||
|
const [isSearching, setIsSearching] = React.useState(false);
|
||||||
|
|
||||||
const scrollRef = React.useRef<HTMLDivElement>(null);
|
const scrollRef = React.useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
// Charger les conversations initiales
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
const fetchConvs = async () => {
|
const fetchConvs = async () => {
|
||||||
try {
|
try {
|
||||||
const data = await MessageService.getConversations();
|
const data = await MessageService.getConversations();
|
||||||
setConversations(data);
|
setConversations(data);
|
||||||
|
|
||||||
|
// Si un utilisateur est spécifié dans l'URL, essayer de trouver la conversation
|
||||||
|
if (targetUserId) {
|
||||||
|
const existing = data.find((c) => c.recipient.uuid === targetUserId);
|
||||||
|
if (existing) {
|
||||||
|
setActiveConv(existing);
|
||||||
|
} else {
|
||||||
|
// Chercher les infos de l'utilisateur pour afficher une interface de chat vide
|
||||||
|
try {
|
||||||
|
const conv = await MessageService.getConversationWith(targetUserId);
|
||||||
|
if (conv) {
|
||||||
|
setConversations((prev) => [conv, ...prev]);
|
||||||
|
setActiveConv(conv);
|
||||||
|
}
|
||||||
|
} catch (_e) {
|
||||||
|
// Peut-être que l'utilisateur n'existe pas ou erreur
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (_error) {
|
} catch (_error) {
|
||||||
toast.error("Erreur lors du chargement des conversations");
|
toast.error("Erreur lors du chargement des conversations");
|
||||||
} finally {
|
} finally {
|
||||||
@@ -40,7 +73,28 @@ export default function MessagesPage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchConvs();
|
fetchConvs();
|
||||||
}, []);
|
}, [targetUserId]);
|
||||||
|
|
||||||
|
// Recherche d'utilisateurs
|
||||||
|
React.useEffect(() => {
|
||||||
|
const delayDebounceFn = setTimeout(async () => {
|
||||||
|
if (searchQuery.length > 1) {
|
||||||
|
setIsSearching(true);
|
||||||
|
try {
|
||||||
|
const results = await UserService.search(searchQuery);
|
||||||
|
setSearchResults(results.filter((u) => u.uuid !== user?.uuid));
|
||||||
|
} catch (_error) {
|
||||||
|
console.error("Search failed");
|
||||||
|
} finally {
|
||||||
|
setIsSearching(false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setSearchResults([]);
|
||||||
|
}
|
||||||
|
}, 300);
|
||||||
|
|
||||||
|
return () => clearTimeout(delayDebounceFn);
|
||||||
|
}, [searchQuery, user?.uuid]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (activeConv) {
|
if (activeConv) {
|
||||||
@@ -98,7 +152,12 @@ export default function MessagesPage() {
|
|||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (scrollRef.current) {
|
if (scrollRef.current) {
|
||||||
scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
|
const scrollContainer = scrollRef.current.querySelector(
|
||||||
|
"[data-slot='scroll-area-viewport']",
|
||||||
|
);
|
||||||
|
if (scrollContainer) {
|
||||||
|
scrollContainer.scrollTop = scrollContainer.scrollHeight;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -114,7 +173,21 @@ export default function MessagesPage() {
|
|||||||
activeConv.recipient.uuid,
|
activeConv.recipient.uuid,
|
||||||
text,
|
text,
|
||||||
);
|
);
|
||||||
setMessages((prev) => [...prev, msg]);
|
|
||||||
|
// Si c'était une conv temporaire, on la remplace par la vraie
|
||||||
|
if (activeConv.id.startsWith("temp-")) {
|
||||||
|
const fetchConvs = async () => {
|
||||||
|
const data = await MessageService.getConversations();
|
||||||
|
setConversations(data);
|
||||||
|
const realConv = data.find(
|
||||||
|
(c) => c.recipient.uuid === activeConv.recipient.uuid,
|
||||||
|
);
|
||||||
|
if (realConv) setActiveConv(realConv);
|
||||||
|
};
|
||||||
|
fetchConvs();
|
||||||
|
} else {
|
||||||
|
setMessages((prev) => [...prev, msg]);
|
||||||
|
}
|
||||||
} catch (_error) {
|
} catch (_error) {
|
||||||
toast.error("Erreur lors de l'envoi");
|
toast.error("Erreur lors de l'envoi");
|
||||||
}
|
}
|
||||||
@@ -125,15 +198,94 @@ export default function MessagesPage() {
|
|||||||
{/* Sidebar - Liste des conversations */}
|
{/* Sidebar - Liste des conversations */}
|
||||||
<div className="w-80 border-r flex flex-col">
|
<div className="w-80 border-r flex flex-col">
|
||||||
<div className="p-4 border-b">
|
<div className="p-4 border-b">
|
||||||
<h2 className="text-xl font-bold mb-4">Messages</h2>
|
<div className="flex items-center justify-between mb-4">
|
||||||
|
<h2 className="text-xl font-bold">Messages</h2>
|
||||||
|
<Button variant="ghost" size="icon" className="rounded-full">
|
||||||
|
<UserPlus className="h-5 w-5" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
||||||
<Input placeholder="Rechercher..." className="pl-9" />
|
<Input
|
||||||
|
placeholder="Rechercher un membre..."
|
||||||
|
className="pl-9"
|
||||||
|
value={searchQuery}
|
||||||
|
onChange={(e) => setSearchQuery(e.target.value)}
|
||||||
|
/>
|
||||||
|
{searchQuery && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setSearchQuery("")}
|
||||||
|
className="absolute right-3 top-1/2 -translate-y-1/2 p-0.5 hover:bg-zinc-100 dark:hover:bg-zinc-800 rounded-full"
|
||||||
|
>
|
||||||
|
<X className="h-3 w-3 text-muted-foreground" />
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<ScrollArea className="flex-1">
|
<ScrollArea className="flex-1">
|
||||||
<div className="p-2 space-y-1">
|
<div className="p-2 space-y-1">
|
||||||
{isLoadingConvs ? (
|
{searchQuery.length > 0 ? (
|
||||||
|
<>
|
||||||
|
<p className="px-3 py-2 text-[10px] font-bold uppercase tracking-wider text-muted-foreground">
|
||||||
|
Membres
|
||||||
|
</p>
|
||||||
|
{isSearching ? (
|
||||||
|
<div className="p-4 text-center text-sm text-muted-foreground">
|
||||||
|
Recherche...
|
||||||
|
</div>
|
||||||
|
) : searchResults.length === 0 ? (
|
||||||
|
<div className="p-4 text-center text-sm text-muted-foreground">
|
||||||
|
Aucun membre trouvé.
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
searchResults.map((result) => (
|
||||||
|
<button
|
||||||
|
key={result.uuid}
|
||||||
|
type="button"
|
||||||
|
onClick={async () => {
|
||||||
|
setSearchQuery("");
|
||||||
|
// Chercher si une conv existe déjà
|
||||||
|
const existing = conversations.find(
|
||||||
|
(c) => c.recipient.uuid === result.uuid,
|
||||||
|
);
|
||||||
|
if (existing) {
|
||||||
|
setActiveConv(existing);
|
||||||
|
} else {
|
||||||
|
// Créer une interface de conv temporaire
|
||||||
|
const newConv: Conversation = {
|
||||||
|
id: `temp-${result.uuid}`,
|
||||||
|
updatedAt: new Date().toISOString(),
|
||||||
|
recipient: {
|
||||||
|
uuid: result.uuid,
|
||||||
|
username: result.username,
|
||||||
|
displayName: result.displayName,
|
||||||
|
avatarUrl: result.avatarUrl,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
setConversations((prev) => [newConv, ...prev]);
|
||||||
|
setActiveConv(newConv);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
className="w-full flex items-center gap-3 p-3 rounded-xl hover:bg-zinc-100 dark:hover:bg-zinc-900 transition-colors"
|
||||||
|
>
|
||||||
|
<Avatar className="h-10 w-10">
|
||||||
|
<AvatarImage src={result.avatarUrl} />
|
||||||
|
<AvatarFallback>{result.username[0].toUpperCase()}</AvatarFallback>
|
||||||
|
</Avatar>
|
||||||
|
<div className="flex-1 text-left overflow-hidden">
|
||||||
|
<span className="font-bold block truncate">
|
||||||
|
{result.displayName || result.username}
|
||||||
|
</span>
|
||||||
|
<span className="text-xs text-muted-foreground block truncate">
|
||||||
|
@{result.username}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
) : isLoadingConvs ? (
|
||||||
<div className="p-4 text-center text-sm text-muted-foreground">
|
<div className="p-4 text-center text-sm text-muted-foreground">
|
||||||
Chargement...
|
Chargement...
|
||||||
</div>
|
</div>
|
||||||
@@ -188,19 +340,24 @@ export default function MessagesPage() {
|
|||||||
{activeConv ? (
|
{activeConv ? (
|
||||||
<>
|
<>
|
||||||
{/* Header */}
|
{/* Header */}
|
||||||
<div className="p-4 border-b flex items-center gap-3">
|
<div className="p-4 border-b flex items-center justify-between">
|
||||||
<Avatar className="h-8 w-8">
|
<Link
|
||||||
<AvatarImage src={activeConv.recipient.avatarUrl} />
|
href={`/user/${activeConv.recipient.username}`}
|
||||||
<AvatarFallback>
|
className="flex items-center gap-3 hover:opacity-80 transition-opacity"
|
||||||
{activeConv.recipient.username[0].toUpperCase()}
|
>
|
||||||
</AvatarFallback>
|
<Avatar className="h-8 w-8">
|
||||||
</Avatar>
|
<AvatarImage src={activeConv.recipient.avatarUrl} />
|
||||||
<div>
|
<AvatarFallback>
|
||||||
<h3 className="font-bold leading-none">
|
{activeConv.recipient.username[0].toUpperCase()}
|
||||||
{activeConv.recipient.displayName || activeConv.recipient.username}
|
</AvatarFallback>
|
||||||
</h3>
|
</Avatar>
|
||||||
<span className="text-xs text-green-500 font-medium">En ligne</span>
|
<div>
|
||||||
</div>
|
<h3 className="font-bold leading-none">
|
||||||
|
{activeConv.recipient.displayName || activeConv.recipient.username}
|
||||||
|
</h3>
|
||||||
|
<span className="text-xs text-green-500 font-medium">En ligne</span>
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Messages */}
|
{/* Messages */}
|
||||||
@@ -226,18 +383,25 @@ export default function MessagesPage() {
|
|||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
<p className="whitespace-pre-wrap">{msg.text}</p>
|
<p className="whitespace-pre-wrap">{msg.text}</p>
|
||||||
<p
|
<div
|
||||||
className={`text-[10px] mt-1 ${
|
className={`flex items-center gap-1 text-[10px] mt-1 ${
|
||||||
msg.senderId === user?.uuid
|
msg.senderId === user?.uuid
|
||||||
? "text-primary-foreground/70"
|
? "text-primary-foreground/70 justify-end"
|
||||||
: "text-muted-foreground"
|
: "text-muted-foreground"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{new Date(msg.createdAt).toLocaleTimeString([], {
|
<span>
|
||||||
hour: "2-digit",
|
{new Date(msg.createdAt).toLocaleTimeString([], {
|
||||||
minute: "2-digit",
|
hour: "2-digit",
|
||||||
})}
|
minute: "2-digit",
|
||||||
</p>
|
})}
|
||||||
|
</span>
|
||||||
|
{msg.senderId === user?.uuid && (
|
||||||
|
<span className="font-bold">
|
||||||
|
{msg.readAt ? "• Lu" : "• Envoyé"}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))
|
))
|
||||||
|
|||||||
@@ -1,12 +1,19 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { Calendar, Share2, User as UserIcon } from "lucide-react";
|
import {
|
||||||
|
Calendar,
|
||||||
|
MessageCircle,
|
||||||
|
Share2,
|
||||||
|
User as UserIcon,
|
||||||
|
} from "lucide-react";
|
||||||
|
import Link from "next/link";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { ContentList } from "@/components/content-list";
|
import { ContentList } from "@/components/content-list";
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Spinner } from "@/components/ui/spinner";
|
import { Spinner } from "@/components/ui/spinner";
|
||||||
|
import { useAuth } from "@/providers/auth-provider";
|
||||||
import { ContentService } from "@/services/content.service";
|
import { ContentService } from "@/services/content.service";
|
||||||
import { UserService } from "@/services/user.service";
|
import { UserService } from "@/services/user.service";
|
||||||
import type { User } from "@/types/user";
|
import type { User } from "@/types/user";
|
||||||
@@ -17,9 +24,12 @@ export default function PublicProfilePage({
|
|||||||
params: Promise<{ username: string }>;
|
params: Promise<{ username: string }>;
|
||||||
}) {
|
}) {
|
||||||
const { username } = React.use(params);
|
const { username } = React.use(params);
|
||||||
|
const { user: currentUser, isAuthenticated } = useAuth();
|
||||||
const [user, setUser] = React.useState<User | null>(null);
|
const [user, setUser] = React.useState<User | null>(null);
|
||||||
const [loading, setLoading] = React.useState(true);
|
const [loading, setLoading] = React.useState(true);
|
||||||
|
|
||||||
|
const isOwnProfile = currentUser?.username === username;
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
UserService.getProfile(username)
|
UserService.getProfile(username)
|
||||||
.then(setUser)
|
.then(setUser)
|
||||||
@@ -93,7 +103,15 @@ export default function PublicProfilePage({
|
|||||||
})}
|
})}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex justify-center md:justify-start pt-2">
|
<div className="flex flex-wrap justify-center md:justify-start gap-2 pt-2">
|
||||||
|
{!isOwnProfile && isAuthenticated && (
|
||||||
|
<Button size="sm" className="h-9 px-4" asChild>
|
||||||
|
<Link href={`/messages?user=${user.uuid}`}>
|
||||||
|
<MessageCircle className="h-4 w-4 mr-2" />
|
||||||
|
Message
|
||||||
|
</Link>
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ import {
|
|||||||
SidebarGroupLabel,
|
SidebarGroupLabel,
|
||||||
SidebarHeader,
|
SidebarHeader,
|
||||||
SidebarMenu,
|
SidebarMenu,
|
||||||
|
SidebarMenuBadge,
|
||||||
SidebarMenuButton,
|
SidebarMenuButton,
|
||||||
SidebarMenuItem,
|
SidebarMenuItem,
|
||||||
SidebarMenuSub,
|
SidebarMenuSub,
|
||||||
@@ -54,7 +55,9 @@ import {
|
|||||||
SidebarTrigger,
|
SidebarTrigger,
|
||||||
} from "@/components/ui/sidebar";
|
} from "@/components/ui/sidebar";
|
||||||
import { useAuth } from "@/providers/auth-provider";
|
import { useAuth } from "@/providers/auth-provider";
|
||||||
|
import { useSocket } from "@/providers/socket-provider";
|
||||||
import { CategoryService } from "@/services/category.service";
|
import { CategoryService } from "@/services/category.service";
|
||||||
|
import { MessageService } from "@/services/message.service";
|
||||||
import type { Category } from "@/types/content";
|
import type { Category } from "@/types/content";
|
||||||
|
|
||||||
const mainNav = [
|
const mainNav = [
|
||||||
@@ -79,15 +82,46 @@ export function AppSidebar() {
|
|||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
const { user, logout, isAuthenticated } = useAuth();
|
const { user, logout, isAuthenticated } = useAuth();
|
||||||
|
const { socket } = useSocket();
|
||||||
const { resolvedTheme } = useTheme();
|
const { resolvedTheme } = useTheme();
|
||||||
const [categories, setCategories] = React.useState<Category[]>([]);
|
const [categories, setCategories] = React.useState<Category[]>([]);
|
||||||
const [mounted, setMounted] = React.useState(false);
|
const [mounted, setMounted] = React.useState(false);
|
||||||
|
const [unreadMessages, setUnreadMessages] = React.useState(0);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
setMounted(true);
|
setMounted(true);
|
||||||
CategoryService.getAll().then(setCategories).catch(console.error);
|
CategoryService.getAll().then(setCategories).catch(console.error);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// Gérer le compteur de messages non-lus
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (isAuthenticated) {
|
||||||
|
MessageService.getUnreadCount().then(setUnreadMessages).catch(console.error);
|
||||||
|
}
|
||||||
|
}, [isAuthenticated]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (socket && isAuthenticated) {
|
||||||
|
socket.on("new_message", () => {
|
||||||
|
// Incrémenter si on n'est pas sur la page messages
|
||||||
|
if (pathname !== "/messages") {
|
||||||
|
setUnreadMessages((prev) => prev + 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
socket.off("new_message");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}, [socket, isAuthenticated, pathname]);
|
||||||
|
|
||||||
|
// Remettre à zéro si on arrive sur la page messages
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (pathname === "/messages") {
|
||||||
|
setUnreadMessages(0);
|
||||||
|
}
|
||||||
|
}, [pathname]);
|
||||||
|
|
||||||
const logoSrc = React.useMemo(() => {
|
const logoSrc = React.useMemo(() => {
|
||||||
if (!mounted) return "/memegoat-color.svg";
|
if (!mounted) return "/memegoat-color.svg";
|
||||||
return resolvedTheme === "dark"
|
return resolvedTheme === "dark"
|
||||||
@@ -193,6 +227,11 @@ export function AppSidebar() {
|
|||||||
<span>Messages</span>
|
<span>Messages</span>
|
||||||
</Link>
|
</Link>
|
||||||
</SidebarMenuButton>
|
</SidebarMenuButton>
|
||||||
|
{unreadMessages > 0 && (
|
||||||
|
<SidebarMenuBadge className="bg-red-500 text-white border-none h-5 min-w-5 flex items-center justify-center p-1 text-[10px]">
|
||||||
|
{unreadMessages > 9 ? "9+" : unreadMessages}
|
||||||
|
</SidebarMenuBadge>
|
||||||
|
)}
|
||||||
</SidebarMenuItem>
|
</SidebarMenuItem>
|
||||||
)}
|
)}
|
||||||
</SidebarMenu>
|
</SidebarMenu>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import { formatDistanceToNow } from "date-fns";
|
import { formatDistanceToNow } from "date-fns";
|
||||||
import { fr } from "date-fns/locale";
|
import { fr } from "date-fns/locale";
|
||||||
import { MoreHorizontal, Send, Trash2 } from "lucide-react";
|
import { Heart, MoreHorizontal, Send, Trash2 } from "lucide-react";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||||
@@ -14,7 +14,9 @@ import {
|
|||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
} from "@/components/ui/dropdown-menu";
|
} from "@/components/ui/dropdown-menu";
|
||||||
import { Textarea } from "@/components/ui/textarea";
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
import { useAuth } from "@/providers/auth-provider";
|
import { useAuth } from "@/providers/auth-provider";
|
||||||
|
import { useSocket } from "@/providers/socket-provider";
|
||||||
import { type Comment, CommentService } from "@/services/comment.service";
|
import { type Comment, CommentService } from "@/services/comment.service";
|
||||||
|
|
||||||
interface CommentSectionProps {
|
interface CommentSectionProps {
|
||||||
@@ -23,8 +25,10 @@ interface CommentSectionProps {
|
|||||||
|
|
||||||
export function CommentSection({ contentId }: CommentSectionProps) {
|
export function CommentSection({ contentId }: CommentSectionProps) {
|
||||||
const { user, isAuthenticated } = useAuth();
|
const { user, isAuthenticated } = useAuth();
|
||||||
|
const { socket } = useSocket();
|
||||||
const [comments, setComments] = React.useState<Comment[]>([]);
|
const [comments, setComments] = React.useState<Comment[]>([]);
|
||||||
const [newComment, setNewComment] = React.useState("");
|
const [newComment, setNewComment] = React.useState("");
|
||||||
|
const [replyingTo, setReplyingTo] = React.useState<Comment | null>(null);
|
||||||
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
||||||
const [isLoading, setIsLoading] = React.useState(true);
|
const [isLoading, setIsLoading] = React.useState(true);
|
||||||
|
|
||||||
@@ -43,15 +47,40 @@ export function CommentSection({ contentId }: CommentSectionProps) {
|
|||||||
fetchComments();
|
fetchComments();
|
||||||
}, [fetchComments]);
|
}, [fetchComments]);
|
||||||
|
|
||||||
|
// Gestion du WebSocket
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (socket) {
|
||||||
|
socket.emit("join_content", contentId);
|
||||||
|
|
||||||
|
socket.on("new_comment", (comment: Comment) => {
|
||||||
|
setComments((prev) => {
|
||||||
|
// Éviter les doublons si l'auteur reçoit son propre commentaire via WS
|
||||||
|
if (prev.some((c) => c.id === comment.id)) return prev;
|
||||||
|
return [comment, ...prev];
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
socket.emit("leave_content", contentId);
|
||||||
|
socket.off("new_comment");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}, [socket, contentId]);
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!newComment.trim() || isSubmitting) return;
|
if (!newComment.trim() || isSubmitting) return;
|
||||||
|
|
||||||
setIsSubmitting(true);
|
setIsSubmitting(true);
|
||||||
try {
|
try {
|
||||||
const comment = await CommentService.create(contentId, newComment.trim());
|
const comment = await CommentService.create(
|
||||||
|
contentId,
|
||||||
|
newComment.trim(),
|
||||||
|
replyingTo?.id,
|
||||||
|
);
|
||||||
setComments((prev) => [comment, ...prev]);
|
setComments((prev) => [comment, ...prev]);
|
||||||
setNewComment("");
|
setNewComment("");
|
||||||
|
setReplyingTo(null);
|
||||||
toast.success("Commentaire publié !");
|
toast.success("Commentaire publié !");
|
||||||
} catch (_error) {
|
} catch (_error) {
|
||||||
toast.error("Erreur lors de la publication du commentaire");
|
toast.error("Erreur lors de la publication du commentaire");
|
||||||
@@ -70,97 +99,214 @@ export function CommentSection({ contentId }: CommentSectionProps) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
const handleLike = async (comment: Comment) => {
|
||||||
<div className="space-y-6 mt-8">
|
if (!isAuthenticated) {
|
||||||
<h3 className="font-bold text-lg">Commentaires ({comments.length})</h3>
|
toast.error("Vous devez être connecté pour liker");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
{isAuthenticated ? (
|
try {
|
||||||
<form onSubmit={handleSubmit} className="flex gap-3">
|
if (comment.isLiked) {
|
||||||
<Avatar className="h-8 w-8">
|
await CommentService.unlike(comment.id);
|
||||||
<AvatarImage src={user?.avatarUrl} />
|
setComments((prev) =>
|
||||||
<AvatarFallback>{user?.username[0].toUpperCase()}</AvatarFallback>
|
prev.map((c) =>
|
||||||
|
c.id === comment.id
|
||||||
|
? { ...c, isLiked: false, likesCount: c.likesCount - 1 }
|
||||||
|
: c,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
await CommentService.like(comment.id);
|
||||||
|
setComments((prev) =>
|
||||||
|
prev.map((c) =>
|
||||||
|
c.id === comment.id
|
||||||
|
? { ...c, isLiked: true, likesCount: c.likesCount + 1 }
|
||||||
|
: c,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (_error) {
|
||||||
|
toast.error("Une erreur est survenue");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Organiser les commentaires : Parents d'abord
|
||||||
|
const rootComments = comments.filter((c) => !c.parentId);
|
||||||
|
|
||||||
|
const renderComment = (comment: Comment, depth = 0) => {
|
||||||
|
const replies = comments.filter((c) => c.parentId === comment.id);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div key={comment.id} className={cn("space-y-4", depth > 0 && "ml-10")}>
|
||||||
|
<div className="flex gap-3">
|
||||||
|
<Avatar className="h-8 w-8 shrink-0">
|
||||||
|
<AvatarImage src={comment.user.avatarUrl} />
|
||||||
|
<AvatarFallback>{comment.user.username[0].toUpperCase()}</AvatarFallback>
|
||||||
</Avatar>
|
</Avatar>
|
||||||
<div className="flex-1 space-y-2">
|
<div className="flex-1 space-y-1">
|
||||||
<Textarea
|
<div className="flex items-center justify-between">
|
||||||
placeholder="Ajouter un commentaire..."
|
<div className="flex items-center gap-2">
|
||||||
value={newComment}
|
<span className="text-sm font-bold">
|
||||||
onChange={(e) => setNewComment(e.target.value)}
|
{comment.user.displayName || comment.user.username}
|
||||||
className="min-h-[80px] resize-none"
|
</span>
|
||||||
/>
|
<span className="text-xs text-muted-foreground">
|
||||||
<div className="flex justify-end">
|
{formatDistanceToNow(new Date(comment.createdAt), {
|
||||||
<Button
|
addSuffix: true,
|
||||||
type="submit"
|
locale: fr,
|
||||||
size="sm"
|
})}
|
||||||
disabled={!newComment.trim() || isSubmitting}
|
</span>
|
||||||
>
|
</div>
|
||||||
{isSubmitting ? "Envoi..." : "Publier"}
|
<div className="flex items-center gap-1">
|
||||||
<Send className="ml-2 h-4 w-4" />
|
<Button
|
||||||
</Button>
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className={cn(
|
||||||
|
"h-8 w-8",
|
||||||
|
comment.isLiked && "text-red-500 hover:text-red-600",
|
||||||
|
)}
|
||||||
|
onClick={() => handleLike(comment)}
|
||||||
|
>
|
||||||
|
<Heart className={cn("h-4 w-4", comment.isLiked && "fill-current")} />
|
||||||
|
</Button>
|
||||||
|
{(user?.uuid === comment.user.uuid ||
|
||||||
|
user?.role === "admin" ||
|
||||||
|
user?.role === "moderator") && (
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button variant="ghost" size="icon" className="h-8 w-8">
|
||||||
|
<MoreHorizontal className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end">
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() => handleDelete(comment.id)}
|
||||||
|
className="text-destructive"
|
||||||
|
>
|
||||||
|
<Trash2 className="h-4 w-4 mr-2" />
|
||||||
|
Supprimer
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p className="text-sm leading-relaxed whitespace-pre-wrap">
|
||||||
|
{comment.text}
|
||||||
|
</p>
|
||||||
|
<div className="flex items-center gap-4 pt-1">
|
||||||
|
{comment.likesCount > 0 && (
|
||||||
|
<span className="text-xs font-semibold text-muted-foreground">
|
||||||
|
{comment.likesCount} like{comment.likesCount > 1 ? "s" : ""}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
{isAuthenticated && depth < 1 && (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
className="h-auto p-0 text-xs font-semibold text-muted-foreground hover:bg-transparent hover:text-foreground"
|
||||||
|
onClick={() => {
|
||||||
|
setReplyingTo(comment);
|
||||||
|
setNewComment(`@${comment.user.username} `);
|
||||||
|
document.querySelector("textarea")?.focus();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Répondre
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</div>
|
||||||
|
{replies.length > 0 && (
|
||||||
|
<div className="space-y-4 pt-2">
|
||||||
|
{replies.map((reply) => renderComment(reply, depth + 1))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-6 mt-8">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<h3 className="font-bold text-lg">Commentaires ({comments.length})</h3>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{isAuthenticated ? (
|
||||||
|
<div className="space-y-2">
|
||||||
|
{replyingTo && (
|
||||||
|
<div className="flex items-center justify-between bg-zinc-100 dark:bg-zinc-800 px-3 py-1.5 rounded-lg text-xs">
|
||||||
|
<span className="text-muted-foreground">
|
||||||
|
En réponse à{" "}
|
||||||
|
<span className="font-bold">@{replyingTo.user.username}</span>
|
||||||
|
</span>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="h-4 w-4"
|
||||||
|
onClick={() => {
|
||||||
|
setReplyingTo(null);
|
||||||
|
setNewComment("");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Trash2 className="h-3 w-3" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<form onSubmit={handleSubmit} className="flex gap-3">
|
||||||
|
<Avatar className="h-8 w-8 shrink-0">
|
||||||
|
<AvatarImage src={user?.avatarUrl} />
|
||||||
|
<AvatarFallback>{user?.username[0].toUpperCase()}</AvatarFallback>
|
||||||
|
</Avatar>
|
||||||
|
<div className="flex-1 space-y-2">
|
||||||
|
<Textarea
|
||||||
|
placeholder={
|
||||||
|
replyingTo ? "Ajouter une réponse..." : "Ajouter un commentaire..."
|
||||||
|
}
|
||||||
|
value={newComment}
|
||||||
|
onChange={(e) => setNewComment(e.target.value)}
|
||||||
|
className="min-h-[80px] resize-none"
|
||||||
|
/>
|
||||||
|
<div className="flex justify-end gap-2">
|
||||||
|
{replyingTo && (
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => {
|
||||||
|
setReplyingTo(null);
|
||||||
|
setNewComment("");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Annuler
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
size="sm"
|
||||||
|
disabled={!newComment.trim() || isSubmitting}
|
||||||
|
>
|
||||||
|
{isSubmitting ? "Envoi..." : replyingTo ? "Répondre" : "Publier"}
|
||||||
|
<Send className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="bg-zinc-100 dark:bg-zinc-800 p-4 rounded-xl text-center text-sm">
|
<div className="bg-zinc-100 dark:bg-zinc-800 p-4 rounded-xl text-center text-sm">
|
||||||
Connectez-vous pour laisser un commentaire.
|
Connectez-vous pour laisser un commentaire.
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="space-y-4">
|
<div className="space-y-6">
|
||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
<div className="text-center text-muted-foreground py-4">Chargement...</div>
|
<div className="text-center text-muted-foreground py-4">Chargement...</div>
|
||||||
) : comments.length === 0 ? (
|
) : rootComments.length === 0 ? (
|
||||||
<div className="text-center text-muted-foreground py-4">
|
<div className="text-center text-muted-foreground py-4">
|
||||||
Aucun commentaire pour le moment. Soyez le premier !
|
Aucun commentaire pour le moment. Soyez le premier !
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
comments.map((comment) => (
|
rootComments.map((comment) => renderComment(comment))
|
||||||
<div key={comment.id} className="flex gap-3">
|
|
||||||
<Avatar className="h-8 w-8">
|
|
||||||
<AvatarImage src={comment.user.avatarUrl} />
|
|
||||||
<AvatarFallback>
|
|
||||||
{comment.user.username[0].toUpperCase()}
|
|
||||||
</AvatarFallback>
|
|
||||||
</Avatar>
|
|
||||||
<div className="flex-1 space-y-1">
|
|
||||||
<div className="flex items-center justify-between">
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<span className="text-sm font-bold">
|
|
||||||
{comment.user.displayName || comment.user.username}
|
|
||||||
</span>
|
|
||||||
<span className="text-xs text-muted-foreground">
|
|
||||||
{formatDistanceToNow(new Date(comment.createdAt), {
|
|
||||||
addSuffix: true,
|
|
||||||
locale: fr,
|
|
||||||
})}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
{(user?.uuid === comment.user.uuid ||
|
|
||||||
user?.role === "admin" ||
|
|
||||||
user?.role === "moderator") && (
|
|
||||||
<DropdownMenu>
|
|
||||||
<DropdownMenuTrigger asChild>
|
|
||||||
<Button variant="ghost" size="icon" className="h-8 w-8">
|
|
||||||
<MoreHorizontal className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
</DropdownMenuTrigger>
|
|
||||||
<DropdownMenuContent align="end">
|
|
||||||
<DropdownMenuItem
|
|
||||||
onClick={() => handleDelete(comment.id)}
|
|
||||||
className="text-destructive"
|
|
||||||
>
|
|
||||||
<Trash2 className="h-4 w-4 mr-2" />
|
|
||||||
Supprimer
|
|
||||||
</DropdownMenuItem>
|
|
||||||
</DropdownMenuContent>
|
|
||||||
</DropdownMenu>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<p className="text-sm leading-relaxed whitespace-pre-wrap">
|
|
||||||
{comment.text}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { Loader2, Shield, ShieldAlert, ShieldCheck } from "lucide-react";
|
import { Loader2, Shield, ShieldAlert, ShieldCheck } from "lucide-react";
|
||||||
|
import Image from "next/image";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
@@ -76,9 +77,7 @@ export function TwoFactorSetup() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Note: We need a way to know if 2FA is enabled.
|
// Note: We need a way to know if 2FA is enabled.
|
||||||
// Assuming user object might have twoFactorEnabled property or similar.
|
const isEnabled = user?.twoFactorEnabled;
|
||||||
// For now, let's assume it's on the user object (we might need to add it to the type).
|
|
||||||
const isEnabled = (user as any)?.twoFactorEnabled;
|
|
||||||
|
|
||||||
if (step === "idle") {
|
if (step === "idle") {
|
||||||
return (
|
return (
|
||||||
@@ -154,7 +153,14 @@ export function TwoFactorSetup() {
|
|||||||
<CardContent className="flex flex-col items-center gap-6">
|
<CardContent className="flex flex-col items-center gap-6">
|
||||||
{qrCode && (
|
{qrCode && (
|
||||||
<div className="bg-white p-4 rounded-xl border-4 border-zinc-100">
|
<div className="bg-white p-4 rounded-xl border-4 border-zinc-100">
|
||||||
<img src={qrCode} alt="QR Code 2FA" className="w-48 h-48" />
|
<Image
|
||||||
|
src={qrCode}
|
||||||
|
alt="QR Code 2FA"
|
||||||
|
width={192}
|
||||||
|
height={192}
|
||||||
|
className="w-48 h-48"
|
||||||
|
unoptimized
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className="w-full space-y-2">
|
<div className="w-full space-y-2">
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import api from "@/lib/api";
|
import api from "@/lib/api";
|
||||||
|
import type { User } from "@/types/user";
|
||||||
import type { Report, ReportStatus } from "./report.service";
|
import type { Report, ReportStatus } from "./report.service";
|
||||||
|
|
||||||
export interface AdminStats {
|
export interface AdminStats {
|
||||||
@@ -29,7 +30,7 @@ export const adminService = {
|
|||||||
await api.delete(`/users/${userId}`);
|
await api.delete(`/users/${userId}`);
|
||||||
},
|
},
|
||||||
|
|
||||||
updateUser: async (userId: string, data: any): Promise<void> => {
|
updateUser: async (userId: string, data: Partial<User>): Promise<void> => {
|
||||||
await api.patch(`/users/admin/${userId}`, data);
|
await api.patch(`/users/admin/${userId}`, data);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ import api from "@/lib/api";
|
|||||||
export interface Comment {
|
export interface Comment {
|
||||||
id: string;
|
id: string;
|
||||||
text: string;
|
text: string;
|
||||||
|
parentId?: string;
|
||||||
|
likesCount: number;
|
||||||
|
isLiked: boolean;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
user: {
|
user: {
|
||||||
@@ -19,9 +22,14 @@ export const CommentService = {
|
|||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
async create(contentId: string, text: string): Promise<Comment> {
|
async create(
|
||||||
|
contentId: string,
|
||||||
|
text: string,
|
||||||
|
parentId?: string,
|
||||||
|
): Promise<Comment> {
|
||||||
const { data } = await api.post<Comment>(`/contents/${contentId}/comments`, {
|
const { data } = await api.post<Comment>(`/contents/${contentId}/comments`, {
|
||||||
text,
|
text,
|
||||||
|
parentId,
|
||||||
});
|
});
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
@@ -29,4 +37,12 @@ export const CommentService = {
|
|||||||
async remove(commentId: string): Promise<void> {
|
async remove(commentId: string): Promise<void> {
|
||||||
await api.delete(`/comments/${commentId}`);
|
await api.delete(`/comments/${commentId}`);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async like(commentId: string): Promise<void> {
|
||||||
|
await api.post(`/comments/${commentId}/like`);
|
||||||
|
},
|
||||||
|
|
||||||
|
async unlike(commentId: string): Promise<void> {
|
||||||
|
await api.delete(`/comments/${commentId}/like`);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -29,6 +29,11 @@ export const MessageService = {
|
|||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async getUnreadCount(): Promise<number> {
|
||||||
|
const { data } = await api.get<number>("/messages/unread-count");
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
async getMessages(conversationId: string): Promise<Message[]> {
|
async getMessages(conversationId: string): Promise<Message[]> {
|
||||||
const { data } = await api.get<Message[]>(
|
const { data } = await api.get<Message[]>(
|
||||||
`/messages/conversations/${conversationId}`,
|
`/messages/conversations/${conversationId}`,
|
||||||
@@ -36,6 +41,13 @@ export const MessageService = {
|
|||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async getConversationWith(userId: string): Promise<Conversation | null> {
|
||||||
|
const { data } = await api.get<Conversation | null>(
|
||||||
|
`/messages/conversations/with/${userId}`,
|
||||||
|
);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
async sendMessage(recipientId: string, text: string): Promise<Message> {
|
async sendMessage(recipientId: string, text: string): Promise<Message> {
|
||||||
const { data } = await api.post<Message>("/messages", {
|
const { data } = await api.post<Message>("/messages", {
|
||||||
recipientId,
|
recipientId,
|
||||||
|
|||||||
@@ -12,6 +12,13 @@ export const UserService = {
|
|||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async search(query: string): Promise<User[]> {
|
||||||
|
const { data } = await api.get<User[]>("/users/search", {
|
||||||
|
params: { q: query },
|
||||||
|
});
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
|
||||||
async updateMe(update: Partial<User>): Promise<User> {
|
async updateMe(update: Partial<User>): Promise<User> {
|
||||||
const { data } = await api.patch<User>("/users/me", update);
|
const { data } = await api.patch<User>("/users/me", update);
|
||||||
return data;
|
return data;
|
||||||
@@ -54,8 +61,8 @@ export const UserService = {
|
|||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
async exportData(): Promise<any> {
|
async exportData(): Promise<Record<string, unknown>> {
|
||||||
const { data } = await api.get("/users/me/export");
|
const { data } = await api.get<Record<string, unknown>>("/users/me/export");
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ export interface User {
|
|||||||
bio?: string;
|
bio?: string;
|
||||||
role?: "user" | "admin" | "moderator";
|
role?: "user" | "admin" | "moderator";
|
||||||
status?: "active" | "verification" | "suspended" | "pending" | "deleted";
|
status?: "active" | "verification" | "suspended" | "pending" | "deleted";
|
||||||
|
twoFactorEnabled?: boolean;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@memegoat/source",
|
"name": "@memegoat/source",
|
||||||
"version": "1.8.1",
|
"version": "1.8.3",
|
||||||
"description": "",
|
"description": "",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"version:get": "cmake -P version.cmake GET",
|
"version:get": "cmake -P version.cmake GET",
|
||||||
|
|||||||
Reference in New Issue
Block a user