2018-03-11 01:21:10 +01:00
|
|
|
import { getIdsThatRebloggedThisStatus, getNotificationIdsForStatuses } from './statuses'
|
2018-02-17 04:38:21 +01:00
|
|
|
import { store } from '../_store/store'
|
|
|
|
import { scheduleIdleTask } from '../_utils/scheduleIdleTask'
|
|
|
|
import { database } from '../_database/database'
|
2018-03-11 01:21:10 +01:00
|
|
|
import forEach from 'lodash/forEach'
|
2018-02-17 04:38:21 +01:00
|
|
|
|
|
|
|
function deleteStatusIdsFromStore (instanceName, idsToDelete) {
|
|
|
|
let idsToDeleteSet = new Set(idsToDelete)
|
2018-03-11 01:21:10 +01:00
|
|
|
let idWasNotDeleted = id => !idsToDeleteSet.has(id)
|
|
|
|
|
|
|
|
let timelinesToTimelineItemIds = store.getAllTimelineData(instanceName, 'timelineItemIds')
|
|
|
|
|
|
|
|
forEach(timelinesToTimelineItemIds, (timelineItemIds, timelineName) => {
|
|
|
|
store.setForTimeline(instanceName, timelineName, {
|
|
|
|
timelineItemIds: timelineItemIds.filter(idWasNotDeleted)
|
2018-02-17 04:38:21 +01:00
|
|
|
})
|
2018-03-11 01:21:10 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
let timelinesToItemIdsToAdd = store.getAllTimelineData(instanceName, 'itemIdsToAdd')
|
|
|
|
|
|
|
|
forEach(timelinesToItemIdsToAdd, (itemIdsToAdd, timelineName) => {
|
|
|
|
store.setForTimeline(instanceName, timelineName, {
|
|
|
|
itemIdsToAdd: itemIdsToAdd.filter(idWasNotDeleted)
|
|
|
|
})
|
|
|
|
})
|
2018-02-17 04:38:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async function deleteStatusesAndNotifications (instanceName, statusIdsToDelete, notificationIdsToDelete) {
|
|
|
|
deleteStatusIdsFromStore(instanceName, statusIdsToDelete)
|
|
|
|
await database.deleteStatusesAndNotifications(instanceName, statusIdsToDelete, notificationIdsToDelete)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function doDeleteStatus (instanceName, statusId) {
|
2018-03-11 01:21:10 +01:00
|
|
|
console.log('deleting statusId', statusId)
|
|
|
|
let rebloggedIds = await getIdsThatRebloggedThisStatus(instanceName, statusId)
|
|
|
|
let statusIdsToDelete = Array.from(new Set([statusId].concat(rebloggedIds).filter(Boolean)))
|
2018-02-17 04:38:21 +01:00
|
|
|
let notificationIdsToDelete = new Set(await getNotificationIdsForStatuses(instanceName, statusIdsToDelete))
|
2018-03-11 05:24:07 +01:00
|
|
|
await deleteStatusesAndNotifications(instanceName, statusIdsToDelete, notificationIdsToDelete)
|
2018-02-17 04:38:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function deleteStatus (instanceName, statusId) {
|
|
|
|
scheduleIdleTask(() => {
|
|
|
|
/* no await */ doDeleteStatus(instanceName, statusId)
|
|
|
|
})
|
|
|
|
}
|