Simplify event signing
This commit is contained in:
parent
e5837ebefb
commit
f318c35544
|
@ -182,13 +182,9 @@ const connectTimelineStream = (
|
||||||
dispatch({ type: MARKER_FETCH_SUCCESS, marker: JSON.parse(data.payload) });
|
dispatch({ type: MARKER_FETCH_SUCCESS, marker: JSON.parse(data.payload) });
|
||||||
break;
|
break;
|
||||||
case 'nostr.sign':
|
case 'nostr.sign':
|
||||||
(async () => {
|
window.nostr?.signEvent(JSON.parse(data.payload))
|
||||||
const event = await window.nostr?.signEvent(JSON.parse(data.payload)).catch(() => undefined);
|
.then((data) => websocket.send(JSON.stringify({ type: 'nostr.sign', data })))
|
||||||
|
.catch(() => console.warn('Failed to sign Nostr event.'));
|
||||||
if (event) {
|
|
||||||
websocket.send(JSON.stringify({ event: 'nostr.sign', payload: JSON.stringify(event) }));
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -201,7 +197,7 @@ const refreshHomeTimelineAndNotification = (dispatch: AppDispatch, done?: () =>
|
||||||
dispatch(fetchAnnouncements(done))))));
|
dispatch(fetchAnnouncements(done))))));
|
||||||
|
|
||||||
const connectUserStream = (opts?: StreamOpts) =>
|
const connectUserStream = (opts?: StreamOpts) =>
|
||||||
connectTimelineStream('home', `user${'nostr' in window ? '&nostr=true' : ''}`, refreshHomeTimelineAndNotification, null, opts);
|
connectTimelineStream('home', 'user', refreshHomeTimelineAndNotification, null, opts);
|
||||||
|
|
||||||
const connectCommunityStream = ({ onlyMedia }: Record<string, any> = {}) =>
|
const connectCommunityStream = ({ onlyMedia }: Record<string, any> = {}) =>
|
||||||
connectTimelineStream(`community${onlyMedia ? ':media' : ''}`, `public:local${onlyMedia ? ':media' : ''}`);
|
connectTimelineStream(`community${onlyMedia ? ':media' : ''}`, `public:local${onlyMedia ? ':media' : ''}`);
|
||||||
|
@ -224,6 +220,9 @@ const connectListStream = (id: string) =>
|
||||||
const connectGroupStream = (id: string) =>
|
const connectGroupStream = (id: string) =>
|
||||||
connectTimelineStream(`group:${id}`, `group&group=${id}`);
|
connectTimelineStream(`group:${id}`, `group&group=${id}`);
|
||||||
|
|
||||||
|
const connectNostrStream = () =>
|
||||||
|
connectTimelineStream('nostr', 'nostr');
|
||||||
|
|
||||||
export {
|
export {
|
||||||
STREAMING_CHAT_UPDATE,
|
STREAMING_CHAT_UPDATE,
|
||||||
STREAMING_FOLLOW_RELATIONSHIPS_UPDATE,
|
STREAMING_FOLLOW_RELATIONSHIPS_UPDATE,
|
||||||
|
@ -236,4 +235,5 @@ export {
|
||||||
connectDirectStream,
|
connectDirectStream,
|
||||||
connectListStream,
|
connectListStream,
|
||||||
connectGroupStream,
|
connectGroupStream,
|
||||||
|
connectNostrStream,
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,7 +16,7 @@ import { openModal } from 'soapbox/actions/modals';
|
||||||
import { expandNotifications } from 'soapbox/actions/notifications';
|
import { expandNotifications } from 'soapbox/actions/notifications';
|
||||||
import { register as registerPushNotifications } from 'soapbox/actions/push-notifications';
|
import { register as registerPushNotifications } from 'soapbox/actions/push-notifications';
|
||||||
import { fetchScheduledStatuses } from 'soapbox/actions/scheduled-statuses';
|
import { fetchScheduledStatuses } from 'soapbox/actions/scheduled-statuses';
|
||||||
import { connectUserStream } from 'soapbox/actions/streaming';
|
import { connectNostrStream, connectUserStream } from 'soapbox/actions/streaming';
|
||||||
import { fetchSuggestionsForTimeline } from 'soapbox/actions/suggestions';
|
import { fetchSuggestionsForTimeline } from 'soapbox/actions/suggestions';
|
||||||
import { expandHomeTimeline } from 'soapbox/actions/timelines';
|
import { expandHomeTimeline } from 'soapbox/actions/timelines';
|
||||||
import GroupLookupHoc from 'soapbox/components/hoc/group-lookup-hoc';
|
import GroupLookupHoc from 'soapbox/components/hoc/group-lookup-hoc';
|
||||||
|
@ -391,7 +391,8 @@ const UI: React.FC<IUI> = ({ children }) => {
|
||||||
const instance = useInstance();
|
const instance = useInstance();
|
||||||
const statContext = useStatContext();
|
const statContext = useStatContext();
|
||||||
|
|
||||||
const disconnect = useRef<any>(null);
|
const userStream = useRef<any>(null);
|
||||||
|
const nostrStream = useRef<any>(null);
|
||||||
const node = useRef<HTMLDivElement | null>(null);
|
const node = useRef<HTMLDivElement | null>(null);
|
||||||
const hotkeys = useRef<HTMLDivElement | null>(null);
|
const hotkeys = useRef<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
|
@ -416,15 +417,24 @@ const UI: React.FC<IUI> = ({ children }) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const connectStreaming = () => {
|
const connectStreaming = () => {
|
||||||
if (!disconnect.current && accessToken && streamingUrl) {
|
if (accessToken && streamingUrl) {
|
||||||
disconnect.current = dispatch(connectUserStream({ statContext }));
|
if (!userStream.current) {
|
||||||
|
userStream.current = dispatch(connectUserStream({ statContext }));
|
||||||
|
}
|
||||||
|
if (!nostrStream.current && window.nostr) {
|
||||||
|
nostrStream.current = dispatch(connectNostrStream());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const disconnectStreaming = () => {
|
const disconnectStreaming = () => {
|
||||||
if (disconnect.current) {
|
if (userStream.current) {
|
||||||
disconnect.current();
|
userStream.current();
|
||||||
disconnect.current = null;
|
userStream.current = null;
|
||||||
|
}
|
||||||
|
if (nostrStream.current) {
|
||||||
|
nostrStream.current();
|
||||||
|
nostrStream.current = null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue