NEAR-DevHub / neardevhub-contract

DevHub Portal Product Contract (Hosted on NEAR Blockchain) – Includes other instances (e.g. Infrastructure, Events)
https://neardevhub.org
19 stars 15 forks source link

Add communities feed #104

Closed PolyProgrammist closed 7 months ago

PolyProgrammist commented 8 months ago

Closes https://github.com/NEAR-DevHub/neardevhub-bos/issues/692

community.devhub.near account to subscribe to all the announcement and discussions subaccounts.

For example, if the account is community.devhub.near, it subscribes to my_comu.community.devhub.near and discussions.my_comu.community.devhub.near

See example for subscriptions: https://near.social/mob.near/widget/FollowPage?accountId=community.truedove38.near&tab=following

PolyProgrammist commented 7 months ago

Command to update existing community factory contract:

cargo near deploy community.truedove38.near without-init-call network-config mainnet sign-with-keychain send

Command to follow existing communities:

near contract call-function as-transaction social.near set json-args '{"data":{"community.devhub.near": {"graph": {"follow": {"nft.community.devhub.near": "", "discussions.nft.community.devhub.near": "", "hot-ideas.community.devhub.near": "", "discussions.hot-ideas.community.devhub.near": "", "protocol.community.devhub.near": "", "discussions.protocol.community.devhub.near": "", "contract-standards.community.devhub.near": "", "discussions.contract-standards.community.devhub.near": "", "tooling.community.devhub.near": "", "discussions.tooling.community.devhub.near": "", "wallet.community.devhub.near": "", "discussions.wallet.community.devhub.near": "", "validators.community.devhub.near": "", "discussions.validators.community.devhub.near": "", "zero-knowledge.community.devhub.near": "", "discussions.zero-knowledge.community.devhub.near": "", "akaia.community.devhub.near": "", "discussions.akaia.community.devhub.near": "", "dao.community.devhub.near": "", "discussions.dao.community.devhub.near": "", "challenges.community.devhub.near": "", "discussions.challenges.community.devhub.near": "", "build.community.devhub.near": "", "discussions.build.community.devhub.near": "", "hacks.community.devhub.near": "", "discussions.hacks.community.devhub.near": "", "keypom.community.devhub.near": "", "discussions.keypom.community.devhub.near": "", "refi.community.devhub.near": "", "discussions.refi.community.devhub.near": "", "ndc.community.devhub.near": "", "discussions.ndc.community.devhub.near": "", "owa.community.devhub.near": "", "discussions.owa.community.devhub.near": "", "developer-dao.community.devhub.near": "", "discussions.developer-dao.community.devhub.near": "", "near-discovery.community.devhub.near": "", "discussions.near-discovery.community.devhub.near": "", "component-libraries.community.devhub.near": "", "discussions.component-libraries.community.devhub.near": "", "documentation.community.devhub.near": "", "discussions.documentation.community.devhub.near": "", "harmonic.community.devhub.near": "", "discussions.harmonic.community.devhub.near": "", "devhub-platform.community.devhub.near": "", "discussions.devhub-platform.community.devhub.near": "", "fellowship.community.devhub.near": "", "discussions.fellowship.community.devhub.near": "", "devrel.community.devhub.near": "", "discussions.devrel.community.devhub.near": "", "near-campus.community.devhub.near": "", "discussions.near-campus.community.devhub.near": "", "devhub-marketing.community.devhub.near": "", "discussions.devhub-marketing.community.devhub.near": "", "near-enterprise.community.devhub.near": "", "discussions.near-enterprise.community.devhub.near": "", "ariz-portfolio.community.devhub.near": "", "discussions.ariz-portfolio.community.devhub.near": "", "nearukraine.community.devhub.near": "", "discussions.nearukraine.community.devhub.near": "", "near-thailand.community.devhub.near": "", "discussions.near-thailand.community.devhub.near": "", "onboard.community.devhub.near": "", "discussions.onboard.community.devhub.near": "", "security.community.devhub.near": "", "discussions.security.community.devhub.near": "", "webassemblymusic.community.devhub.near": "", "discussions.webassemblymusic.community.devhub.near": "", "she-is-near.community.devhub.near": "", "discussions.she-is-near.community.devhub.near": "", "data.community.devhub.near": "", "discussions.data.community.devhub.near": "", "neardevnews.community.devhub.near": "", "discussions.neardevnews.community.devhub.near": "", "chain-abstraction.community.devhub.near": "", "discussions.chain-abstraction.community.devhub.near": ""}}, "index": {"graph": "[{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"nft.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.nft.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"hot-ideas.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.hot-ideas.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"protocol.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.protocol.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"contract-standards.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.contract-standards.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"tooling.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.tooling.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"wallet.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.wallet.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"validators.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.validators.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"zero-knowledge.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.zero-knowledge.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"akaia.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.akaia.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"dao.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.dao.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"challenges.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.challenges.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"build.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.build.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"hacks.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.hacks.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"keypom.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.keypom.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"refi.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.refi.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"ndc.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.ndc.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"owa.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.owa.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"developer-dao.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.developer-dao.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"near-discovery.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.near-discovery.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"component-libraries.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.component-libraries.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"documentation.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.documentation.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"harmonic.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.harmonic.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"devhub-platform.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.devhub-platform.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"fellowship.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.fellowship.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"devrel.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.devrel.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"near-campus.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.near-campus.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"devhub-marketing.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.devhub-marketing.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"near-enterprise.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.near-enterprise.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"ariz-portfolio.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.ariz-portfolio.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"nearukraine.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.nearukraine.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"near-thailand.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.near-thailand.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"onboard.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.onboard.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"security.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.security.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"webassemblymusic.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.webassemblymusic.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"she-is-near.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.she-is-near.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"data.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.data.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"neardevnews.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.neardevnews.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"chain-abstraction.community.devhub.near\"}},{\"key\":\"follow\",\"value\":{\"type\":\"follow\",\"accountId\":\"discussions.chain-abstraction.community.devhub.near\"}}]"}}}}' \
    prepaid-gas '300 Tgas' \
    attached-deposit '0.1 NEAR' \
    sign-as community.devhub.near  \
    network-config mainnet \
    sign-with-keychain \
    send

