Page MenuHomePhabricator

D11746.id39456.diff
No OneTemporary

D11746.id39456.diff

diff --git a/lib/shared/thread-utils.js b/lib/shared/thread-utils.js
--- a/lib/shared/thread-utils.js
+++ b/lib/shared/thread-utils.js
@@ -151,6 +151,28 @@
return permissionLookup(threadInfo.currentUser.permissions, permission);
}
+function useThreadHasPermission(
+ threadInfo: ?ThreadInfo,
+ permission: ThreadPermission,
+): boolean {
+ const loggedInUserInfo = useLoggedInUserInfo();
+ const userInfos = useSelector(state => state.userStore.userInfos);
+
+ if (!threadInfo) {
+ return false;
+ }
+
+ const permissions = threadFrozenDueToBlock(
+ threadInfo,
+ loggedInUserInfo?.id,
+ userInfos,
+ )
+ ? filterOutDisabledPermissions(threadInfo.currentUser.permissions)
+ : threadInfo.currentUser.permissions;
+
+ return hasPermission(permissions, permission);
+}
+
function viewerIsMember(
threadInfo: ?(ThreadInfo | LegacyRawThreadInfo | RawThreadInfo),
): boolean {
@@ -1850,6 +1872,7 @@
export {
threadHasPermission,
+ useThreadHasPermission,
viewerIsMember,
threadInChatList,
threadIsTopLevel,
diff --git a/web/tooltips/tooltip-action-utils.js b/web/tooltips/tooltip-action-utils.js
--- a/web/tooltips/tooltip-action-utils.js
+++ b/web/tooltips/tooltip-action-utils.js
@@ -14,8 +14,8 @@
import { createMessageReply } from 'lib/shared/message-utils.js';
import { useCanCreateReactionFromMessage } from 'lib/shared/reaction-utils.js';
import {
- threadHasPermission,
useSidebarExistsOrCanBeCreated,
+ useThreadHasPermission,
} from 'lib/shared/thread-utils.js';
import { messageTypes } from 'lib/types/message-types-enum.js';
import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js';
@@ -179,11 +179,12 @@
const inputState = React.useContext(InputStateContext);
invariant(inputState, 'inputState is required');
const { addReply } = inputState;
+ const currentUserIsVoiced = useThreadHasPermission(
+ threadInfo,
+ threadPermissions.VOICED,
+ );
return React.useMemo(() => {
- if (
- item.messageInfo.type !== messageTypes.TEXT ||
- !threadHasPermission(threadInfo, threadPermissions.VOICED)
- ) {
+ if (item.messageInfo.type !== messageTypes.TEXT || !currentUserIsVoiced) {
return null;
}
const buttonContent = <CommIcon icon="reply-filled" size={18} />;
@@ -200,7 +201,13 @@
onClick,
label: 'Reply',
};
- }, [popModal, addReply, item.messageInfo.type, messageInfo, threadInfo]);
+ }, [
+ popModal,
+ addReply,
+ item.messageInfo.type,
+ messageInfo,
+ currentUserIsVoiced,
+ ]);
}
const copiedMessageDurationMs = 2000;

File Metadata

Mime Type
text/plain
Expires
Sat, Dec 28, 7:30 PM (7 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2728273
Default Alt Text
D11746.id39456.diff (2 KB)

Event Timeline