Skip to content

Commit

Permalink
fix leaving + clearing
Browse files Browse the repository at this point in the history
  • Loading branch information
atomrc committed Oct 10, 2023
1 parent 9857a07 commit 3ae923a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/script/conversation/ConversationRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1752,13 +1752,13 @@ export class ConversationRepository {
/**
* Remove the current user from a conversation.
*
* @param conversationEntity Conversation to remove user from
* @param conversation Conversation to remove user from
* @param clearContent Should we clear the conversation content from the database?
* @returns Resolves when user was removed from the conversation
*/
public async leaveConversation(conversationEntity: Conversation, {localOnly = false} = {}) {
public async leaveConversation(conversation: Conversation, {localOnly = false} = {}) {
const userQualifiedId = this.userState.self().qualifiedId;
return this.removeMember(conversationEntity, userQualifiedId, {localOnly});
return this.removeMember(conversation, userQualifiedId, {localOnly});
}

/**
Expand Down
35 changes: 25 additions & 10 deletions src/script/view_model/ActionsViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,32 @@ export class ActionsViewModel {
});
};

private readonly leaveOrClearConversation = async (
conversation: Conversation,
{
leave,
clear,
}: {
leave: boolean;
clear: boolean;
},
): Promise<void> => {
if (leave) {
await this.conversationRepository.leaveConversation(conversation);
}
if (clear) {
await this.conversationRepository.clearConversation(conversation);
}
};

readonly clearConversation = (conversationEntity: Conversation): void => {
if (conversationEntity) {
const modalType = conversationEntity.isLeavable() ? PrimaryModal.type.OPTION : PrimaryModal.type.CONFIRM;

PrimaryModal.show(modalType, {
primaryAction: {
action: async (leaveConversation = false) => {
if (leaveConversation) {
await this.conversationRepository.leaveConversation(conversationEntity);
}
await this.conversationRepository.clearConversation(conversationEntity);
action: async (leave = false) => {
await this.leaveOrClearConversation(conversationEntity, {clear: true, leave: leave});
},
text: t('modalConversationClearAction'),
},
Expand Down Expand Up @@ -264,25 +279,25 @@ export class ActionsViewModel {
return this.connectionRepository.ignoreRequest(userEntity);
};

readonly leaveConversation = (conversationEntity: Conversation): Promise<void> => {
if (!conversationEntity) {
readonly leaveConversation = (conversation: Conversation): Promise<void> => {
if (!conversation) {
return Promise.reject();
}

return new Promise(resolve => {
PrimaryModal.show(PrimaryModal.type.OPTION, {
primaryAction: {
action: async (clearContent = false) => {
await this.conversationRepository.leaveConversation(conversationEntity, {clearContent});
await this.leaveOrClearConversation(conversation, {clear: clearContent, leave: true});
resolve();
},
text: t('modalConversationLeaveAction'),
},
text: {
closeBtnLabel: t('modalConversationLeaveMessageCloseBtn', conversationEntity.display_name()),
closeBtnLabel: t('modalConversationLeaveMessageCloseBtn', conversation.display_name()),
message: t('modalConversationLeaveMessage'),
option: t('modalConversationLeaveOption'),
title: t('modalConversationLeaveHeadline', conversationEntity.display_name()),
title: t('modalConversationLeaveHeadline', conversation.display_name()),
},
});
});
Expand Down

0 comments on commit 3ae923a

Please sign in to comment.