chore: split content into content, system

This commit is contained in:
Paul Makles
2022-04-21 17:46:14 +01:00
parent 231f0cf3f8
commit 0a8e8c9c08
6 changed files with 46 additions and 48 deletions

View File

@@ -228,7 +228,7 @@ export default observer(({ channel }: Props) => {
);
renderer.messages.reverse();
if (msg) {
if (msg?.content) {
// eslint-disable-next-line prefer-const
let [_, toReplace, newText, flags] = content.split(/\//);

View File

@@ -77,11 +77,8 @@ export const SystemMessage = observer(
iconDictionary[data.type as API.SystemMessage["type"]] ??
InfoCircle;
let children;
let children = null;
switch (data.type) {
case "text":
children = <span>{data.content}</span>;
break;
case "user_added":
case "user_remove":
children = (

View File

@@ -82,7 +82,7 @@ function Notifier() {
}
let body, icon;
if (typeof msg.content === "string") {
if (msg.content) {
body = client.markdownToText(msg.content);
if (msg.masquerade?.avatar) {
@@ -90,22 +90,23 @@ function Notifier() {
} else {
icon = msg.author?.generateAvatarURL({ max_side: 256 });
}
} else {
} else if (msg.system) {
const users = client.users;
switch (msg.content.type) {
switch (msg.system.type) {
case "user_added":
case "user_remove":
{
const user = users.get(msg.content.id);
const user = users.get(msg.system.id);
body = translate(
`app.main.channel.system.${
msg.content.type === "user_added"
msg.system.type === "user_added"
? "added_by"
: "removed_by"
}`,
{
user: user?.username,
other_user: users.get(msg.content.by)
other_user: users.get(msg.system.by)
?.username,
},
);
@@ -119,9 +120,9 @@ function Notifier() {
case "user_kicked":
case "user_banned":
{
const user = users.get(msg.content.id);
const user = users.get(msg.system.id);
body = translate(
`app.main.channel.system.${msg.content.type}`,
`app.main.channel.system.${msg.system.type}`,
{ user: user?.username },
);
icon = user?.generateAvatarURL({
@@ -131,12 +132,12 @@ function Notifier() {
break;
case "channel_renamed":
{
const user = users.get(msg.content.by);
const user = users.get(msg.system.by);
body = translate(
`app.main.channel.system.channel_renamed`,
{
user: users.get(msg.content.by)?.username,
name: msg.content.name,
user: users.get(msg.system.by)?.username,
name: msg.system.name,
},
);
icon = user?.generateAvatarURL({
@@ -147,10 +148,10 @@ function Notifier() {
case "channel_description_changed":
case "channel_icon_changed":
{
const user = users.get(msg.content.by);
const user = users.get(msg.system.by);
body = translate(
`app.main.channel.system.${msg.content.type}`,
{ user: users.get(msg.content.by)?.username },
`app.main.channel.system.${msg.system.type}`,
{ user: users.get(msg.system.by)?.username },
);
icon = user?.generateAvatarURL({
max_side: 256,

View File

@@ -6,23 +6,23 @@ import { Children } from "../../types/Preact";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function takeError(error: any): string {
const type = error?.response?.data?.type;
const id = type;
if (!type) {
if (
error?.response?.status === 401 ||
error?.response?.status === 403
) {
return "Unauthorized";
} else if (error && !!error.isAxiosError && !error.response) {
return "NetworkError";
if (error.response) {
const status = error.response.status;
switch (status) {
case 429:
return "TooManyRequests";
case 401:
case 403:
return "Unauthorized";
default:
return error.response.type ?? "UnknownError";
}
console.error(error);
return "UnknownError";
} else if (error.request) {
return "NetworkError";
}
return id;
console.error(error);
return "UnknownError";
}
export function getChannelName(