From b950911108a4b23aa4e9d5b60a84ff8387a1c61c Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 23 Jan 2024 16:52:45 -0600 Subject: [PATCH 01/26] initial commit --- src/app.jsx | 2 +- src/core/adapter/devhub-contract.jsx | 9 ++ src/devhub/entity/community/Discussions.jsx | 148 ++++++++++++++++++++ src/devhub/page/community/index.jsx | 7 + 4 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 src/devhub/entity/community/Discussions.jsx diff --git a/src/app.jsx b/src/app.jsx index d8a741f4d..706d569c8 100644 --- a/src/app.jsx +++ b/src/app.jsx @@ -64,7 +64,7 @@ function Page() { // ?page=community case "community": { return ( - // Considering to consolsidate this into a single widget, + // Considering to consolidate this into a single widget, // where each level handles its own routing. // Modularizing a page just like we do with addons <>); +setCommunitySocialDB = setCommunitySocialDB || (() => <>); + +const communityData = getCommunity({ handle }); + +const MainContent = styled.div` + padding-left: 2rem; + flex: 3; + @media screen and (max-width: 960px) { + padding-left: 0rem; + } + .post:hover { + background-color: inherit !important; + } +`; + +const SidebarContainer = styled.div` + flex: 1; +`; + +const Heading = styled.div` + font-size: 19px; + font-weight: 600; +`; + +const SubHeading = styled.div` + font-size: 15px; + font-weight: 600; +`; + +const Container = styled.div` + flex-wrap: no-wrap; + max-width: 100%; + + .max-width-100 { + max-width: 100%; + } + @media screen and (max-width: 960px) { + flex-wrap: wrap; + } + + .card { + border-radius: 1rem !important; + } +`; + +const Tag = styled.div` + border-top-right-radius: 50px; + border-bottom-right-radius: 50px; + border-top-left-radius: 50px; + border-bottom-left-radius: 50px; + padding-inline: 0.8rem; + padding-block: 0.3rem; + display: flex; + gap: 0.5rem; + border-width: 1px; + border-style: solid; + font-size: 14px; + color: rgba(0, 236, 151, 1); + font-weight: 800; +`; + +const [sort, setSort] = useState("timedesc"); + +return ( +
+ + +
+ {context.accountId && ( +
+ + setCommunityDiscussionSocialDB({ + handle, + data: v, + }), + }} + /> +
+ )} +
+ Announcements +
+ +
+
+ + +
+
+ +
+
+
{communityData?.description}
+
+ {communityData?.tag} +
+
+
+ Community Admins + {(communityData?.admins ?? []).map((accountId) => ( +
+ +
+ ))} +
+
+
+
+
+); diff --git a/src/devhub/page/community/index.jsx b/src/devhub/page/community/index.jsx index 4600d6084..375851e46 100644 --- a/src/devhub/page/community/index.jsx +++ b/src/devhub/page/community/index.jsx @@ -62,6 +62,13 @@ const tabs = [ handle: community.handle, }, }, + { + title: "Discussions", + view: "${REPL_DEVHUB}/widget/devhub.entity.community.Discussions", + params: { + handle: community.handle, + }, + }, { title: "Activity", view: "${REPL_DEVHUB}/widget/devhub.entity.community.Activity", From 8de82ab4a9841ea47a9a73030e3dbb052b2d607f Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 26 Jan 2024 14:56:20 -0600 Subject: [PATCH 02/26] added createDiscussion and dynamic feed action --- src/core/adapter/devhub-contract.jsx | 4 ++-- src/devhub/components/organism/Feed.jsx | 2 +- src/devhub/entity/community/Discussions.jsx | 13 +++++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/core/adapter/devhub-contract.jsx b/src/core/adapter/devhub-contract.jsx index c36c092b8..090bb8b12 100644 --- a/src/core/adapter/devhub-contract.jsx +++ b/src/core/adapter/devhub-contract.jsx @@ -131,9 +131,9 @@ function setCommunitySocialDB({ handle, data }) { ); } -function setCommunityDiscussionSocialDB({ handle, data }) { +function createDiscussion({ handle, data }) { return ( - Near.call("${REPL_DEVHUB_CONTRACT}", "set_discussions_community_socialdb", { + Near.call("${REPL_DEVHUB_CONTRACT}", "create_discussion", { handle, data, }) ?? null diff --git a/src/devhub/components/organism/Feed.jsx b/src/devhub/components/organism/Feed.jsx index 733745506..d9bd1767b 100644 --- a/src/devhub/components/organism/Feed.jsx +++ b/src/devhub/components/organism/Feed.jsx @@ -84,7 +84,7 @@ return ( <>); const communityData = getCommunity({ handle }); +const result = Social.get("thomasguntenaar.near/post/**", { + with_block_height: true, +}); + +if (result) { + console.log({ result }); +} + const MainContent = styled.div` padding-left: 2rem; flex: 3; @@ -78,7 +86,7 @@ return ( src={"${REPL_DEVHUB}/widget/devhub.entity.community.Compose"} props={{ onSubmit: (v) => - setCommunityDiscussionSocialDB({ + createDiscussion({ handle, data: v, }), @@ -110,8 +118,9 @@ return ( src="${REPL_DEVHUB}/widget/devhub.components.organism.Feed" props={{ showFlagAccountFeature: true, + action: "repost", filteredAccountIds: [ - `discussions.${handle}.community.${REPL_DEVHUB_CONTRACT}`, + `${handle}.community.${REPL_DEVHUB_CONTRACT}`, ], sort: sort, }} From 3a7dd60f7e58096d0a986aeedb05e2594287872d Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 26 Jan 2024 14:58:29 -0600 Subject: [PATCH 03/26] remove old test --- src/devhub/entity/community/Discussions.jsx | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/devhub/entity/community/Discussions.jsx b/src/devhub/entity/community/Discussions.jsx index dbcf4c4ab..f8110b74e 100644 --- a/src/devhub/entity/community/Discussions.jsx +++ b/src/devhub/entity/community/Discussions.jsx @@ -8,14 +8,6 @@ setCommunitySocialDB = setCommunitySocialDB || (() => <>); const communityData = getCommunity({ handle }); -const result = Social.get("thomasguntenaar.near/post/**", { - with_block_height: true, -}); - -if (result) { - console.log({ result }); -} - const MainContent = styled.div` padding-left: 2rem; flex: 3; From b6f3db7b364a526bea590e3b76bdc0e754d6dcc8 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 26 Jan 2024 15:15:52 -0600 Subject: [PATCH 04/26] call grant_write_permission on socialdb contract to repost --- src/devhub/entity/community/Discussions.jsx | 59 +++++++++++++++++++-- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/src/devhub/entity/community/Discussions.jsx b/src/devhub/entity/community/Discussions.jsx index f8110b74e..209d1411c 100644 --- a/src/devhub/entity/community/Discussions.jsx +++ b/src/devhub/entity/community/Discussions.jsx @@ -67,6 +67,28 @@ const Tag = styled.div` const [sort, setSort] = useState("timedesc"); +let grantNotify = Near.view( + "${REPL_SOCIAL_CONTRACT}", + "is_write_permission_granted", + { + predecessor_id: "${REPL_DEVHUB_LEGACY}", + key: context.accountId + "/index/notify", + } +); + +let grantRepost = Near.view( + "${REPL_SOCIAL_CONTRACT}", + "is_write_permission_granted", + { + predecessor_id: "${REPL_DEVHUB_LEGACY}", + key: context.accountId + "/index/repost", + } +); + +if (grantNotify === null || grantRepost === null) { + return; +} + return (
@@ -77,11 +99,38 @@ return ( - createDiscussion({ - handle, - data: v, - }), + onSubmit: (v) => { + let createDiscussionTx = [ + { + contractName: "${REPL_DEVHUB_CONTRACT}", + methodName: "create_discussion", + args: { + handle, + data: v, + }, + gas: Big(10).pow(14), + }, + ]; + + if (grantNotify === false || grantRepost === false) { + createDiscussionTx.unshift({ + contractName: "${REPL_SOCIAL_CONTRACT}", + methodName: "grant_write_permission", + args: { + // @ailisp this shouldn't be legacy right? because with notification it is + predecessor_id: "${REPL_DEVHUB_CONTRACT}", + keys: [ + context.accountId + "/index/notify", + context.accountId + "/index/repost", + ], + }, + gas: Big(10).pow(14), + deposit: + getDepositAmountForWriteAccess(userStorageDeposit), + }); + } + Near.call(createDiscussionTx); + }, }} />
From d9846b5899bc0e4458ecb3fe99fd63170479623a Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 26 Jan 2024 15:23:42 -0600 Subject: [PATCH 05/26] removed comment --- src/devhub/entity/community/Discussions.jsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/devhub/entity/community/Discussions.jsx b/src/devhub/entity/community/Discussions.jsx index 209d1411c..604814aea 100644 --- a/src/devhub/entity/community/Discussions.jsx +++ b/src/devhub/entity/community/Discussions.jsx @@ -117,7 +117,6 @@ return ( contractName: "${REPL_SOCIAL_CONTRACT}", methodName: "grant_write_permission", args: { - // @ailisp this shouldn't be legacy right? because with notification it is predecessor_id: "${REPL_DEVHUB_CONTRACT}", keys: [ context.accountId + "/index/notify", From 51a1a1e296a489a07549e16047e580b4d26667c9 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 26 Jan 2024 15:29:08 -0600 Subject: [PATCH 06/26] add import for getDepositAmountForWriteAccess --- src/devhub/entity/community/Discussions.jsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/devhub/entity/community/Discussions.jsx b/src/devhub/entity/community/Discussions.jsx index 604814aea..ab5715e8d 100644 --- a/src/devhub/entity/community/Discussions.jsx +++ b/src/devhub/entity/community/Discussions.jsx @@ -2,6 +2,11 @@ const { handle } = props; const { getCommunity, setCommunitySocialDB } = VM.require( "${REPL_DEVHUB}/widget/core.adapter.devhub-contract" ); +const { getDepositAmountForWriteAccess } = VM.require( + "${REPL_DEVHUB}/widget/core.lib.common" +); + +getDepositAmountForWriteAccess || (getDepositAmountForWriteAccess = () => {}); getCommunity = getCommunity || (() => <>); setCommunitySocialDB = setCommunitySocialDB || (() => <>); From 60409463af3b4dcdc69b0e39de9a1de46c0082e7 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 26 Jan 2024 15:34:07 -0600 Subject: [PATCH 07/26] get storage_balance_of user --- src/devhub/entity/community/Discussions.jsx | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/devhub/entity/community/Discussions.jsx b/src/devhub/entity/community/Discussions.jsx index ab5715e8d..cd7754043 100644 --- a/src/devhub/entity/community/Discussions.jsx +++ b/src/devhub/entity/community/Discussions.jsx @@ -72,7 +72,7 @@ const Tag = styled.div` const [sort, setSort] = useState("timedesc"); -let grantNotify = Near.view( +const grantNotify = Near.view( "${REPL_SOCIAL_CONTRACT}", "is_write_permission_granted", { @@ -81,7 +81,7 @@ let grantNotify = Near.view( } ); -let grantRepost = Near.view( +const grantRepost = Near.view( "${REPL_SOCIAL_CONTRACT}", "is_write_permission_granted", { @@ -90,7 +90,19 @@ let grantRepost = Near.view( } ); -if (grantNotify === null || grantRepost === null) { +const userStorageDeposit = Near.view( + "${REPL_SOCIAL_CONTRACT}", + "storage_balance_of", + { + account_id: context.accountId, + } +); + +if ( + grantNotify === null || + grantRepost === null || + userStorageDeposit === null +) { return; } From ae0034e98443787b9498bab310567b9d79ad05ce Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 31 Jan 2024 10:17:37 -0600 Subject: [PATCH 08/26] grant permission for discussion to write post --- src/devhub/entity/community/Discussions.jsx | 26 ++++----------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/src/devhub/entity/community/Discussions.jsx b/src/devhub/entity/community/Discussions.jsx index cd7754043..696f1d3f6 100644 --- a/src/devhub/entity/community/Discussions.jsx +++ b/src/devhub/entity/community/Discussions.jsx @@ -72,21 +72,12 @@ const Tag = styled.div` const [sort, setSort] = useState("timedesc"); -const grantNotify = Near.view( +const grantPost = Near.view( "${REPL_SOCIAL_CONTRACT}", "is_write_permission_granted", { predecessor_id: "${REPL_DEVHUB_LEGACY}", - key: context.accountId + "/index/notify", - } -); - -const grantRepost = Near.view( - "${REPL_SOCIAL_CONTRACT}", - "is_write_permission_granted", - { - predecessor_id: "${REPL_DEVHUB_LEGACY}", - key: context.accountId + "/index/repost", + key: context.accountId + "/main/post", } ); @@ -98,11 +89,7 @@ const userStorageDeposit = Near.view( } ); -if ( - grantNotify === null || - grantRepost === null || - userStorageDeposit === null -) { +if (grantPost === null || userStorageDeposit === null) { return; } @@ -129,16 +116,13 @@ return ( }, ]; - if (grantNotify === false || grantRepost === false) { + if (grantPost === false) { createDiscussionTx.unshift({ contractName: "${REPL_SOCIAL_CONTRACT}", methodName: "grant_write_permission", args: { predecessor_id: "${REPL_DEVHUB_CONTRACT}", - keys: [ - context.accountId + "/index/notify", - context.accountId + "/index/repost", - ], + keys: [context.accountId + "/post/main"], }, gas: Big(10).pow(14), deposit: From 61ca49d1ccc249495655d00c5a0603818b1a05c5 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 2 Feb 2024 10:33:26 -0600 Subject: [PATCH 09/26] follow the discussions account in the feed --- src/devhub/entity/community/Discussions.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devhub/entity/community/Discussions.jsx b/src/devhub/entity/community/Discussions.jsx index 696f1d3f6..cbb8e304b 100644 --- a/src/devhub/entity/community/Discussions.jsx +++ b/src/devhub/entity/community/Discussions.jsx @@ -161,7 +161,7 @@ return ( showFlagAccountFeature: true, action: "repost", filteredAccountIds: [ - `${handle}.community.${REPL_DEVHUB_CONTRACT}`, + `discussions.${handle}.community.${REPL_DEVHUB_CONTRACT}`, ], sort: sort, }} From 787fbb4e877de5c72be78b77ed6c654bb8e3bb8b Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 5 Feb 2024 17:18:26 -0600 Subject: [PATCH 10/26] removed grant_write_permission --- src/devhub/entity/community/Discussions.jsx | 73 +++++++-------------- 1 file changed, 23 insertions(+), 50 deletions(-) diff --git a/src/devhub/entity/community/Discussions.jsx b/src/devhub/entity/community/Discussions.jsx index cbb8e304b..3b713a262 100644 --- a/src/devhub/entity/community/Discussions.jsx +++ b/src/devhub/entity/community/Discussions.jsx @@ -2,11 +2,6 @@ const { handle } = props; const { getCommunity, setCommunitySocialDB } = VM.require( "${REPL_DEVHUB}/widget/core.adapter.devhub-contract" ); -const { getDepositAmountForWriteAccess } = VM.require( - "${REPL_DEVHUB}/widget/core.lib.common" -); - -getDepositAmountForWriteAccess || (getDepositAmountForWriteAccess = () => {}); getCommunity = getCommunity || (() => <>); setCommunitySocialDB = setCommunitySocialDB || (() => <>); @@ -72,27 +67,6 @@ const Tag = styled.div` const [sort, setSort] = useState("timedesc"); -const grantPost = Near.view( - "${REPL_SOCIAL_CONTRACT}", - "is_write_permission_granted", - { - predecessor_id: "${REPL_DEVHUB_LEGACY}", - key: context.accountId + "/main/post", - } -); - -const userStorageDeposit = Near.view( - "${REPL_SOCIAL_CONTRACT}", - "storage_balance_of", - { - account_id: context.accountId, - } -); - -if (grantPost === null || userStorageDeposit === null) { - return; -} - return (
@@ -104,32 +78,31 @@ return ( src={"${REPL_DEVHUB}/widget/devhub.entity.community.Compose"} props={{ onSubmit: (v) => { - let createDiscussionTx = [ + const result = Social.set( + `${context.accountId}/post/main`, + v, { - contractName: "${REPL_DEVHUB_CONTRACT}", - methodName: "create_discussion", - args: { - handle, - data: v, - }, - gas: Big(10).pow(14), - }, - ]; - - if (grantPost === false) { - createDiscussionTx.unshift({ - contractName: "${REPL_SOCIAL_CONTRACT}", - methodName: "grant_write_permission", - args: { - predecessor_id: "${REPL_DEVHUB_CONTRACT}", - keys: [context.accountId + "/post/main"], + onCommit: (data) => { + // Near.get( + // "${REPL_DEVHUB_CONTRACT}", + // "get_block_height", + // { + // onReturn: (blockHeight) => { + // Near.call( + // "${REPL_DEVHUB_CONTRACT}", + // "create_discussion", + // { + // community_handle: "...", + // near_social_post_block_height: blockHeight, + // } + // ); + // }, + // } + // ); }, - gas: Big(10).pow(14), - deposit: - getDepositAmountForWriteAccess(userStorageDeposit), - }); - } - Near.call(createDiscussionTx); + } + ); + console.log("result", result); }, }} /> From c8ac8eba3caa9ee67e0ae4ac02998bfd0d9ceddf Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 5 Feb 2024 18:05:11 -0600 Subject: [PATCH 11/26] need a better way to get the blockheight --- src/devhub/entity/community/Discussions.jsx | 134 +++++++++++++++++--- 1 file changed, 118 insertions(+), 16 deletions(-) diff --git a/src/devhub/entity/community/Discussions.jsx b/src/devhub/entity/community/Discussions.jsx index 3b713a262..4d4e842f3 100644 --- a/src/devhub/entity/community/Discussions.jsx +++ b/src/devhub/entity/community/Discussions.jsx @@ -67,6 +67,64 @@ const Tag = styled.div` const [sort, setSort] = useState("timedesc"); +function fetchGraphQL(operationsDoc, operationName, variables) { + return asyncFetch(`${GRAPHQL_ENDPOINT}/v1/graphql`, { + method: "POST", + headers: { "x-hasura-role": "dataplatform_near" }, + body: JSON.stringify({ + query: operationsDoc, + variables: variables, + operationName: operationName, + }), + }); +} +let lastPostSocialApi = Social.index("post", "main", { + limit: 1, + order: "desc", +}); + +if (lastPostSocialApi == null) { + return "Loading..."; +} + +// console.log("context", context.accountId); +// let test = Social.get(`${context.accountId}/post/main`, { +// options: { with_block_height: true }, +// }); +// console.log("test", test); + +function repostOnDiscussions(blockHeight) { + Near.call([ + { + contractName: "${REPL_DEVHUB_CONTRACT}", + methodName: "create_discussion", + args: { + handle, + data: { + [`discussions.${handle}.community.${REPL_DEVHUB_CONTRACT}`]: { + index: { + repost: JSON.stringify([ + { + key: "main", + value: { + type: "repost", + item: { + type: "social", + path: context.accountId + "/post/main", + blockHeight, + }, + }, + }, + ]), + }, + }, + }, + }, + gas: Big(10).pow(14), + }, + ]); +} + return (
@@ -78,27 +136,70 @@ return ( src={"${REPL_DEVHUB}/widget/devhub.entity.community.Compose"} props={{ onSubmit: (v) => { + // Post to users social db const result = Social.set( `${context.accountId}/post/main`, v, { onCommit: (data) => { - // Near.get( - // "${REPL_DEVHUB_CONTRACT}", - // "get_block_height", - // { - // onReturn: (blockHeight) => { - // Near.call( - // "${REPL_DEVHUB_CONTRACT}", - // "create_discussion", - // { - // community_handle: "...", - // near_social_post_block_height: blockHeight, - // } - // ); - // }, - // } - // ); + // TODO remove + console.log("onCommit"); + console.log("data", data); + // TODO get the block height in another way + const lastPostQuery = ` + query IndexerQuery { + dataplatform_near_social_feed_posts( limit: 1, order_by: { block_height: desc }) { + block_height + } + } + `; + + fetchGraphQL(lastPostQuery, "IndexerQuery", {}) + .then((feedIndexerResponse) => { + // TODO remove + console.log( + "feedIndexerResponse", + feedIndexerResponse + ); + if ( + feedIndexerResponse && + feedIndexerResponse.body.data + .dataplatform_near_social_feed_posts.length > + 0 + ) { + const nearSocialBlockHeight = + lastPostSocialApi[0].blockHeight; + const feedIndexerBlockHeight = + feedIndexerResponse.body.data + .dataplatform_near_social_feed_posts[0] + .block_height; + // TODO necessary? + const lag = + nearSocialBlockHeight - + feedIndexerBlockHeight; + let shouldFallback = + lag > 2 || !feedIndexerBlockHeight; + if (shouldFallback === true) { + console.log( + "Falling back to Social index feed. Block difference is: ", + nearSocialBlockHeight - + feedIndexerBlockHeight + ); + } + + repostOnDiscussions(nearSocialBlockHeight); + } else { + console.log( + "Falling back to Social index feed. No QueryApi data received." + ); + } + }) + .catch((error) => { + console.log( + "Error while fetching QueryApi feed (falling back to index feed): ", + error + ); + }); }, } ); @@ -135,6 +236,7 @@ return ( action: "repost", filteredAccountIds: [ `discussions.${handle}.community.${REPL_DEVHUB_CONTRACT}`, + // "thomasguntenaar.near", // TODO: get index/repost ], sort: sort, }} From 815c8db25da894b207c0806fe2de9d4a57c309d8 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 6 Feb 2024 15:52:09 -0600 Subject: [PATCH 12/26] added near view get with_block_height --- src/core/adapter/devhub-contract.jsx | 4 + src/devhub/entity/community/Discussions.jsx | 133 ++++++-------------- 2 files changed, 39 insertions(+), 98 deletions(-) diff --git a/src/core/adapter/devhub-contract.jsx b/src/core/adapter/devhub-contract.jsx index 090bb8b12..d1da9e88b 100644 --- a/src/core/adapter/devhub-contract.jsx +++ b/src/core/adapter/devhub-contract.jsx @@ -99,6 +99,10 @@ function getAllCommunitiesMetadata() { ); } +function getSocialWithBlockHeight(data) { + return Near.view("${REPL_SOCIAL_CONTRACT}", "get", data) ?? null; +} + function getAllLabels() { return Near.view("${REPL_DEVHUB_LEGACY}", "get_all_labels") ?? null; } diff --git a/src/devhub/entity/community/Discussions.jsx b/src/devhub/entity/community/Discussions.jsx index 4d4e842f3..1f9929513 100644 --- a/src/devhub/entity/community/Discussions.jsx +++ b/src/devhub/entity/community/Discussions.jsx @@ -67,32 +67,6 @@ const Tag = styled.div` const [sort, setSort] = useState("timedesc"); -function fetchGraphQL(operationsDoc, operationName, variables) { - return asyncFetch(`${GRAPHQL_ENDPOINT}/v1/graphql`, { - method: "POST", - headers: { "x-hasura-role": "dataplatform_near" }, - body: JSON.stringify({ - query: operationsDoc, - variables: variables, - operationName: operationName, - }), - }); -} -let lastPostSocialApi = Social.index("post", "main", { - limit: 1, - order: "desc", -}); - -if (lastPostSocialApi == null) { - return "Loading..."; -} - -// console.log("context", context.accountId); -// let test = Social.get(`${context.accountId}/post/main`, { -// options: { with_block_height: true }, -// }); -// console.log("test", test); - function repostOnDiscussions(blockHeight) { Near.call([ { @@ -125,6 +99,40 @@ function repostOnDiscussions(blockHeight) { ]); } +function setSocialDbAndRepost(v) { + console.log("v", v); + // Post to users social db + // `${context.accountId}/post/main`, + const result = Social.set(v, { + onCommit: (data) => { + console.log("onCommit"); + console.log("data", data); + + let testSocialGet = Social.get(`${context.accountId}/post/main`, null, { + with_block_height: true, + }); + console.log("testSocialGet", testSocialGet); + + // TODO move to devhub-contract when it works + let getData = Near.view("${REPL_SOCIAL_CONTRACT}", "get", { + keys: [`${context.accountId}/post/main`], + options: { + with_block_height: true, + }, + }); + console.log("getData", getData); + getData.blockHeight = getData.blockHeight || 0; + if (getData.blockHeight) { + repostOnDiscussions(getData.blockHeight); + } else { + // TODO remove + repostOnDiscussions(94381896); + } + }, + }); + console.log("result", result); +} + return (
@@ -135,76 +143,7 @@ return ( { - // Post to users social db - const result = Social.set( - `${context.accountId}/post/main`, - v, - { - onCommit: (data) => { - // TODO remove - console.log("onCommit"); - console.log("data", data); - // TODO get the block height in another way - const lastPostQuery = ` - query IndexerQuery { - dataplatform_near_social_feed_posts( limit: 1, order_by: { block_height: desc }) { - block_height - } - } - `; - - fetchGraphQL(lastPostQuery, "IndexerQuery", {}) - .then((feedIndexerResponse) => { - // TODO remove - console.log( - "feedIndexerResponse", - feedIndexerResponse - ); - if ( - feedIndexerResponse && - feedIndexerResponse.body.data - .dataplatform_near_social_feed_posts.length > - 0 - ) { - const nearSocialBlockHeight = - lastPostSocialApi[0].blockHeight; - const feedIndexerBlockHeight = - feedIndexerResponse.body.data - .dataplatform_near_social_feed_posts[0] - .block_height; - // TODO necessary? - const lag = - nearSocialBlockHeight - - feedIndexerBlockHeight; - let shouldFallback = - lag > 2 || !feedIndexerBlockHeight; - if (shouldFallback === true) { - console.log( - "Falling back to Social index feed. Block difference is: ", - nearSocialBlockHeight - - feedIndexerBlockHeight - ); - } - - repostOnDiscussions(nearSocialBlockHeight); - } else { - console.log( - "Falling back to Social index feed. No QueryApi data received." - ); - } - }) - .catch((error) => { - console.log( - "Error while fetching QueryApi feed (falling back to index feed): ", - error - ); - }); - }, - } - ); - console.log("result", result); - }, + onSubmit: setSocialDbAndRepost, }} />
@@ -228,7 +167,6 @@ return (
- Date: Wed, 7 Feb 2024 10:39:22 -0600 Subject: [PATCH 13/26] change title --- src/devhub/entity/community/Discussions.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devhub/entity/community/Discussions.jsx b/src/devhub/entity/community/Discussions.jsx index 1f9929513..b17156bf5 100644 --- a/src/devhub/entity/community/Discussions.jsx +++ b/src/devhub/entity/community/Discussions.jsx @@ -149,7 +149,7 @@ return ( )}
- Announcements + Discussions
- + {!postsExists && ( +
+
No discussions exists.
+
+ )} +
+ +
From 6af9aa1370fe35cf112ce7f4fe5a3331bf834cea Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 8 Feb 2024 00:26:51 -0600 Subject: [PATCH 16/26] wip --- src/devhub/entity/community/Discussions.jsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/devhub/entity/community/Discussions.jsx b/src/devhub/entity/community/Discussions.jsx index 04b6ae59d..48b551aad 100644 --- a/src/devhub/entity/community/Discussions.jsx +++ b/src/devhub/entity/community/Discussions.jsx @@ -163,6 +163,17 @@ return ( )}
+ {/* TODO: this feed is from https://near.org/near/widget/ComponentDetailsPage?src=mob.near/widget/ProfileTabs */} + + {/* This is our custom feed which uses the one from near builders which should also show reposts! */} Date: Fri, 9 Feb 2024 19:10:03 -0600 Subject: [PATCH 17/26] wip props.transactionHashes not recognized ? --- src/devhub/entity/community/Discussions.jsx | 76 ++++++++++++++++++--- 1 file changed, 65 insertions(+), 11 deletions(-) diff --git a/src/devhub/entity/community/Discussions.jsx b/src/devhub/entity/community/Discussions.jsx index 48b551aad..03c384b75 100644 --- a/src/devhub/entity/community/Discussions.jsx +++ b/src/devhub/entity/community/Discussions.jsx @@ -94,25 +94,77 @@ function repostOnDiscussions(blockHeight) { * blockheight from my profile and reposting that message. */ +// https://near.org/devhub.near/widget/app?page=community&handle=devhub-test&tab=discussions&transactionHashes=Gx1QLChBRWenfZFHos9pf9nqpavfeeQEQEb8DoEsFp6p function setSocialDbAndRepost(v) { // Post to users social db Social.set(v, { onCommit: (data) => { console.log("onCommit data", data); - Near.asyncView("${REPL_SOCIAL_CONTRACT}", "get", { - keys: [`${context.accountId}/**`], - options: { - with_block_height: true, - }, - }) - .then((response) => { - let blockHeight = response[context.accountId]["post"][":block"]; - repostOnDiscussions(blockHeight); - }) - .catch(console.log); + // onCommit is dead after redirect to near wallet }, }); } + +function checkHashes() { + console.log("checking.."); + if (props.transactionHashes) { + console.log("passed first check props.transactionHashes"); + const transaction = useCache( + () => + asyncFetch("https://rpc.mainnet.near.org", { + method: "POST", + headers: { + "content-type": "application/json", + }, + body: JSON.stringify({ + jsonrpc: "2.0", + id: "dontcare", + method: "tx", + params: [props.transactionHashes, context.accountId], + }), + }).then((res) => res), + props.transactionHashes + context.accountId, + { subscribe: false } + ); + + console.log("transaction", transaction); + + if (transaction !== null) { + const transaction_method_name = + transaction?.body?.result?.transaction?.actions[0].FunctionCall + .method_name; + + console.log("transaction_method_name", transaction_method_name); + if (transaction_method_name === "set") { + // props.onDraftStateChange(null); + console.log("getBlockHeightAndRepost"); + getBlockHeightAndRepost(); + } + + // show the latest created post to user + if (transaction_method_name === "create_discussion") { + console.log("Discussions created in the last call, show it to user."); + } + } + } +} + +function getBlockHeightAndRepost() { + Near.asyncView("${REPL_SOCIAL_CONTRACT}", "get", { + keys: [`${context.accountId}/**`], + options: { + with_block_height: true, + }, + }) + .then((response) => { + let blockHeight = response[context.accountId]["post"][":block"]; + repostOnDiscussions(blockHeight); + }) + .catch(console.log); +} + +checkHashes(); + console.log(`discussions.${handle}.community.${REPL_DEVHUB_CONTRACT}`); return ( @@ -134,6 +186,8 @@ return ( )}
Discussions + {/* TODO: Remove */} +

This component props: {JSON.stringify(props)}

Date: Fri, 9 Feb 2024 19:18:42 -0600 Subject: [PATCH 18/26] pass transactionHashes on from the page --- src/devhub/page/community/index.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/devhub/page/community/index.jsx b/src/devhub/page/community/index.jsx index 375851e46..ca13dd64c 100644 --- a/src/devhub/page/community/index.jsx +++ b/src/devhub/page/community/index.jsx @@ -67,6 +67,7 @@ const tabs = [ view: "${REPL_DEVHUB}/widget/devhub.entity.community.Discussions", params: { handle: community.handle, + transactionHashes: props.transactionHashes, }, }, { From f95363a3ce0651ceea690d8e1c2af901428478fd Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 12 Feb 2024 11:27:12 -0600 Subject: [PATCH 19/26] Ready for review @frol --- src/devhub/entity/community/Discussions.jsx | 99 ++++++++------------- 1 file changed, 36 insertions(+), 63 deletions(-) diff --git a/src/devhub/entity/community/Discussions.jsx b/src/devhub/entity/community/Discussions.jsx index 03c384b75..0d0ae6d7b 100644 --- a/src/devhub/entity/community/Discussions.jsx +++ b/src/devhub/entity/community/Discussions.jsx @@ -79,10 +79,9 @@ function repostOnDiscussions(blockHeight) { methodName: "create_discussion", args: { handle, - blockHeight, + block_height: blockHeight, }, gas: Big(10).pow(14), - deposit: Big(10).pow(22), }, ]); } @@ -94,79 +93,56 @@ function repostOnDiscussions(blockHeight) { * blockheight from my profile and reposting that message. */ -// https://near.org/devhub.near/widget/app?page=community&handle=devhub-test&tab=discussions&transactionHashes=Gx1QLChBRWenfZFHos9pf9nqpavfeeQEQEb8DoEsFp6p -function setSocialDbAndRepost(v) { - // Post to users social db - Social.set(v, { - onCommit: (data) => { - console.log("onCommit data", data); - // onCommit is dead after redirect to near wallet - }, - }); -} - -function checkHashes() { - console.log("checking.."); +async function checkHashes() { if (props.transactionHashes) { - console.log("passed first check props.transactionHashes"); - const transaction = useCache( - () => - asyncFetch("https://rpc.mainnet.near.org", { - method: "POST", - headers: { - "content-type": "application/json", - }, - body: JSON.stringify({ - jsonrpc: "2.0", - id: "dontcare", - method: "tx", - params: [props.transactionHashes, context.accountId], - }), - }).then((res) => res), - props.transactionHashes + context.accountId, - { subscribe: false } - ); - - console.log("transaction", transaction); - - if (transaction !== null) { - const transaction_method_name = - transaction?.body?.result?.transaction?.actions[0].FunctionCall - .method_name; - - console.log("transaction_method_name", transaction_method_name); - if (transaction_method_name === "set") { - // props.onDraftStateChange(null); - console.log("getBlockHeightAndRepost"); - getBlockHeightAndRepost(); - } - - // show the latest created post to user - if (transaction_method_name === "create_discussion") { - console.log("Discussions created in the last call, show it to user."); + asyncFetch("https://rpc.mainnet.near.org", { + method: "POST", + headers: { + "content-type": "application/json", + }, + body: JSON.stringify({ + jsonrpc: "2.0", + id: "dontcare", + method: "tx", + params: [props.transactionHashes, context.accountId], + }), + }).then((transaction) => { + if (transaction !== null) { + const transaction_method_name = + transaction?.body?.result?.transaction?.actions[0].FunctionCall + .method_name; + + if (transaction_method_name === "set") { + getBlockHeightAndRepost(); + } + + // show the latest created post to user + if (transaction_method_name === "create_discussion") { + console.log("Discussions created in the last call, show it to user."); + } } - } + }); } } function getBlockHeightAndRepost() { Near.asyncView("${REPL_SOCIAL_CONTRACT}", "get", { - keys: [`${context.accountId}/**`], + keys: [`${context.accountId}/post/**`], options: { with_block_height: true, }, }) .then((response) => { - let blockHeight = response[context.accountId]["post"][":block"]; + let blockHeight = response[context.accountId][":block"]; repostOnDiscussions(blockHeight); }) - .catch(console.log); + .catch((error) => { + console.log("error", error); + }); } checkHashes(); -console.log(`discussions.${handle}.community.${REPL_DEVHUB_CONTRACT}`); - return (
@@ -174,11 +150,10 @@ return (
{context.accountId && (
- {/* TODO: compose is only used for post not repost */} setSocialDbAndRepost(v), + onSubmit: (v) => Social.set(v), communityAccountId: `discussions.${handle}.community.${REPL_DEVHUB_CONTRACT}`, }} /> @@ -186,8 +161,6 @@ return ( )}
Discussions - {/* TODO: Remove */} -

This component props: {JSON.stringify(props)}

- {!postsExists && ( + {/* TODO: add this with the new feed {!postsExists && (
No discussions exists.
- )} + )} */}
{/* TODO: this feed is from https://near.org/near/widget/ComponentDetailsPage?src=mob.near/widget/ProfileTabs */} Date: Fri, 16 Feb 2024 14:44:33 +0100 Subject: [PATCH 20/26] added force option and getBlockHeightAndRepost onCommit --- src/devhub/entity/community/Discussions.jsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/devhub/entity/community/Discussions.jsx b/src/devhub/entity/community/Discussions.jsx index 0d0ae6d7b..464d182e2 100644 --- a/src/devhub/entity/community/Discussions.jsx +++ b/src/devhub/entity/community/Discussions.jsx @@ -86,13 +86,6 @@ function repostOnDiscussions(blockHeight) { ]); } -/** - * I'm posting this message in the discussions of community devhub-test. - * Which posts this to my profile @thomasguntenaar.near and reposts it - * to discusssions.devhub-test.community.devhub.near by getting the latest - * blockheight from my profile and reposting that message. - */ - async function checkHashes() { if (props.transactionHashes) { asyncFetch("https://rpc.mainnet.near.org", { @@ -153,7 +146,14 @@ return ( Social.set(v), + onSubmit: (v) => { + Social.set(v, { + force: true, + onCommit: () => { + getBlockHeightAndRepost(); + }, + }); + }, communityAccountId: `discussions.${handle}.community.${REPL_DEVHUB_CONTRACT}`, }} /> From b4309207144cbff01d32aa23e00c0624d57a96b6 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 17 Feb 2024 07:54:35 +0100 Subject: [PATCH 21/26] Change the profile preview where discussions is posted from --- src/devhub/entity/community/Announcements.jsx | 1 + src/devhub/entity/community/Compose.jsx | 14 ++++++++++---- src/devhub/entity/community/Discussions.jsx | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/devhub/entity/community/Announcements.jsx b/src/devhub/entity/community/Announcements.jsx index 6e1334823..72563ae87 100644 --- a/src/devhub/entity/community/Announcements.jsx +++ b/src/devhub/entity/community/Announcements.jsx @@ -85,6 +85,7 @@ return ( props={{ onSubmit: (v) => setCommunitySocialDB({ handle, data: v }), communityAccountId: `${handle}.community.${REPL_DEVHUB_CONTRACT}`, + profileAccountId: `${handle}.community.${REPL_DEVHUB_CONTRACT}`, }} />
diff --git a/src/devhub/entity/community/Compose.jsx b/src/devhub/entity/community/Compose.jsx index f938e2c24..f22689399 100644 --- a/src/devhub/entity/community/Compose.jsx +++ b/src/devhub/entity/community/Compose.jsx @@ -1,5 +1,7 @@ const communityAccountId = props.communityAccountId; -if (!communityAccountId) { +const profileAccountId = props.profileAccountId; + +if (!communityAccountId || !profileAccountId) { return <>; } @@ -11,7 +13,7 @@ State.init({ mentionsArray: [], // all the mentions in the description }); -const profile = Social.getr(`${communityAccountId}/profile`); +const profile = Social.getr(`${profileAccountId}/profile`); const autocompleteEnabled = true; const content = { @@ -40,7 +42,10 @@ function extractMentions(text) { function extractTagNotifications(text, item) { return extractMentions(text || "") - .filter((accountId) => accountId !== communityAccountId) + .filter( + (accountId) => + accountId !== communityAccountId && accountId !== profileAccountId + ) .map((accountId) => ({ key: accountId, value: { @@ -65,6 +70,7 @@ function composeData() { }, }; + // TODO notification for discussions const notifications = extractTagNotifications(state.text, { type: "social", path: `${communityAccountId}/post/main`, @@ -363,7 +369,7 @@ return ( src="${REPL_NEAR}/widget/v1.Posts.Post" loading={
} props={{ - accountId: communityAccountId, + accountId: profileAccountId, blockHeight: "now", content, }} diff --git a/src/devhub/entity/community/Discussions.jsx b/src/devhub/entity/community/Discussions.jsx index 464d182e2..3ceccb436 100644 --- a/src/devhub/entity/community/Discussions.jsx +++ b/src/devhub/entity/community/Discussions.jsx @@ -155,6 +155,7 @@ return ( }); }, communityAccountId: `discussions.${handle}.community.${REPL_DEVHUB_CONTRACT}`, + profileAccountId: context.accountId, }} />
From 54d6c4b45c41b119aeabdf40a08dcfe80c88c6d3 Mon Sep 17 00:00:00 2001 From: T guntenaar Date: Sat, 17 Feb 2024 18:21:28 +0100 Subject: [PATCH 22/26] Update src/devhub/entity/community/Discussions.jsx Co-authored-by: Vlad Frolov --- src/devhub/entity/community/Discussions.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/devhub/entity/community/Discussions.jsx b/src/devhub/entity/community/Discussions.jsx index 3ceccb436..0f8700e87 100644 --- a/src/devhub/entity/community/Discussions.jsx +++ b/src/devhub/entity/community/Discussions.jsx @@ -130,7 +130,7 @@ function getBlockHeightAndRepost() { repostOnDiscussions(blockHeight); }) .catch((error) => { - console.log("error", error); + console.log("DevHub Error [Discussions]: getBlockHeightAndRepost failed", error); }); } From 1b922802d8a524f5ea72f8cbf6bc02774ac058ca Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 17 Feb 2024 18:26:59 +0100 Subject: [PATCH 23/26] added REPL_RPC_URL --- replacements.dev.json | 5 +++-- replacements.mainnet.json | 5 +++-- replacements.testnet.json | 5 +++-- src/devhub/entity/community/Discussions.jsx | 2 +- src/devhub/entity/post/PostEditor.jsx | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/replacements.dev.json b/replacements.dev.json index 83271d001..c9242253d 100644 --- a/replacements.dev.json +++ b/replacements.dev.json @@ -6,5 +6,6 @@ "REPL_MOB": "eugenethedream", "REPL_EFIZ": "efiz.testnet", "REPL_DEVS": "nearbuilders.testnet", - "REPL_SOCIAL_CONTRACT": "v1.social08.testnet" -} + "REPL_SOCIAL_CONTRACT": "v1.social08.testnet", + "REPL_RPC_URL": "https://rpc.testnet.near.org" +} \ No newline at end of file diff --git a/replacements.mainnet.json b/replacements.mainnet.json index 371511cd1..f88c1dd2f 100644 --- a/replacements.mainnet.json +++ b/replacements.mainnet.json @@ -6,5 +6,6 @@ "REPL_MOB": "mob.near", "REPL_EFIZ": "efiz.near", "REPL_DEVS": "devs.near", - "REPL_SOCIAL_CONTRACT": "social.near" -} + "REPL_SOCIAL_CONTRACT": "social.near", + "REPL_RPC_URL": "https://rpc.mainnet.near.org" +} \ No newline at end of file diff --git a/replacements.testnet.json b/replacements.testnet.json index 0a37cf09a..8ebedfffc 100644 --- a/replacements.testnet.json +++ b/replacements.testnet.json @@ -6,5 +6,6 @@ "REPL_MOB": "eugenethedream", "REPL_EFIZ": "efiz.testnet", "REPL_DEVS": "nearbuilders.testnet", - "REPL_SOCIAL_CONTRACT": "v1.social08.testnet" -} + "REPL_SOCIAL_CONTRACT": "v1.social08.testnet", + "REPL_RPC_URL": "https://rpc.testnet.near.org" +} \ No newline at end of file diff --git a/src/devhub/entity/community/Discussions.jsx b/src/devhub/entity/community/Discussions.jsx index 3ceccb436..69c2eac79 100644 --- a/src/devhub/entity/community/Discussions.jsx +++ b/src/devhub/entity/community/Discussions.jsx @@ -88,7 +88,7 @@ function repostOnDiscussions(blockHeight) { async function checkHashes() { if (props.transactionHashes) { - asyncFetch("https://rpc.mainnet.near.org", { + asyncFetch("${REPL_RPC_URL}", { method: "POST", headers: { "content-type": "application/json", diff --git a/src/devhub/entity/post/PostEditor.jsx b/src/devhub/entity/post/PostEditor.jsx index 43f8908e3..a48756914 100644 --- a/src/devhub/entity/post/PostEditor.jsx +++ b/src/devhub/entity/post/PostEditor.jsx @@ -175,7 +175,7 @@ const AutoComplete = styled.div` if (props.transactionHashes) { const transaction = useCache( () => - asyncFetch("https://rpc.mainnet.near.org", { + asyncFetch("${REPL_RPC_URL}", { method: "POST", headers: { "content-type": "application/json", From ce7be7c4c54670f3eebbb22a5b0cc8c300b60632 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 17 Feb 2024 18:36:21 +0100 Subject: [PATCH 24/26] removed double feed --- src/devhub/entity/community/Discussions.jsx | 39 +++++---------------- 1 file changed, 9 insertions(+), 30 deletions(-) diff --git a/src/devhub/entity/community/Discussions.jsx b/src/devhub/entity/community/Discussions.jsx index 162ded01d..85511f9f5 100644 --- a/src/devhub/entity/community/Discussions.jsx +++ b/src/devhub/entity/community/Discussions.jsx @@ -7,7 +7,6 @@ getCommunity = getCommunity || (() => <>); setCommunitySocialDB = setCommunitySocialDB || (() => <>); const communityData = getCommunity({ handle }); -const [postsExists, setPostExists] = useState(false); const MainContent = styled.div` padding-left: 2rem; @@ -130,7 +129,10 @@ function getBlockHeightAndRepost() { repostOnDiscussions(blockHeight); }) .catch((error) => { - console.log("DevHub Error [Discussions]: getBlockHeightAndRepost failed", error); + console.log( + "DevHub Error [Discussions]: getBlockHeightAndRepost failed", + error + ); }); } @@ -162,13 +164,7 @@ return ( )}
Discussions -
+