Added blocking service.
CI / lint (push) Failing after 26s
CI / test (3.9) (push) Failing after 25s
CI / test (3.12) (push) Failing after 26s
CI / build (push) Failing after 27s
CI / test (3.8) (push) Failing after 24s
CI / test (3.11) (push) Failing after 47s
CI / test (3.10) (push) Failing after 49s
CI / lint (push) Failing after 26s
CI / test (3.9) (push) Failing after 25s
CI / test (3.12) (push) Failing after 26s
CI / build (push) Failing after 27s
CI / test (3.8) (push) Failing after 24s
CI / test (3.11) (push) Failing after 47s
CI / test (3.10) (push) Failing after 49s
This commit is contained in:
@@ -22,11 +22,27 @@ class AuthService {
|
||||
username: authData.username
|
||||
};
|
||||
this.notifyAuthChange();
|
||||
this.fetchAndUpdateUsername(authData);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
async fetchAndUpdateUsername(authData) {
|
||||
if (!authData.userId) return;
|
||||
try {
|
||||
const profileResult = await this.api.getProfile(authData.userId);
|
||||
if (profileResult?.success && profileResult.profile?.username) {
|
||||
this.currentUser.username = profileResult.profile.username;
|
||||
if (authData.username !== profileResult.profile.username) {
|
||||
authData.username = profileResult.profile.username;
|
||||
this.storage.setAuth(authData);
|
||||
}
|
||||
this.notifyAuthChange();
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
async login(username, password, remember = true) {
|
||||
const result = await this.api.login(username, password);
|
||||
if (result.success) {
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
class BlockService {
|
||||
constructor(storageService) {
|
||||
this.storage = storageService;
|
||||
this.blockedUsers = new Set();
|
||||
this.onBlockChange = null;
|
||||
}
|
||||
|
||||
init() {
|
||||
const blocked = this.storage.getBlockedUsers();
|
||||
this.blockedUsers = new Set(blocked.map(u => u.toLowerCase()));
|
||||
}
|
||||
|
||||
isBlocked(username) {
|
||||
if (!username) return false;
|
||||
return this.blockedUsers.has(username.toLowerCase());
|
||||
}
|
||||
|
||||
block(username) {
|
||||
if (!username) return false;
|
||||
const normalized = username.toLowerCase();
|
||||
if (this.blockedUsers.has(normalized)) return false;
|
||||
this.blockedUsers.add(normalized);
|
||||
this.save();
|
||||
this.notifyChange();
|
||||
return true;
|
||||
}
|
||||
|
||||
unblock(username) {
|
||||
if (!username) return false;
|
||||
const normalized = username.toLowerCase();
|
||||
if (!this.blockedUsers.has(normalized)) return false;
|
||||
this.blockedUsers.delete(normalized);
|
||||
this.save();
|
||||
this.notifyChange();
|
||||
return true;
|
||||
}
|
||||
|
||||
toggle(username) {
|
||||
if (this.isBlocked(username)) {
|
||||
return this.unblock(username);
|
||||
}
|
||||
return this.block(username);
|
||||
}
|
||||
|
||||
getBlockedUsers() {
|
||||
return Array.from(this.blockedUsers).sort();
|
||||
}
|
||||
|
||||
getBlockedCount() {
|
||||
return this.blockedUsers.size;
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.blockedUsers.clear();
|
||||
this.save();
|
||||
this.notifyChange();
|
||||
}
|
||||
|
||||
save() {
|
||||
this.storage.setBlockedUsers(Array.from(this.blockedUsers));
|
||||
}
|
||||
|
||||
notifyChange() {
|
||||
if (this.onBlockChange) {
|
||||
this.onBlockChange(this.getBlockedUsers());
|
||||
}
|
||||
window.dispatchEvent(new CustomEvent('rantii:block-change', {
|
||||
detail: { blockedUsers: this.getBlockedUsers() }
|
||||
}));
|
||||
}
|
||||
|
||||
setBlockChangeCallback(callback) {
|
||||
this.onBlockChange = callback;
|
||||
}
|
||||
|
||||
filterRants(rants) {
|
||||
if (!rants || !Array.isArray(rants)) return [];
|
||||
return rants.filter(rant => !this.isBlocked(rant.user_username));
|
||||
}
|
||||
|
||||
filterComments(comments) {
|
||||
if (!comments || !Array.isArray(comments)) return [];
|
||||
return comments.filter(comment => !this.isBlocked(comment.user_username));
|
||||
}
|
||||
|
||||
filterNotifications(notifications) {
|
||||
if (!notifications || !Array.isArray(notifications)) return [];
|
||||
return notifications.filter(notif => {
|
||||
const username = notif.username?.name || notif.user_username?.name || notif.name;
|
||||
return !this.isBlocked(username);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export { BlockService };
|
||||
@@ -133,6 +133,37 @@ class StorageService {
|
||||
return this.remove(`draft_comment_${rantId}`);
|
||||
}
|
||||
|
||||
getBlockedUsers() {
|
||||
return this.get('blocked_users', []);
|
||||
}
|
||||
|
||||
setBlockedUsers(users) {
|
||||
return this.set('blocked_users', users);
|
||||
}
|
||||
|
||||
addBlockedUser(username) {
|
||||
const blocked = this.getBlockedUsers();
|
||||
const normalized = username.toLowerCase();
|
||||
if (!blocked.includes(normalized)) {
|
||||
blocked.push(normalized);
|
||||
return this.setBlockedUsers(blocked);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
removeBlockedUser(username) {
|
||||
const blocked = this.getBlockedUsers();
|
||||
const normalized = username.toLowerCase();
|
||||
const filtered = blocked.filter(u => u !== normalized);
|
||||
return this.setBlockedUsers(filtered);
|
||||
}
|
||||
|
||||
isUserBlocked(username) {
|
||||
if (!username) return false;
|
||||
const blocked = this.getBlockedUsers();
|
||||
return blocked.includes(username.toLowerCase());
|
||||
}
|
||||
|
||||
getCachedProfile(userId) {
|
||||
return this.get(`profile_cache_${userId}`, null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user