Command to get existing communities:

near contract \                                 
    call-function \    as-read-only devhub.near get_all_communities_metadata \    json-args '{}' \                                       network-config pagoda-mainnet \    now > result.json

Existing communities:

['nft', 'hot-ideas', 'protocol', 'contract-standards', 'tooling', 'wallet', 'validators', 'zero-knowledge', 'akaia', 'dao', 'challenges', 'build', 'hacks', 'keypom', 'refi', 'ndc', 'owa', 'developer-dao', 'near-discovery', 'component-libraries', 'documentation', 'harmonic', 'devhub-platform', 'fellowship', 'devrel', 'near-campus', 'devhub-marketing', 'near-enterprise', 'ariz-portfolio', 'nearukraine', 'near-thailand', 'onboard', 'security', 'webassemblymusic', 'she-is-near', 'data', 'neardevnews', 'chain-abstraction']

Code to create transaction data:

import json

main_contract_acc = "devhub.near"

existing_communities = json.load(open("result.json"))
existing_communities = [i['handle'] for i in existing_communities]
print(existing_communities)

follow_dict = {}
for community in existing_communities:
    follow_dict[f"{community}.community.{main_contract_acc}"] = ""
    follow_dict[f"discussions.{community}.community.{main_contract_acc}"] = ""

def get_graph_item(account_id):
    return {
        "key": "follow",
        "value": {
            "type": "follow",
            "accountId": account_id
        }
    }

graph_array = []
for community in existing_communities:
    graph_array.append(get_graph_item(f"{community}.community.{main_contract_acc}"))
    graph_array.append(get_graph_item(f"discussions.{community}.community.{main_contract_acc}"))

json_args = {
    f"community.{main_contract_acc}": {
        "graph": {
            "follow": follow_dict
        },
        "index": {
            "graph": json.dumps(graph_array, separators=(',', ':'))
        }                  
    },
}

print(json.dumps(json_args))