Fix stuck safety number modal overlay
This commit is contained in:
parent
3aa488c3d5
commit
f5eb17e0d1
2 changed files with 49 additions and 27 deletions
|
@ -1,4 +1,4 @@
|
||||||
// Copyright 2021 Signal Messenger, LLC
|
// Copyright 2021-2022 Signal Messenger, LLC
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import * as log from '../logging/log';
|
import * as log from '../logging/log';
|
||||||
|
@ -7,19 +7,19 @@ import type { MessageAttributesType } from '../model-types.d';
|
||||||
import * as Errors from '../types/errors';
|
import * as Errors from '../types/errors';
|
||||||
|
|
||||||
export async function getMessagesById(
|
export async function getMessagesById(
|
||||||
messageIds: ReadonlyArray<string>
|
messageIds: Iterable<string>
|
||||||
): Promise<Array<MessageModel>> {
|
): Promise<Array<MessageModel>> {
|
||||||
const messagesFromMemory: Array<MessageModel> = [];
|
const messagesFromMemory: Array<MessageModel> = [];
|
||||||
const messageIdsToLookUpInDatabase: Array<string> = [];
|
const messageIdsToLookUpInDatabase: Array<string> = [];
|
||||||
|
|
||||||
messageIds.forEach(messageId => {
|
for (const messageId of messageIds) {
|
||||||
const message = window.MessageController.getById(messageId);
|
const message = window.MessageController.getById(messageId);
|
||||||
if (message) {
|
if (message) {
|
||||||
messagesFromMemory.push(message);
|
messagesFromMemory.push(message);
|
||||||
} else {
|
} else {
|
||||||
messageIdsToLookUpInDatabase.push(messageId);
|
messageIdsToLookUpInDatabase.push(messageId);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
let rawMessagesFromDatabase: Array<MessageAttributesType>;
|
let rawMessagesFromDatabase: Array<MessageAttributesType>;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -369,12 +369,17 @@ export const getConversationCallMode = (
|
||||||
return CallMode.None;
|
return CallMode.None;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const retryMessages = async (messageIds: Iterable<string>): Promise<void> => {
|
||||||
|
const messages = await getMessagesById(messageIds);
|
||||||
|
await Promise.all(messages.map(message => message.retrySend()));
|
||||||
|
};
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
|
|
||||||
|
const CLEAR_MESSAGES_PENDING_CONVERSATION_VERIFICATION =
|
||||||
|
'conversations/CLEAR_MESSAGES_PENDING_CONVERSATION_VERIFICATION';
|
||||||
export const COLORS_CHANGED = 'conversations/COLORS_CHANGED';
|
export const COLORS_CHANGED = 'conversations/COLORS_CHANGED';
|
||||||
export const COLOR_SELECTED = 'conversations/COLOR_SELECTED';
|
export const COLOR_SELECTED = 'conversations/COLOR_SELECTED';
|
||||||
const CANCEL_MESSAGES_PENDING_CONVERSATION_VERIFICATION =
|
|
||||||
'conversations/CANCEL_MESSAGES_PENDING_CONVERSATION_VERIFICATION';
|
|
||||||
const COMPOSE_TOGGLE_EDITING_AVATAR =
|
const COMPOSE_TOGGLE_EDITING_AVATAR =
|
||||||
'conversations/compose/COMPOSE_TOGGLE_EDITING_AVATAR';
|
'conversations/compose/COMPOSE_TOGGLE_EDITING_AVATAR';
|
||||||
const COMPOSE_ADD_AVATAR = 'conversations/compose/ADD_AVATAR';
|
const COMPOSE_ADD_AVATAR = 'conversations/compose/ADD_AVATAR';
|
||||||
|
@ -386,9 +391,6 @@ const MESSAGE_STOPPED_BY_MISSING_VERIFICATION =
|
||||||
const REPLACE_AVATARS = 'conversations/REPLACE_AVATARS';
|
const REPLACE_AVATARS = 'conversations/REPLACE_AVATARS';
|
||||||
const UPDATE_USERNAME_SAVE_STATE = 'conversations/UPDATE_USERNAME_SAVE_STATE';
|
const UPDATE_USERNAME_SAVE_STATE = 'conversations/UPDATE_USERNAME_SAVE_STATE';
|
||||||
|
|
||||||
type CancelMessagesPendingConversationVerificationActionType = {
|
|
||||||
type: typeof CANCEL_MESSAGES_PENDING_CONVERSATION_VERIFICATION;
|
|
||||||
};
|
|
||||||
type CantAddContactToGroupActionType = {
|
type CantAddContactToGroupActionType = {
|
||||||
type: 'CANT_ADD_CONTACT_TO_GROUP';
|
type: 'CANT_ADD_CONTACT_TO_GROUP';
|
||||||
payload: {
|
payload: {
|
||||||
|
@ -399,6 +401,9 @@ type ClearGroupCreationErrorActionType = { type: 'CLEAR_GROUP_CREATION_ERROR' };
|
||||||
type ClearInvitedUuidsForNewlyCreatedGroupActionType = {
|
type ClearInvitedUuidsForNewlyCreatedGroupActionType = {
|
||||||
type: 'CLEAR_INVITED_UUIDS_FOR_NEWLY_CREATED_GROUP';
|
type: 'CLEAR_INVITED_UUIDS_FOR_NEWLY_CREATED_GROUP';
|
||||||
};
|
};
|
||||||
|
type ClearMessagesPendingConversationVerificationActionType = {
|
||||||
|
type: typeof CLEAR_MESSAGES_PENDING_CONVERSATION_VERIFICATION;
|
||||||
|
};
|
||||||
type CloseCantAddContactToGroupModalActionType = {
|
type CloseCantAddContactToGroupModalActionType = {
|
||||||
type: 'CLOSE_CANT_ADD_CONTACT_TO_GROUP_MODAL';
|
type: 'CLOSE_CANT_ADD_CONTACT_TO_GROUP_MODAL';
|
||||||
};
|
};
|
||||||
|
@ -730,11 +735,11 @@ type ReplaceAvatarsActionType = {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
export type ConversationActionType =
|
export type ConversationActionType =
|
||||||
| CancelMessagesPendingConversationVerificationActionType
|
|
||||||
| CantAddContactToGroupActionType
|
| CantAddContactToGroupActionType
|
||||||
| ClearChangedMessagesActionType
|
| ClearChangedMessagesActionType
|
||||||
| ClearGroupCreationErrorActionType
|
| ClearGroupCreationErrorActionType
|
||||||
| ClearInvitedUuidsForNewlyCreatedGroupActionType
|
| ClearInvitedUuidsForNewlyCreatedGroupActionType
|
||||||
|
| ClearMessagesPendingConversationVerificationActionType
|
||||||
| ClearSelectedMessageActionType
|
| ClearSelectedMessageActionType
|
||||||
| ClearUnreadMetricsActionType
|
| ClearUnreadMetricsActionType
|
||||||
| CloseCantAddContactToGroupModalActionType
|
| CloseCantAddContactToGroupModalActionType
|
||||||
|
@ -1243,19 +1248,39 @@ function verifyConversationsStoppingMessageSend(): ThunkAction<
|
||||||
void,
|
void,
|
||||||
RootStateType,
|
RootStateType,
|
||||||
unknown,
|
unknown,
|
||||||
never
|
ClearMessagesPendingConversationVerificationActionType
|
||||||
> {
|
> {
|
||||||
return async (_dispatch, getState) => {
|
return async (dispatch, getState) => {
|
||||||
const conversationIds = Object.keys(
|
const { outboundMessagesPendingConversationVerification } =
|
||||||
getState().conversations.outboundMessagesPendingConversationVerification
|
getState().conversations;
|
||||||
|
|
||||||
|
const allMessageIds = new Set<string>();
|
||||||
|
const promises: Array<Promise<unknown>> = [];
|
||||||
|
|
||||||
|
Object.entries(outboundMessagesPendingConversationVerification).forEach(
|
||||||
|
([conversationId, messageIds]) => {
|
||||||
|
for (const messageId of messageIds) {
|
||||||
|
allMessageIds.add(messageId);
|
||||||
|
}
|
||||||
|
|
||||||
|
const conversation = window.ConversationController.get(conversationId);
|
||||||
|
if (!conversation) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (conversation.isUnverified()) {
|
||||||
|
promises.push(conversation.setVerifiedDefault());
|
||||||
|
}
|
||||||
|
promises.push(conversation.setApproved());
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
await Promise.all(
|
promises.push(retryMessages(allMessageIds));
|
||||||
conversationIds.map(async conversationId => {
|
|
||||||
const conversation = window.ConversationController.get(conversationId);
|
dispatch({
|
||||||
await conversation?.setVerifiedDefault();
|
type: CLEAR_MESSAGES_PENDING_CONVERSATION_VERIFICATION,
|
||||||
})
|
});
|
||||||
);
|
|
||||||
|
await Promise.all(promises);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1317,7 +1342,7 @@ function cancelMessagesPendingConversationVerification(): ThunkAction<
|
||||||
void,
|
void,
|
||||||
RootStateType,
|
RootStateType,
|
||||||
unknown,
|
unknown,
|
||||||
CancelMessagesPendingConversationVerificationActionType
|
ClearMessagesPendingConversationVerificationActionType
|
||||||
> {
|
> {
|
||||||
return async (dispatch, getState) => {
|
return async (dispatch, getState) => {
|
||||||
const messageIdsPending = getMessageIdsPendingBecauseOfVerification(
|
const messageIdsPending = getMessageIdsPendingBecauseOfVerification(
|
||||||
|
@ -1329,7 +1354,7 @@ function cancelMessagesPendingConversationVerification(): ThunkAction<
|
||||||
});
|
});
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: CANCEL_MESSAGES_PENDING_CONVERSATION_VERIFICATION,
|
type: CLEAR_MESSAGES_PENDING_CONVERSATION_VERIFICATION,
|
||||||
});
|
});
|
||||||
|
|
||||||
await window.Signal.Data.saveMessages(
|
await window.Signal.Data.saveMessages(
|
||||||
|
@ -1384,10 +1409,7 @@ function conversationChanged(
|
||||||
id
|
id
|
||||||
) ?? [];
|
) ?? [];
|
||||||
if (messageIdsPending.length) {
|
if (messageIdsPending.length) {
|
||||||
const messagesPending = await getMessagesById(messageIdsPending);
|
retryMessages(messageIdsPending);
|
||||||
messagesPending.forEach(message => {
|
|
||||||
message.retrySend();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2237,7 +2259,7 @@ export function reducer(
|
||||||
state: Readonly<ConversationsStateType> = getEmptyState(),
|
state: Readonly<ConversationsStateType> = getEmptyState(),
|
||||||
action: Readonly<ConversationActionType>
|
action: Readonly<ConversationActionType>
|
||||||
): ConversationsStateType {
|
): ConversationsStateType {
|
||||||
if (action.type === CANCEL_MESSAGES_PENDING_CONVERSATION_VERIFICATION) {
|
if (action.type === CLEAR_MESSAGES_PENDING_CONVERSATION_VERIFICATION) {
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
outboundMessagesPendingConversationVerification: {},
|
outboundMessagesPendingConversationVerification: {},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue