Skip to content

Commit 55a92ca

Browse files
committed
Add closed:note changeset tag for closed OSM notes
1 parent 46dd90c commit 55a92ca

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

modules/services/osm.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var oauth = osmAuth({
4747

4848
var _blacklists = ['.*\.google(apis)?\..*/(vt|kh)[\?/].*([xyz]=.*){3}.*'];
4949
var _tileCache = { loaded: {}, inflight: {}, seen: {} };
50-
var _noteCache = { loaded: {}, inflight: {}, inflightPost: {}, note: {}, rtree: rbush() };
50+
var _noteCache = { loaded: {}, inflight: {}, inflightPost: {}, note: {}, closed: {}, rtree: rbush() };
5151
var _userCache = { toLoad: {}, user: {} };
5252
var _changeset = {};
5353

@@ -385,7 +385,7 @@ export default {
385385
if (_changeset.inflight) abortRequest(_changeset.inflight);
386386

387387
_tileCache = { loaded: {}, inflight: {}, seen: {} };
388-
_noteCache = { loaded: {}, inflight: {}, inflightPost: {}, note: {}, rtree: rbush() };
388+
_noteCache = { loaded: {}, inflight: {}, inflightPost: {}, note: {}, closed: {}, rtree: rbush() };
389389
_userCache = { toLoad: {}, user: {} };
390390
_changeset = {};
391391

@@ -956,6 +956,13 @@ export default {
956956
// we get the updated note back, remove from caches and reparse..
957957
this.removeNote(note);
958958

959+
// update closed note cache - used to populate `closed:note` changeset tag
960+
if (action === 'close') {
961+
_noteCache.closed[note.id] = true;
962+
} else if (action === 'reopen') {
963+
delete _noteCache.closed[note.id];
964+
}
965+
959966
var options = { skipSeen: false };
960967
return parseXML(xml, function(err, results) {
961968
if (err) {
@@ -1118,6 +1125,13 @@ export default {
11181125
_noteCache.note[note.id] = note;
11191126
updateRtree(encodeNoteRtree(note), true); // true = replace
11201127
return note;
1128+
},
1129+
1130+
1131+
// Get an array of note IDs closed during this session.
1132+
// Used to populate `closed:note` changeset tag
1133+
getClosedIDs: function() {
1134+
return Object.keys(_noteCache.closed).sort();
11211135
}
11221136

11231137
};

modules/ui/commit.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ export function uiCommit(context) {
6464
}
6565

6666
var tags;
67+
// Initialize changeset if one does not exist yet.
68+
// Also pull values from local storage.
6769
if (!_changeset) {
6870
var detected = utilDetect();
6971
tags = {
@@ -82,13 +84,9 @@ export function uiCommit(context) {
8284
tags.hashtags = hashtags;
8385
}
8486

85-
// iD 2.8.1 could write a literal 'undefined' here.. see #5021
86-
// (old source values expire after 2 days, so 'undefined' checks can go away in v2.9)
8787
var source = context.storage('source');
88-
if (source && source !== 'undefined') {
88+
if (source) {
8989
tags.source = source;
90-
} else if (source === 'undefined') {
91-
context.storage('source', null);
9290
}
9391

9492
_changeset = new osmChangeset({ tags: tags });
@@ -101,6 +99,10 @@ export function uiCommit(context) {
10199
tags.imagery_used = imageryUsed || 'None';
102100

103101
// assign tags for closed issues and notes
102+
var osmClosed = osm.getClosedIDs();
103+
if (osmClosed.length) {
104+
tags['closed:note'] = osmClosed.join(';').substr(0, 255);
105+
}
104106
if (services.keepRight) {
105107
var krClosed = services.keepRight.getClosedIDs();
106108
if (krClosed.length) {

0 commit comments

Comments
 (0)