From 86d0c05dd4bf8fb38cc41b2956fbffce455418d0 Mon Sep 17 00:00:00 2001 From: Bloctans <93960460+Bloctans@users.noreply.github.com> Date: Thu, 8 Feb 2024 15:58:58 -0600 Subject: [PATCH 1/3] a --- src/lib/PostList.svelte | 10 +++++++--- src/lib/clmanager.js | 26 ++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/lib/PostList.svelte b/src/lib/PostList.svelte index 0cf92c25..2294a9e6 100644 --- a/src/lib/PostList.svelte +++ b/src/lib/PostList.svelte @@ -191,9 +191,8 @@ if ($user.hide_blocked_users) { // @ts-ignore result = result.filter( - post => - $relationships[post._id] !== 2 && - $relationships[post.u] !== 2 + post => + $relationships[post.user] !== 2 ); } const numPages = json["pages"]; @@ -268,6 +267,11 @@ if (!cmd.val) return; const isGC = postOrigin !== "home"; + + if (!(isGC && cmd.val.chatid === postOrigin)) { + if ($relationships[cmd.val.u] == 2 && $user.hide_blocked_users) return; + } + if (cmd.val.mode === "delete") { if (adminView) return; items = items.filter(post => post.post_id !== cmd.val.id); diff --git a/src/lib/clmanager.js b/src/lib/clmanager.js index e3ec6dd2..d62e708d 100644 --- a/src/lib/clmanager.js +++ b/src/lib/clmanager.js @@ -81,6 +81,9 @@ authHeader.subscribe(v => { let _relationships = null; relationships.subscribe(v => (_relationships = v)); +let _ulistsub = null; +ulist.subscribe(v => (_ulistsub = v)); + let _chats = null; chats.subscribe(v => (_chats = v)); @@ -197,6 +200,20 @@ let disconnectRequest = null; */ let pingInterval = null; +/** + * Rids the ulist of blocked users + */ +export function fix_ulist_blocked_users() { + let _ulist = _ulistsub + if (_user.hide_blocked_users) { + _ulist = _ulist.filter( + theuser => _relationships[theuser] !== 2 + ); + } + _ulist = _ulist + ulist.set(_ulist) +} + /** * Connect to the server, initializing some other things such as pinging. * @@ -342,12 +359,14 @@ export async function connect() { modals.showModal(ConnectionFailedModal); } }); - ulistEvent = link.on("ulist", cmd => { + ulistEvent = link.on("ulist", async cmd => { const _ulist = cmd.val.split(";"); if (_ulist[_ulist.length - 1] === "") { _ulist.pop(); } ulist.set(_ulist); + await tick() + fix_ulist_blocked_users() }); authEvent = link.on("direct", async cmd => { if (cmd.val.mode === "auth") { @@ -370,6 +389,7 @@ export async function connect() { // get and set chats await tick(); + fix_ulist_blocked_users() const resp = await fetch(`${apiUrl}chats?autoget=1`, { headers: _authHeader, }); @@ -390,6 +410,7 @@ export async function connect() { }); relationshipUpdateEvent = link.on("direct", cmd => { if (cmd.val.mode === "update_relationship") { + fix_ulist_blocked_users() _relationships[cmd.val.payload.username] = cmd.val.payload.state; relationships.set(_relationships); } @@ -477,7 +498,7 @@ export async function connect() { try { return await link.connect(linkUrl); } catch (e) { - link.error("manager", "conenction error:", e); + link.error("manager", "connection error:", e); modals.showModal(ConnectionFailedModal); return e; } @@ -558,6 +579,7 @@ export async function updateProfile(updatedValues) { if (!_user.name) return; Object.assign(_user, updatedValues); user.set(_user); + fix_ulist_blocked_users() return fetch(`${apiUrl}me/config`, { method: "PATCH", headers: { From 11f19da2b613898126a023058ae1c9b6ea1e505a Mon Sep 17 00:00:00 2001 From: Bloctans <93960460+Bloctans@users.noreply.github.com> Date: Thu, 8 Feb 2024 16:17:53 -0600 Subject: [PATCH 2/3] Update clmanager.js --- src/lib/clmanager.js | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/src/lib/clmanager.js b/src/lib/clmanager.js index d62e708d..67d18fb0 100644 --- a/src/lib/clmanager.js +++ b/src/lib/clmanager.js @@ -81,9 +81,6 @@ authHeader.subscribe(v => { let _relationships = null; relationships.subscribe(v => (_relationships = v)); -let _ulistsub = null; -ulist.subscribe(v => (_ulistsub = v)); - let _chats = null; chats.subscribe(v => (_chats = v)); @@ -200,20 +197,6 @@ let disconnectRequest = null; */ let pingInterval = null; -/** - * Rids the ulist of blocked users - */ -export function fix_ulist_blocked_users() { - let _ulist = _ulistsub - if (_user.hide_blocked_users) { - _ulist = _ulist.filter( - theuser => _relationships[theuser] !== 2 - ); - } - _ulist = _ulist - ulist.set(_ulist) -} - /** * Connect to the server, initializing some other things such as pinging. * @@ -366,7 +349,6 @@ export async function connect() { } ulist.set(_ulist); await tick() - fix_ulist_blocked_users() }); authEvent = link.on("direct", async cmd => { if (cmd.val.mode === "auth") { @@ -389,7 +371,6 @@ export async function connect() { // get and set chats await tick(); - fix_ulist_blocked_users() const resp = await fetch(`${apiUrl}chats?autoget=1`, { headers: _authHeader, }); @@ -410,7 +391,6 @@ export async function connect() { }); relationshipUpdateEvent = link.on("direct", cmd => { if (cmd.val.mode === "update_relationship") { - fix_ulist_blocked_users() _relationships[cmd.val.payload.username] = cmd.val.payload.state; relationships.set(_relationships); } @@ -579,7 +559,6 @@ export async function updateProfile(updatedValues) { if (!_user.name) return; Object.assign(_user, updatedValues); user.set(_user); - fix_ulist_blocked_users() return fetch(`${apiUrl}me/config`, { method: "PATCH", headers: { From 166ac116687dd41f0daabd7d12e92063ab0e0c58 Mon Sep 17 00:00:00 2001 From: Bloctans <93960460+Bloctans@users.noreply.github.com> Date: Tue, 20 Feb 2024 20:32:51 -0600 Subject: [PATCH 3/3] fix --- src/lib/ProfileView.svelte | 14 ++++++++------ src/lib/clmanager.js | 21 ++++++++++++++++----- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/lib/ProfileView.svelte b/src/lib/ProfileView.svelte index 518e4f6f..2e918134 100644 --- a/src/lib/ProfileView.svelte +++ b/src/lib/ProfileView.svelte @@ -23,7 +23,7 @@ import ReportUserModal from "./modals/safety/ReportUser.svelte"; import AccountBannedModal from "./modals/safety/AccountBanned.svelte"; - import {authHeader, chats, ulist, user} from "./stores.js"; + import {relationships, authHeader, chats, ulist, user} from "./stores.js"; import {apiUrl} from "./urls.js"; import {userFlags} from "./bitField.js"; import loadProfile from "./loadProfile.js"; @@ -199,7 +199,7 @@ on:click={$goto(`/users/${data._id}`)} > {:else} {/if}
- {#if $ulist.includes(data._id)} + {#if $relationships[data._id] === 2 && $user.hide_blocked_users} + User Blocked + {:else if data.banned} + Banned + {:else if $ulist.includes(data._id)} Online {:else if (data.flags & userFlags.SYSTEM) === userFlags.SYSTEM} System {:else if (data.flags & userFlags.DELETED) === userFlags.DELETED} Deleted - {:else if data.banned} - Banned {:else if data.last_seen} Offline since _relationships[theuser] !== 2 + ); + } + return _ulist +} + /** * The single CloudLink instance used by the manager. */ @@ -342,13 +351,13 @@ export async function connect() { modals.showModal(ConnectionFailedModal); } }); - ulistEvent = link.on("ulist", async cmd => { - const _ulist = cmd.val.split(";"); + ulistEvent = link.on("ulist", cmd => { + var _ulist = cmd.val.split(";"); if (_ulist[_ulist.length - 1] === "") { _ulist.pop(); } + _ulist = fix_ulist_blocked_users(_ulist) ulist.set(_ulist); - await tick() }); authEvent = link.on("direct", async cmd => { if (cmd.val.mode === "auth") { @@ -389,19 +398,21 @@ export async function connect() { user.set(_user); } }); - relationshipUpdateEvent = link.on("direct", cmd => { + relationshipUpdateEvent = link.on("direct", async cmd => { if (cmd.val.mode === "update_relationship") { _relationships[cmd.val.payload.username] = cmd.val.payload.state; relationships.set(_relationships); + link.send({cmd: "get_ulist", val:""}) } }); - configUpdateEvent = link.on("direct", cmd => { + configUpdateEvent = link.on("direct", async cmd => { if (cmd.val.mode === "update_config") { _user = { ..._user, ...cmd.val.payload, }; user.set(_user); + link.send({cmd: "get_ulist", val:""}) } }); chatCreateEvent = link.on("direct", cmd => {