bug: improve relay handeling
This commit is contained in:
@ -8,6 +8,8 @@ const PrivateKeyItem = "secret";
|
||||
const PublicKeyItem = "pubkey";
|
||||
const NotificationsReadItem = "notifications-read";
|
||||
const UserPreferencesKey = "preferences";
|
||||
const RelayListKey = "last-relays";
|
||||
const FollowList = "last-follows";
|
||||
|
||||
export interface UserPreferences {
|
||||
/**
|
||||
@ -38,7 +40,7 @@ export interface UserPreferences {
|
||||
/**
|
||||
* Show debugging menus to help diagnose issues
|
||||
*/
|
||||
showDebugMenus: boolean
|
||||
showDebugMenus: boolean
|
||||
}
|
||||
|
||||
export interface LoginStore {
|
||||
@ -138,8 +140,6 @@ const LoginSlice = createSlice({
|
||||
state.loggedOut = true;
|
||||
}
|
||||
|
||||
state.relays = Object.fromEntries(DefaultRelays.entries());
|
||||
|
||||
// check pub key only
|
||||
let pubKey = window.localStorage.getItem(PublicKeyItem);
|
||||
if (pubKey && !state.privateKey) {
|
||||
@ -147,6 +147,18 @@ const LoginSlice = createSlice({
|
||||
state.loggedOut = false;
|
||||
}
|
||||
|
||||
let lastRelayList = window.localStorage.getItem(RelayListKey);
|
||||
if (lastRelayList) {
|
||||
state.relays = JSON.parse(lastRelayList);
|
||||
} else if (state.loggedOut === true) {
|
||||
state.relays = Object.fromEntries(DefaultRelays.entries());
|
||||
}
|
||||
|
||||
let lastFollows = window.localStorage.getItem(FollowList);
|
||||
if (lastFollows) {
|
||||
state.follows = JSON.parse(lastFollows);
|
||||
}
|
||||
|
||||
// notifications
|
||||
let readNotif = parseInt(window.localStorage.getItem(NotificationsReadItem) ?? "0");
|
||||
if (!isNaN(readNotif)) {
|
||||
@ -187,10 +199,12 @@ const LoginSlice = createSlice({
|
||||
|
||||
state.relays = Object.fromEntries(filtered.entries());
|
||||
state.latestRelays = createdAt;
|
||||
window.localStorage.setItem(RelayListKey, JSON.stringify(state.relays));
|
||||
},
|
||||
removeRelay: (state, action: PayloadAction<string>) => {
|
||||
delete state.relays[action.payload];
|
||||
state.relays = { ...state.relays };
|
||||
window.localStorage.setItem(RelayListKey, JSON.stringify(state.relays));
|
||||
},
|
||||
setFollows: (state, action: PayloadAction<string | string[]>) => {
|
||||
let existing = new Set(state.follows);
|
||||
@ -205,6 +219,7 @@ const LoginSlice = createSlice({
|
||||
}
|
||||
if (changes) {
|
||||
state.follows = Array.from(existing);
|
||||
window.localStorage.setItem(FollowList, JSON.stringify(state.follows));
|
||||
}
|
||||
},
|
||||
addNotifications: (state, action: PayloadAction<TaggedRawEvent | TaggedRawEvent[]>) => {
|
||||
@ -249,10 +264,10 @@ const LoginSlice = createSlice({
|
||||
state.dmInteraction += 1;
|
||||
},
|
||||
logout: (state) => {
|
||||
window.localStorage.clear();
|
||||
Object.assign(state, InitState);
|
||||
state.loggedOut = true;
|
||||
state.relays = Object.fromEntries(DefaultRelays.entries());
|
||||
window.localStorage.clear();
|
||||
},
|
||||
markNotificationsRead: (state) => {
|
||||
state.readNotifications = new Date().getTime();
|
||||
|
Reference in New Issue
Block a user