Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/subscriptionClasses.js

Issue 29802575: Issue 6559 - Replace fromObject with fromMap (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created June 8, 2018, 1:59 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/filterStorage.js ('k') | test/filterClasses.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 return subscription; 172 return subscription;
173 173
174 if (url[0] != "~") 174 if (url[0] != "~")
175 return new DownloadableSubscription(url, null); 175 return new DownloadableSubscription(url, null);
176 return new SpecialSubscription(url); 176 return new SpecialSubscription(url);
177 }; 177 };
178 178
179 /** 179 /**
180 * Deserializes a subscription 180 * Deserializes a subscription
181 * 181 *
182 * @param {Object} obj 182 * @param {Map.<string,string>} map
183 * map of serialized properties and their values 183 * map of serialized properties and their values
184 * @return {Subscription} 184 * @return {Subscription}
185 * subscription or null if the subscription couldn't be created 185 * subscription or null if the subscription couldn't be created
186 */ 186 */
187 Subscription.fromObject = function(obj) 187 Subscription.fromMap = function(map)
188 { 188 {
189 let result; 189 let result;
190 if (obj.url[0] != "~") 190
191 let url = map.get("url");
192 let title = map.get("title");
193 if (url[0] != "~")
191 { 194 {
192 // URL is valid - this is a downloadable subscription 195 // URL is valid - this is a downloadable subscription
193 result = new DownloadableSubscription(obj.url, obj.title); 196 result = new DownloadableSubscription(url, title);
194 if ("downloadStatus" in obj) 197
195 result._downloadStatus = obj.downloadStatus; 198 let downloadStatus = map.get("downloadStatus");
196 if ("lastSuccess" in obj) 199 let lastSuccess = map.get("lastSuccess");
197 result.lastSuccess = parseInt(obj.lastSuccess, 10) || 0; 200 let lastCheck = map.get("lastCheck");
198 if ("lastCheck" in obj) 201 let expires = map.get("expires");
199 result._lastCheck = parseInt(obj.lastCheck, 10) || 0; 202 let softExpiration = map.get("softExpiration");
200 if ("expires" in obj) 203 let errors = map.get("errors");
201 result.expires = parseInt(obj.expires, 10) || 0; 204 let version = map.get("version");
202 if ("softExpiration" in obj) 205 let requiredVersion = map.get("requiredVersion");
203 result.softExpiration = parseInt(obj.softExpiration, 10) || 0; 206 let homepage = map.get("homepage");
204 if ("errors" in obj) 207 let lastDownload = map.get("lastDownload");
205 result._errors = parseInt(obj.errors, 10) || 0; 208 let downloadCount = map.get("downloadCount");
206 if ("version" in obj) 209 if (typeof downloadStatus != "undefined")
207 result.version = parseInt(obj.version, 10) || 0; 210 result._downloadStatus = downloadStatus;
208 if ("requiredVersion" in obj) 211 if (typeof lastSuccess != "undefined")
209 result.requiredVersion = obj.requiredVersion; 212 result.lastSuccess = parseInt(lastSuccess, 10) || 0;
210 if ("homepage" in obj) 213 if (typeof lastCheck != "undefined")
211 result._homepage = obj.homepage; 214 result._lastCheck = parseInt(lastCheck, 10) || 0;
212 if ("lastDownload" in obj) 215 if (typeof expires != "undefined")
213 result._lastDownload = parseInt(obj.lastDownload, 10) || 0; 216 result.expires = parseInt(expires, 10) || 0;
214 if ("downloadCount" in obj) 217 if (typeof softExpiration != "undefined")
215 result.downloadCount = parseInt(obj.downloadCount, 10) || 0; 218 result.softExpiration = parseInt(softExpiration, 10) || 0;
219 if (typeof errors != "undefined")
220 result._errors = parseInt(errors, 10) || 0;
221 if (typeof version != "undefined")
222 result.version = parseInt(version, 10) || 0;
223 if (typeof requiredVersion != "undefined")
224 result.requiredVersion = requiredVersion;
225 if (typeof homepage != "undefined")
226 result._homepage = homepage;
227 if (typeof lastDownload != "undefined")
228 result._lastDownload = parseInt(lastDownload, 10) || 0;
229 if (typeof downloadCount != "undefined")
230 result.downloadCount = parseInt(downloadCount, 10) || 0;
216 } 231 }
217 else 232 else
218 { 233 {
219 result = new SpecialSubscription(obj.url, obj.title); 234 result = new SpecialSubscription(url, title);
220 if ("defaults" in obj) 235
221 result.defaults = obj.defaults.split(" "); 236 let defaults = map.get("defaults");
237 if (typeof defaults != "undefined")
238 result.defaults = defaults.split(" ");
222 } 239 }
223 if ("fixedTitle" in obj) 240
224 result._fixedTitle = (obj.fixedTitle == "true"); 241 let fixedTitle = map.get("fixedTitle");
225 if ("disabled" in obj) 242 let disabled = map.get("disabled");
226 result._disabled = (obj.disabled == "true"); 243 if (typeof fixedTitle != "undefined")
244 result._fixedTitle = (fixedTitle == "true");
245 if (typeof disabled != "undefined")
246 result._disabled = (disabled == "true");
227 247
228 return result; 248 return result;
229 }; 249 };
230 250
231 /** 251 /**
232 * Class for special filter subscriptions (user's filters) 252 * Class for special filter subscriptions (user's filters)
233 * @param {string} url see Subscription() 253 * @param {string} url see Subscription()
234 * @param {string} [title] see Subscription() 254 * @param {string} [title] see Subscription()
235 * @constructor 255 * @constructor
236 * @augments Subscription 256 * @augments Subscription
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 if (this.errors) 586 if (this.errors)
567 buffer.push("errors=" + this.errors); 587 buffer.push("errors=" + this.errors);
568 if (this.version) 588 if (this.version)
569 buffer.push("version=" + this.version); 589 buffer.push("version=" + this.version);
570 if (this.requiredVersion) 590 if (this.requiredVersion)
571 buffer.push("requiredVersion=" + this.requiredVersion); 591 buffer.push("requiredVersion=" + this.requiredVersion);
572 if (this.downloadCount) 592 if (this.downloadCount)
573 buffer.push("downloadCount=" + this.downloadCount); 593 buffer.push("downloadCount=" + this.downloadCount);
574 } 594 }
575 }); 595 });
OLDNEW
« no previous file with comments | « lib/filterStorage.js ('k') | test/filterClasses.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld