Both UI timer and database timer will remove expired message
This commit is contained in:
parent
9f920aa35b
commit
37f3054976
4 changed files with 26 additions and 6 deletions
|
@ -166,15 +166,18 @@
|
||||||
this.updateLastMessage();
|
this.updateLastMessage();
|
||||||
|
|
||||||
const removeMessage = () => {
|
const removeMessage = () => {
|
||||||
const existing = this.messageCollection.get(message.id);
|
const { id } = message;
|
||||||
|
const existing = this.messageCollection.get(id);
|
||||||
if (!existing) {
|
if (!existing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.log.info('Remove expired message from collection', {
|
window.log.info('Remove expired message from collection', {
|
||||||
sentAt: message.get('sent_at'),
|
sentAt: existing.get('sent_at'),
|
||||||
});
|
});
|
||||||
this.messageCollection.remove(message.id);
|
|
||||||
|
this.messageCollection.remove(id);
|
||||||
|
existing.trigger('expired');
|
||||||
};
|
};
|
||||||
|
|
||||||
// If a fetch is in progress, then we need to wait until that's complete to
|
// If a fetch is in progress, then we need to wait until that's complete to
|
||||||
|
|
|
@ -83,6 +83,7 @@
|
||||||
this.on('change:expirationStartTimestamp', this.setToExpire);
|
this.on('change:expirationStartTimestamp', this.setToExpire);
|
||||||
this.on('change:expireTimer', this.setToExpire);
|
this.on('change:expireTimer', this.setToExpire);
|
||||||
this.on('unload', this.unload);
|
this.on('unload', this.unload);
|
||||||
|
this.on('expired', this.onExpired);
|
||||||
this.setToExpire();
|
this.setToExpire();
|
||||||
},
|
},
|
||||||
idForLogging() {
|
idForLogging() {
|
||||||
|
@ -233,7 +234,9 @@
|
||||||
this.quotedMessage = null;
|
this.quotedMessage = null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onExpired() {
|
||||||
|
this.hasExpired = true;
|
||||||
|
},
|
||||||
getPropsForTimerNotification() {
|
getPropsForTimerNotification() {
|
||||||
const { expireTimer, fromSync, source } = this.get(
|
const { expireTimer, fromSync, source } = this.get(
|
||||||
'expirationTimerUpdate'
|
'expirationTimerUpdate'
|
||||||
|
@ -424,6 +427,7 @@
|
||||||
attachment: this.getPropsForAttachment(firstAttachment),
|
attachment: this.getPropsForAttachment(firstAttachment),
|
||||||
quote: this.getPropsForQuote(),
|
quote: this.getPropsForQuote(),
|
||||||
authorAvatarPath,
|
authorAvatarPath,
|
||||||
|
isExpired: this.hasExpired,
|
||||||
expirationLength,
|
expirationLength,
|
||||||
expirationTimestamp,
|
expirationTimestamp,
|
||||||
onReply: () => this.trigger('reply', this),
|
onReply: () => this.trigger('reply', this),
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
this.listenTo(this.model, 'change', this.onChange);
|
this.listenTo(this.model, 'change', this.onChange);
|
||||||
this.listenTo(this.model, 'destroy', this.onDestroy);
|
this.listenTo(this.model, 'destroy', this.onDestroy);
|
||||||
this.listenTo(this.model, 'unload', this.onUnload);
|
this.listenTo(this.model, 'unload', this.onUnload);
|
||||||
|
this.listenTo(this.model, 'expired', this.onExpired);
|
||||||
},
|
},
|
||||||
onChange() {
|
onChange() {
|
||||||
this.addId();
|
this.addId();
|
||||||
|
@ -27,6 +28,9 @@
|
||||||
const { id } = this.model;
|
const { id } = this.model;
|
||||||
this.$el.attr('id', id);
|
this.$el.attr('id', id);
|
||||||
},
|
},
|
||||||
|
onExpired() {
|
||||||
|
setTimeout(() => this.onUnload(), 1000);
|
||||||
|
},
|
||||||
onUnload() {
|
onUnload() {
|
||||||
if (this.childView) {
|
if (this.childView) {
|
||||||
this.childView.remove();
|
this.childView.remove();
|
||||||
|
@ -93,6 +97,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
this.listenTo(this.model, 'change', update);
|
this.listenTo(this.model, 'change', update);
|
||||||
|
this.listenTo(this.model, 'expired', update);
|
||||||
|
|
||||||
this.conversation = this.model.getConversation();
|
this.conversation = this.model.getConversation();
|
||||||
this.listenTo(this.conversation, 'change', update);
|
this.listenTo(this.conversation, 'change', update);
|
||||||
|
|
|
@ -81,6 +81,7 @@ export interface Props {
|
||||||
referencedMessageNotFound: boolean;
|
referencedMessageNotFound: boolean;
|
||||||
};
|
};
|
||||||
authorAvatarPath?: string;
|
authorAvatarPath?: string;
|
||||||
|
isExpired: boolean;
|
||||||
expirationLength?: number;
|
expirationLength?: number;
|
||||||
expirationTimestamp?: number;
|
expirationTimestamp?: number;
|
||||||
onClickAttachment?: () => void;
|
onClickAttachment?: () => void;
|
||||||
|
@ -211,15 +212,22 @@ export class Message extends React.Component<Props, State> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public componentDidUpdate() {
|
||||||
|
this.checkExpired();
|
||||||
|
}
|
||||||
|
|
||||||
public checkExpired() {
|
public checkExpired() {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const { expirationTimestamp, expirationLength } = this.props;
|
const { isExpired, expirationTimestamp, expirationLength } = this.props;
|
||||||
|
|
||||||
if (!expirationTimestamp || !expirationLength) {
|
if (!expirationTimestamp || !expirationLength) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (this.expiredTimeout) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (now >= expirationTimestamp) {
|
if (isExpired || now >= expirationTimestamp) {
|
||||||
this.setState({
|
this.setState({
|
||||||
expiring: true,
|
expiring: true,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue