Skip to content

Commit f3b81ba

Browse files
authored
Merge pull request #50 from widgetbot-io/development
v2.2.0
2 parents 7552855 + f55f1ec commit f3b81ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1611
-176
lines changed

.storybook/preview.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const preview = {
1515
values: [
1616
{
1717
name: "discord-dark",
18-
value: "#424549",
18+
value: "#313338",
1919
},
2020
],
2121
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@widgetbot/message-renderer",
3-
"version": "v2.1.0",
3+
"version": "v2.2.0",
44
"description": "",
55
"module": "dist/message-renderer.mjs",
66
"files": [

src/ChatTag/index.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function isVerifiedBot(flags?: number) {
3030
}
3131

3232
interface TagProps {
33-
author: APIUser;
33+
author: APIUser | "automod";
3434
crossPost: boolean;
3535
referenceGuild: string | undefined;
3636
}
@@ -40,14 +40,18 @@ function ChatTag({ author, crossPost, referenceGuild }: TagProps) {
4040

4141
const { chatBadge: ChatBadge } = useConfig();
4242

43-
if (ChatBadge !== undefined) {
43+
if (author !== "automod" && ChatBadge !== undefined) {
4444
const chatBadgeResult = ChatBadge({ user: author, TagWrapper: Styles.Tag });
4545
if (chatBadgeResult !== null) return chatBadgeResult;
4646
}
4747

48-
if (!author.bot) return null;
48+
if (author !== "automod" && !author.bot) return null;
4949

50-
if (author.system || referenceGuild === "667560445975986187")
50+
if (
51+
author === "automod" ||
52+
author.system ||
53+
referenceGuild === "667560445975986187"
54+
)
5155
return (
5256
<Styles.Tag className="verified system">
5357
{verified} {t("chatTag.system")}

src/Content/index.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, { Children, memo, useMemo } from "react";
33
import Moment from "moment/moment";
44
import Message from "../Message";
55
import * as Styles from "./style";
6-
import type { APIEmbedImage, APIMessage } from "discord-api-types/v10";
6+
import type { APIEmbedImage } from "discord-api-types/v10";
77
import { MessageFlags } from "discord-api-types/v10";
88
import Tooltip from "../Tooltip";
99
import SvgFromUrl from "../SvgFromUrl";
@@ -16,6 +16,7 @@ import ThreadButton from "./Thread/ThreadButton";
1616
import Components from "../Message/Components";
1717
import getDisplayName from "../utils/getDisplayName";
1818
import { useTranslation } from "react-i18next";
19+
import type { ChatMessage } from "../types";
1920

2021
interface EditedProps {
2122
editedAt: string;
@@ -57,7 +58,10 @@ interface MessageAccessoriesProps {
5758
children?: ReactNode;
5859
}
5960

60-
function MessageAccessories({ children, active }: MessageAccessoriesProps) {
61+
export function MessageAccessories({
62+
children,
63+
active,
64+
}: MessageAccessoriesProps) {
6165
if (!active || !children || Children.count(children) === 0) return <></>;
6266

6367
return <Styles.MessageAccessories>{children}</Styles.MessageAccessories>;
@@ -66,7 +70,7 @@ function MessageAccessories({ children, active }: MessageAccessoriesProps) {
6670
interface ContentCoreProps {
6771
children: ReactNode;
6872
showTooltip: boolean;
69-
referencedMessage: APIMessage | null;
73+
referencedMessage: ChatMessage | null;
7074
}
7175

7276
function ContentCore(props: ContentCoreProps) {
@@ -94,7 +98,7 @@ function ContentCore(props: ContentCoreProps) {
9498
}
9599

96100
interface ContentProps {
97-
message: APIMessage;
101+
message: ChatMessage;
98102
isReplyContent?: boolean;
99103
noThreadButton?: boolean;
100104
}
@@ -197,12 +201,18 @@ function Content(props: ContentProps) {
197201

198202
return (
199203
<>
200-
<Styles.Base isReplyContent={props.isReplyContent}>
204+
<Styles.MessageContent
205+
isReplyContent={props.isReplyContent}
206+
isOptimistic={props.message.optimistic}
207+
>
201208
<ContentCore
202209
referencedMessage={props.message}
203210
showTooltip={props.isReplyContent ?? false}
204211
>
205-
<Styles.ContentContainer isReplyContent={props.isReplyContent}>
212+
<Styles.ContentContainer
213+
isReplyContent={props.isReplyContent}
214+
didFailToSend={props.message.failedToSend}
215+
>
206216
{props.message.content.length > 0 ? (
207217
<>
208218
{props.message.webhook_id !== undefined ? (
@@ -226,7 +236,7 @@ function Content(props: ContentProps) {
226236
</Styles.ContentContainer>
227237
</ContentCore>
228238
{props.isReplyContent && <ReplyIcon message={props.message} />}
229-
</Styles.Base>
239+
</Styles.MessageContent>
230240
{!props.isReplyContent && (
231241
<MessageAccessories
232242
active={

src/Content/style.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@ import { CodeBlock } from "../markdown/render/elements/code/style";
88
import SvgFromUrl from "../SvgFromUrl";
99
import { Heading } from "../markdown/render/elements";
1010

11-
export const Base = styled.withConfig({
11+
export const MessageContent = styled.withConfig({
1212
displayName: "message-content",
1313
componentId: commonComponentId,
1414
})("span", {
1515
color: theme.colors.primaryOpacity20,
1616
whiteSpace: "break-spaces",
1717
fontSize: theme.fontSizes.l,
1818
variants: {
19+
isOptimistic: {
20+
true: {
21+
opacity: 0.5,
22+
},
23+
},
1924
isReplyContent: {
2025
true: {
2126
fontSize: theme.fontSizes.m,
@@ -57,6 +62,11 @@ export const ContentContainer = styled.withConfig({
5762
lineHeight: "1.375rem",
5863

5964
variants: {
65+
didFailToSend: {
66+
true: {
67+
color: theme.colors.danger,
68+
},
69+
},
6070
isReplyContent: {
6171
true: {
6272
overflow: "hidden",

src/Message/Components/ActionRow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import type {
22
APIActionRowComponent,
3-
APIMessage,
43
APIMessageActionRowComponent,
54
} from "discord-api-types/v10";
65
import * as Styles from "./style";
76
import React from "react";
87
import Component from "./Component";
8+
import type { ChatMessage } from "../../types";
99

1010
interface ActionRowProps {
1111
actionRow: APIActionRowComponent<APIMessageActionRowComponent>;
12-
message: APIMessage;
12+
message: ChatMessage;
1313
}
1414

1515
function ActionRow({ actionRow, message }: ActionRowProps) {

src/Message/Components/ButtonComponent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type {
22
APIButtonComponentWithCustomId,
33
APIButtonComponentWithURL,
4-
APIMessage,
54
} from "discord-api-types/v10";
65
import * as Styles from "./style";
76
import type { ComponentProps } from "react";
@@ -11,6 +10,7 @@ import { ButtonStyle } from "discord-api-types/v10";
1110
import Emoji from "../../Emoji";
1211
import { useConfig } from "../../core/ConfigContext";
1312
import ExternalLink from "../../ExternalLink";
13+
import type { ChatMessage } from "../../types";
1414

1515
const buttonStyleMap: Record<
1616
ButtonStyle,
@@ -33,7 +33,7 @@ type ButtonComponentWithURL = APIButtonComponentWithURL & {
3333

3434
interface ButtonComponentProps {
3535
button: ButtonComponentWithCustomId | ButtonComponentWithURL;
36-
message: APIMessage;
36+
message: ChatMessage;
3737
}
3838

3939
function ButtonComponent({ button, message }: ButtonComponentProps) {

src/Message/Components/Component.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import type {
2-
APIMessage,
3-
APIMessageActionRowComponent,
4-
} from "discord-api-types/v10";
1+
import type { APIMessageActionRowComponent } from "discord-api-types/v10";
52
import { ComponentType } from "discord-api-types/v10";
63
import ButtonComponent from "./ButtonComponent";
74
import React from "react";
5+
import type { ChatMessage } from "../../types";
86

97
interface ComponentProps {
108
component: APIMessageActionRowComponent;
11-
message: APIMessage;
9+
message: ChatMessage;
1210
}
1311

1412
function Component({ component, message }: ComponentProps) {

src/Message/Components/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import type { APIMessage } from "discord-api-types/v10";
21
import ActionRow from "./ActionRow";
32
import React from "react";
43
import * as Styles from "./style";
4+
import type { ChatMessage } from "../../types";
55

66
interface ComponentsProps {
7-
components: APIMessage["components"];
8-
message: APIMessage;
7+
components: ChatMessage["components"];
8+
message: ChatMessage;
99
}
1010

1111
function Components({ components, message }: ComponentsProps) {

src/Message/MessageAuthor.tsx

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,33 @@ import * as Styles from "./style/author";
88
import type { APIRole, APIUser, Snowflake } from "discord-api-types/v10";
99
import { useConfig } from "../core/ConfigContext";
1010
import getDisplayName from "../utils/getDisplayName";
11+
import { useTranslation } from "react-i18next";
12+
13+
interface AutomodAuthorProps {
14+
isAvatarAnimated?: boolean;
15+
}
16+
17+
export function AutomodAuthor({ isAvatarAnimated }: AutomodAuthorProps) {
18+
const {
19+
automodAvatar: { still: avatarStill, animated: avatarAnimated },
20+
} = useConfig();
21+
const { t } = useTranslation();
22+
23+
const automodAvatar = isAvatarAnimated ? avatarAnimated : avatarStill;
24+
25+
return (
26+
<Styles.MessageAuthor>
27+
<Styles.Avatar data={automodAvatar} draggable={false} type="image/png" />
28+
<Styles.Username automod>{t("AutomodAction.username")}</Styles.Username>
29+
<ChatTag author="automod" crossPost={false} referenceGuild={undefined} />
30+
</Styles.MessageAuthor>
31+
);
32+
}
1133

1234
interface MessageAuthorProps
1335
extends ComponentProps<typeof Styles.MessageAuthor> {
1436
author: APIUser;
15-
avatarAnimated?: boolean;
37+
isAvatarAnimated?: boolean;
1638
onlyShowUsername?: boolean;
1739
crossPost?: boolean;
1840
referenceGuild?: Snowflake;
@@ -22,7 +44,6 @@ interface MessageAuthorProps
2244
function MessageAuthor({
2345
onlyShowUsername,
2446
author,
25-
avatarAnimated,
2647
crossPost,
2748
referenceGuild,
2849
guildId,
@@ -33,11 +54,8 @@ function MessageAuthor({
3354
const member = guildId ? resolveMember(author, guildId) : null;
3455
const isGuildMember = member !== null;
3556

36-
const avatarUrl =
37-
avatarUrlOverride?.(author) ??
38-
getAvatar(author, {
39-
animated: avatarAnimated ?? false,
40-
});
57+
const { stillAvatarUrl, animatedAvatarUrl } =
58+
avatarUrlOverride?.(author) ?? getAvatar(author);
4159

4260
const displayName = isGuildMember
4361
? member.nick ?? getDisplayName(author)
@@ -98,15 +116,40 @@ function MessageAuthor({
98116
{...props}
99117
onClick={() => userOnClick?.(author)}
100118
>
101-
<Styles.Avatar data={avatarUrl} draggable={false} type="image/png">
102-
<Styles.AvatarFallback
103-
src={getAvatar(author, {
104-
animated: false,
105-
forceDefault: true,
106-
})}
107-
alt="avatar"
108-
/>
109-
</Styles.Avatar>
119+
<Styles.AnimatedAvatarTrigger
120+
data-is-animated={animatedAvatarUrl !== undefined}
121+
>
122+
<Styles.StillAvatar
123+
data={stillAvatarUrl}
124+
draggable={false}
125+
type="image/png"
126+
>
127+
<Styles.AvatarFallback
128+
src={
129+
getAvatar(author, {
130+
forceDefault: true,
131+
}).stillAvatarUrl
132+
}
133+
alt="avatar"
134+
/>
135+
</Styles.StillAvatar>
136+
{animatedAvatarUrl && (
137+
<Styles.AnimatedAvatar
138+
data={animatedAvatarUrl}
139+
draggable={false}
140+
type="image/gif"
141+
>
142+
<Styles.AvatarFallback
143+
src={
144+
getAvatar(author, {
145+
forceDefault: true,
146+
}).stillAvatarUrl
147+
}
148+
alt="avatar"
149+
/>
150+
</Styles.AnimatedAvatar>
151+
)}
152+
</Styles.AnimatedAvatarTrigger>
110153
<Styles.Username style={{ color: dominantRoleColor }}>
111154
{displayName}
112155
</Styles.Username>

0 commit comments

Comments
 (0)