Merge branch 'frost' of https://github.com/Aevann1/rDrama into frost

master
Aevann1 2022-09-25 05:44:00 +02:00
commit 705d3d9e4b
5 changed files with 18 additions and 14 deletions

1
chat/global.d.ts vendored
View File

@ -9,6 +9,7 @@ declare interface IChatMessage {
hat: string; hat: string;
namecolor: string; namecolor: string;
text: string; text: string;
base_text_censored: string;
text_censored: string; text_censored: string;
text_html: string; text_html: string;
time: number; time: number;

View File

@ -1,6 +1,6 @@
{ {
"name": "chat", "name": "chat",
"version": "0.0.22", "version": "0.0.23",
"main": "./src/index.tsx", "main": "./src/index.tsx",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {

View File

@ -1,17 +1,14 @@
import React from "react"; import React from "react";
import { useChat, useRootContext } from "../../hooks"; import { useChat } from "../../hooks";
import { Username } from "./Username";
import "./QuotedMessage.css"; import "./QuotedMessage.css";
import { QuotedMessageLink } from "./QuotedMessageLink"; import { QuotedMessageLink } from "./QuotedMessageLink";
export function QuotedMessage() { export function QuotedMessage() {
const { quote, quoteMessage } = useChat(); const { quote, quoteMessage } = useChat();
const { censored } = useRootContext();
return ( return (
<div className="QuotedMessage"> <div className="QuotedMessage">
<QuotedMessageLink message={quote} /> <QuotedMessageLink message={quote} />
<button <button
type="button" type="button"
className="btn btn-secondary" className="btn btn-secondary"

View File

@ -1,4 +1,4 @@
import React, { useCallback } from "react"; import React, { useCallback, useMemo } from "react";
import { useRootContext } from "../../hooks"; import { useRootContext } from "../../hooks";
const SCROLL_TO_QUOTED_OVERFLOW = 250; const SCROLL_TO_QUOTED_OVERFLOW = 250;
@ -6,7 +6,7 @@ const QUOTED_MESSAGE_CONTEXTUAL_HIGHLIGHTING_DURATION = 2500;
const QUOTED_MESSAGE_CONTEXTUAL_SNIPPET_LENGTH = 30; const QUOTED_MESSAGE_CONTEXTUAL_SNIPPET_LENGTH = 30;
export function QuotedMessageLink({ message }: { message: IChatMessage }) { export function QuotedMessageLink({ message }: { message: IChatMessage }) {
const { themeColor } = useRootContext(); const { censored, themeColor } = useRootContext();
const handleLinkClick = useCallback(() => { const handleLinkClick = useCallback(() => {
const element = document.getElementById(message.id); const element = document.getElementById(message.id);
@ -27,17 +27,22 @@ export function QuotedMessageLink({ message }: { message: IChatMessage }) {
} }
} }
}, []); }, []);
const replyText = useMemo(() => {
const textToUse = censored ? message.base_text_censored || message.text : message.text;
const slicedText = textToUse.slice(
0,
QUOTED_MESSAGE_CONTEXTUAL_SNIPPET_LENGTH
);
return textToUse.length >= QUOTED_MESSAGE_CONTEXTUAL_SNIPPET_LENGTH
? `${slicedText}...`
: slicedText;
}, [message, censored]);
return ( return (
<a href="#" onClick={handleLinkClick}> <a href="#" onClick={handleLinkClick}>
Replying to @{message.username}:{" "} Replying to @{message.username}:{" "}
<em> <em>"{replyText}"</em>
"{message.text.slice(0, QUOTED_MESSAGE_CONTEXTUAL_SNIPPET_LENGTH)}
{message.text.length >= QUOTED_MESSAGE_CONTEXTUAL_SNIPPET_LENGTH
? "..."
: ""}
"
</em>
</a> </a>
); );
} }

View File

@ -69,6 +69,7 @@ def speak(data, v):
"namecolor": v.name_color, "namecolor": v.name_color,
"text": text, "text": text,
"text_html": text_html, "text_html": text_html,
"base_text_censored": censor_slurs(text, 'chat'),
"text_censored": censor_slurs(text_html, 'chat'), "text_censored": censor_slurs(text_html, 'chat'),
"time": int(time.time()), "time": int(time.time()),
} }