conversation list

This commit is contained in:
Abron
2025-03-06 13:18:06 +03:30
parent 20a9573440
commit 7143a46a6e
2 changed files with 29 additions and 11 deletions

View File

@@ -88,8 +88,12 @@ const Divider = styled.div`
export const MessageOverlayBar = observer( export const MessageOverlayBar = observer(
({ reactionsOpen, setReactionsOpen, message, queued }: Props) => { ({ reactionsOpen, setReactionsOpen, message, queued }: Props) => {
if (!message) {
return null;
}
const client = message.client; const client = message.client;
const isAuthor = message.author_id === client.user!._id; const isAuthor = message.author_id === client.user?._id;
const [copied, setCopied] = useState<"link" | "id">(null!); const [copied, setCopied] = useState<"link" | "id">(null!);
const [extraActions, setExtra] = useState(shiftKeyPressed); const [extraActions, setExtra] = useState(shiftKeyPressed);
@@ -147,17 +151,17 @@ export const MessageOverlayBar = observer(
</Tooltip> </Tooltip>
)} )}
{isAuthor || {isAuthor ||
(message.channel && (message.channel &&
message.channel.havePermission("ManageMessages")) ? ( message.channel.havePermission("ManageMessages")) ? (
<Tooltip content="Delete"> <Tooltip content="Delete">
<Entry <Entry
onClick={(e) => onClick={(e) =>
e.shiftKey e.shiftKey
? message.delete() ? message.delete()
: modalController.push({ : modalController.push({
type: "delete_message", type: "delete_message",
target: message, target: message,
}) })
}> }>
<Trash size={18} color={"var(--error)"} /> <Trash size={18} color={"var(--error)"} />
</Entry> </Entry>

View File

@@ -19,6 +19,7 @@ import Tooltip from "../../common/Tooltip";
import UserIcon from "../../common/user/UserIcon"; import UserIcon from "../../common/user/UserIcon";
import { Username } from "../../common/user/UserShort"; import { Username } from "../../common/user/UserShort";
import UserStatus from "../../common/user/UserStatus"; import UserStatus from "../../common/user/UserStatus";
import { useClient } from "../../../controllers/client/ClientController";
type CommonProps = Omit< type CommonProps = Omit<
JSX.HTMLAttributes<HTMLDivElement>, JSX.HTMLAttributes<HTMLDivElement>,
@@ -37,6 +38,15 @@ type UserProps = CommonProps & {
channel?: Channel; channel?: Channel;
}; };
// Helper function to convert mentions to usernames
function convertMentionsToUsernames(content: string, client: any): string {
const mentionRegex = /<@([A-z0-9]{26})>/g;
return content.replace(mentionRegex, (match, userId) => {
const user = client.users.get(userId);
return user ? `@${user.username}` : match;
});
}
// TODO: Gray out blocked names. // TODO: Gray out blocked names.
export const UserButton = observer((props: UserProps) => { export const UserButton = observer((props: UserProps) => {
const { const {
@@ -50,6 +60,8 @@ export const UserButton = observer((props: UserProps) => {
...divProps ...divProps
} = props; } = props;
const client = useClient();
return ( return (
<div <div
{...divProps} {...divProps}
@@ -81,8 +93,8 @@ export const UserButton = observer((props: UserProps) => {
{ {
<div className={styles.subText}> <div className={styles.subText}>
{typeof channel?.last_message?.content === "string" && {typeof channel?.last_message?.content === "string" &&
alert ? ( alert ? (
channel.last_message.content.slice(0, 32) convertMentionsToUsernames(channel.last_message.content, client).slice(0, 32)
) : ( ) : (
<UserStatus user={user} tooltip /> <UserStatus user={user} tooltip />
)} )}
@@ -140,6 +152,8 @@ export const ChannelButton = observer((props: ChannelProps) => {
...divProps ...divProps
} = props; } = props;
const client = useClient();
if (channel.channel_type === "SavedMessages") throw "Invalid channel type."; if (channel.channel_type === "SavedMessages") throw "Invalid channel type.";
if (channel.channel_type === "DirectMessage") { if (channel.channel_type === "DirectMessage") {
if (typeof user === "undefined") throw "No user provided."; if (typeof user === "undefined") throw "No user provided.";
@@ -170,9 +184,9 @@ export const ChannelButton = observer((props: ChannelProps) => {
{channel.channel_type === "Group" && ( {channel.channel_type === "Group" && (
<div className={styles.subText}> <div className={styles.subText}>
{typeof channel.last_message?.content === "string" && {typeof channel.last_message?.content === "string" &&
alert && alert &&
!muted ? ( !muted ? (
channel.last_message.content.slice(0, 32) convertMentionsToUsernames(channel.last_message.content, client).slice(0, 32)
) : ( ) : (
<Text <Text
id="quantities.members" id="quantities.members"