From 748258f59b5d55a760cb057b0f7ff2eb13a75cde Mon Sep 17 00:00:00 2001 From: ccd0 Date: Fri, 28 Nov 2014 23:28:01 -0800 Subject: [PATCH] Unread.postsQuotingYou -> ECMAScript 6 Set --- src/General/lib/classes.coffee | 1 + src/General/lib/set.class | 16 ++++++++++++++++ src/Monitoring/Unread.coffee | 12 ++++++------ 3 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 src/General/lib/set.class diff --git a/src/General/lib/classes.coffee b/src/General/lib/classes.coffee index 3b0b36558..7a504d479 100755 --- a/src/General/lib/classes.coffee +++ b/src/General/lib/classes.coffee @@ -8,3 +8,4 @@ <%= grunt.file.read('src/General/lib/notice.class') %> <%= grunt.file.read('src/General/lib/randomaccesslist.class') %> <%= grunt.file.read('src/General/lib/simpledict.class') %> +<%= grunt.file.read('src/General/lib/set.class') %> diff --git a/src/General/lib/set.class b/src/General/lib/set.class new file mode 100644 index 000000000..b48d6e160 --- /dev/null +++ b/src/General/lib/set.class @@ -0,0 +1,16 @@ +class ShimSet + constructor: -> + @elements = {} + @size = 0 + has: (value) -> + value of @elements + add: (value) -> + return if @elements[value] + @elements[value] = true + @size++ + delete: (value) -> + return unless @elements[value] + delete @elements[value] + @size-- + +window.Set = ShimSet unless 'Set' of window diff --git a/src/Monitoring/Unread.coffee b/src/Monitoring/Unread.coffee index 95c456947..3c0de729f 100755 --- a/src/Monitoring/Unread.coffee +++ b/src/Monitoring/Unread.coffee @@ -13,7 +13,7 @@ Unread = @hr = $.el 'hr', id: 'unread-line' @posts = new RandomAccessList - @postsQuotingYou = {} + @postsQuotingYou = new Set Thread.callbacks.push name: 'Unread' @@ -74,7 +74,7 @@ Unread = ID = postIDs[i] break if +ID > Unread.lastReadPost Unread.posts.rm ID - delete Unread.postsQuotingYou[ID] + Unread.postsQuotingYou.delete ID Unread.readCount++ Unread.setLine() if Conf['Unread Line'] and not Conf['Quote Threading'] @@ -91,7 +91,7 @@ Unread = addPostQuotingYou: (post) -> for quotelink in post.nodes.quotelinks when QR.db?.get Get.postDataFromLink quotelink - Unread.postsQuotingYou[post.ID] = post + Unread.postsQuotingYou.add post.ID Unread.openNotification post return @@ -120,7 +120,7 @@ Unread = {posts} = Unread return unless posts[ID] posts.rm ID - delete Unread.postsQuotingYou[ID] + Unread.postsQuotingYou.delete ID Unread.saveLastReadPost() Unread.update() @@ -135,7 +135,7 @@ Unread = {ID, data} = post count++ posts.rm ID - delete Unread.postsQuotingYou[ID] + Unread.postsQuotingYou.delete ID if Conf['Mark Quotes of You'] and QR.db?.get { boardID: data.board.ID @@ -172,7 +172,7 @@ Unread = update: -> count = Unread.posts.length - countQuotingYou = Object.keys(Unread.postsQuotingYou).length + countQuotingYou = Unread.postsQuotingYou.size if Conf['Unread Count'] titleQuotingYou = if Conf['Quoted Title'] and countQuotingYou then '(!) ' else ''