From cf642108a864cc910f23e2c5fe48ec6aeaf338f9 Mon Sep 17 00:00:00 2001 From: Makyen Date: Thu, 20 Sep 2018 17:09:43 -0700 Subject: [PATCH 1/5] Don't show multiple feedbacks for the same user. --- autoflagging/autoflagging.user.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/autoflagging/autoflagging.user.js b/autoflagging/autoflagging.user.js index 8ea80d2..15f8b9a 100644 --- a/autoflagging/autoflagging.user.js +++ b/autoflagging/autoflagging.user.js @@ -292,6 +292,22 @@ autoflagging.decorate.feedback._each = function ($feedback, data) { // Group feedback by type var allFeedbacks = $feedback.data("feedbacks") || {}; + // Don't show multiple feedbacks by the same user. New feedbacks override old feedbacks. + // Unfortunately, MS only sends the user_name with WebScocket feedbacks, which makes + // this incorrect if there is an actual duplicate username. + // In addition, it is possible, under some conditions, for MS to have more than one + // feedback from the same user, which this will hide. + const currentUsername = data.user_name; + Object.keys(allFeedbacks).forEach(function (feedbackType) { + if (Array.isArray(allFeedbacks[feedbackType])) { + allFeedbacks[feedbackType] = allFeedbacks[feedbackType].filter(function (testFeedback) { + return testFeedback.user_name !== currentUsername; + }); + if (allFeedbacks[feedbackType].length === 0) { + delete allFeedbacks[feedbackType]; + } + } + }); allFeedbacks[data.feedback_type] = (allFeedbacks[data.feedback_type] || []).concat(data); $feedback.data("feedbacks", allFeedbacks); From ad85e17472bd8833fcc37578c552ec9966cd0b96 Mon Sep 17 00:00:00 2001 From: Makyen Date: Thu, 20 Sep 2018 17:13:04 -0700 Subject: [PATCH 2/5] More descriptive text in error notifications (i.e. show it's from AIM). --- autoflagging/autoflagging.user.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/autoflagging/autoflagging.user.js b/autoflagging/autoflagging.user.js index 15f8b9a..ce56340 100644 --- a/autoflagging/autoflagging.user.js +++ b/autoflagging/autoflagging.user.js @@ -435,7 +435,7 @@ $.get(url, function (flaggingData) { autoflagging.decorateMessage($element, flaggingData.items[0]); }).fail(function (xhr) { - autoflagging.notify("Failed to load data:", xhr); + autoflagging.notify("AIM: Failed to load MS flag data:", xhr); }); } else { // No autoflags @@ -448,7 +448,7 @@ $.get(url, function (feedbackData) { autoflagging.decorateMessage($element, {feedbacks: feedbackData.items}); }).fail(function (xhr) { - autoflagging.notify("Failed to load data:", xhr); + autoflagging.notify("AIM: Failed to load MS feedback data:", xhr); }); // Get weight @@ -461,7 +461,7 @@ } autoflagging.decorateMessage($element, {reason_weight: totalWeight}); }).fail(function (xhr) { - autoflagging.notify("Failed to load data:", xhr); + autoflagging.notify("AIM: Failed to load MS reason data:", xhr); }); }); @@ -470,7 +470,7 @@ autoflagging.callAPI(urls, ++page); } }).fail(function (xhr) { - autoflagging.notify("Failed to load data:", xhr); + autoflagging.notify("AIM: Failed to load MS post data:", xhr); }); }; From 0d5756f677136079d46e9034902c90a689eaa85c Mon Sep 17 00:00:00 2001 From: Makyen Date: Thu, 20 Sep 2018 17:14:38 -0700 Subject: [PATCH 3/5] Add room: The Restaurant at the End of the Universe --- autoflagging/autoflagging.user.js | 1 + 1 file changed, 1 insertion(+) diff --git a/autoflagging/autoflagging.user.js b/autoflagging/autoflagging.user.js index ce56340..824948a 100644 --- a/autoflagging/autoflagging.user.js +++ b/autoflagging/autoflagging.user.js @@ -32,6 +32,7 @@ // @match *://chat.stackexchange.com/rooms/38932/* // @match *://chat.stackexchange.com/rooms/47869/* // @match *://chat.stackexchange.com/rooms/56223/the-spam-blot* +// @match *://chat.stackexchange.com/rooms/58631/* // @match *://chat.stackexchange.com/rooms/59281/* // @match *://chat.stackexchange.com/rooms/61165/* // @match *://chat.stackexchange.com/rooms/65945/* From 56517f01ec6ad7afece7ca561780503e710a7f98 Mon Sep 17 00:00:00 2001 From: Makyen Date: Thu, 20 Sep 2018 17:17:35 -0700 Subject: [PATCH 4/5] Add/increase per_page on MS requests to reduce requests and avoid the need to fix fetching (reasons) when `has_more` is true. --- autoflagging/autoflagging.user.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/autoflagging/autoflagging.user.js b/autoflagging/autoflagging.user.js index 824948a..8bb13f0 100644 --- a/autoflagging/autoflagging.user.js +++ b/autoflagging/autoflagging.user.js @@ -125,7 +125,7 @@ autoflagging.getAllReasons = function ($message, data) { if (autoflagging.hasMoreRegex.test($message.html())) { $.get( - "https://metasmoke.erwaysoftware.com/api/v2.0/post/" + data.id + "/reasons", + "https://metasmoke.erwaysoftware.com/api/v2.0/post/" + data.id + "/reasons?per_page=30", {key: autoflagging.key}, function (response) { if (response && response.items) { @@ -408,6 +408,8 @@ page = 1; } var autoflagData = {}; + // With a large value of per_page this can timeout the request. 20 appeared to work here, but 30 got timeouts. + // IMO, it's better to leave this as the default 10, rather than risk timeouts. var url = autoflagging.baseURL + "&page=" + page + "&urls=" + urls; debug("URL:", url); $.get(url, function (data) { @@ -444,7 +446,7 @@ } // Get feedback - url = autoflagging.apiURL + "/feedbacks/post/" + postData.id + "?filter=HNKJJKGNHOHLNOKINNGOOIHJNLHLOJOHIOFFLJIJJHLNNF&key=" + autoflagging.key; + url = autoflagging.apiURL + "/feedbacks/post/" + postData.id + "?filter=HNKJJKGNHOHLNOKINNGOOIHJNLHLOJOHIOFFLJIJJHLNNF&key=" + autoflagging.key + "&per_page=20"; debug("URL:", url); $.get(url, function (feedbackData) { autoflagging.decorateMessage($element, {feedbacks: feedbackData.items}); @@ -453,7 +455,7 @@ }); // Get weight - url = autoflagging.apiURL + "/posts/" + postData.id + "/reasons?key=" + autoflagging.key; + url = autoflagging.apiURL + "/posts/" + postData.id + "/reasons?key=" + autoflagging.key + "&per_page=30"; debug("URL:", url); $.get(url, function (reasonsData) { var totalWeight = 0; From 3d232e3ffbe77969d5737f24060e47330eff569e Mon Sep 17 00:00:00 2001 From: Makyen Date: Thu, 20 Sep 2018 23:28:51 -0700 Subject: [PATCH 5/5] AIM: version 0.25 --- autoflagging/autoflagging.meta.js | 3 ++- autoflagging/autoflagging.user.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/autoflagging/autoflagging.meta.js b/autoflagging/autoflagging.meta.js index 48a1f3f..74a0fc6 100644 --- a/autoflagging/autoflagging.meta.js +++ b/autoflagging/autoflagging.meta.js @@ -8,7 +8,7 @@ // @contributor ArtOfCode // @contributor Cerbrus // @contributor Makyen -// @version 0.24 +// @version 0.25 // @updateURL https://raw.githubusercontent.com/Charcoal-SE/Userscripts/master/autoflagging/autoflagging.meta.js // @downloadURL https://raw.githubusercontent.com/Charcoal-SE/Userscripts/master/autoflagging/autoflagging.user.js // @supportURL https://github.com/Charcoal-SE/Userscripts/issues @@ -32,6 +32,7 @@ // @match *://chat.stackexchange.com/rooms/38932/* // @match *://chat.stackexchange.com/rooms/47869/* // @match *://chat.stackexchange.com/rooms/56223/the-spam-blot* +// @match *://chat.stackexchange.com/rooms/58631/* // @match *://chat.stackexchange.com/rooms/59281/* // @match *://chat.stackexchange.com/rooms/61165/* // @match *://chat.stackexchange.com/rooms/65945/* diff --git a/autoflagging/autoflagging.user.js b/autoflagging/autoflagging.user.js index 8bb13f0..bfcd1f5 100644 --- a/autoflagging/autoflagging.user.js +++ b/autoflagging/autoflagging.user.js @@ -8,7 +8,7 @@ // @contributor ArtOfCode // @contributor Cerbrus // @contributor Makyen -// @version 0.24 +// @version 0.25 // @updateURL https://raw.githubusercontent.com/Charcoal-SE/Userscripts/master/autoflagging/autoflagging.meta.js // @downloadURL https://raw.githubusercontent.com/Charcoal-SE/Userscripts/master/autoflagging/autoflagging.user.js // @supportURL https://github.com/Charcoal-SE/Userscripts/issues