forked from Kieran/snort
bug: unfollow not working
This commit is contained in:
parent
27ccf9cb5b
commit
df122d6150
@ -4,13 +4,14 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|||||||
import { faUserMinus, faUserPlus } from "@fortawesome/free-solid-svg-icons";
|
import { faUserMinus, faUserPlus } from "@fortawesome/free-solid-svg-icons";
|
||||||
import { HexKey } from "Nostr";
|
import { HexKey } from "Nostr";
|
||||||
import { RootState } from "State/Store";
|
import { RootState } from "State/Store";
|
||||||
|
import { parseId } from "Util";
|
||||||
|
|
||||||
export interface FollowButtonProps {
|
export interface FollowButtonProps {
|
||||||
pubkey: HexKey,
|
pubkey: HexKey,
|
||||||
className?: string,
|
className?: string,
|
||||||
}
|
}
|
||||||
export default function FollowButton(props: FollowButtonProps) {
|
export default function FollowButton(props: FollowButtonProps) {
|
||||||
const pubkey = props.pubkey;
|
const pubkey = parseId(props.pubkey);
|
||||||
const publiser = useEventPublisher();
|
const publiser = useEventPublisher();
|
||||||
const isFollowing = useSelector<RootState, boolean>(s => s.login.follows?.includes(pubkey) ?? false);
|
const isFollowing = useSelector<RootState, boolean>(s => s.login.follows?.includes(pubkey) ?? false);
|
||||||
const baseClassName = isFollowing ? `btn btn-warn follow-button` : `btn btn-success follow-button`
|
const baseClassName = isFollowing ? `btn btn-warn follow-button` : `btn btn-success follow-button`
|
||||||
|
@ -182,6 +182,9 @@ export default function useEventPublisher() {
|
|||||||
temp.add(pkAdd);
|
temp.add(pkAdd);
|
||||||
}
|
}
|
||||||
for (let pk of temp) {
|
for (let pk of temp) {
|
||||||
|
if (pk.length !== 64) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
ev.Tags.push(new Tag(["p", pk], ev.Tags.length));
|
ev.Tags.push(new Tag(["p", pk], ev.Tags.length));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,7 +197,7 @@ export default function useEventPublisher() {
|
|||||||
ev.Kind = EventKind.ContactList;
|
ev.Kind = EventKind.ContactList;
|
||||||
ev.Content = JSON.stringify(relays);
|
ev.Content = JSON.stringify(relays);
|
||||||
for (let pk of follows) {
|
for (let pk of follows) {
|
||||||
if (pk === pkRemove) {
|
if (pk === pkRemove || pk.length !== 64) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ev.Tags.push(new Tag(["p", pk], ev.Tags.length));
|
ev.Tags.push(new Tag(["p", pk], ev.Tags.length));
|
||||||
|
@ -206,21 +206,29 @@ const LoginSlice = createSlice({
|
|||||||
state.relays = { ...state.relays };
|
state.relays = { ...state.relays };
|
||||||
window.localStorage.setItem(RelayListKey, JSON.stringify(state.relays));
|
window.localStorage.setItem(RelayListKey, JSON.stringify(state.relays));
|
||||||
},
|
},
|
||||||
setFollows: (state, action: PayloadAction<string | string[]>) => {
|
setFollows: (state, action: PayloadAction<HexKey | HexKey[]>) => {
|
||||||
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(action.payload) ? action.payload : [action.payload];
|
||||||
|
|
||||||
let changes = false;
|
let changes = false;
|
||||||
for (let pk of update) {
|
for (let pk of update.filter(a => a.length === 64)) {
|
||||||
if (!existing.has(pk)) {
|
if (!existing.has(pk)) {
|
||||||
existing.add(pk);
|
existing.add(pk);
|
||||||
changes = true;
|
changes = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (let pk of existing) {
|
||||||
|
if (!update.includes(pk)) {
|
||||||
|
existing.delete(pk);
|
||||||
|
changes = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (changes) {
|
if (changes) {
|
||||||
state.follows = Array.from(existing);
|
state.follows = Array.from(existing);
|
||||||
window.localStorage.setItem(FollowList, JSON.stringify(state.follows));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.localStorage.setItem(FollowList, JSON.stringify(state.follows));
|
||||||
},
|
},
|
||||||
addNotifications: (state, action: PayloadAction<TaggedRawEvent | TaggedRawEvent[]>) => {
|
addNotifications: (state, action: PayloadAction<TaggedRawEvent | TaggedRawEvent[]>) => {
|
||||||
let n = action.payload;
|
let n = action.payload;
|
||||||
|
Loading…
Reference in New Issue
Block a user