Skip to content

Commit

Permalink
feat: add ability to delete gray messages (WPB-5840) (#16375) (#16585)
Browse files Browse the repository at this point in the history
* feat: add ability to delete gray messages (WPB-5840) (#16375)

* feat: add ability to delete gray messages (WPB-5840)

* test: add testing for gray message deleting

* update tests
  • Loading branch information
thisisamir98 authored Jan 22, 2024
1 parent 8f5e2b4 commit 7f83dbe
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
20 changes: 20 additions & 0 deletions src/script/conversation/MessageRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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', () => {
Expand Down
5 changes: 5 additions & 0 deletions src/script/conversation/MessageRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/script/entity/message/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions test/unit_tests/entity/message/MemberMessageSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 7f83dbe

Please sign in to comment.