diff --git a/src/script/conversation/MessageRepository.test.ts b/src/script/conversation/MessageRepository.test.ts index 15fb7d51b2f..64973a354f3 100644 --- a/src/script/conversation/MessageRepository.test.ts +++ b/src/script/conversation/MessageRepository.test.ts @@ -44,6 +44,7 @@ import {CryptographyRepository} from '../cryptography/CryptographyRepository'; import {ContentMessage} from '../entity/message/ContentMessage'; import {EventRepository} from '../event/EventRepository'; import {EventService} from '../event/EventService'; +import {StatusType} from '../message/StatusType'; import {PropertiesRepository} from '../properties/PropertiesRepository'; import {TeamState} from '../team/TeamState'; import {ServerTimeHandler, serverTimeHandler} from '../time/serverTimeHandler'; @@ -236,6 +237,25 @@ describe('MessageRepository', () => { }), ); }); + + it('should send delete and deletes message for own pending/gray messages', async () => { + const conversation = generateConversation(CONVERSATION_TYPE.REGULAR); + conversation.participating_user_ets.push(new User('user1')); + + const messageToDelete = new Message(createUuid()); + messageToDelete.user(selfUser); + messageToDelete.status(StatusType.SENDING); + conversation.addMessage(messageToDelete); + + const [messageRepository, {core, eventRepository}] = await buildMessageRepository(); + jest.spyOn(core.service!.conversation, 'send').mockResolvedValue(successPayload); + spyOn(eventRepository.eventService, 'deleteEvent').and.returnValue(Promise.resolve()); + spyOn(messageRepository, 'deleteMessageById'); + + await messageRepository.deleteMessageForEveryone(conversation, messageToDelete); + + expect(messageRepository.deleteMessageById).toHaveBeenCalledWith(conversation, messageToDelete.id); + }); }); describe('resetSession', () => { diff --git a/src/script/conversation/MessageRepository.ts b/src/script/conversation/MessageRepository.ts index ccb46f45999..6449b49fff6 100644 --- a/src/script/conversation/MessageRepository.ts +++ b/src/script/conversation/MessageRepository.ts @@ -1000,6 +1000,11 @@ export class MessageRepository { const conversationId = conversation.id; const messageId = message.id; + // directly delete message from local database when status is sending + if (message.status() === StatusType.SENDING) { + await this.deleteMessageById(conversation, message.id); + } + try { if (!message.user().isMe && !message.ephemeral_expires()) { throw new ConversationError(ConversationError.TYPE.WRONG_USER, ConversationError.MESSAGE.WRONG_USER); diff --git a/src/script/entity/message/Message.ts b/src/script/entity/message/Message.ts index 26307ae4abb..be16d8b20d9 100644 --- a/src/script/entity/message/Message.ts +++ b/src/script/entity/message/Message.ts @@ -240,7 +240,7 @@ export class Message { * @returns `true`, if message is deletable, `false` otherwise. */ isDeletable(): boolean { - return !this.hasUnavailableAsset(false) && !this.isComposite() && this.status() !== StatusType.SENDING; + return !this.hasUnavailableAsset(false) && !this.isComposite(); } /** diff --git a/test/unit_tests/entity/message/MemberMessageSpec.js b/test/unit_tests/entity/message/MemberMessageSpec.js index 6570e4130b1..f2f6c9be4c8 100644 --- a/test/unit_tests/entity/message/MemberMessageSpec.js +++ b/test/unit_tests/entity/message/MemberMessageSpec.js @@ -93,11 +93,11 @@ describe('Member Message', () => { expect(message_et.isDeletable()).toBe(true); }); - it('should not be deletable while message is sending', () => { + it('should be deletable while message is sending', () => { message_et.assets.push(new Text()); message_et.status(StatusType.SENDING); - expect(message_et.isDeletable()).toBe(false); + expect(message_et.isDeletable()).toBe(true); }); it('should not be deletable when message is a file and uploading or downloading', () => {