diff --git a/package.json b/package.json index 3da5ed12..be6ce16a 100644 --- a/package.json +++ b/package.json @@ -147,7 +147,7 @@ "react-scroll": "^1.8.2", "react-virtualized-auto-sizer": "^1.0.5", "react-virtuoso": "^1.10.4", - "revolt.js": "6.0.0-rc.3", + "revolt.js": "6.0.0-rc.11", "rimraf": "^3.0.2", "sass": "^1.35.1", "shade-blend-color": "^1.0.0", diff --git a/src/components/common/messaging/MessageBox.tsx b/src/components/common/messaging/MessageBox.tsx index 4a64f4c7..53314b72 100644 --- a/src/components/common/messaging/MessageBox.tsx +++ b/src/components/common/messaging/MessageBox.tsx @@ -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(/\//); diff --git a/src/components/common/messaging/SystemMessage.tsx b/src/components/common/messaging/SystemMessage.tsx index e96fdd74..13db0366 100644 --- a/src/components/common/messaging/SystemMessage.tsx +++ b/src/components/common/messaging/SystemMessage.tsx @@ -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 = {data.content}; - break; case "user_added": case "user_remove": children = ( diff --git a/src/context/revoltjs/Notifications.tsx b/src/context/revoltjs/Notifications.tsx index 950a8041..48178c63 100644 --- a/src/context/revoltjs/Notifications.tsx +++ b/src/context/revoltjs/Notifications.tsx @@ -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, diff --git a/src/context/revoltjs/util.tsx b/src/context/revoltjs/util.tsx index c99924cb..625176f8 100644 --- a/src/context/revoltjs/util.tsx +++ b/src/context/revoltjs/util.tsx @@ -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( diff --git a/yarn.lock b/yarn.lock index f9aa2894..cab3f272 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1375,10 +1375,10 @@ resolved "https://registry.yarnpkg.com/@insertish/isomorphic-ws/-/isomorphic-ws-4.0.1.tgz#5bcd6f73b93efa9ccdb6abf887ae808d40827169" integrity sha512-kFD/p8T4Hkqr992QrdkbW/cQ/W/q2d9MPCobwzBv2PwTKLkCD9RaYDy6m17qRnSLQQ5PU0kHCG8kaOwAqzj1vQ== -"@insertish/oapi@0.1.13": - version "0.1.13" - resolved "https://registry.yarnpkg.com/@insertish/oapi/-/oapi-0.1.13.tgz#92579172bd6896152e9b68ef5bafcf8cc2048492" - integrity sha512-yj1Jk3VlNCjp0hNOsknevyR7PwVzSzc5pbUTuyhtyPlbuHRTv1b9DWs8Ki7xbF/mrIy2DzkHoUu4Ik/Q4oS93w== +"@insertish/oapi@0.1.15": + version "0.1.15" + resolved "https://registry.yarnpkg.com/@insertish/oapi/-/oapi-0.1.15.tgz#ee58b82d879ed5af54db846699941b8ad0262e7b" + integrity sha512-2G8eFxrojF651tBoRutQ8CJOw0u8UjYSlw/LQU+xycw5KpXslhWp/KSR86uIFyDIPddwfMCNA91vwHGCFRA63w== dependencies: typescript "^4.6.2" optionalDependencies: @@ -4364,19 +4364,19 @@ reusify@^1.0.4: resolved "https://registry.yarnpkg.com/reusify/-/reusify-1.0.4.tgz#90da382b1e126efc02146e90845a88db12925d76" integrity sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw== -revolt-api@0.5.3-rc.7: - version "0.5.3-rc.7" - resolved "https://registry.yarnpkg.com/revolt-api/-/revolt-api-0.5.3-rc.7.tgz#eed82fcd014a25a4d080c4502c0ae4aa283adddb" - integrity sha512-72SJ+P19nRRD+xE8bXAV8mFZNBgtKkXogQACDvNSIdATUmszYl91YRPqX+UQ1Oz4ePgKFwyWPxrnmfede7Q83g== +revolt-api@0.5.3-rc.13: + version "0.5.3-rc.13" + resolved "https://registry.yarnpkg.com/revolt-api/-/revolt-api-0.5.3-rc.13.tgz#df6e6f9ee595481f81779fc65a1b2edd9ced1db7" + integrity sha512-73W2MNj+/hucqhka2P3Q60OUFmL1Z374kMu8VEuldnE1H5GHiRjb1mkzoPVQDfS3TUzBG8StoSnSTF6dnRKJaA== dependencies: - "@insertish/oapi" "0.1.13" + "@insertish/oapi" "0.1.15" axios "^0.26.1" lodash.defaultsdeep "^4.6.1" -revolt.js@6.0.0-rc.3: - version "6.0.0-rc.3" - resolved "https://registry.yarnpkg.com/revolt.js/-/revolt.js-6.0.0-rc.3.tgz#0bf791eebf49b70c0baa2d2bd645c500c40ba737" - integrity sha512-b3jh/U80cWHJgjZxhyufCEspsWUOgKHPV+h3/1gWpt3fvpUWC2BPxDtJSVNXKe9AjQOpofpYaNQ8l9wlEfxA4A== +revolt.js@6.0.0-rc.11: + version "6.0.0-rc.11" + resolved "https://registry.yarnpkg.com/revolt.js/-/revolt.js-6.0.0-rc.11.tgz#0c3a13add396ce74aeab7c18e03a738df91abcdc" + integrity sha512-gw5pzbE55RAPISBFlao1e7qC/tNzPUBNQ4yg9IXwqfWSsDJAGd/xrDwpsaVnH2a52zgJWGsdNraIPniGHA/ImQ== dependencies: "@insertish/exponential-backoff" "3.1.0-patch.0" "@insertish/isomorphic-ws" "^4.0.1" @@ -4387,7 +4387,7 @@ revolt.js@6.0.0-rc.3: lodash.isequal "^4.5.0" long "^5.2.0" mobx "^6.3.2" - revolt-api "0.5.3-rc.7" + revolt-api "0.5.3-rc.13" ulid "^2.3.0" ws "^8.2.2"