Add no-misused/floating-promises lint rule
This commit is contained in:
parent
1a68c3db62
commit
ed271d92ea
150 changed files with 1296 additions and 991 deletions
|
@ -12,6 +12,7 @@ import { isStory } from '../state/selectors/message';
|
|||
import { normalizeUuid } from './normalizeUuid';
|
||||
import { queueUpdateMessage } from './messageBatcher';
|
||||
import { isMe } from './whatTypeOfConversation';
|
||||
import { drop } from './drop';
|
||||
|
||||
export async function onStoryRecipientUpdate(
|
||||
event: StoryRecipientUpdateEvent
|
||||
|
@ -45,156 +46,161 @@ export async function onStoryRecipientUpdate(
|
|||
return;
|
||||
}
|
||||
|
||||
targetConversation.queueJob(logId, async () => {
|
||||
log.info(`${logId}: updating`);
|
||||
drop(
|
||||
targetConversation.queueJob(logId, async () => {
|
||||
log.info(`${logId}: updating`);
|
||||
|
||||
// Build up some maps for fast/easy lookups
|
||||
const isAllowedToReply = new Map<string, boolean>();
|
||||
const distributionListIdToConversationIds = new Map<string, Set<string>>();
|
||||
data.storyMessageRecipients.forEach(item => {
|
||||
if (!item.destinationUuid) {
|
||||
return;
|
||||
}
|
||||
|
||||
const convo = window.ConversationController.get(
|
||||
normalizeUuid(item.destinationUuid, `${logId}.destinationUuid`)
|
||||
);
|
||||
|
||||
if (!convo || !item.distributionListIds) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const rawUuid of item.distributionListIds) {
|
||||
const uuid = normalizeUuid(rawUuid, `${logId}.distributionListId`);
|
||||
|
||||
const existing = distributionListIdToConversationIds.get(uuid);
|
||||
if (existing === undefined) {
|
||||
distributionListIdToConversationIds.set(uuid, new Set([convo.id]));
|
||||
} else {
|
||||
existing.add(convo.id);
|
||||
// Build up some maps for fast/easy lookups
|
||||
const isAllowedToReply = new Map<string, boolean>();
|
||||
const distributionListIdToConversationIds = new Map<
|
||||
string,
|
||||
Set<string>
|
||||
>();
|
||||
data.storyMessageRecipients.forEach(item => {
|
||||
if (!item.destinationUuid) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
isAllowedToReply.set(convo.id, item.isAllowedToReply !== false);
|
||||
});
|
||||
|
||||
const ourConversationId =
|
||||
window.ConversationController.getOurConversationIdOrThrow();
|
||||
const now = Date.now();
|
||||
const convo = window.ConversationController.get(
|
||||
normalizeUuid(item.destinationUuid, `${logId}.destinationUuid`)
|
||||
);
|
||||
|
||||
const messages = await window.Signal.Data.getMessagesBySentAt(timestamp);
|
||||
|
||||
// Now we figure out who needs to be added and who needs to removed
|
||||
const handledMessages = messages.filter(item => {
|
||||
if (!isStory(item)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const { sendStateByConversationId, storyDistributionListId } = item;
|
||||
|
||||
if (!sendStateByConversationId || !storyDistributionListId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const newConversationIds =
|
||||
distributionListIdToConversationIds.get(storyDistributionListId) ??
|
||||
new Set();
|
||||
|
||||
const nextSendStateByConversationId = {
|
||||
...sendStateByConversationId,
|
||||
};
|
||||
|
||||
// Find conversation ids present in the local send state, but missing
|
||||
// in the remote state, and remove them from the local state.
|
||||
for (const oldId of Object.keys(sendStateByConversationId)) {
|
||||
if (!newConversationIds.has(oldId)) {
|
||||
const recipient = window.ConversationController.get(oldId);
|
||||
|
||||
const recipientLogId = recipient
|
||||
? getConversationIdForLogging(recipient.attributes)
|
||||
: oldId;
|
||||
|
||||
log.info(`${logId}: removing`, {
|
||||
recipient: recipientLogId,
|
||||
messageId: item.id,
|
||||
storyDistributionListId,
|
||||
});
|
||||
delete nextSendStateByConversationId[oldId];
|
||||
if (!convo || !item.distributionListIds) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Find conversation ids present in the remote send state, but missing in
|
||||
// the local send state, and add them to the local state.
|
||||
for (const newId of newConversationIds) {
|
||||
if (sendStateByConversationId[newId] === undefined) {
|
||||
const recipient = window.ConversationController.get(newId);
|
||||
for (const rawUuid of item.distributionListIds) {
|
||||
const uuid = normalizeUuid(rawUuid, `${logId}.distributionListId`);
|
||||
|
||||
const recipientLogId = recipient
|
||||
? getConversationIdForLogging(recipient.attributes)
|
||||
: newId;
|
||||
|
||||
log.info(`${logId}: adding`, {
|
||||
recipient: recipientLogId,
|
||||
messageId: item.id,
|
||||
storyDistributionListId,
|
||||
});
|
||||
nextSendStateByConversationId[newId] = {
|
||||
isAllowedToReplyToStory: Boolean(isAllowedToReply.get(newId)),
|
||||
status: SendStatus.Sent,
|
||||
updatedAt: now,
|
||||
};
|
||||
const existing = distributionListIdToConversationIds.get(uuid);
|
||||
if (existing === undefined) {
|
||||
distributionListIdToConversationIds.set(uuid, new Set([convo.id]));
|
||||
} else {
|
||||
existing.add(convo.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
isAllowedToReply.set(convo.id, item.isAllowedToReply !== false);
|
||||
});
|
||||
|
||||
if (isEqual(sendStateByConversationId, nextSendStateByConversationId)) {
|
||||
log.info(`${logId}: sendStateByConversationId does not need update`, {
|
||||
messageId: item.id,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
const ourConversationId =
|
||||
window.ConversationController.getOurConversationIdOrThrow();
|
||||
const now = Date.now();
|
||||
|
||||
const message = window.MessageController.register(item.id, item);
|
||||
const messages = await window.Signal.Data.getMessagesBySentAt(timestamp);
|
||||
|
||||
const sendStateConversationIds = new Set(
|
||||
Object.keys(nextSendStateByConversationId)
|
||||
);
|
||||
// Now we figure out who needs to be added and who needs to removed
|
||||
const handledMessages = messages.filter(item => {
|
||||
if (!isStory(item)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
sendStateConversationIds.size === 0 ||
|
||||
(sendStateConversationIds.size === 1 &&
|
||||
sendStateConversationIds.has(ourConversationId))
|
||||
) {
|
||||
log.info(`${logId} DOE`, {
|
||||
messageId: item.id,
|
||||
storyDistributionListId,
|
||||
});
|
||||
const delAttributes: DeleteAttributesType = {
|
||||
fromId: ourConversationId,
|
||||
serverTimestamp: Number(item.serverTimestamp),
|
||||
targetSentTimestamp: item.timestamp,
|
||||
const { sendStateByConversationId, storyDistributionListId } = item;
|
||||
|
||||
if (!sendStateByConversationId || !storyDistributionListId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const newConversationIds =
|
||||
distributionListIdToConversationIds.get(storyDistributionListId) ??
|
||||
new Set();
|
||||
|
||||
const nextSendStateByConversationId = {
|
||||
...sendStateByConversationId,
|
||||
};
|
||||
const doe = new DeleteModel(delAttributes);
|
||||
|
||||
// There are no longer any remaining members for this message so lets
|
||||
// run it through deleteForEveryone which marks the message as
|
||||
// deletedForEveryone locally.
|
||||
//
|
||||
// NOTE: We don't call `Deletes.onDelete()` so the message lookup by
|
||||
// sent timestamp doesn't happen (it would return all copies of the
|
||||
// story, not just the one we want to delete).
|
||||
message.handleDeleteForEveryone(doe);
|
||||
} else {
|
||||
message.set({
|
||||
sendStateByConversationId: nextSendStateByConversationId,
|
||||
});
|
||||
queueUpdateMessage(message.attributes);
|
||||
// Find conversation ids present in the local send state, but missing
|
||||
// in the remote state, and remove them from the local state.
|
||||
for (const oldId of Object.keys(sendStateByConversationId)) {
|
||||
if (!newConversationIds.has(oldId)) {
|
||||
const recipient = window.ConversationController.get(oldId);
|
||||
|
||||
const recipientLogId = recipient
|
||||
? getConversationIdForLogging(recipient.attributes)
|
||||
: oldId;
|
||||
|
||||
log.info(`${logId}: removing`, {
|
||||
recipient: recipientLogId,
|
||||
messageId: item.id,
|
||||
storyDistributionListId,
|
||||
});
|
||||
delete nextSendStateByConversationId[oldId];
|
||||
}
|
||||
}
|
||||
|
||||
// Find conversation ids present in the remote send state, but missing in
|
||||
// the local send state, and add them to the local state.
|
||||
for (const newId of newConversationIds) {
|
||||
if (sendStateByConversationId[newId] === undefined) {
|
||||
const recipient = window.ConversationController.get(newId);
|
||||
|
||||
const recipientLogId = recipient
|
||||
? getConversationIdForLogging(recipient.attributes)
|
||||
: newId;
|
||||
|
||||
log.info(`${logId}: adding`, {
|
||||
recipient: recipientLogId,
|
||||
messageId: item.id,
|
||||
storyDistributionListId,
|
||||
});
|
||||
nextSendStateByConversationId[newId] = {
|
||||
isAllowedToReplyToStory: Boolean(isAllowedToReply.get(newId)),
|
||||
status: SendStatus.Sent,
|
||||
updatedAt: now,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (isEqual(sendStateByConversationId, nextSendStateByConversationId)) {
|
||||
log.info(`${logId}: sendStateByConversationId does not need update`, {
|
||||
messageId: item.id,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
const message = window.MessageController.register(item.id, item);
|
||||
|
||||
const sendStateConversationIds = new Set(
|
||||
Object.keys(nextSendStateByConversationId)
|
||||
);
|
||||
|
||||
if (
|
||||
sendStateConversationIds.size === 0 ||
|
||||
(sendStateConversationIds.size === 1 &&
|
||||
sendStateConversationIds.has(ourConversationId))
|
||||
) {
|
||||
log.info(`${logId} DOE`, {
|
||||
messageId: item.id,
|
||||
storyDistributionListId,
|
||||
});
|
||||
const delAttributes: DeleteAttributesType = {
|
||||
fromId: ourConversationId,
|
||||
serverTimestamp: Number(item.serverTimestamp),
|
||||
targetSentTimestamp: item.timestamp,
|
||||
};
|
||||
const doe = new DeleteModel(delAttributes);
|
||||
|
||||
// There are no longer any remaining members for this message so lets
|
||||
// run it through deleteForEveryone which marks the message as
|
||||
// deletedForEveryone locally.
|
||||
//
|
||||
// NOTE: We don't call `Deletes.onDelete()` so the message lookup by
|
||||
// sent timestamp doesn't happen (it would return all copies of the
|
||||
// story, not just the one we want to delete).
|
||||
void message.handleDeleteForEveryone(doe);
|
||||
} else {
|
||||
message.set({
|
||||
sendStateByConversationId: nextSendStateByConversationId,
|
||||
});
|
||||
queueUpdateMessage(message.attributes);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
if (handledMessages.length) {
|
||||
window.Whisper.events.trigger('incrementProgress');
|
||||
confirm();
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
if (handledMessages.length) {
|
||||
window.Whisper.events.trigger('incrementProgress');
|
||||
confirm();
|
||||
}
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue