Stories/lists management for removed contact

This commit is contained in:
Fedor Indutny 2023-07-21 22:01:12 +02:00 committed by GitHub
parent 7340ea64b9
commit 2601197888
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 69 additions and 0 deletions

View file

@ -965,6 +965,14 @@ export class ConversationModel extends window.Backbone
shouldSave: false,
});
window.reduxActions?.stories.removeAllContactStories(this.id);
const uuid = this.get('uuid');
if (uuid) {
window.reduxActions?.storyDistributionLists.removeMemberFromAllDistributionLists(
uuid
);
}
// Add notification
drop(this.queueJob('removeContact', () => this.maybeSetContactRemoved()));

View file

@ -1365,6 +1365,45 @@ function setStoriesDisabled(
};
}
function removeAllContactStories(
conversationId: string
): ThunkAction<void, RootStateType, unknown, NoopActionType> {
return async (dispatch, getState) => {
const logId = `removeAllContactStories(${conversationId})`;
const { stories } = getState().stories;
const messageIds = stories
.filter(item => item.conversationId === conversationId)
.map(({ messageId }) => messageId);
const messages = (
await Promise.all(
messageIds.map(async messageId => {
const message = await getMessageById(messageId);
if (!message) {
log.warn(`${logId}: no message found ${messageId}`);
return;
}
return message;
})
)
).filter(isNotNil);
log.info(`${logId}: removing ${messages.length} stories`);
await Promise.all([
messages.map(m => m.cleanup()),
await dataInterface.removeMessages(messageIds),
]);
dispatch({
type: 'NOOP',
payload: null,
});
};
}
export const actions = {
deleteStoryForEveryone,
loadStoryReplies,
@ -1386,6 +1425,7 @@ export const actions = {
setStoriesDisabled,
setHasAllStoriesUnmuted,
setStorySending,
removeAllContactStories,
};
export const useStoriesActions = (): BoundActionCreatorsMapObject<

View file

@ -481,6 +481,26 @@ function updateStoryViewers(
};
}
function removeMemberFromAllDistributionLists(
member: UUIDStringType
): ThunkAction<void, RootStateType, null, ModifyListActionType> {
return async dispatch => {
const logId = `removeMemberFromAllDistributionLists(${member})`;
const lists = await dataInterface.getAllStoryDistributionsWithMembers();
const listsWithMember = lists.filter(({ members }) =>
members.includes(member)
);
log.info(
`${logId}: removing ${member} from ${listsWithMember.length} lists`
);
for (const { id } of listsWithMember) {
dispatch(removeMembersFromDistributionList(id, [member]));
}
};
}
export const actions = {
allowsRepliesChanged,
createDistributionList,
@ -488,6 +508,7 @@ export const actions = {
hideMyStoriesFrom,
modifyDistributionList,
removeMembersFromDistributionList,
removeMemberFromAllDistributionLists,
setMyStoriesToAllSignalConnections,
updateStoryViewers,
};