Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 30 additions & 39 deletions src/app/room/classChat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import ChatHeader from "./ChatHeader";
import ChatInput from "./ChatInput";
import FilterTabs from "./FilterTabs";
import type { Question, Comment, Role } from "@/utils/types";
import type { Question, Comment, Role, User } from "@/utils/types";
import { showRateLimitToast } from "@/components/RateLimitToast";

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -416,21 +416,18 @@
authorRole: Role;
}) => {
if (!payload.authorName) return;
setQuestions((prev) =>
prev.map((q) =>
q.id === payload.id
? {
...q,
user: {
id: payload.authorId,
utorid: payload.authorUtorid ?? undefined,
username: payload.authorName!,
pfp: "",
role: payload.authorRole,
},
}
: q
)
const author: User = {
id: payload.authorId,
utorid: payload.authorUtorid ?? undefined,
username: payload.authorName,
pfp: "",
role: payload.authorRole,
};
setQuestions((prev) => prev.map((q) => (q.id === payload.id ? { ...q, user: author } : q)));
// The export reads historyRef, so the reveal has to land there too —
// otherwise a live anonymous question stays unattributed in the transcript.
historyRef.current = historyRef.current.map((q) =>
q.id === payload.id ? { ...q, user: author } : q
);
};

Expand All @@ -443,29 +440,23 @@
authorRole: Role;
}) => {
if (!payload.authorName) return;
setQuestions((prev) =>
prev.map((q) =>
q.id === payload.questionId
? {
...q,
replies: q.replies.map((r) =>
r.id === payload.id
? {
...r,
user: {
id: payload.authorId,
utorid: payload.authorUtorid ?? undefined,
username: payload.authorName!,
pfp: "",
role: payload.authorRole,
},
}
: r
),
}
: q
)
);
const author: User = {
id: payload.authorId,
utorid: payload.authorUtorid ?? undefined,
username: payload.authorName,
pfp: "",
role: payload.authorRole,
};
const attachAuthor = (q: Question): Question =>
q.id === payload.questionId
? {
...q,
replies: q.replies.map((r) => (r.id === payload.id ? { ...r, user: author } : r)),
}
: q;

setQuestions((prev) => prev.map(attachAuthor));
historyRef.current = historyRef.current.map(attachAuthor);
};

// Rate-limit refusals arrive already phrased for the user, and they are not
Expand Down Expand Up @@ -545,7 +536,7 @@
socket.off("question:author:revealed", onQuestionAuthorRevealed);
socket.off("answer:author:revealed", onAnswerAuthorRevealed);
};
}, [socket, sessionId, chatHistoryRef, role, userId, notificationMode]);

Check warning on line 539 in src/app/room/classChat/index.tsx

View workflow job for this annotation

GitHub Actions / build (20)

React Hook useEffect has missing dependencies: 'isOwnPost', 'playQuestionBeep', 'sessionTitle', and 'showBrowserNotification'. Either include them or remove the dependency array

// Keep chatHistoryRef in sync whenever historyRef is updated via data load
// or new questions/answers arriving (deletions update it inline above).
Expand Down
18 changes: 13 additions & 5 deletions src/app/room/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,30 @@ function generateAndDownloadTxt(questions: Question[], sessionTitle: string): vo
const sep = "─".repeat(44);
const lines: string[] = [`=== ${sessionTitle} ===`, new Date().toLocaleString(), ""];

function label(user: { username: string; utorid?: string } | null): string {
if (!user) return "Anonymous";
return user.utorid ? `${user.username} - ${user.utorid}` : user.username;
// Transcripts are instructor-only, so they mirror the reveal view rather than
// the student view: an anonymous author is named and tagged, never redacted.
function label(post: {
user: { username: string; utorid?: string } | null;
isAnonymous?: boolean;
}): string {
if (!post.user) return "Anonymous";
const name = post.user.utorid
? `${post.user.username} - ${post.user.utorid}`
: post.user.username;
return post.isAnonymous ? `${name} (anonymous)` : name;
}

if (questions.length === 0) {
lines.push("No questions were asked during this session.");
} else {
for (const q of questions) {
lines.push(sep);
lines.push(`${q.timestamp} — ${label(q.user)}`);
lines.push(`${q.timestamp} — ${label(q)}`);
lines.push(`Q: ${q.content}`);
if (q.replies.length > 0) {
lines.push("");
for (const r of q.replies) {
lines.push(` ${r.timestamp} — ${label(r.user)}`);
lines.push(` ${r.timestamp} — ${label(r)}`);
lines.push(` A: ${r.content}`);
}
}
Expand Down
Loading