From 305243ab43aa2779c8460ef84dcc50785dc67146 Mon Sep 17 00:00:00 2001
From: Paul <paulmakles@gmail.com>
Date: Sat, 31 Jul 2021 10:05:59 +0100
Subject: [PATCH] Fix server id not being replaced properly. Fix links in
 spoilers opening when revealing. Fix unread icon appearing for home. Fix
 unreads not being acknowledged.

---
 external/lang                                  |  2 +-
 package.json                                   |  2 +-
 src/components/markdown/Markdown.module.scss   |  2 ++
 src/components/markdown/Renderer.tsx           | 18 +++++++-----------
 .../navigation/left/ServerListSidebar.tsx      |  2 +-
 src/components/navigation/left/common.ts       | 13 +++++++------
 yarn.lock                                      |  8 ++++----
 7 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/external/lang b/external/lang
index f3c9912..eb880a9 160000
--- a/external/lang
+++ b/external/lang
@@ -1 +1 @@
-Subproject commit f3c991242044c0125111e533a94350633a681d62
+Subproject commit eb880a90254df406b25caf6b969ed3aee3142f6c
diff --git a/package.json b/package.json
index 6c92c72..406bd01 100644
--- a/package.json
+++ b/package.json
@@ -97,7 +97,7 @@
     "react-router-dom": "^5.2.0",
     "react-scroll": "^1.8.2",
     "redux": "^4.1.0",
-    "revolt.js": "5.0.0-alpha.10",
+    "revolt.js": "5.0.0-alpha.11",
     "rimraf": "^3.0.2",
     "sass": "^1.35.1",
     "shade-blend-color": "^1.0.0",
diff --git a/src/components/markdown/Markdown.module.scss b/src/components/markdown/Markdown.module.scss
index de057a5..eb0113c 100644
--- a/src/components/markdown/Markdown.module.scss
+++ b/src/components/markdown/Markdown.module.scss
@@ -118,6 +118,7 @@
 
         > * {
             opacity: 0;
+            pointer-events: none;
         }
 
         &:global(.shown) {
@@ -128,6 +129,7 @@
 
             > * {
                 opacity: 1;
+                pointer-events: unset;
             }
         }
     }
diff --git a/src/components/markdown/Renderer.tsx b/src/components/markdown/Renderer.tsx
index cbbd188..c7283ab 100644
--- a/src/components/markdown/Renderer.tsx
+++ b/src/components/markdown/Renderer.tsx
@@ -92,9 +92,8 @@ export default function Renderer({ content, disallowBigEmoji }: MarkdownProps) {
 
     // We replace the message with the mention at the time of render.
     // We don't care if the mention changes.
-    const newContent = content.replace(
-        RE_MENTIONS,
-        (sub: string, ...args: any[]) => {
+    const newContent = content
+        .replace(RE_MENTIONS, (sub: string, ...args: any[]) => {
             const id = args[0],
                 user = client.users.get(id);
 
@@ -103,20 +102,17 @@ export default function Renderer({ content, disallowBigEmoji }: MarkdownProps) {
             }
 
             return sub;
-        },
-    ).replace(
-        RE_CHANNELS,
-        (sub: string, ...args: any[]) => {
+        })
+        .replace(RE_CHANNELS, (sub: string, ...args: any[]) => {
             const id = args[0],
                 channel = client.channels.get(id);
 
-            if (channel?.channel_type === 'TextChannel') {
-                return `[#${channel.name}](/server/${channel.server}/channel/${id})`;
+            if (channel?.channel_type === "TextChannel") {
+                return `[#${channel.name}](/server/${channel.server_id}/channel/${id})`;
             }
 
             return sub;
-        },
-    );
+        });
 
     const useLargeEmojis = disallowBigEmoji
         ? false
diff --git a/src/components/navigation/left/ServerListSidebar.tsx b/src/components/navigation/left/ServerListSidebar.tsx
index a00897e..53ea0e1 100644
--- a/src/components/navigation/left/ServerListSidebar.tsx
+++ b/src/components/navigation/left/ServerListSidebar.tsx
@@ -218,7 +218,7 @@ export const ServerListSidebar = observer(({ unreads, lastOpened }: Props) => {
         if (
             (x.channel?.channel_type === "DirectMessage"
                 ? x.channel?.active
-                : true) &&
+                : x.channel?.channel_type === "Group") &&
             x.unread
         ) {
             homeUnread = "unread";
diff --git a/src/components/navigation/left/common.ts b/src/components/navigation/left/common.ts
index 4f085d8..1416b63 100644
--- a/src/components/navigation/left/common.ts
+++ b/src/components/navigation/left/common.ts
@@ -1,4 +1,4 @@
-import { autorun } from "mobx";
+import { autorun, isObservableProp, reaction } from "mobx";
 import { Channel } from "revolt.js/dist/maps/Channels";
 
 import { useLayoutEffect } from "preact/hooks";
@@ -17,10 +17,7 @@ export function useUnreads({ channel, unreads }: UnreadProps) {
     const client = useClient();
 
     useLayoutEffect(() => {
-        function checkUnread(
-            target: Channel,
-            last_message: Channel["last_message"],
-        ) {
+        function checkUnread(target: Channel) {
             if (!target) return;
             if (target._id !== channel._id) return;
             if (
@@ -50,7 +47,11 @@ export function useUnreads({ channel, unreads }: UnreadProps) {
             }
         }
 
-        return autorun(() => checkUnread(channel!, channel!.last_message));
+        checkUnread(channel);
+        return reaction(
+            () => channel.last_message,
+            () => checkUnread(channel),
+        );
     }, [channel, unreads]);
 }
 
diff --git a/yarn.lock b/yarn.lock
index 4b36651..8044269 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3570,10 +3570,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.10:
-  version "5.0.0-alpha.10"
-  resolved "https://registry.yarnpkg.com/revolt.js/-/revolt.js-5.0.0-alpha.10.tgz#3fa1a8944a338134da09626278ee47b91f20ce2a"
-  integrity sha512-b5nCQDtLUei4mfXhZNkIfQiyG8WDHBnpOVRaRaJz2ZjcQtdBjxIPXxOWkBYL7N/dBJ7sn5xgLMqra9UzkwkewA==
+revolt.js@5.0.0-alpha.11:
+  version "5.0.0-alpha.11"
+  resolved "https://registry.yarnpkg.com/revolt.js/-/revolt.js-5.0.0-alpha.11.tgz#af131150ce37a39b979501c730ec2bee5a4e38a1"
+  integrity sha512-aOD8IV2DM9Ebq15FVQ2GJDGBaICppk+jP06dW0KlrDeVoE3Hra5CRLHSIRtp2mJN/vh1cH+9eA78jssAlAgwAw==
   dependencies:
     axios "^0.19.2"
     eventemitter3 "^4.0.7"
-- 
GitLab