fix: dont take into account old contact lists

This commit is contained in:
Alejandro Gomez 2023-01-27 18:35:55 +01:00
parent c183633efc
commit 592a8b04c0
No known key found for this signature in database
GPG Key ID: 4DF39E566658C817
5 changed files with 34 additions and 16 deletions

View File

@ -304,4 +304,4 @@ const barierNip07 = async (then: () => Promise<any>) => {
} finally { } finally {
isNip07Busy = false; isNip07Busy = false;
} }
}; };

View File

@ -30,6 +30,7 @@ export default function useLoginFeed() {
sub.Id = `login:meta`; sub.Id = `login:meta`;
sub.Authors = new Set([pubKey]); sub.Authors = new Set([pubKey]);
sub.Kinds = new Set([EventKind.ContactList, EventKind.SetMetadata]); sub.Kinds = new Set([EventKind.ContactList, EventKind.SetMetadata]);
sub.Limit = 2
return sub; return sub;
}, [pubKey]); }, [pubKey]);
@ -92,7 +93,7 @@ export default function useLoginFeed() {
dispatch(setRelays({ relays, createdAt: cl.created_at })); 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({ keys: pTags, createdAt: cl.created_at }));
} }
(async () => { (async () => {

View File

@ -27,7 +27,7 @@ export default function useMutedFeed(pubkey: HexKey) {
return useSubscription(sub); return useSubscription(sub);
} }
export function getMutedKeys(rawNotes: TaggedRawEvent[]): { at: number, keys: HexKey[] } { export function getMutedKeys(rawNotes: TaggedRawEvent[]): { createdAt: number, keys: HexKey[] } {
const notes = [...rawNotes] const notes = [...rawNotes]
notes.sort((a, b) => a.created_at - b.created_at) notes.sort((a, b) => a.created_at - b.created_at)
const newest = notes && notes[0] const newest = notes && notes[0]
@ -36,12 +36,12 @@ export function getMutedKeys(rawNotes: TaggedRawEvent[]): { at: number, keys: He
const mutedIndex = tags.findIndex(t => t[0] === "d" && t[1] === MUTE_LIST_TAG) const mutedIndex = tags.findIndex(t => t[0] === "d" && t[1] === MUTE_LIST_TAG)
if (mutedIndex !== -1) { if (mutedIndex !== -1) {
return { return {
at: newest.created_at, createdAt: newest.created_at,
keys: tags.slice(mutedIndex).filter(t => t[0] === "p").map(t => t[1]) keys: tags.slice(mutedIndex).filter(t => t[0] === "p").map(t => t[1])
} }
} }
} }
return { at: 0, keys: [] } return { createdAt: 0, keys: [] }
} }
export function getMuted(feed: NoteStore, pubkey: HexKey): HexKey[] { export function getMuted(feed: NoteStore, pubkey: HexKey): HexKey[] {

View File

@ -28,7 +28,7 @@ export default function useModeration() {
function unmute(id: HexKey) { function unmute(id: HexKey) {
const newMuted = muted.filter(p => p !== id) const newMuted = muted.filter(p => p !== id)
dispatch(setMuted({ dispatch(setMuted({
at: new Date().getTime(), createdAt: new Date().getTime(),
keys: newMuted keys: newMuted
})) }))
setMutedList(newMuted) setMutedList(newMuted)
@ -38,7 +38,7 @@ export default function useModeration() {
const newMuted = muted.concat([id]) const newMuted = muted.concat([id])
setMutedList(newMuted) setMutedList(newMuted)
dispatch(setMuted({ dispatch(setMuted({
at: new Date().getTime(), createdAt: new Date().getTime(),
keys: newMuted keys: newMuted
})) }))
} }
@ -47,7 +47,7 @@ export default function useModeration() {
const newMuted = Array.from(new Set(muted.concat(ids))) const newMuted = Array.from(new Set(muted.concat(ids)))
setMutedList(newMuted) setMutedList(newMuted)
dispatch(setMuted({ dispatch(setMuted({
at: new Date().getTime(), createdAt: new Date().getTime(),
keys: newMuted keys: newMuted
})) }))
} }

View File

@ -72,6 +72,11 @@ export interface LoginStore {
*/ */
follows: HexKey[], follows: HexKey[],
/**
* Newest relay list timestamp
*/
latestFollows: number,
/** /**
* A list of pubkeys this user has muted * A list of pubkeys this user has muted
*/ */
@ -80,7 +85,7 @@ export interface LoginStore {
/** /**
* Last seen mute list event timestamp * Last seen mute list event timestamp
*/ */
lastMutedSeenAt: number, latestMuted: number,
/** /**
* Notifications for this login session * Notifications for this login session
@ -115,8 +120,9 @@ const InitState = {
relays: {}, relays: {},
latestRelays: 0, latestRelays: 0,
follows: [], follows: [],
lastMutedSeenAt: 0, latestFollows: 0,
muted: [], muted: [],
latestMuted: 0,
notifications: [], notifications: [],
readNotifications: new Date().getTime(), readNotifications: new Date().getTime(),
dms: [], dms: [],
@ -136,6 +142,11 @@ export interface SetRelaysPayload {
createdAt: number createdAt: number
}; };
export interface SetFollowsPayload {
keys: HexKey[]
createdAt: number
};
const LoginSlice = createSlice({ const LoginSlice = createSlice({
name: "Login", name: "Login",
initialState: InitState, initialState: InitState,
@ -204,9 +215,14 @@ const LoginSlice = createSlice({
delete state.relays[action.payload]; delete state.relays[action.payload];
state.relays = { ...state.relays }; state.relays = { ...state.relays };
}, },
setFollows: (state, action: PayloadAction<string | string[]>) => { setFollows: (state, action: PayloadAction<SetFollowsPayload>) => {
const { keys, createdAt } = action.payload
if (state.latestFollows > createdAt) {
return;
}
let existing = new Set(state.follows); let existing = new Set(state.follows);
let update = Array.isArray(action.payload) ? action.payload : [action.payload]; let update = Array.isArray(keys) ? keys : [keys];
let changes = false; let changes = false;
for (let pk of update) { for (let pk of update) {
@ -217,14 +233,15 @@ const LoginSlice = createSlice({
} }
if (changes) { if (changes) {
state.follows = Array.from(existing); state.follows = Array.from(existing);
state.latestFollows = createdAt;
} }
}, },
setMuted(state, action: PayloadAction<{at: number, keys: HexKey[]}>) { setMuted(state, action: PayloadAction<{createdAt: number, keys: HexKey[]}>) {
const { at, keys } = action.payload const { createdAt, keys } = action.payload
if (at > state.lastMutedSeenAt) { if (createdAt > state.latestMuted) {
const muted = new Set([...keys]) const muted = new Set([...keys])
state.muted = Array.from(muted) state.muted = Array.from(muted)
state.lastMutedSeenAt = at state.latestMuted = createdAt
} }
}, },
addNotifications: (state, action: PayloadAction<TaggedRawEvent | TaggedRawEvent[]>) => { addNotifications: (state, action: PayloadAction<TaggedRawEvent | TaggedRawEvent[]>) => {