Remove "delete for everyone" option from failed messages
This commit is contained in:
parent
f82639dc3a
commit
1891375c6c
2 changed files with 114 additions and 17 deletions
|
@ -38,6 +38,7 @@ import { AttachmentType, isVoiceMessage } from '../../types/Attachment';
|
|||
import { CallingNotificationType } from '../../util/callingNotification';
|
||||
import { missingCaseError } from '../../util/missingCaseError';
|
||||
import { isNotNil } from '../../util/isNotNil';
|
||||
import { isMoreRecentThan } from '../../util/timestamp';
|
||||
|
||||
import { ConversationType } from '../ducks/conversations';
|
||||
|
||||
|
@ -1153,23 +1154,25 @@ export function canReply(
|
|||
return false;
|
||||
}
|
||||
|
||||
export function canDeleteForEveryone(message: MessageAttributesType): boolean {
|
||||
// is someone else's message
|
||||
if (isIncoming(message)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// has already been deleted for everyone
|
||||
if (message.deletedForEveryone) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// is too old to delete
|
||||
if (Date.now() - message.sent_at > THREE_HOURS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
export function canDeleteForEveryone(
|
||||
message: Pick<
|
||||
MessageAttributesType,
|
||||
'type' | 'deletedForEveryone' | 'sent_at' | 'sendStateByConversationId'
|
||||
>
|
||||
): boolean {
|
||||
return (
|
||||
// Is this a message I sent?
|
||||
isOutgoing(message) &&
|
||||
// Has the message already been deleted?
|
||||
!message.deletedForEveryone &&
|
||||
// Is it too old to delete?
|
||||
isMoreRecentThan(message.sent_at, THREE_HOURS) &&
|
||||
// Is it pending/sent to anyone?
|
||||
someSendStatus(
|
||||
message.sendStateByConversationId,
|
||||
sendStatus => sendStatus !== SendStatus.Failed
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export function canDownload(
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
import * as moment from 'moment';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { SendStatus } from '../../../messages/MessageSendState';
|
||||
import {
|
||||
|
@ -11,6 +12,7 @@ import {
|
|||
import { ConversationType } from '../../../state/ducks/conversations';
|
||||
|
||||
import {
|
||||
canDeleteForEveryone,
|
||||
canReply,
|
||||
getMessagePropStatus,
|
||||
isEndSession,
|
||||
|
@ -26,6 +28,98 @@ describe('state/selectors/messages', () => {
|
|||
ourConversationId = uuid();
|
||||
});
|
||||
|
||||
describe('canDeleteForEveryone', () => {
|
||||
it('returns false for incoming messages', () => {
|
||||
const message = {
|
||||
type: 'incoming' as const,
|
||||
sent_at: Date.now() - 1000,
|
||||
};
|
||||
|
||||
assert.isFalse(canDeleteForEveryone(message));
|
||||
});
|
||||
|
||||
it('returns false for messages that were already deleted for everyone', () => {
|
||||
const message = {
|
||||
type: 'outgoing' as const,
|
||||
deletedForEveryone: true,
|
||||
sent_at: Date.now() - 1000,
|
||||
sendStateByConversationId: {
|
||||
[ourConversationId]: {
|
||||
status: SendStatus.Read,
|
||||
updatedAt: Date.now(),
|
||||
},
|
||||
[uuid()]: {
|
||||
status: SendStatus.Delivered,
|
||||
updatedAt: Date.now(),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
assert.isFalse(canDeleteForEveryone(message));
|
||||
});
|
||||
|
||||
it('returns false for messages that were are too old to delete', () => {
|
||||
const message = {
|
||||
type: 'outgoing' as const,
|
||||
sent_at: Date.now() - moment.duration(4, 'hours').asMilliseconds(),
|
||||
sendStateByConversationId: {
|
||||
[ourConversationId]: {
|
||||
status: SendStatus.Read,
|
||||
updatedAt: Date.now(),
|
||||
},
|
||||
[uuid()]: {
|
||||
status: SendStatus.Delivered,
|
||||
updatedAt: Date.now(),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
assert.isFalse(canDeleteForEveryone(message));
|
||||
});
|
||||
|
||||
it('returns false for messages that failed to send to anyone', () => {
|
||||
const message = {
|
||||
type: 'outgoing' as const,
|
||||
sent_at: Date.now() - 1000,
|
||||
sendStateByConversationId: {
|
||||
[ourConversationId]: {
|
||||
status: SendStatus.Failed,
|
||||
updatedAt: Date.now(),
|
||||
},
|
||||
[uuid()]: {
|
||||
status: SendStatus.Failed,
|
||||
updatedAt: Date.now(),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
assert.isFalse(canDeleteForEveryone(message));
|
||||
});
|
||||
|
||||
it('returns true for messages that meet all criteria for deletion', () => {
|
||||
const message = {
|
||||
type: 'outgoing' as const,
|
||||
sent_at: Date.now() - 1000,
|
||||
sendStateByConversationId: {
|
||||
[ourConversationId]: {
|
||||
status: SendStatus.Pending,
|
||||
updatedAt: Date.now(),
|
||||
},
|
||||
[uuid()]: {
|
||||
status: SendStatus.Pending,
|
||||
updatedAt: Date.now(),
|
||||
},
|
||||
[uuid()]: {
|
||||
status: SendStatus.Failed,
|
||||
updatedAt: Date.now(),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
assert.isTrue(canDeleteForEveryone(message));
|
||||
});
|
||||
});
|
||||
|
||||
describe('canReply', () => {
|
||||
const defaultConversation: ConversationType = {
|
||||
id: uuid(),
|
||||
|
|
Loading…
Reference in a new issue