manage expired nessage deletion in setExpired
This commit is contained in:
parent
6bbabce8e3
commit
beca14982c
|
@ -28,16 +28,17 @@ import { isFileDangerous } from '../../util/isFileDangerous';
|
|||
import _ from 'lodash';
|
||||
import { animation, contextMenu, Item, Menu } from 'react-contexify';
|
||||
import uuid from 'uuid';
|
||||
import { InView } from 'react-intersection-observer';
|
||||
import { withTheme } from 'styled-components';
|
||||
import { MessageMetadata } from './message/MessageMetadata';
|
||||
import { PubKey } from '../../session/types';
|
||||
import { getConversationController } from '../../session/conversations';
|
||||
import { MessageRegularProps } from '../../models/messageType';
|
||||
import {
|
||||
addSenderAsModerator,
|
||||
removeSenderFromModerator,
|
||||
} from '../../interactions/messageInteractions';
|
||||
import { updateUserDetailsModal } from '../../state/ducks/modalDialog';
|
||||
import { actions as conversationActions } from '../../state/ducks/conversations';
|
||||
import { MessageInteraction } from '../../interactions';
|
||||
import autoBind from 'auto-bind';
|
||||
import { AudioPlayerWithEncryptedFile } from './H5AudioPlayer';
|
||||
|
@ -104,7 +105,7 @@ class MessageInner extends React.PureComponent<MessageRegularProps, State> {
|
|||
|
||||
public checkExpired() {
|
||||
const now = Date.now();
|
||||
const { isExpired, expirationTimestamp, expirationLength } = this.props;
|
||||
const { isExpired, expirationTimestamp, expirationLength, convoId, id } = this.props;
|
||||
|
||||
if (!expirationTimestamp || !expirationLength) {
|
||||
return;
|
||||
|
@ -118,10 +119,19 @@ class MessageInner extends React.PureComponent<MessageRegularProps, State> {
|
|||
expiring: true,
|
||||
});
|
||||
|
||||
const setExpired = () => {
|
||||
const setExpired = async () => {
|
||||
this.setState({
|
||||
expired: true,
|
||||
});
|
||||
await window.Signal.Data.removeMessage(id);
|
||||
window.inboxStore?.dispatch(
|
||||
conversationActions.messageExpired({
|
||||
conversationKey: convoId,
|
||||
messageId: id,
|
||||
})
|
||||
);
|
||||
const convo = getConversationController().get(convoId);
|
||||
convo.updateLastMessage();
|
||||
};
|
||||
this.expiredTimeout = setTimeout(setExpired, EXPIRED_DELAY);
|
||||
}
|
||||
|
|
|
@ -637,7 +637,7 @@ export async function saveMessages(arrayOfMessages: Array<MessageAttributes>): P
|
|||
}
|
||||
|
||||
export async function removeMessage(id: string): Promise<void> {
|
||||
const message = await getMessageById(id);
|
||||
const message = await getMessageById(id, true);
|
||||
|
||||
// Note: It's important to have a fully database-hydrated model to delete here because
|
||||
// it needs to delete all associated on-disk files along with the database delete.
|
||||
|
@ -659,11 +659,17 @@ export async function getMessageIdsFromServerIds(
|
|||
return channels.getMessageIdsFromServerIds(serverIds, conversationId);
|
||||
}
|
||||
|
||||
export async function getMessageById(id: string): Promise<MessageModel | null> {
|
||||
export async function getMessageById(
|
||||
id: string,
|
||||
skipTimerInit: boolean = false
|
||||
): Promise<MessageModel | null> {
|
||||
const message = await channels.getMessageById(id);
|
||||
if (!message) {
|
||||
return null;
|
||||
}
|
||||
if (skipTimerInit) {
|
||||
message.skipTimerInit = skipTimerInit;
|
||||
}
|
||||
|
||||
return new MessageModel(message);
|
||||
}
|
||||
|
@ -748,13 +754,18 @@ export async function getUnreadCountByConversation(conversationId: string): Prom
|
|||
|
||||
export async function getMessagesByConversation(
|
||||
conversationId: string,
|
||||
{ limit = 100, receivedAt = Number.MAX_VALUE, type = '%' }
|
||||
{ limit = 100, receivedAt = Number.MAX_VALUE, type = '%', skipTimerInit = false }
|
||||
): Promise<MessageCollection> {
|
||||
const messages = await channels.getMessagesByConversation(conversationId, {
|
||||
limit,
|
||||
receivedAt,
|
||||
type,
|
||||
});
|
||||
if (skipTimerInit) {
|
||||
for (const message of messages) {
|
||||
message.skipTimerInit = skipTimerInit;
|
||||
}
|
||||
}
|
||||
return new MessageCollection(messages);
|
||||
}
|
||||
|
||||
|
|
|
@ -758,6 +758,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
|
|||
}
|
||||
const messages = await getMessagesByConversation(this.id, {
|
||||
limit: 1,
|
||||
skipTimerInit: true,
|
||||
});
|
||||
const lastMessageModel = messages.at(0);
|
||||
const lastMessageJSON = lastMessageModel ? lastMessageModel.toJSON() : null;
|
||||
|
@ -947,7 +948,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
|
|||
|
||||
// Build the list of updated message models so we can mark them all as read on a single sqlite call
|
||||
for (const nowRead of oldUnreadNowRead) {
|
||||
await nowRead.markReadNoCommit(options.readAt);
|
||||
nowRead.markReadNoCommit(options.readAt);
|
||||
|
||||
const errors = nowRead.get('errors');
|
||||
read.push({
|
||||
|
|
|
@ -63,7 +63,9 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
|
|||
}
|
||||
|
||||
// this.on('expired', this.onExpired);
|
||||
void this.setToExpire();
|
||||
if (!filledAttrs.skipTimerInit) {
|
||||
void this.setToExpire();
|
||||
}
|
||||
autoBind(this);
|
||||
|
||||
window.contextMenuShown = false;
|
||||
|
@ -1045,20 +1047,20 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
|
|||
}
|
||||
|
||||
public async markRead(readAt: number) {
|
||||
await this.markReadNoCommit(readAt);
|
||||
this.markReadNoCommit(readAt);
|
||||
|
||||
this.getConversation()?.markRead(this.attributes.received_at);
|
||||
|
||||
await this.commit();
|
||||
}
|
||||
|
||||
public async markReadNoCommit(readAt: number) {
|
||||
public markReadNoCommit(readAt: number) {
|
||||
this.set({ unread: 0 });
|
||||
|
||||
if (this.get('expireTimer') && !this.get('expirationStartTimestamp')) {
|
||||
const expirationStartTimestamp = Math.min(Date.now(), readAt || Date.now());
|
||||
this.set({ expirationStartTimestamp });
|
||||
await this.setToExpire(false);
|
||||
//await this.setToExpire(false);
|
||||
}
|
||||
|
||||
window.Whisper.Notifications.remove(
|
||||
|
|
|
@ -101,6 +101,12 @@ export interface MessageAttributes {
|
|||
* We display a small message just below the message referenced
|
||||
*/
|
||||
dataExtractionNotification?: DataExtractionNotificationMsg;
|
||||
|
||||
/**
|
||||
* This is used to choose whether to initialize the timer or not in the MessageModel object.
|
||||
* If false or undefined, timer will be in itialized.
|
||||
*/
|
||||
skipTimerInit?: boolean;
|
||||
}
|
||||
|
||||
export interface DataExtractionNotificationMsg {
|
||||
|
@ -165,6 +171,7 @@ export interface MessageAttributesOptionals {
|
|||
sync?: boolean;
|
||||
snippet?: any;
|
||||
direction?: any;
|
||||
skipTimerInit?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue