Skip to content

Commit d2fa80d

Browse files
authored
fix: hasSendableData logic for offline storage enabled (#1692)
Change logic for the `hasSendableData` when the composition exists for except the quoted message when offline storage is enabled.
1 parent 7402673 commit d2fa80d

2 files changed

Lines changed: 30 additions & 15 deletions

File tree

src/messageComposer/messageComposer.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,12 @@ export class MessageComposer extends WithSubscriptions {
327327
get hasSendableData() {
328328
// If the offline mode is enabled, we allow sending a message if the composition is not empty.
329329
if (this.client.offlineDb) {
330-
return !this.compositionIsEmpty;
330+
return (
331+
!this.textComposer.textIsEmpty ||
332+
!!this.attachmentManager.attachments.length ||
333+
!!this.pollId ||
334+
!!this.locationComposer.validLocation
335+
);
331336
}
332337
return !!(
333338
(!this.attachmentManager.uploadsInProgressCount &&

test/unit/MessageComposer/messageComposer.test.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -627,26 +627,36 @@ describe('MessageComposer', () => {
627627
});
628628

629629
describe('offlineDB enabled', () => {
630-
it('hasSendableData should return false if the composition is empty', () => {
631-
const { messageComposer } = offlineModeMessageComposerSetup();
630+
it('hasSendableData should return true if the composition is not empty', () => {
631+
const { messageComposer } = offlineModeMessageComposerSetup({
632+
composition: {
633+
id: 'test-message-id',
634+
type: 'regular',
635+
text: 'Hello',
636+
},
637+
});
632638

633-
const spyCompositionIsEmpty = vi
634-
.spyOn(messageComposer, 'compositionIsEmpty', 'get')
635-
.mockReturnValue(true);
639+
expect(messageComposer.hasSendableData).toBe(true);
640+
});
636641

637-
expect(messageComposer.hasSendableData).toBe(false);
638-
spyCompositionIsEmpty.mockRestore();
642+
it('hasSendableData should return true if the composition is not empty with attachments', () => {
643+
const { messageComposer } = offlineModeMessageComposerSetup({
644+
composition: {
645+
id: 'test-message-id',
646+
type: 'regular',
647+
attachments: [
648+
{ type: 'x', localMetadata: { id: 'x,', uploadState: 'finished', file: {} } },
649+
],
650+
},
651+
});
652+
653+
expect(messageComposer.hasSendableData).toBe(true);
639654
});
640655

641-
it('hasSendableData should return true if the composition is not empty', () => {
656+
it('hasSendableData should return false if the composition is empty', () => {
642657
const { messageComposer } = offlineModeMessageComposerSetup();
643658

644-
const spyCompositionIsEmpty = vi
645-
.spyOn(messageComposer, 'compositionIsEmpty', 'get')
646-
.mockReturnValue(false);
647-
648-
expect(messageComposer.hasSendableData).toBe(true);
649-
spyCompositionIsEmpty.mockRestore();
659+
expect(messageComposer.hasSendableData).toBe(false);
650660
});
651661
});
652662

0 commit comments

Comments
 (0)