-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Followup PR to #3280 Additions: - Endpoint for fetching the revision history of a message - Card which allows moderators to view the revision history of a message
- Loading branch information
1 parent
b0bb643
commit c0edd79
Showing
12 changed files
with
209 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Text, useColorModeValue } from "@chakra-ui/react"; | ||
import { useCurrentLocale } from "src/hooks/locale/useCurrentLocale"; | ||
|
||
export const MessageCreateDate = ({ date }: { date: string }) => { | ||
const locale = useCurrentLocale(); | ||
const createdDateColor = useColorModeValue("blackAlpha.600", "gray.400"); | ||
|
||
return ( | ||
<Text as="span" fontSize="small" color={createdDateColor} fontWeight="medium" me={{ base: 3, md: 6 }}> | ||
{new Intl.DateTimeFormat(locale, { | ||
hour: "2-digit", | ||
minute: "2-digit", | ||
year: "numeric", | ||
month: "2-digit", | ||
day: "2-digit", | ||
}).format(new Date(date))} | ||
</Text> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { Badge, Flex, Stack, Tooltip } from "@chakra-ui/react"; | ||
import { boolean } from "boolean"; | ||
import { User } from "lucide-react"; | ||
import { useRouter } from "next/router"; | ||
import { useTranslation } from "next-i18next"; | ||
import { ROUTES } from "src/lib/routes"; | ||
import { Message, MessageRevision } from "src/types/Conversation"; | ||
|
||
import { BaseMessageEntry } from "./BaseMessageEntry"; | ||
import { MessageCreateDate } from "./MessageCreateDate"; | ||
import { BaseMessageEmojiButton } from "./MessageEmojiButton"; | ||
import { MessageInlineEmojiRow } from "./MessageInlineEmojiRow"; | ||
|
||
export interface MessageHistoryTableProps { | ||
message: Message; | ||
revisions: MessageRevision[]; | ||
} | ||
|
||
export function MessageHistoryTable({ message, revisions }: MessageHistoryTableProps) { | ||
const { t } = useTranslation(["message"]); | ||
const router = useRouter(); | ||
|
||
return ( | ||
<Stack spacing={4}> | ||
{(revisions.length === 0 | ||
? ([ | ||
{ | ||
text: message.text, | ||
created_date: message.created_date, | ||
user_id: message.user_id, | ||
user_is_author: message.user_is_author, | ||
}, | ||
] as Omit<MessageRevision, "id" | "message_id">[]) | ||
: (revisions.map((revision) => ({ | ||
text: revision.text, | ||
created_date: revision.created_date, | ||
user_id: revision.user_id, | ||
user_is_author: revision.user_is_author, | ||
})) as Omit<MessageRevision, "id" | "message_id">[]) | ||
).map(({ text, created_date, user_id, user_is_author }, index, array) => ( | ||
<BaseMessageEntry | ||
key={`version-${index}`} | ||
content={text} | ||
avatarProps={{ | ||
name: `${boolean(message.is_assistant) ? "Assistant" : "User"}`, | ||
src: `${boolean(message.is_assistant) ? "/images/logos/logo.png" : "/images/temp-avatars/av1.jpg"}`, | ||
}} | ||
highlight={index === array.length - 1} | ||
> | ||
<Flex justifyContent={"space-between"} marginTop={2} alignItems={"center"}> | ||
<MessageCreateDate date={created_date} /> | ||
<MessageInlineEmojiRow> | ||
<BaseMessageEmojiButton | ||
emoji={User} | ||
label="Manage User" | ||
onClick={() => router.push(ROUTES.ADMIN_USER_DETAIL(user_id))} | ||
/> | ||
</MessageInlineEmojiRow> | ||
</Flex> | ||
<Flex | ||
position={"absolute"} | ||
gap="2" | ||
top="-2.5" | ||
style={{ | ||
insetInlineEnd: "1.25rem", | ||
}} | ||
> | ||
{index === 0 && ( | ||
<Tooltip label={"This is the original version of this message"} placement="top"> | ||
<Badge colorScheme={"blue"}>Original</Badge> | ||
</Tooltip> | ||
)} | ||
{user_is_author && ( | ||
<Tooltip label={t("message_author_explain")} placement="top"> | ||
<Badge size="sm" colorScheme="green" textTransform="capitalize"> | ||
{t("message_author")} | ||
</Badge> | ||
</Tooltip> | ||
)} | ||
</Flex> | ||
</BaseMessageEntry> | ||
))} | ||
</Stack> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { withAnyRole } from "src/lib/auth"; | ||
import { createApiClientFromUser } from "src/lib/oasst_client_factory"; | ||
import { getBackendUserCore } from "src/lib/users"; | ||
|
||
export default withAnyRole(["moderator", "admin"], async (req, res, token) => { | ||
const { id } = req.query; | ||
|
||
const user = await getBackendUserCore(token.sub); | ||
const client = createApiClientFromUser(user); | ||
|
||
const revision_history = await client.fetch_message_revision_history(id as string); | ||
res.status(200).json(revision_history); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters