Refactor settings conversion from loadletter.

This commit is contained in:
ccd0 2015-08-22 06:40:21 -07:00
parent dcc5e4973d
commit b1e095d18a
2 changed files with 12 additions and 14 deletions

View File

@ -183,9 +183,8 @@ Settings =
c.error err.stack c.error err.stack
reader.readAsText file reader.readAsText file
loadSettings: (data, cb) -> convertFrom:
version = data.version.split '.' loadletter: (data) ->
if version[0] is '2'
convertSettings = (data, map) -> convertSettings = (data, map) ->
for prevKey, newKey of map for prevKey, newKey of map
data.Conf[newKey] = data.Conf[prevKey] if newKey data.Conf[newKey] = data.Conf[prevKey] if newKey
@ -261,10 +260,16 @@ Settings =
for key, val of Config.hotkeys when key of data.Conf for key, val of Config.hotkeys when key of data.Conf
data.Conf[key] = data.Conf[key].replace(/ctrl|alt|meta/g, (s) -> "#{s[0].toUpperCase()}#{s[1..]}").replace /(^|.+\+)[A-Z]$/g, (s) -> data.Conf[key] = data.Conf[key].replace(/ctrl|alt|meta/g, (s) -> "#{s[0].toUpperCase()}#{s[1..]}").replace /(^|.+\+)[A-Z]$/g, (s) ->
"Shift+#{s[0...-1]}#{s[-1..].toLowerCase()}" "Shift+#{s[0...-1]}#{s[-1..].toLowerCase()}"
data.Conf['WatchedThreads'] = data.WatchedThreads if data.WatchedThreads
if data.Conf['WatchedThreads'] data.Conf['watchedThreads'] = boards: {}
data.Conf['watchedThreads'] = boards: ThreadWatcher.convert data.Conf['WatchedThreads'] for boardID, threads of data.WatchedThreads
delete data.Conf['WatchedThreads'] for threadID, threadData of threads
(data.Conf['watchedThreads'].boards[boardID] or= {})[threadID] = excerpt: threadData.textContent
data
loadSettings: (data, cb) ->
if data.version.split('.')[0] is '2' # https://github.com/loadletter/4chan-x
data = Settings.convertFrom.loadletter data
$.clear (err) -> $.clear (err) ->
return cb err if err return cb err if err
$.set data.Conf, cb $.set data.Conf, cb

View File

@ -401,13 +401,6 @@ ThreadWatcher =
ThreadWatcher.db.delete {boardID, threadID} ThreadWatcher.db.delete {boardID, threadID}
ThreadWatcher.refresh() ThreadWatcher.refresh()
convert: (oldFormat) ->
newFormat = {}
for boardID, threads of oldFormat
for threadID, data of threads
(newFormat[boardID] or= {})[threadID] = excerpt: data.textContent
newFormat
menu: menu:
refreshers: [] refreshers: []
init: -> init: ->