mirror of
https://github.com/RoboSats/robosats.git
synced 2025-07-19 09:13:28 +00:00
Refactor
This commit is contained in:
@ -46,11 +46,32 @@ const EncryptedChat: React.FC<Props> = ({
|
||||
const { federation } = useContext<UseFederationStoreType>(FederationContext);
|
||||
|
||||
useEffect(() => {
|
||||
// const slot = garage.getSlot();
|
||||
const coordinator = federation.getCoordinator(order.shortAlias);
|
||||
federation.roboPool.connect([coordinator.getRelayUrl()]);
|
||||
|
||||
// const since = new Date(order.created_at);
|
||||
// since.setDate(since.getDate() - 2);
|
||||
|
||||
// federation.roboPool.subscribeChat(
|
||||
// [order.maker_nostr_pubkey, order.taker_nostr_pubkey],
|
||||
// Math.floor((since.getTime() / 1000)),
|
||||
// {
|
||||
// oneose: () => {},
|
||||
// onevent(event) {
|
||||
// if (slot?.nostrSecKey) {
|
||||
// console.log(nip17.unwrapEvent(event, slot.nostrSecKey))
|
||||
// }
|
||||
// },
|
||||
// }
|
||||
// )
|
||||
}, []);
|
||||
|
||||
const onSendMessage = (content: string): void => {
|
||||
sendToNostr(content);
|
||||
};
|
||||
|
||||
const sendToNostr = (content: string): void => {
|
||||
const slot = garage.getSlot();
|
||||
const coordinator = federation.getCoordinator(order.shortAlias);
|
||||
|
||||
|
@ -128,7 +128,7 @@ class RoboPool {
|
||||
this.sendMessage(JSON.stringify(requestSuccess));
|
||||
};
|
||||
|
||||
subscribeRatings = (events: RoboPoolEvents, coordinators?: string[]): void => {
|
||||
subscribeRatings = (events: RoboPoolEvents): void => {
|
||||
const pubkeys = Object.values(defaultFederation)
|
||||
.map((f) => f.nostrHexPubkey)
|
||||
.filter((item) => item !== undefined);
|
||||
@ -150,6 +150,20 @@ class RoboPool {
|
||||
this.sendMessage(JSON.stringify(requestRatings));
|
||||
};
|
||||
|
||||
subscribeChat = (hexPubKeys: string[], since: number, events: RoboPoolEvents): void => {
|
||||
const requestRatings = ['REQ', 'subscribeChat', { kinds: [1059], '#p': hexPubKeys, since }];
|
||||
|
||||
this.messageHandlers.push((_url: string, messageEvent: MessageEvent) => {
|
||||
const jsonMessage = JSON.parse(messageEvent.data);
|
||||
if (jsonMessage[0] === 'EVENT') {
|
||||
events.onevent(jsonMessage[2]);
|
||||
} else if (jsonMessage[0] === 'EOSE') {
|
||||
events.oneose();
|
||||
}
|
||||
});
|
||||
this.sendMessage(JSON.stringify(requestRatings));
|
||||
};
|
||||
|
||||
sendEvent = (event: Event): void => {
|
||||
const message = ['EVENT', event];
|
||||
|
||||
|
Reference in New Issue
Block a user