mapcomplete/Logic/Osm/Actions/DeleteAction.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

67 lines
2.1 KiB
TypeScript
Raw Normal View History

import {OsmObject} from "../OsmObject"
import OsmChangeAction from "./OsmChangeAction"
import {Changes} from "../Changes"
import {ChangeDescription} from "./ChangeDescription"
import ChangeTagAction from "./ChangeTagAction"
import {TagsFilter} from "../../Tags/TagsFilter"
import {And} from "../../Tags/And"
import {Tag} from "../../Tags/Tag"
import {Utils} from "../../../Utils";
export default class DeleteAction extends OsmChangeAction {
private readonly _softDeletionTags: TagsFilter
private readonly meta: {
theme: string
specialMotivation: string
changeType: "deletion"
}
private readonly _id: string
private _hardDelete: boolean
2022-09-08 21:40:48 +02:00
constructor(
id: string,
softDeletionTags: TagsFilter,
meta: {
theme: string
specialMotivation: string
},
hardDelete: boolean
) {
2022-01-26 21:40:38 +01:00
super(id, true)
this._id = id
this._hardDelete = hardDelete
this.meta = {...meta, changeType: "deletion"}
if (softDeletionTags?.usedKeys()?.indexOf("fixme") >= 0) {
this._softDeletionTags = softDeletionTags
} else {
this._softDeletionTags = new And(Utils.NoNull([
softDeletionTags,
new Tag(
"fixme",
`A mapcomplete user marked this feature to be deleted (${meta.specialMotivation})`
),
]))
}
}
2021-12-23 03:36:03 +01:00
public async CreateChangeDescriptions(changes: Changes): Promise<ChangeDescription[]> {
const osmObject = await OsmObject.DownloadObjectAsync(this._id)
if (this._hardDelete) {
return [
{
meta: this.meta,
doDelete: true,
type: osmObject.type,
id: osmObject.id,
2022-09-08 21:40:48 +02:00
},
]
} else {
return await new ChangeTagAction(this._id, this._softDeletionTags, osmObject.tags, {
2022-01-26 21:40:38 +01:00
...this.meta,
changeType: "soft-delete",
}).CreateChangeDescriptions(changes)
}
}
}