Remove a message from lightbox if its been DOE
This commit is contained in:
parent
b8234765bf
commit
6dd32456c6
3 changed files with 59 additions and 13 deletions
|
@ -495,8 +495,9 @@ export const SELECTED_CONVERSATION_CHANGED =
|
||||||
'conversations/SELECTED_CONVERSATION_CHANGED';
|
'conversations/SELECTED_CONVERSATION_CHANGED';
|
||||||
const PUSH_PANEL = 'conversations/PUSH_PANEL';
|
const PUSH_PANEL = 'conversations/PUSH_PANEL';
|
||||||
const POP_PANEL = 'conversations/POP_PANEL';
|
const POP_PANEL = 'conversations/POP_PANEL';
|
||||||
export const MESSAGE_EXPIRED = 'conversations/MESSAGE_EXPIRED';
|
export const MESSAGE_CHANGED = 'MESSAGE_CHANGED';
|
||||||
export const MESSAGE_DELETED = 'MESSAGE_DELETED';
|
export const MESSAGE_DELETED = 'MESSAGE_DELETED';
|
||||||
|
export const MESSAGE_EXPIRED = 'conversations/MESSAGE_EXPIRED';
|
||||||
export const SET_VOICE_NOTE_PLAYBACK_RATE =
|
export const SET_VOICE_NOTE_PLAYBACK_RATE =
|
||||||
'conversations/SET_VOICE_NOTE_PLAYBACK_RATE';
|
'conversations/SET_VOICE_NOTE_PLAYBACK_RATE';
|
||||||
export const CONVERSATION_UNLOADED = 'CONVERSATION_UNLOADED';
|
export const CONVERSATION_UNLOADED = 'CONVERSATION_UNLOADED';
|
||||||
|
@ -647,7 +648,7 @@ type ConversationStoppedByMissingVerificationActionType = {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
export type MessageChangedActionType = {
|
export type MessageChangedActionType = {
|
||||||
type: 'MESSAGE_CHANGED';
|
type: typeof MESSAGE_CHANGED;
|
||||||
payload: {
|
payload: {
|
||||||
id: string;
|
id: string;
|
||||||
conversationId: string;
|
conversationId: string;
|
||||||
|
@ -2403,7 +2404,7 @@ function messageChanged(
|
||||||
data: MessageAttributesType
|
data: MessageAttributesType
|
||||||
): MessageChangedActionType {
|
): MessageChangedActionType {
|
||||||
return {
|
return {
|
||||||
type: 'MESSAGE_CHANGED',
|
type: MESSAGE_CHANGED,
|
||||||
payload: {
|
payload: {
|
||||||
id,
|
id,
|
||||||
conversationId,
|
conversationId,
|
||||||
|
@ -4455,7 +4456,7 @@ export function reducer(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.type === 'MESSAGE_CHANGED') {
|
if (action.type === MESSAGE_CHANGED) {
|
||||||
const { id, conversationId, data } = action.payload;
|
const { id, conversationId, data } = action.payload;
|
||||||
const existingConversation = state.messagesByConversation[conversationId];
|
const existingConversation = state.messagesByConversation[conversationId];
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,11 @@ import type { ThunkAction } from 'redux-thunk';
|
||||||
import type { AttachmentType } from '../../types/Attachment';
|
import type { AttachmentType } from '../../types/Attachment';
|
||||||
import type { BoundActionCreatorsMapObject } from '../../hooks/useBoundActions';
|
import type { BoundActionCreatorsMapObject } from '../../hooks/useBoundActions';
|
||||||
import type { MediaItemType } from '../../types/MediaItem';
|
import type { MediaItemType } from '../../types/MediaItem';
|
||||||
import type { MessageExpiredActionType } from './conversations';
|
import type {
|
||||||
|
MessageChangedActionType,
|
||||||
|
MessageDeletedActionType,
|
||||||
|
MessageExpiredActionType,
|
||||||
|
} from './conversations';
|
||||||
import type { ShowStickerPackPreviewActionType } from './globalModals';
|
import type { ShowStickerPackPreviewActionType } from './globalModals';
|
||||||
import type { ShowToastActionType } from './toast';
|
import type { ShowToastActionType } from './toast';
|
||||||
import type { StateType as RootStateType } from '../reducer';
|
import type { StateType as RootStateType } from '../reducer';
|
||||||
|
@ -21,7 +25,12 @@ import {
|
||||||
import { isTapToView } from '../selectors/message';
|
import { isTapToView } from '../selectors/message';
|
||||||
import { SHOW_TOAST } from './toast';
|
import { SHOW_TOAST } from './toast';
|
||||||
import { ToastType } from '../../types/Toast';
|
import { ToastType } from '../../types/Toast';
|
||||||
import { MESSAGE_EXPIRED, saveAttachmentFromMessage } from './conversations';
|
import {
|
||||||
|
MESSAGE_CHANGED,
|
||||||
|
MESSAGE_DELETED,
|
||||||
|
MESSAGE_EXPIRED,
|
||||||
|
saveAttachmentFromMessage,
|
||||||
|
} from './conversations';
|
||||||
import { showStickerPackPreview } from './globalModals';
|
import { showStickerPackPreview } from './globalModals';
|
||||||
import { useBoundActions } from '../../hooks/useBoundActions';
|
import { useBoundActions } from '../../hooks/useBoundActions';
|
||||||
|
|
||||||
|
@ -54,6 +63,8 @@ type ShowLightboxActionType = {
|
||||||
|
|
||||||
type LightboxActionType =
|
type LightboxActionType =
|
||||||
| CloseLightboxActionType
|
| CloseLightboxActionType
|
||||||
|
| MessageChangedActionType
|
||||||
|
| MessageDeletedActionType
|
||||||
| MessageExpiredActionType
|
| MessageExpiredActionType
|
||||||
| ShowLightboxActionType;
|
| ShowLightboxActionType;
|
||||||
|
|
||||||
|
@ -156,7 +167,6 @@ function showLightboxForViewOnceMedia(
|
||||||
objectURL: getAbsoluteTempPath(path),
|
objectURL: getAbsoluteTempPath(path),
|
||||||
contentType,
|
contentType,
|
||||||
index: 0,
|
index: 0,
|
||||||
// TODO maybe we need to listen for message change?
|
|
||||||
message: {
|
message: {
|
||||||
attachments: message.get('attachments') || [],
|
attachments: message.get('attachments') || [],
|
||||||
id: message.get('id'),
|
id: message.get('id'),
|
||||||
|
@ -315,25 +325,43 @@ export function reducer(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.type === MESSAGE_EXPIRED) {
|
if (
|
||||||
|
action.type === MESSAGE_CHANGED ||
|
||||||
|
action.type === MESSAGE_DELETED ||
|
||||||
|
action.type === MESSAGE_EXPIRED
|
||||||
|
) {
|
||||||
if (!state.isShowingLightbox) {
|
if (!state.isShowingLightbox) {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!state.isViewOnce) {
|
if (action.type === MESSAGE_EXPIRED && !state.isViewOnce) {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
const hasExpiredMedia = state.media.some(
|
if (
|
||||||
item => item.message.id === action.payload.id
|
action.type === MESSAGE_CHANGED &&
|
||||||
|
!action.payload.data.deletedForEveryone
|
||||||
|
) {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
const nextMedia = state.media.filter(
|
||||||
|
item => item.message.id !== action.payload.id
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!hasExpiredMedia) {
|
if (nextMedia.length === state.media.length) {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!nextMedia.length) {
|
||||||
return getEmptyState();
|
return getEmptyState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
media: nextMedia,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import type { AttachmentType } from '../../types/Attachment';
|
||||||
import type { BoundActionCreatorsMapObject } from '../../hooks/useBoundActions';
|
import type { BoundActionCreatorsMapObject } from '../../hooks/useBoundActions';
|
||||||
import type {
|
import type {
|
||||||
ConversationUnloadedActionType,
|
ConversationUnloadedActionType,
|
||||||
|
MessageChangedActionType,
|
||||||
MessageDeletedActionType,
|
MessageDeletedActionType,
|
||||||
MessageExpiredActionType,
|
MessageExpiredActionType,
|
||||||
} from './conversations';
|
} from './conversations';
|
||||||
|
@ -17,6 +18,7 @@ import type { StateType as RootStateType } from '../reducer';
|
||||||
import dataInterface from '../../sql/Client';
|
import dataInterface from '../../sql/Client';
|
||||||
import {
|
import {
|
||||||
CONVERSATION_UNLOADED,
|
CONVERSATION_UNLOADED,
|
||||||
|
MESSAGE_CHANGED,
|
||||||
MESSAGE_DELETED,
|
MESSAGE_DELETED,
|
||||||
MESSAGE_EXPIRED,
|
MESSAGE_EXPIRED,
|
||||||
} from './conversations';
|
} from './conversations';
|
||||||
|
@ -60,6 +62,7 @@ type LoadMediaItemslActionType = {
|
||||||
type MediaGalleryActionType =
|
type MediaGalleryActionType =
|
||||||
| ConversationUnloadedActionType
|
| ConversationUnloadedActionType
|
||||||
| LoadMediaItemslActionType
|
| LoadMediaItemslActionType
|
||||||
|
| MessageChangedActionType
|
||||||
| MessageDeletedActionType
|
| MessageDeletedActionType
|
||||||
| MessageExpiredActionType;
|
| MessageExpiredActionType;
|
||||||
|
|
||||||
|
@ -207,6 +210,20 @@ export function reducer(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (action.type === MESSAGE_CHANGED) {
|
||||||
|
if (!action.payload.data.deletedForEveryone) {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
media: state.media.filter(item => item.message.id !== action.payload.id),
|
||||||
|
documents: state.documents.filter(
|
||||||
|
item => item.message.id !== action.payload.id
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (action.type === MESSAGE_DELETED || action.type === MESSAGE_EXPIRED) {
|
if (action.type === MESSAGE_DELETED || action.type === MESSAGE_EXPIRED) {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue