@@ -10,6 +10,7 @@ import Foundation
1010import osmparser
1111import MapKit
1212import osmapi
13+ import RealmSwift
1314
1415
1516// Class that handles data handling and display of annotations
@@ -135,6 +136,56 @@ class AppQuestManager {
135136 let unitsToBeDisplayed = displayUnits. filter { !hiddenIds. contains ( $0. id) }
136137 return unitsToBeDisplayed
137138 }
139+
140+ // FIXME: Make this function better
141+ // Fetches the quest for a specific changeset based on the element
142+ // If there is no need to show the element after undo, it will return nil
143+ func fetchQuestForChangeset( storedChangesetId: String ) -> DisplayUnitWithCoordinate ? {
144+ if let changeset = dbInstance. getChangeset ( for: storedChangesetId) {
145+ // Get the element based on the changeset
146+ let storedElementId = changeset. elementId
147+ let storedElementType = changeset. elementType
148+ var parserElement : osmparser . Element ? = nil
149+ if ( storedElementType == . node) {
150+ let storedElement = dbInstance. getNode ( id: storedElementId, version: . original)
151+ parserElement = storedElement? . asNode ( )
152+ }
153+ else if ( storedElementType == . way) {
154+ let storedElement = dbInstance. getWay ( id: storedElementId, version: . original)
155+ parserElement = storedElement? . asWay ( )
156+ }
157+ if let parserElement = parserElement {
158+ let allQuests = QuestsRepository . shared. applicableQuests
159+ for quest in allQuests {
160+ if quest. quest. filter. isEmpty {
161+ continue
162+ }
163+ if quest. quest. isApplicable ( element: parserElement) {
164+ let duplicateQuest = quest. quest. copyWithElement ( element: parserElement)
165+ // Assign stuff based on the type of element
166+ if parserElement. type == . node {
167+ if let nodObj = parserElement as? osmparser . Node {
168+ let unit = DisplayUnitWithCoordinate ( displayUnit: duplicateQuest. displayUnit, coordinateInfo: CLLocationCoordinate2D ( latitude: nodObj. position. latitude, longitude: nodObj. position. longitude) , id: nodObj. id, isHidden: false )
169+ return unit
170+ }
171+
172+ }
173+ else if parserElement. type == . way {
174+ let position = dbInstance. getCenterForWay ( id: String ( parserElement. id) ) ?? CLLocationCoordinate2D ( )
175+ let unit = DisplayUnitWithCoordinate ( displayUnit: duplicateQuest. displayUnit, coordinateInfo: position, id: parserElement. id, isHidden: false )
176+ return unit
177+ }
178+
179+ }
180+ }
181+
182+ }
183+
184+
185+
186+ }
187+ return nil
188+ }
138189}
139190
140191
0 commit comments