MCPcopy Create free account
hub / github.com/facebook/Rapid / initChangeset

Function initChangeset

modules/ui/commit.js:70–124  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

68 // Creates an initial changeset
69 //
70 function initChangeset() {
71 const localeCode = l10n.localeCode();
72
73 // Expire stored comment, hashtags, source after cutoff datetime - iD#3947 iD#4899
74 const commentDate = +storage.getItem('commentDate') || 0;
75 const currDate = Date.now();
76 const cutoff = 2 * 86400 * 1000; // 2 days
77 if (commentDate > currDate || currDate - commentDate > cutoff) {
78 storage.removeItem('comment');
79 storage.removeItem('hashtags');
80 storage.removeItem('source');
81 }
82
83 // Override with any `comment`,`source`,`hashtags` that we got from the urlhash, if any
84 const defaultChangesetComment = urlhash.initialHashParams.get('comment');
85 const defaultChangesetSource = urlhash.initialHashParams.get('source');
86 const defaultChangesetHashtags = urlhash.initialHashParams.get('hashtags');
87
88 if (defaultChangesetComment) {
89 storage.setItem('comment', defaultChangesetComment);
90 storage.setItem('commentDate', Date.now());
91 }
92 if (defaultChangesetSource) {
93 storage.setItem('source', defaultChangesetSource);
94 storage.setItem('commentDate', Date.now());
95 }
96 if (defaultChangesetHashtags) {
97 storage.setItem('hashtags', defaultChangesetHashtags);
98 storage.setItem('commentDate', Date.now());
99 }
100
101 const detected = utilDetect();
102 const tags = {
103 comment: storage.getItem('comment') || '',
104 created_by: context.cleanTagValue('Rapid ' + context.version),
105 host: context.cleanTagValue(detected.host),
106 locale: context.cleanTagValue(localeCode)
107 };
108
109 // Call findHashtags initially - this will remove stored
110 // hashtags if any hashtags are found in the comment - iD#4304
111 findHashtags(tags, true);
112
113 const hashtags = storage.getItem('hashtags');
114 if (hashtags) {
115 tags.hashtags = hashtags;
116 }
117
118 const source = storage.getItem('source');
119 if (source) {
120 tags.source = source;
121 }
122
123 uploader.changeset = new osmChangeset({ tags: tags });
124 }
125
126
127 //

Callers 1

commitFunction · 0.85

Calls 8

utilDetectFunction · 0.90
findHashtagsFunction · 0.85
getMethod · 0.80
localeCodeMethod · 0.45
getItemMethod · 0.45
removeItemMethod · 0.45
setItemMethod · 0.45
cleanTagValueMethod · 0.45

Tested by

no test coverage detected