Skip to content

Commit

Permalink
Add publisher query
Browse files Browse the repository at this point in the history
  • Loading branch information
jo-es committed Jul 31, 2020
1 parent 11e7949 commit ae824d0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
3 changes: 3 additions & 0 deletions public/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
}
Expand Down
6 changes: 5 additions & 1 deletion src/Components/Reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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);
})();
}, [])
Expand Down
22 changes: 5 additions & 17 deletions src/services/publisher.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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) => {
Expand All @@ -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);
}

0 comments on commit ae824d0

Please sign in to comment.