Fix relay list loading
This commit is contained in:
parent
953b5a6b08
commit
f5a5fcf22a
@ -47,7 +47,7 @@ export default function useLoginFeed() {
|
|||||||
for (let cl of contactList) {
|
for (let cl of contactList) {
|
||||||
if (cl.content !== "") {
|
if (cl.content !== "") {
|
||||||
let relays = JSON.parse(cl.content);
|
let relays = JSON.parse(cl.content);
|
||||||
dispatch(setRelays(relays));
|
dispatch(setRelays({ relays, createdAt: cl.created_at }));
|
||||||
}
|
}
|
||||||
let pTags = cl.tags.filter(a => a[0] === "p").map(a => a[1]);
|
let pTags = cl.tags.filter(a => a[0] === "p").map(a => a[1]);
|
||||||
dispatch(setFollows(pTags));
|
dispatch(setFollows(pTags));
|
||||||
|
@ -29,6 +29,11 @@ const LoginSlice = createSlice({
|
|||||||
*/
|
*/
|
||||||
relays: {},
|
relays: {},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Newest relay list timestamp
|
||||||
|
*/
|
||||||
|
latestRelays: null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list of pubkeys this user follows
|
* A list of pubkeys this user follows
|
||||||
*/
|
*/
|
||||||
@ -87,11 +92,18 @@ const LoginSlice = createSlice({
|
|||||||
state.publicKey = action.payload;
|
state.publicKey = action.payload;
|
||||||
},
|
},
|
||||||
setRelays: (state, action) => {
|
setRelays: (state, action) => {
|
||||||
|
let relays = action.payload.relays;
|
||||||
|
let createdAt = action.payload.createdAt;
|
||||||
|
if(state.latestRelays > createdAt) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// filter out non-websocket urls
|
// filter out non-websocket urls
|
||||||
let filtered = Object.entries({ ...state.relays, ...action.payload })
|
let filtered = Object.entries(relays)
|
||||||
.filter(a => a[0].startsWith("ws://") || a[0].startsWith("wss://"));
|
.filter(a => a[0].startsWith("ws://") || a[0].startsWith("wss://"));
|
||||||
|
|
||||||
state.relays = Object.fromEntries(filtered);
|
state.relays = Object.fromEntries(filtered);
|
||||||
|
state.latestRelays = createdAt;
|
||||||
},
|
},
|
||||||
removeRelay: (state, action) => {
|
removeRelay: (state, action) => {
|
||||||
delete state.relays[action.payload];
|
delete state.relays[action.payload];
|
||||||
|
Loading…
Reference in New Issue
Block a user