Skip to content

Commit 2b49076

Browse files
committed
Revert "feat: add guest comment support (#514)"
This reverts commit f6b99b3.
1 parent c278aef commit 2b49076

6 files changed

Lines changed: 54 additions & 222 deletions

File tree

client/src/page/feed.tsx

Lines changed: 22 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -376,67 +376,33 @@ function CommentInput({
376376
}) {
377377
const { t } = useTranslation();
378378
const [content, setContent] = useState("");
379-
const [guestName, setGuestName] = useState("");
380-
const [guestEmail, setGuestEmail] = useState("");
381-
const [guestWebsite, setGuestWebsite] = useState("");
382379
const [error, setError] = useState("");
383380
const { showAlert, AlertUI } = useAlert();
384381
const profile = useContext(ProfileContext);
385382
const [, setLocation] = useLocation();
386-
const config = useContext(ClientConfigContext);
387-
// guest comments enabled by default; admin can disable via client config `comment.guest.enabled=false`
388-
const rawGuest = config.get('comment.guest.enabled');
389-
const guestEnabled = rawGuest !== false && rawGuest !== 'false';
390383
function errorHumanize(error: string) {
391384
if (error === "Unauthorized") return t("login.required");
392385
else if (error === "Content is required") return t("comment.empty");
393-
else if (error === "Guest name is required") return t("comment.guest_name_required");
394386
return error;
395387
}
396388
function submit() {
397-
if (profile) {
398-
client.comment
399-
.create(parseInt(id), { content })
400-
.then(({ error }) => {
401-
if (error) {
402-
setError(errorHumanize(error.value as string));
403-
} else {
404-
setContent("");
405-
setError("");
406-
showAlert(t("comment.success"), () => {
407-
onRefresh();
408-
});
409-
}
410-
});
411-
} else if (guestEnabled) {
412-
if (!guestName.trim()) {
413-
setError(t("comment.guest_name_required"));
414-
return;
415-
}
416-
client.comment
417-
.create(parseInt(id), {
418-
content,
419-
guestName: guestName.trim(),
420-
guestEmail: guestEmail.trim() || undefined,
421-
guestWebsite: guestWebsite.trim() || undefined,
422-
})
423-
.then(({ error }) => {
424-
if (error) {
425-
setError(errorHumanize(error.value as string));
426-
} else {
427-
setContent("");
428-
setGuestName("");
429-
setGuestEmail("");
430-
setGuestWebsite("");
431-
setError("");
432-
showAlert(t("comment.success"), () => {
433-
onRefresh();
434-
});
435-
}
436-
});
437-
} else {
438-
setLocation('/login');
389+
if (!profile) {
390+
setLocation('/login')
391+
return;
439392
}
393+
client.comment
394+
.create(parseInt(id), { content })
395+
.then(({ error }) => {
396+
if (error) {
397+
setError(errorHumanize(error.value as string));
398+
} else {
399+
setContent("");
400+
setError("");
401+
showAlert(t("comment.success"), () => {
402+
onRefresh();
403+
});
404+
}
405+
});
440406
}
441407
return (
442408
<div className="w-full rounded-2xl bg-w t-primary p-6 items-end flex flex-col">
@@ -457,42 +423,7 @@ function CommentInput({
457423
>
458424
{t("comment.submit")}
459425
</button>
460-
</>) : guestEnabled ? (<>
461-
<input
462-
type="text"
463-
placeholder={t("comment.guest_name_placeholder")}
464-
className="bg-w w-full rounded-lg px-3 py-2 mb-2 border border-gray-200 dark:border-gray-700"
465-
value={guestName}
466-
onChange={(e) => setGuestName(e.target.value)}
467-
/>
468-
<input
469-
type="email"
470-
placeholder={t("comment.guest_email_placeholder")}
471-
className="bg-w w-full rounded-lg px-3 py-2 mb-2 border border-gray-200 dark:border-gray-700"
472-
value={guestEmail}
473-
onChange={(e) => setGuestEmail(e.target.value)}
474-
/>
475-
<input
476-
type="url"
477-
placeholder={t("comment.guest_website_placeholder")}
478-
className="bg-w w-full rounded-lg px-3 py-2 mb-2 border border-gray-200 dark:border-gray-700"
479-
value={guestWebsite}
480-
onChange={(e) => setGuestWebsite(e.target.value)}
481-
/>
482-
<textarea
483-
id="comment"
484-
placeholder={t("comment.placeholder.title")}
485-
className="bg-w w-full h-24 rounded-lg"
486-
value={content}
487-
onChange={(e) => setContent(e.target.value)}
488-
/>
489-
<button
490-
className="mt-4 bg-theme text-white px-4 py-2 rounded-full"
491-
onClick={submit}
492-
>
493-
{t("comment.submit")}
494-
</button>
495-
</>) : (
426+
</> ) : (
496427
<div className="flex flex-row w-full items-center justify-center space-x-2 py-12">
497428
<button
498429
className="mt-2 bg-theme text-white px-4 py-2 rounded-full"
@@ -513,15 +444,12 @@ type Comment = {
513444
content: string;
514445
createdAt: Date;
515446
updatedAt: Date;
516-
user?: {
447+
user: {
517448
id: number;
518449
username: string;
519450
avatar: string | null;
520451
permission: number | null;
521-
} | null;
522-
guestName?: string;
523-
guestEmail?: string;
524-
guestWebsite?: string;
452+
};
525453
};
526454

527455
function Comments({ id }: { id: string }) {
@@ -593,8 +521,6 @@ function CommentItem({
593521
const { showAlert, AlertUI } = useAlert();
594522
const { t } = useTranslation();
595523
const profile = useContext(ProfileContext);
596-
const commenterName = comment.user?.username || comment.guestName || t("anonymous");
597-
const commenterAvatar = comment.user?.avatar || "";
598524
function deleteComment() {
599525
showConfirm(
600526
t("delete.comment.title"),
@@ -616,24 +542,14 @@ function CommentItem({
616542
return (
617543
<div className="flex flex-row items-start rounded-xl mt-2">
618544
<img
619-
src={commenterAvatar}
545+
src={comment.user.avatar || ""}
620546
className="w-8 h-8 rounded-full mt-4"
621547
/>
622548
<div className="flex flex-col flex-1 w-0 ml-2 bg-w rounded-xl p-4">
623549
<div className="flex flex-row">
624550
<span className="t-primary text-base font-bold">
625-
{commenterName}
551+
{comment.user.username}
626552
</span>
627-
{comment.guestWebsite && (
628-
<a
629-
href={comment.guestWebsite}
630-
target="_blank"
631-
rel="noopener noreferrer"
632-
className="ml-2 text-gray-400 hover:text-theme transition-colors"
633-
>
634-
<i className="ri-external-link-line"></i>
635-
</a>
636-
)}
637553
<div className="flex-1 w-0" />
638554
<span
639555
title={new Date(comment.createdAt).toLocaleString()}
@@ -644,7 +560,7 @@ function CommentItem({
644560
</div>
645561
<p className="t-primary break-words">{comment.content}</p>
646562
<div className="flex flex-row justify-end">
647-
{(profile?.permission || (comment.user && profile?.id == comment.user.id)) && (
563+
{(profile?.permission || profile?.id == comment.user.id) && (
648564
<Popup
649565
arrow={false}
650566
trigger={

packages/api/src/schemas.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ export const updateProfileSchema = t.Object({
6262

6363
export const commentCreateSchema = t.Object({
6464
content: t.String(),
65-
guestName: t.String({ optional: true }),
66-
guestEmail: t.String({ optional: true }),
67-
guestWebsite: t.String({ optional: true }),
6865
});
6966

7067
// ============================================================================

packages/api/src/types.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -165,31 +165,16 @@ export interface Comment {
165165
content: string;
166166
createdAt: string;
167167
updatedAt: string;
168-
/** 登录用户的评论 */
169-
user?: {
168+
user: {
170169
id: number;
171170
username: string;
172171
avatar: string | null;
173172
permission: number | null;
174-
} | null;
175-
/** 游客评论的昵称 */
176-
guestName?: string;
177-
/** 游客评论的邮箱 */
178-
guestEmail?: string;
179-
/** 游客评论的网站 */
180-
guestWebsite?: string;
181-
/** 审核状态 */
182-
approved: boolean;
173+
};
183174
}
184175

185176
export interface CreateCommentRequest {
186177
content: string;
187-
/** 游客昵称(未登录时必填) */
188-
guestName?: string;
189-
/** 游客邮箱(可选) */
190-
guestEmail?: string;
191-
/** 游客网站(可选) */
192-
guestWebsite?: string;
193178
}
194179

195180
// ============================================================================

server/sql/0010.sql

Lines changed: 0 additions & 7 deletions
This file was deleted.

server/src/db/schema.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,8 @@ export const users = sqliteTable("users", {
7676
export const comments = sqliteTable("comments", {
7777
id: integer("id").primaryKey(),
7878
feedId: integer("feed_id").references(() => feeds.id, { onDelete: 'cascade' }).notNull(),
79-
userId: integer("user_id").references(() => users.id, { onDelete: 'cascade' }),
79+
userId: integer("user_id").references(() => users.id, { onDelete: 'cascade' }).notNull(),
8080
content: text("content").notNull(),
81-
guestName: text("guest_name").default(""),
82-
guestEmail: text("guest_email").default(""),
83-
guestWebsite: text("guest_website").default(""),
84-
approved: integer("approved").default(1).notNull(),
8581
createdAt: created_at,
8682
updatedAt: updated_at,
8783
});

0 commit comments

Comments
 (0)