fix: read following state from current X user schema

This commit is contained in:
Darío Sevilla committed 2026-10-15 08:15:38 +00:00
1 parent 5a492b0cc3
commit c31dfa14db
3 files changed
+14 -4

No files matched your search

+2 -2
View File
@@ -17,9 +17,9 @@
seen.add(value);
const legacy = value.legacy && typeof value.legacy === "object" ? value.legacy : value;
const screenName = legacy.screen_name || value.screen_name || value.username;
const screenName = legacy.screen_name || value.screen_name || value.core?.screen_name || value.username;
if (screenName && String(screenName).toLowerCase() === username.toLowerCase()) {
const following = legacy.following ?? value.following;
const following = legacy.following ?? value.following ?? value.relationship_perspectives?.following;
const location = legacy.location || value.location;
return {
following: typeof following === "boolean" ? following : null,
+2 -2
View File
@@ -31,8 +31,8 @@
if (!value || typeof value !== "object" || seen.has(value) || depth > 12) continue;
seen.add(value);
const legacy = value.legacy && typeof value.legacy === "object" ? value.legacy : value;
const screenName = legacy.screen_name || value.screen_name;
const following = legacy.following ?? value.following;
const screenName = legacy.screen_name || value.screen_name || value.core?.screen_name;
const following = legacy.following ?? value.following ?? value.relationship_perspectives?.following;
if (typeof screenName === "string" && screenName.toLowerCase() === username.toLowerCase() &&
typeof following === "boolean") return following;
for (const key of Object.keys(value)) {
+10
View File
@@ -12,6 +12,16 @@ test("finds following state in nested X user data", () => {
test("does not confuse another user record", () => {
assert.equal(findUserRecord({ legacy: { screen_name: "Bob", following: false } }, "alice"), null);
});
test("finds following state in the current X user schema", () => {
const source = {
result: {
core: { screen_name: "Alice" },
relationship_perspectives: { following: false, followed_by: true },
location: "United States"
}
};
assert.deepEqual(findUserRecord(source, "alice"), { following: false, location: "United States" });
});
test("normalizes country aliases", () => {
assert.equal(normalizeCountry(" Russian Federation "), "russia");
assert.equal(isBlacklisted("Russian Federation", ["Russia"]), true);