diff --git a/external/lang b/external/lang index d2175617..0dc9e46b 160000 --- a/external/lang +++ b/external/lang @@ -1 +1 @@ -Subproject commit d217561756c7f397f177e43911c247497107c515 +Subproject commit 0dc9e46b376621b8af99784a7134fb8648cc3701 diff --git a/package.json b/package.json index 4c732d7d..d22d5150 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,7 @@ "react-router-dom": "^5.2.0", "react-scroll": "^1.8.2", "redux": "^4.1.0", - "revolt.js": "4.3.3-alpha.2", + "revolt.js": "4.3.3-alpha.4", "rimraf": "^3.0.2", "sass": "^1.35.1", "shade-blend-color": "^1.0.0", diff --git a/src/context/revoltjs/events.ts b/src/context/revoltjs/events.ts index 21472bdd..806ddcef 100644 --- a/src/context/revoltjs/events.ts +++ b/src/context/revoltjs/events.ts @@ -112,6 +112,7 @@ export function registerEvents({ client.users.addListener('mutation', logMutation); client.servers.addListener('mutation', logMutation); client.channels.addListener('mutation', logMutation); + client.servers.members.addListener('mutation', logMutation); } const online = () => { @@ -142,6 +143,7 @@ export function registerEvents({ client.users.removeListener('mutation', logMutation); client.servers.removeListener('mutation', logMutation); client.channels.removeListener('mutation', logMutation); + client.servers.members.removeListener('mutation', logMutation); } window.removeEventListener("online", online); diff --git a/src/context/revoltjs/hooks.ts b/src/context/revoltjs/hooks.ts index 987a9d53..f57038bb 100644 --- a/src/context/revoltjs/hooks.ts +++ b/src/context/revoltjs/hooks.ts @@ -117,10 +117,29 @@ export function useUserPermission(id: string, context?: HookContext) { export function useChannelPermission(id: string, context?: HookContext) { const ctx = useForceUpdate(context); + const channel = ctx.client.channels.get(id); + const server = (channel && (channel.channel_type === 'TextChannel' || channel.channel_type === 'VoiceChannel')) ? channel.server : undefined; + const mutation = (target: string) => (target === id) && ctx.forceUpdate(); + const mutationServer = (target: string) => (target === server) && ctx.forceUpdate(); + const mutationMember = (target: string) => (target.substr(26) === ctx.client.user!._id) && ctx.forceUpdate(); + useEffect(() => { ctx.client.channels.addListener("update", mutation); - return () => ctx.client.channels.removeListener("update", mutation); + + if (server) { + ctx.client.servers.addListener("update", mutationServer); + ctx.client.servers.members.addListener("update", mutationMember); + } + + return () => { + ctx.client.channels.removeListener("update", mutation); + + if (server) { + ctx.client.servers.removeListener("update", mutationServer); + ctx.client.servers.members.removeListener("update", mutationMember); + } + } }, [id]); let calculator = new PermissionCalculator(ctx.client); @@ -131,9 +150,16 @@ export function useServerPermission(id: string, context?: HookContext) { const ctx = useForceUpdate(context); const mutation = (target: string) => (target === id) && ctx.forceUpdate(); + const mutationMember = (target: string) => (target.substr(26) === ctx.client.user!._id) && ctx.forceUpdate(); + useEffect(() => { ctx.client.servers.addListener("update", mutation); - return () => ctx.client.servers.removeListener("update", mutation); + ctx.client.servers.members.addListener("update", mutationMember); + + return () => { + ctx.client.servers.removeListener("update", mutation); + ctx.client.servers.members.removeListener("update", mutationMember); + } }, [id]); let calculator = new PermissionCalculator(ctx.client); diff --git a/yarn.lock b/yarn.lock index 3fb7ff58..b3a3e352 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3420,10 +3420,10 @@ reusify@^1.0.4: resolved "https://registry.yarnpkg.com/reusify/-/reusify-1.0.4.tgz#90da382b1e126efc02146e90845a88db12925d76" integrity sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw== -revolt.js@4.3.3-alpha.2: - version "4.3.3-alpha.2" - resolved "https://registry.yarnpkg.com/revolt.js/-/revolt.js-4.3.3-alpha.2.tgz#1fb876205d74712c45e5f022624ac8d176ab01a1" - integrity sha512-/irTDDtBj63yQtpBk1asnqCNacc+HQXcz0jBOBk1VaOeDsjE6lTO2tGue6wFAG76AL89z9bziQbHIa6cQmWIjg== +revolt.js@4.3.3-alpha.4: + version "4.3.3-alpha.4" + resolved "https://registry.yarnpkg.com/revolt.js/-/revolt.js-4.3.3-alpha.4.tgz#7d393c9016a9d89151b1c091f6b02bc193b3a553" + integrity sha512-d6SGjRKFDlWG5fEveaVf0DRGb8d0RW8iv1E0kEG0W3R138KdeWCK8zUU0H+ykUdd5OjS7ESBKaEcwSP2BXMRSA== dependencies: "@insertish/mutable" "1.1.0" axios "^0.19.2"