Starting out nostr followback

This commit is contained in:
minimo-io 2024-04-15 20:01:50 -03:00
parent 24333a0231
commit 5fed66133d
9 changed files with 224 additions and 1 deletions

41
.gitignore vendored
View File

@ -1,4 +1,43 @@
.DS_Store
**/.DS_Store
.editorconfig
# Bundler cache
.bundle
vendor
Gemfile.lock
# Jekyll cache
.jekyll-cache
_site
build
dist
.editorconfig
# RubyGems
*.gem
# NPM dependencies
node_modules
package-lock.json
# IDE configurations
.idea
.vscode
# Misc
assets/js/dist
.editorconfig
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# netlify
.netlify
.svelte-kit

View File

@ -0,0 +1,10 @@
# Nostr Reciprocal Follow
Check who does and does not follow you back on Nostr.
## ToDo
- Create this but without SvelteKit (just Vite + Svelte)
- Polish the proof-of-concept code
- Configure Vite for the miniapp to be loaded in the article's url as base
- Save followbackers and not followbackers in lists to see details

View File

@ -0,0 +1,21 @@
{
"name": "test-nostr-reciprocal",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"svelte": "^4.2.7",
"vite": "^5.0.3"
},
"type": "module",
"dependencies": {
"@nostr-dev-kit/ndk": "^2.7.1"
}
}

View File

@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
</html>

View File

@ -0,0 +1 @@
// place files you want to import through the `$lib` alias in this folder.

View File

@ -0,0 +1,121 @@
<script>
// Import the package
import NDK from "@nostr-dev-kit/ndk";
let npubToQuery = "npub1wujhdsytm3w6g0mpsqh8v7ezx83jcm64dlkwuqgm5v8lv0pds55ssudkw0";
let userName;
let userThumb;
let followsCount;
let followBackCount = 0;
let notFollowBackCount = 0;
let unknownFollowBack = 0;
async function fetchUserProfile(npub, ndk) {
const user = ndk.getUser({ npub });
await user.fetchProfile();
// console.log("User profile:", user.profile);
// console.log("User profile:", user);
return user;
}
async function fetchNotes(hexkey, ndk) {
const kind1filter = { kinds: [3], authors: [hexkey] };
return ndk.fetchEvent(kind1filter);
// const kind1filter = { author: [hexkey] };
// return ndk.fetchEvent(kind1filter);
}
async function bootstrap() {
try {
const ndk = new NDK({
explicitRelayUrls: [
"wss://relay.hodl.ar",
"wss://relay.current.fyi",
"wss://nostr.wine",
"wss://nostr.plebchain.org",
"wss://purplepag.es",
"wss://nos.lol",
"wss://nostr.mom",
"wss://nostrelay.yeghro.site",
"wss://relay.damus.io",
"wss://relay.nostr.bg",
"wss://relay.snort.social",
"wss://relay.primal.net",
"wss://nostr.bitcoiner.social",
"wss://nostr.mutinywallet.com",
"wss://relay.current.fyi",
"wss://nostr-pub.wellorder.net",
// "wss://brb.io",
// "wss://eden.nostr.land",
// "wss://nostr.orangepill.dev",
],
});
await ndk.connect();
// const user = await fetchUserProfile("npub1l8hja34gyeqrhc8plpcl3sql476n2rkgrzexazsfytwjkmy9kndqhx6pk9", ndk);
const user = await fetchUserProfile(npubToQuery, ndk);
userName = user.profile.name;
userThumb = user.profile.image;
if (userName) {
// console.log(user.profile);
const follows = await user.follows();
followsCount = follows.size;
follows.forEach(async (follower) => {
await new Promise((resolve) => setTimeout(resolve, 1000));
const followerFollowList = await follower.follows();
if (followerFollowList.size) {
// console.log(followerFollowList);
// check if the user is in the queried user follow list
let doesFollowBack = false;
for (const contact of followerFollowList) {
if (contact.npub == npubToQuery) {
doesFollowBack = true;
break;
}
}
if (doesFollowBack) {
followBackCount++;
} else {
notFollowBackCount++;
}
} else {
unknownFollowBack++;
}
});
}
// console.log("Followers:");
// let followers = await fetchNotes(user.hexpubkey, ndk);
// console.log(followers.tags.length);
// const longNotes = await fetchLongNotes(hexkey, ndk);
} catch (error) {
console.error("Error fetching data:", error);
}
}
bootstrap();
</script>
<h1>Who does not follows you on Nostr</h1>
{#if !userThumb}
{npubToQuery}
{/if}
<hr />
{#if userThumb}
<div class="user-box">
<img src={userThumb} width="50" style="border-radius:100%;" alt="user-thumb" />
User: {userName} |  Follows: {followsCount}
<br />
Unknown: {unknownFollowBack} | Follow_Back: {followBackCount} | Not_Follow_Back: {notFollowBackCount}
</div>
{:else}
<div class="loader">Loading data...</div>
{/if}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -0,0 +1,13 @@
import adapter from '@sveltejs/adapter-auto';
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
adapter: adapter()
}
};
export default config;

View File

@ -0,0 +1,6 @@
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [sveltekit()]
});