From a0c4d86deeb9e70c9722c4f69e48c0fbdd775881 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Thu, 4 Apr 2013 23:05:30 +0200 Subject: [PATCH] Delete entire boards from DataBoards when cleaning it gives us a 404. This would happen when a board gets deleted, like /s4s/ hopefully one day. --- src/databoard.coffee | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/databoard.coffee b/src/databoard.coffee index 3323ac97d..26743c68f 100644 --- a/src/databoard.coffee +++ b/src/databoard.coffee @@ -65,14 +65,18 @@ class DataBoard $.set @key, @data ajaxClean: (boardID) -> $.ajax "//api.4chan.org/#{boardID}/threads.json", onload: (e) => - board = @data.boards[boardID] - threads = {} - for page in JSON.parse e.target.response - for thread in page.threads - if thread.no of board - threads[thread.no] = board[thread.no] - @data.boards[boardID] = threads - @deleteIfEmpty {boardID} + if e.target.status is 404 + # Deleted board. + @delete boardID + else if e.target.status is 200 + board = @data.boards[boardID] + threads = {} + for page in JSON.parse e.target.response + for thread in page.threads + if thread.no of board + threads[thread.no] = board[thread.no] + @data.boards[boardID] = threads + @deleteIfEmpty {boardID} $.set @key, @data onSync: (data) ->