From ae824d014eb2163c139a218d7e45c1274e219fc6 Mon Sep 17 00:00:00 2001 From: jo-es Date: Fri, 31 Jul 2020 16:57:34 +0200 Subject: [PATCH] Add publisher query --- public/content.js | 3 +++ src/Components/Reader.js | 6 +++++- src/services/publisher.js | 22 +++++----------------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/public/content.js b/public/content.js index 2a147a1..12a5289 100644 --- a/public/content.js +++ b/public/content.js @@ -69,11 +69,14 @@ async function onDidReceiveMessage(event) { if (event.data.type && (event.data.type === 'QUERY_PUBLISHER')) { try { const response = await fetch(event.data.url); + console.log(response); if (response.status !== 200) { throw new Error(response); } try { const result = await response.json(); + console.log(result); window.postMessage({ type: 'QUERY_PUBLISHER_RESPONSE', result }, '*'); } catch (error) { + console.log(error); console.log(error); throw new Error('Response body is empty.') } diff --git a/src/Components/Reader.js b/src/Components/Reader.js index b318265..d1df7be 100644 --- a/src/Components/Reader.js +++ b/src/Components/Reader.js @@ -4,7 +4,7 @@ import { connectMetamask, signV4 } from '../services/ethereum' import Annotation from '../Models/Annotation' import Logo from '../images/logo' import { ModalContext } from '../Contexts/ModalProvider'; -// import { getAnnotationCIDs } from '../services/publisher' +import { getAnnotationsByReference } from '../services/publisher' import { getAnnotationCIDsByReference } from '../services/graph' import { getAnnotationData } from '../services/ipfs' import { getTweetData } from '../helpers' @@ -22,6 +22,10 @@ const Reader = ({ setPage }) => { for (const annotationCID of annotationCIDs) { annotations.push(new Annotation({ payload: await getAnnotationData(annotationCID) })); } + // combine perisisted and pending annotations + // const annotationsFromPublisher = await getAnnotationsByReference({ reference: tweetId }); + // console.log(annotations); + // console.log(annotationsFromPublisher); setTweetAnnotations(annotations); })(); }, []) diff --git a/src/services/publisher.js b/src/services/publisher.js index 4d604ad..16a5720 100644 --- a/src/services/publisher.js +++ b/src/services/publisher.js @@ -1,5 +1,5 @@ // const PUBLISHER_URL = 'https://pan.network/annotation/v1'; -const PUBLISHER_URL = 'http://134.122.90.29:8000'; +const PUBLISHER_URL = 'https://134.122.90.29:8000'; async function get(params) { @@ -17,7 +17,7 @@ async function get(params) { }); } -export async function post(route, body) { +export async function post(body) { return new Promise((resolve) => { window.postMessage({ type: 'POST_PUBLISHER', url: PUBLISHER_URL, body: JSON.stringify(body) }, '*'); window.addEventListener('message', (event) => { @@ -28,22 +28,10 @@ export async function post(route, body) { }); } -// export async function getAnnotationCIDs( {first=10, skip=0} ) { -// const result = await get({ limit: first, offset: skip }); - -// return result; -// } - -export const getAnnotationCIDs = async ({ first = 10, skip = 0 }) => { - const result = await get({ limit: first, offset: skip }); - - return result; -} - -export async function getAnnotationCIDsByReference({ first, skip, reference }) { - return; +export async function getAnnotationsByReference({ first = 10, skip = 0, reference }) { + return get({ limit: first, offset: skip, content: reference }); } export async function sendAnnotationToPublisher(annotation) { - return post(PUBLISHER_URL, annotation); + return post(annotation); } \ No newline at end of file