From bb6ac68c8ec6c76e0898af82453f2feea8461738 Mon Sep 17 00:00:00 2001 From: Paul Date: Sat, 7 Aug 2021 10:32:18 +0100 Subject: [PATCH] Clean up system message code. Fixes #3 --- package.json | 2 +- .../common/messaging/SystemMessage.tsx | 67 ++----------------- yarn.lock | 8 +-- 3 files changed, 9 insertions(+), 68 deletions(-) diff --git a/package.json b/package.json index b3b8f789..937c6046 100644 --- a/package.json +++ b/package.json @@ -113,7 +113,7 @@ "react-scroll": "^1.8.2", "redux": "^4.1.0", "revolt-api": "0.5.1-alpha.10-patch.0", - "revolt.js": "5.0.0-alpha.18-patch.0", + "revolt.js": "5.0.0-alpha.19", "rimraf": "^3.0.2", "sass": "^1.35.1", "shade-blend-color": "^1.0.0", diff --git a/src/components/common/messaging/SystemMessage.tsx b/src/components/common/messaging/SystemMessage.tsx index 6912fc84..d027b055 100644 --- a/src/components/common/messaging/SystemMessage.tsx +++ b/src/components/common/messaging/SystemMessage.tsx @@ -11,16 +11,14 @@ import { MessageSquareEdit, } from "@styled-icons/boxicons-solid"; import { observer } from "mobx-react-lite"; +import { SystemMessage as SystemMessageI } from "revolt-api/types/Channels"; import { Message } from "revolt.js/dist/maps/Messages"; -import { User } from "revolt.js/dist/maps/Users"; import styled from "styled-components"; import { attachContextMenu } from "preact-context-menu"; import { TextReact } from "../../../lib/i18n"; -import { useClient } from "../../../context/revoltjs/RevoltClient"; - import UserShort from "../user/UserShort"; import MessageBase, { MessageDetail, MessageInfo } from "./MessageBase"; @@ -33,18 +31,6 @@ const SystemContent = styled.div` flex-direction: row; `; -type SystemMessageParsed = - | { type: "text"; content: string } - | { type: "user_added"; user: User; by: User } - | { type: "user_remove"; user: User; by: User } - | { type: "user_joined"; user: User } - | { type: "user_left"; user: User } - | { type: "user_kicked"; user: User } - | { type: "user_banned"; user: User } - | { type: "channel_renamed"; name: string; by: User } - | { type: "channel_description_changed"; by: User } - | { type: "channel_icon_changed"; by: User }; - interface Props { attachContext?: boolean; message: Message; @@ -67,54 +53,9 @@ const iconDictionary = { export const SystemMessage = observer( ({ attachContext, message, highlight, hideInfo }: Props) => { - const client = useClient(); - - let data: SystemMessageParsed; - const content = message.content; - if (typeof content === "object") { - switch (content.type) { - case "text": - data = content; - break; - case "user_added": - case "user_remove": - data = { - type: content.type, - user: client.users.get(content.id)!, - by: client.users.get(content.by)!, - }; - break; - case "user_joined": - case "user_left": - case "user_kicked": - case "user_banned": - data = { - type: content.type, - user: client.users.get(content.id)!, - }; - break; - case "channel_renamed": - data = { - type: "channel_renamed", - name: content.name, - by: client.users.get(content.by)!, - }; - break; - case "channel_description_changed": - case "channel_icon_changed": - data = { - type: content.type, - by: client.users.get(content.by)!, - }; - break; - default: - data = { type: "text", content: JSON.stringify(content) }; - } - } else { - data = { type: "text", content }; - } - - const SystemMessageIcon = iconDictionary[data.type] ?? InfoCircle; + const data = message.asSystemMessage; + const SystemMessageIcon = + iconDictionary[data.type as SystemMessageI["type"]] ?? InfoCircle; const SystemIcon = styled(SystemMessageIcon)` height: 1.33em; diff --git a/yarn.lock b/yarn.lock index 0c6cf548..90c3b743 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3572,10 +3572,10 @@ revolt-api@0.5.1-alpha.10-patch.0: resolved "https://registry.yarnpkg.com/revolt-api/-/revolt-api-0.5.1-alpha.10-patch.0.tgz#97d31bec7dfa4573567097443acb059c4feaac20" integrity sha512-UyM890HkGlYNQOxpHuEpUsJHLt8Ujnjg9/zPEDGpbvS4iy0jmHX23Hh8tOCfb/ewxbNrtT3G1HpSWKOneW/vYg== -revolt.js@5.0.0-alpha.18-patch.0: - version "5.0.0-alpha.18-patch.0" - resolved "https://registry.yarnpkg.com/revolt.js/-/revolt.js-5.0.0-alpha.18-patch.0.tgz#38ac237bac9f4b935a456bc276eaed2d471b6023" - integrity sha512-D4M3cYbF/MRDd3rVcWJ9DSQctecRnc/0QltFjgr9XhkFHkVkCn32CDUnklMgQdh1uE8C8t7jaJsCV5DdalxUXg== +revolt.js@5.0.0-alpha.19: + version "5.0.0-alpha.19" + resolved "https://registry.yarnpkg.com/revolt.js/-/revolt.js-5.0.0-alpha.19.tgz#51f75d02d173e6f6de1b10fae22ba31a99785f76" + integrity sha512-D4HWszUozO4ss252GZw1k0m8p2yjnFtzAARUGo2bJsBYlC00l61hg2xsAvXcemfFParh9x6hAK9xq7olcAt6KA== dependencies: axios "^0.19.2" eventemitter3 "^4.0.7"