Reintroduce 'expired' event, simplify handling of View Once media

This commit is contained in:
Scott Nonnenberg 2022-06-22 17:21:38 -07:00 committed by GitHub
parent 4545eee8f5
commit b8d6a591d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 21 deletions

View file

@ -52,6 +52,10 @@ class ExpiringMessagesDeletionService {
});
const conversation = message.getConversation();
// We do this to update the UI, if this message is being displayed somewhere
message.trigger('expired');
if (conversation) {
// An expired message only counts as decrementing the message count, not
// the sent message count

View file

@ -21,6 +21,9 @@ async function eraseTapToViewMessages() {
message.idForLogging()
);
// We do this to update the UI, if this message is being displayed somewhere
message.trigger('expired');
await message.eraseContents();
})
);

View file

@ -115,11 +115,7 @@ import {
suspendLinkPreviews,
} from '../services/LinkPreview';
import { LinkPreviewSourceType } from '../types/LinkPreview';
import {
closeLightbox,
isLightboxOpen,
showLightbox,
} from '../util/showLightbox';
import { closeLightbox, showLightbox } from '../util/showLightbox';
type AttachmentOptions = {
messageId: string;
@ -1894,21 +1890,16 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
await message.markViewOnceMessageViewed();
this.listenTo(message, 'expired', async () => {
log.info('displayTapToViewMessage: attempting to close lightbox');
// This isn't really a bullet-proof check because the lightbox could
// be open while we're viewing a regular media message
if (!isLightboxOpen()) {
log.info('displayTapToViewMessage: lightbox was already closed');
return;
const close = (): void => {
try {
this.stopListening(message);
closeLightbox();
} finally {
deleteTempFile(tempPath);
}
};
this.stopListening(message);
closeLightbox();
await deleteTempFile(tempPath);
});
this.listenTo(message, 'expired', close);
this.listenTo(message, 'change', () => {
showLightbox(getProps());
});
@ -1917,9 +1908,7 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
const { path, contentType } = tempAttachment;
return {
close: () => {
closeLightbox();
},
close,
i18n: window.i18n,
media: [
{