Skip to content

Commit

Permalink
[web][native] fix relationship buttons in thread settings
Browse files Browse the repository at this point in the history
Summary:
[ENG-9320](https://linear.app/comm/issue/ENG-9320/relationship-menu-is-available-on-web-in-sidebars).

1. Fixing rendering relationship tab on web condition.
2. Updating check on native to support thick threads.

Test Plan: Buttons visible only on personal threads.

Reviewers: tomek, ashoat

Reviewed By: tomek

Differential Revision: https://phab.comm.dev/D13449
  • Loading branch information
xsanm committed Sep 25, 2024
1 parent 57b94fa commit d788f39
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
9 changes: 9 additions & 0 deletions lib/types/thread-types-enum.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ export const sidebarThreadTypes: $ReadOnlyArray<number> = Object.freeze([
threadTypes.THICK_SIDEBAR,
]);

export const personalThreadTypes: $ReadOnlyArray<number> = Object.freeze([
threadTypes.PERSONAL,
threadTypes.GENESIS_PERSONAL,
]);

export function threadTypeIsCommunityRoot(threadType: ThreadType): boolean {
return communityThreadTypes.includes(threadType);
}
Expand All @@ -174,3 +179,7 @@ export function threadTypeIsAnnouncementThread(
export function threadTypeIsSidebar(threadType: ThreadType): boolean {
return sidebarThreadTypes.includes(threadType);
}

export function threadTypeIsPersonal(threadType: ThreadType): boolean {
return personalThreadTypes.includes(threadType);
}
6 changes: 2 additions & 4 deletions native/chat/settings/thread-settings.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ import type {
import type { RelationshipButton } from 'lib/types/relationship-types.js';
import { threadPermissions } from 'lib/types/thread-permission-types.js';
import {
threadTypes,
threadTypeIsSidebar,
threadTypeIsThick,
threadTypeIsPersonal,
} from 'lib/types/thread-types-enum.js';
import type { UserInfos } from 'lib/types/user-types.js';
import {
Expand Down Expand Up @@ -768,9 +768,7 @@ class ThreadSettings extends React.PureComponent<Props, State> {
});
}

const threadIsPersonal =
threadInfo.type === threadTypes.GENESIS_PERSONAL;
if (threadIsPersonal && viewerID) {
if (threadInfo && threadTypeIsPersonal(threadInfo.type) && viewerID) {
const otherMemberID = getSingleOtherUser(threadInfo, viewerID);
if (otherMemberID) {
const otherUserInfo = userInfos[otherMemberID];
Expand Down
13 changes: 10 additions & 3 deletions web/modals/threads/settings/thread-settings-modal.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import {
import type { ThreadInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js';
import type { RelationshipButton } from 'lib/types/relationship-types.js';
import { threadPermissions } from 'lib/types/thread-permission-types.js';
import { threadTypes } from 'lib/types/thread-types-enum.js';
import {
threadTypeIsPersonal,
threadTypes,
} from 'lib/types/thread-types-enum.js';
import { type ThreadChanges } from 'lib/types/thread-types.js';
import { useResolvedThreadInfo } from 'lib/utils/entity-helpers.js';

Expand Down Expand Up @@ -91,11 +94,15 @@ const ConnectedThreadSettingsModal: React.ComponentType<BaseProps> =
const otherUserInfo = otherMemberID ? userInfos[otherMemberID] : null;

const availableRelationshipActions = React.useMemo(() => {
if (!otherUserInfo) {
if (
!otherUserInfo ||
!threadInfo?.type ||
!threadTypeIsPersonal(threadInfo.type)
) {
return ([]: RelationshipButton[]);
}
return getAvailableRelationshipButtons(otherUserInfo);
}, [otherUserInfo]);
}, [otherUserInfo, threadInfo?.type]);

const canEditThreadName = useThreadHasPermission(
threadInfo,
Expand Down

0 comments on commit d788f39

Please sign in to comment.