Skip to content

Commit 225bf9f

Browse files
committed
fix: admins can only delete group
also fixed the right click on pending groupv2 invite
1 parent a121091 commit 225bf9f

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

ts/components/conversation/header/ConversationHeaderItems.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,26 @@ import {
1313
} from '../../../state/selectors/selectedConversation';
1414
import { Avatar, AvatarSize } from '../../avatar/Avatar';
1515
import { SessionIconButton } from '../../icon';
16-
import { useIsLegacyGroup } from '../../../hooks/useParamSelector';
16+
import { useIsGroupV2, useIsLegacyGroup } from '../../../hooks/useParamSelector';
17+
import { useLibGroupInvitePending } from '../../../state/selectors/userGroups';
1718

1819
export const AvatarHeader = (props: { pubkey: string; onAvatarClick?: () => void }) => {
1920
const { pubkey, onAvatarClick } = props;
2021
const isApproved = useSelectedIsApproved();
2122

2223
const isLegacyGroup = useIsLegacyGroup(pubkey);
24+
const invitePending = useLibGroupInvitePending(pubkey);
25+
const isPrivate = useSelectedIsPrivate();
26+
const isGroupV2 = useIsGroupV2(pubkey);
27+
28+
const canClickLegacy = isLegacyGroup && false; // we can never click the avatar if it's a legacy group
29+
const canClickPrivateApproved = isApproved && isPrivate; // we can only click the avatar if it's a private and approved conversation
30+
const canClick03GroupAccepted = isGroupV2 && !invitePending; // we can only click the avatar if it's a group and have accepted the invite already
2331

24-
const optOnAvatarClick = !isLegacyGroup && isApproved ? onAvatarClick : undefined;
32+
const optOnAvatarClick =
33+
canClickLegacy || canClickPrivateApproved || canClick03GroupAccepted
34+
? onAvatarClick
35+
: undefined;
2536

2637
return (
2738
<span className="module-conversation-header__avatar">

ts/components/menuAndSettingsHooks/useShowLeaveGroup.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
useIsKickedFromGroup,
44
useIsGroupDestroyed,
55
useConversationUsername,
6+
useWeAreAdmin,
67
} from '../../hooks/useParamSelector';
78
import {
89
showDeleteGroupByConvoId,
@@ -16,6 +17,7 @@ export function useShowLeaveGroupCb(conversationId?: string) {
1617
const isGroupDestroyed = useIsGroupDestroyed(conversationId);
1718
const isMessageRequestShown = useIsMessageRequestOverlayShown();
1819
const username = useConversationUsername(conversationId) || conversationId;
20+
const weAreAdmin = useWeAreAdmin(conversationId);
1921

2022
// Note: if we are the only admin, leaving it will warn that it will actually delete it for everyone.
2123

@@ -24,7 +26,8 @@ export function useShowLeaveGroupCb(conversationId?: string) {
2426
isMessageRequestShown ||
2527
isGroupDestroyed ||
2628
isKickedFromGroup ||
27-
!conversationId
29+
!conversationId ||
30+
weAreAdmin
2831
) {
2932
return null;
3033
}

ts/state/selectors/selectedConversation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ export function useSelectedIsBlocked() {
262262

263263
export function useSelectedIsApproved() {
264264
return useSelector((state: StateType): boolean => {
265-
return !!(getSelectedConversation(state)?.isApproved || false);
265+
return getSelectedConversation(state)?.isApproved || false;
266266
});
267267
}
268268

0 commit comments

Comments
 (0)