Skip to content

Commit

Permalink
feat: new copy when trying to open a 1:1 with blocked user
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrykBuniX committed Jan 18, 2024
1 parent 1925336 commit eb97aca
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,8 @@
"conversationNewConversation": "Communication in Wire is always end-to-end encrypted. Everything you send and receive in this conversation is only accessible to you and your contact.",
"conversationNotClassified": "Security level: Unclassified",
"conversationNotFoundMessage": "You may not have permission with this account or it no longer exists.",
"conversationWithBlockedUserMessage": "The link to this group conversation is no longer valid or leads to a conversation with someone you blocked.",
"conversationWithBlockedUserTitle": "Conversation not reachable",
"conversationNotFoundTitle": "{{brandName}} can’t open this conversation.",
"conversationParticipantsSearchPlaceholder": "Search by name",
"conversationParticipantsTitle": "People",
Expand Down
3 changes: 3 additions & 0 deletions src/script/error/ConversationError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {BaseError, BASE_ERROR_TYPE} from './BaseError';

enum CONVERSATION_ERROR_TYPE {
CONVERSATION_NOT_FOUND = 'CONVERSATION_NOT_FOUND',
CONVERSATION_WITH_BLOCKED_USER = 'CONVERSATION_WITH_BLOCKED_USER',
INVALID_PARAMETER = 'INVALID_PARAMETER',
LEGAL_HOLD_CONVERSATION_CANCELLATION = 'LEGAL_HOLD_CONVERSATION_CANCELLATION',
MESSAGE_NOT_FOUND = 'MESSAGE_NOT_FOUND',
Expand All @@ -46,6 +47,7 @@ export class ConversationError extends BaseError {
static get MESSAGE(): Record<CONVERSATION_ERROR_TYPE | string, string> {
return {
CONVERSATION_NOT_FOUND: 'Conversation not found',
CONVERSATION_WITH_BLOCKED_USER: 'Conversation not reachable',
INVALID_PARAMETER: 'Invalid parameter passed',
LEGAL_HOLD_CONVERSATION_CANCELLATION: 'Sending to legal hold conversation was canceled by user',
MESSAGE_NOT_FOUND: 'Message not found in conversation',
Expand All @@ -64,6 +66,7 @@ export class ConversationError extends BaseError {
static get TYPE(): Record<CONVERSATION_ERROR_TYPE, CONVERSATION_ERROR_TYPE> {
return {
CONVERSATION_NOT_FOUND: CONVERSATION_ERROR_TYPE.CONVERSATION_NOT_FOUND,
CONVERSATION_WITH_BLOCKED_USER: CONVERSATION_ERROR_TYPE.CONVERSATION_WITH_BLOCKED_USER,
INVALID_PARAMETER: CONVERSATION_ERROR_TYPE.INVALID_PARAMETER,
LEGAL_HOLD_CONVERSATION_CANCELLATION: CONVERSATION_ERROR_TYPE.LEGAL_HOLD_CONVERSATION_CANCELLATION,
MESSAGE_NOT_FOUND: CONVERSATION_ERROR_TYPE.MESSAGE_NOT_FOUND,
Expand Down
37 changes: 33 additions & 4 deletions src/script/view_model/ContentViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,27 @@ export class ContentViewModel {
);
}

private showConversationWithBlockedUserErrorModal(): void {
PrimaryModal.show(
PrimaryModal.type.ACKNOWLEDGE,
{
text: {
message: t('conversationWithBlockedUserMessage'),
title: t('conversationWithBlockedUserTitle'),
},
},
undefined,
);
}

private isConversationNotFoundError(error: any): boolean {
return error.type === ConversationError.TYPE.CONVERSATION_NOT_FOUND;
}

private isConversationWithBlockedUserError(error: any): boolean {
return error.type === ConversationError.TYPE.CONVERSATION_WITH_BLOCKED_USER;
}

/**
* Opens the specified conversation.
*
Expand Down Expand Up @@ -251,14 +268,22 @@ export class ContentViewModel {
const conversationEntity = await this.getConversationEntity(conversation, domain);
const isConnectionBlocked = conversationEntity?.connection()?.isBlocked();

if (!conversationEntity || isConnectionBlocked) {
if (!conversationEntity) {
this.closeRightSidebar();
throw new ConversationError(
ConversationError.TYPE.CONVERSATION_NOT_FOUND,
ConversationError.MESSAGE.CONVERSATION_NOT_FOUND,
);
}

if (isConnectionBlocked) {
this.closeRightSidebar();
throw new ConversationError(
ConversationError.TYPE.CONVERSATION_WITH_BLOCKED_USER,
ConversationError.MESSAGE.CONVERSATION_WITH_BLOCKED_USER,
);
}

const isActiveConversation = this.conversationState.isActiveConversation(conversationEntity);

if (!isActiveConversation) {
Expand All @@ -277,10 +302,14 @@ export class ContentViewModel {
this.showAndNavigate(conversationEntity, openNotificationSettings);
} catch (error: any) {
if (this.isConversationNotFoundError(error)) {
this.showConversationNotFoundErrorModal();
} else {
throw error;
return this.showConversationNotFoundErrorModal();
}

if (this.isConversationWithBlockedUserError(error)) {
return this.showConversationWithBlockedUserErrorModal();
}

throw error;
}
};

Expand Down

0 comments on commit eb97aca

Please sign in to comment.