commit
						4661c89774
					
				@ -1,42 +1,53 @@
 | 
			
		||||
function sharedEnabled({
 | 
			
		||||
  isGroup,
 | 
			
		||||
  isPublic,
 | 
			
		||||
  isMessageRequestShown,
 | 
			
		||||
}: Pick<Parameters<typeof showLeaveGroupItem>[0], 'isGroup' | 'isMessageRequestShown'>) {
 | 
			
		||||
  return isGroup && !isMessageRequestShown;
 | 
			
		||||
}: Pick<
 | 
			
		||||
  Parameters<typeof showLeaveGroupItem>[0],
 | 
			
		||||
  'isGroup' | 'isMessageRequestShown' | 'isPublic'
 | 
			
		||||
>) {
 | 
			
		||||
  return isGroup && !isMessageRequestShown && !isPublic;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * We can try leave a group if
 | 
			
		||||
 * - we are an admin of the group (that group would be marked as destroyed on delete)
 | 
			
		||||
 * and
 | 
			
		||||
 * - we are a **not kicked** member (if we are kicked without knowing about it and try to leave, we will silently remove the group)
 | 
			
		||||
 *
 | 
			
		||||
 * Note: Those actions are hidden if the group is a group request (as we have other buttons to accept/decline a group request).
 | 
			
		||||
 *
 | 
			
		||||
 * Note: If we fail to leave the group but that error is retryable, we will keep the group displaying the "leave" option.
 | 
			
		||||
 */
 | 
			
		||||
export function showLeaveGroupItem({
 | 
			
		||||
  isGroup,
 | 
			
		||||
  isPublic,
 | 
			
		||||
  isKickedFromGroup,
 | 
			
		||||
  isMessageRequestShown,
 | 
			
		||||
  lastMessageIsLeaveError,
 | 
			
		||||
  isGroupDestroyed,
 | 
			
		||||
}: {
 | 
			
		||||
  isGroup: boolean;
 | 
			
		||||
  isPublic: boolean;
 | 
			
		||||
  isMessageRequestShown: boolean;
 | 
			
		||||
  lastMessageIsLeaveError: boolean;
 | 
			
		||||
  isKickedFromGroup: boolean;
 | 
			
		||||
  isGroupDestroyed: boolean;
 | 
			
		||||
}) {
 | 
			
		||||
  // we can't try to leave the group if we were kicked from it, or if we've already tried to (lastMessageIsLeaveError is true)
 | 
			
		||||
  return (
 | 
			
		||||
    sharedEnabled({ isGroup, isMessageRequestShown }) &&
 | 
			
		||||
    sharedEnabled({ isGroup, isMessageRequestShown, isPublic }) &&
 | 
			
		||||
    !isKickedFromGroup &&
 | 
			
		||||
    !lastMessageIsLeaveError
 | 
			
		||||
    !isGroupDestroyed
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function showDeleteGroupItem({
 | 
			
		||||
  isGroup,
 | 
			
		||||
  isKickedFromGroup,
 | 
			
		||||
  isMessageRequestShown,
 | 
			
		||||
  lastMessageIsLeaveError,
 | 
			
		||||
}: {
 | 
			
		||||
/**
 | 
			
		||||
 * We can try to delete a group only if the `showLeaveGroupItem` returns false.
 | 
			
		||||
 * Note: those actions are hidden if the group is a group request (as we have other buttons to accept/decline a group request)
 | 
			
		||||
 */
 | 
			
		||||
export function showDeleteGroupItem(args: {
 | 
			
		||||
  isGroup: boolean;
 | 
			
		||||
  isPublic: boolean;
 | 
			
		||||
  isMessageRequestShown: boolean;
 | 
			
		||||
  lastMessageIsLeaveError: boolean;
 | 
			
		||||
  isKickedFromGroup: boolean;
 | 
			
		||||
  isGroupDestroyed: boolean;
 | 
			
		||||
}) {
 | 
			
		||||
  return (
 | 
			
		||||
    sharedEnabled({ isGroup, isMessageRequestShown }) &&
 | 
			
		||||
    (isKickedFromGroup || lastMessageIsLeaveError)
 | 
			
		||||
  );
 | 
			
		||||
  return sharedEnabled(args) && !showLeaveGroupItem(args);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
					Loading…
					
					
				
		Reference in New Issue