New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mutual Checker: Sideblog Update #1603
Mutual Checker: Sideblog Update #1603
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good overall, left some random comments if you want em because i'm not super familiar with the overall style guide for the repo
XKit.extensions.mutualchecker.add_label($name_div, url); | ||
} | ||
}); | ||
var fake_obj = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's fake_obj
? could you use a more descriptive name than this or leave an inline comment?
XKit.extensions.mutualchecker.mutuals[json_obj.name] = false; | ||
XKit.tools.Nx_XHR({ | ||
method: "GET", | ||
url: "https://www.tumblr.com/svc/conversations/participant_info?q=" + json_obj.name + "&participant=" + this.preferences.main_blog.value, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you write https://www.tumblr.com/
for every one of these URLs, or is that something you could bake into your XKit.tools.Nx_XHR()
helper to reduce the redundancy?
method: "GET", | ||
url: "https://www.tumblr.com/svc/conversations/participant_info?q=" + json_obj.name + "&participant=" + this.preferences.main_blog.value, | ||
headers: { | ||
"X-Requested-With": "XMLHttpRequest", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same Q here and for X-Tumblr-Form-Key
below -- is this used every time? if so, can you bake it into XKit.tools.Nx_XHR()
to reduce redundancy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is in fact on my to-do list, the entire function was kinda written in a huge hurry
@@ -100,6 +121,17 @@ XKit.extensions.mutualchecker = new Object({ | |||
} | |||
}, | |||
|
|||
plain_check: function(json_obj, $link) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does plain_check
mean? could you add some inline documentation here to make this clearer? JSDocs can be super helpful to people trying to contribute to your code 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would prefer a descriptive function name to inline documentation. group_blog_fallback
is probably the best bet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer a descriptive function name to inline documentation
100% that this is generally the best first step, but overall i think it's a great one-two punch for any shared codebase to complement descriptive feature names with detailed inline documentation. there are many times when you just can't make a function or variable name descriptive enough, like the always-around options
object variable, which is kind of like the json_obj
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, but in this case that's because the function is taking a opaque and poorly specified object when it's only using one of its variables—this should just be group_blog_fallback(username, $link)
. json_obj should probably be named something like popover_metadata, and we should explicitly destructure the variables we expect from it when we parse it from the DOM. (const {name, following, customizable} = JSON.parse(popover_metadata)
). Inline documentation in this case would obscure the more fundamental encapsulation problem.
inline documentation is bad because either 1) you're making up for illegible code by half-heartedly explaining it, and any change is going to put your comment out of date, or 2) you're justifying design decisions that should be written up in a more long-form way and live in the pull request description or commit message—because they're also a record of a particular place and time and should be tied to their specific context, not living in the codebase forever.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall i think 80% of the code needs to be moved to xkit_patches.
@@ -100,6 +121,17 @@ XKit.extensions.mutualchecker = new Object({ | |||
} | |||
}, | |||
|
|||
plain_check: function(json_obj, $link) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would prefer a descriptive function name to inline documentation. group_blog_fallback
is probably the best bet.
XKit.extensions.mutualchecker.mutuals[json_obj.name] = false; | ||
XKit.tools.Nx_XHR({ | ||
method: "GET", | ||
url: "https://www.tumblr.com/svc/conversations/participant_info?q=" + json_obj.name + "&participant=" + this.preferences.main_blog.value, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be built using $.params
instead of string-interpolated
"X-Requested-With": "XMLHttpRequest", | ||
"X-Tumblr-Form-Key": XKit.interface.form_key() | ||
}, | ||
onerror: function(response) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use promises, not callbacks.
XKit.extensions.mutualchecker.mutuals[json_obj.name] = true; | ||
} else { | ||
XKit.extensions.mutualchecker.mutuals[json_obj.name] = false; | ||
XKit.tools.Nx_XHR({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should extract this whole request into is_following
so that we can provide sideblog-correct results everywhere, it shouldn't just live in mutualchecker
XKit.extensions.mutualchecker.plain_check(json_obj, $link); | ||
} else { | ||
var data = raw_data.response; | ||
if (data.is_following_blog && data.is_blog_following_you) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get that having the additional information available is good, but now we have two distinct cases for when we'll add the mutual icon. Either we use this, which checks for mutual follow/following, or we use the fallback, in which case we're only checking for if they're following us, and we still have to be careful about where to call this function.
This entangling makes it hard to reason about this code path. We should either 1) drop the is_blog_following_you check here, 2) drop the fallback or 3) add an is_following check to the fallback that's going the other way, if that's possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mutual checker already only activates on username links with data-json
that says you're following the blog, so the end result is the same. i just thought that since tumblr provides a double confirmation of it here, it might as well be used
the logic should only live in one place. if we put the double check here,
then it's very likely someone (probably future April) will come in
somewhere down the line and go "oh, let's just remove this redundant
data-json check" and break the fallback.
…On Tue, Oct 9, 2018, 3:51 PM April Sylph ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In Extensions/mutualchecker.js
<#1603 (comment)>:
> + url: "https://www.tumblr.com/svc/conversations/participant_info?q=" + json_obj.name + "&participant=" + this.preferences.main_blog.value,
+ headers: {
+ "X-Requested-With": "XMLHttpRequest",
+ "X-Tumblr-Form-Key": XKit.interface.form_key()
+ },
+ onerror: function(response) {
+ XKit.extensions.mutualchecker.plain_check(json_obj, $link);
+ },
+ onload: function(response) {
+ try {
+ var raw_data = JSON.parse(response.responseText);
+ if (raw_data.errors) {
+ XKit.extensions.mutualchecker.plain_check(json_obj, $link);
+ } else {
+ var data = raw_data.response;
+ if (data.is_following_blog && data.is_blog_following_you) {
mutual checker already only activates on username links with data-json
that says you're following the blog, so the end result is the same. i just
thought that since tumblr provides a double confirmation of it here, it
might as well be used
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1603 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAORV-CUjJG-B6vXkYXztMHiqJg-sC3Iks5ujP4pgaJpZM4VbClB>
.
|
the however I really really really do not want to touch XKit Patches before #1614 is dealt with properly, after which I would very much like to
|
Uses messaging information by default to check if you're mutuals, which accurately reports single-member sideblogs as mutuals if the main blog follows you/your chosen sideblog (without actually exposing the URL of the main blog). Keeps the original method as a fallback for when the messaging data cannot be obtained, which happens if your chosen sideblog is a group blog.