From df1b39256daa927e9ff7168572a0dd3e3672184d Mon Sep 17 00:00:00 2001 From: Paul Makles Date: Thu, 14 Jul 2022 15:06:37 +0100 Subject: [PATCH 1/2] feat: show message that user can't message another --- src/lib/ContextMenus.tsx | 28 ++++++++++++++++++++-------- src/styles/_context-menu.scss | 2 +- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/lib/ContextMenus.tsx b/src/lib/ContextMenus.tsx index 90e3869c..de991c21 100644 --- a/src/lib/ContextMenus.tsx +++ b/src/lib/ContextMenus.tsx @@ -628,14 +628,26 @@ export default function ContextMenus() { }); } - if ( - user._id !== userId && - userPermissions & UserPermission.SendMessage - ) { - generateAction({ - action: "message_user", - user, - }); + if (user._id !== userId) { + if (userPermissions & UserPermission.SendMessage) { + generateAction({ + action: "message_user", + user, + }); + } else { + elements.push( + + + + + , + ); + } } for (let i = 0; i < actions.length; i++) { diff --git a/src/styles/_context-menu.scss b/src/styles/_context-menu.scss index 6fb154bf..1c0cb384 100644 --- a/src/styles/_context-menu.scss +++ b/src/styles/_context-menu.scss @@ -1,5 +1,5 @@ .preact-context-menu .context-menu { - z-index: 10000; + z-index: 9998; min-width: 190px; font-weight: 500; padding: 6px 8px; From f3822b625d6b23e29557a409e5360c33e88177db Mon Sep 17 00:00:00 2001 From: Paul Makles Date: Thu, 14 Jul 2022 17:13:51 +0100 Subject: [PATCH 2/2] feat: make emoji picker close on select / interact elsewhere --- package.json | 2 +- .../common/messaging/MessageBox.tsx | 99 ++++++++++--------- yarn.lock | 10 +- 3 files changed, 61 insertions(+), 50 deletions(-) diff --git a/package.json b/package.json index ba735b78..25afb96b 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "@hcaptcha/react-hcaptcha": "^0.3.6", "@insertish/vite-plugin-babel-macros": "^1.0.5", "@preact/preset-vite": "^2.0.0", - "@revoltchat/ui": "1.0.76", + "@revoltchat/ui": "1.0.77", "@rollup/plugin-replace": "^2.4.2", "@styled-icons/boxicons-logos": "^10.38.0", "@styled-icons/boxicons-regular": "^10.38.0", diff --git a/src/components/common/messaging/MessageBox.tsx b/src/components/common/messaging/MessageBox.tsx index ec964227..093d03d2 100644 --- a/src/components/common/messaging/MessageBox.tsx +++ b/src/components/common/messaging/MessageBox.tsx @@ -143,56 +143,62 @@ const RE_SED = new RegExp("^s/([^])*/([^])*$"); // Tests for code block delimiters (``` at start of line) const RE_CODE_DELIMITER = new RegExp("^```", "gm"); -const HackAlertThisFileWillBeReplaced = observer(({ channel }: Props) => { - const renderEmoji = useMemo( - () => - memo(({ emoji }: { emoji: string }) => ( - - )), - [], - ); +const HackAlertThisFileWillBeReplaced = observer( + ({ channel, onClose }: Props & { onClose: () => void }) => { + const renderEmoji = useMemo( + () => + memo(({ emoji }: { emoji: string }) => ( + + )), + [], + ); - const emojis: Record = { - default: Object.keys(emojiDictionary), - }; + const emojis: Record = { + default: Object.keys(emojiDictionary).map((id) => ({ id })), + }; - // ! FIXME: also expose typing from component - const categories: any[] = []; + // ! FIXME: also expose typing from component + const categories: any[] = []; - for (const server of state.ordering.orderedServers) { - // ! FIXME: add a separate map on each server for emoji - const list = [...channel.client.emojis.values()] - .filter((emoji) => emoji.parent.id === server._id) - .map((x) => x._id); + for (const server of state.ordering.orderedServers) { + // ! FIXME: add a separate map on each server for emoji + const list = [...channel.client.emojis.values()] + .filter((emoji) => emoji.parent.id === server._id) + .map(({ _id, name }) => ({ id: _id, name })); - if (list.length > 0) { - emojis[server._id] = list; - categories.push({ - id: server._id, - name: server.name, - iconURL: server.generateIconURL({ max_side: 256 }), - }); + if (list.length > 0) { + emojis[server._id] = list; + categories.push({ + id: server._id, + name: server.name, + iconURL: server.generateIconURL({ max_side: 256 }), + }); + } } - } - categories.push({ - id: "default", - name: "Default", - emoji: "smiley", - }); + categories.push({ + id: "default", + name: "Default", + emoji: "smiley", + }); - return ( - { - const v = state.draft.get(channel._id); - state.draft.set(channel._id, `${v ? `${v} ` : ""}:${emoji}:`); - }} - /> - ); -}); + return ( + { + const v = state.draft.get(channel._id); + state.draft.set( + channel._id, + `${v ? `${v} ` : ""}:${emoji}:`, + ); + }} + onClose={onClose} + /> + ); + }, +); // ! FIXME: add to app config and load from app config export const CAN_UPLOAD_AT_ONCE = 5; @@ -209,6 +215,8 @@ export default observer(({ channel }: Props) => { const client = useClient(); const translate = useTranslation(); + const closePicker = useCallback(() => setPicker(false), []); + const renderer = getRenderer(channel); if (!channel.havePermission("SendMessage")) { @@ -559,7 +567,10 @@ export default observer(({ channel }: Props) => { /> {picker && ( - + )} diff --git a/yarn.lock b/yarn.lock index c433932b..799719ba 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2240,9 +2240,9 @@ __metadata: languageName: node linkType: hard -"@revoltchat/ui@npm:1.0.76": - version: 1.0.76 - resolution: "@revoltchat/ui@npm:1.0.76" +"@revoltchat/ui@npm:1.0.77": + version: 1.0.77 + resolution: "@revoltchat/ui@npm:1.0.77" dependencies: "@styled-icons/boxicons-logos": ^10.38.0 "@styled-icons/boxicons-regular": ^10.38.0 @@ -2256,7 +2256,7 @@ __metadata: react-virtuoso: ^2.12.0 peerDependencies: revolt.js: "*" - checksum: b4051c759bd2e350eaab0f28c4d27b8df391086d63d58db14edf0c557d19da6d1f95df20327682086db46c6348ab7c7a0e6c696829e16d18fd341e4fbc8cbaf2 + checksum: ac3cf9787ff11df2156db0e871e48072013d0827b14b5dbcb54e9fe7f8f97daa19325d0fda93ded7487c642df57d6aee998bbe0ccf20bb095b1027f247e47e64 languageName: node linkType: hard @@ -3626,7 +3626,7 @@ __metadata: "@hcaptcha/react-hcaptcha": ^0.3.6 "@insertish/vite-plugin-babel-macros": ^1.0.5 "@preact/preset-vite": ^2.0.0 - "@revoltchat/ui": 1.0.76 + "@revoltchat/ui": 1.0.77 "@rollup/plugin-replace": ^2.4.2 "@styled-icons/boxicons-logos": ^10.38.0 "@styled-icons/boxicons-regular": ^10.38.0