Replace rm in DataBoard.extend with properties of val set to undefined.

This commit is contained in:
ccd0 2019-04-03 23:35:33 -07:00
parent cc02b152ff
commit 9ab1c94e31
2 changed files with 9 additions and 6 deletions

View File

@ -350,11 +350,11 @@ ThreadWatcher =
else if @status is 404 else if @status is 404
if SW[software].mayLackJSON and !data.last? if SW[software].mayLackJSON and !data.last?
ThreadWatcher.db.extend {siteID, boardID, threadID, val: {last: -1}, rm: ['unread', 'quotingYou']} ThreadWatcher.db.extend {siteID, boardID, threadID, val: {last: -1, unread: undefined, quotingYou: undefined}}
else if Conf['Auto Prune'] else if Conf['Auto Prune']
ThreadWatcher.db.delete {siteID, boardID, threadID} ThreadWatcher.db.delete {siteID, boardID, threadID}
else else
ThreadWatcher.db.extend {siteID, boardID, threadID, val: {isDead: true}, rm: ['unread', 'quotingYou']} ThreadWatcher.db.extend {siteID, boardID, threadID, val: {isDead: true, unread: undefined, quotingYou: undefined}}
ThreadWatcher.refresh() ThreadWatcher.refresh()
@ -493,7 +493,7 @@ ThreadWatcher =
ThreadWatcher.db.delete {boardID, threadID} ThreadWatcher.db.delete {boardID, threadID}
return cb() return cb()
return cb() if data.isDead and not (data.unread? or data.quotingYou?) return cb() if data.isDead and not (data.unread? or data.quotingYou?)
ThreadWatcher.db.extend {boardID, threadID, val: {isDead: true}, rm: ['unread', 'quotingYou']}, cb ThreadWatcher.db.extend {boardID, threadID, val: {isDead: true, unread: undefined, quotingYou: undefined}}, cb
toggle: (thread) -> toggle: (thread) ->
siteID = Site.hostname siteID = Site.hostname

View File

@ -85,11 +85,14 @@ class DataBoard
else else
@data[siteID].boards[boardID] = val @data[siteID].boards[boardID] = val
extend: ({siteID, boardID, threadID, postID, val, rm}, cb) -> extend: ({siteID, boardID, threadID, postID, val}, cb) ->
@save => @save =>
oldVal = @get {siteID, boardID, threadID, postID, defaultValue: {}} oldVal = @get {siteID, boardID, threadID, postID, defaultValue: {}}
delete oldVal[key] for key in rm or [] for key, subVal of val
$.extend oldVal, val if subVal is undefined
delete oldVal[key]
else
oldVal[key] = subVal
@setUnsafe {siteID, boardID, threadID, postID, val: oldVal} @setUnsafe {siteID, boardID, threadID, postID, val: oldVal}
, cb , cb