mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-10-02 01:09:14 +02:00
updates on noogle example
This commit is contained in:
@@ -24,10 +24,11 @@ import {
|
|||||||
Filter,
|
Filter,
|
||||||
initLogger,
|
initLogger,
|
||||||
LogLevel,
|
LogLevel,
|
||||||
Timestamp
|
Timestamp, Keys, NostrDatabase, ClientBuilder
|
||||||
} from "@rust-nostr/nostr-sdk";
|
} from "@rust-nostr/nostr-sdk";
|
||||||
import VueNotifications from "vue-notifications";
|
import VueNotifications from "vue-notifications";
|
||||||
import store from '../store';
|
import store from '../store';
|
||||||
|
import miniToastr from "mini-toastr";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
@@ -41,28 +42,7 @@ export default {
|
|||||||
async mounted() {
|
async mounted() {
|
||||||
await this.sign_in();
|
await this.sign_in();
|
||||||
},
|
},
|
||||||
notifications: {
|
|
||||||
showSuccessMsg: {
|
|
||||||
type: VueNotifications.types.success,
|
|
||||||
title: 'Login',
|
|
||||||
message: 'That\'s the success!'
|
|
||||||
},
|
|
||||||
showInfoMsg: {
|
|
||||||
type: VueNotifications.types.info,
|
|
||||||
title: 'Hey you',
|
|
||||||
message: 'Here is some info for you'
|
|
||||||
},
|
|
||||||
showWarnMsg: {
|
|
||||||
type: VueNotifications.types.warn,
|
|
||||||
title: 'Wow, man',
|
|
||||||
message: 'That\'s the kind of warning'
|
|
||||||
},
|
|
||||||
showErrorMsg: {
|
|
||||||
type: VueNotifications.types.error,
|
|
||||||
title: 'Wow-wow',
|
|
||||||
message: 'That\'s the error'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
methods: {
|
||||||
async sign_in() {
|
async sign_in() {
|
||||||
|
|
||||||
@@ -77,27 +57,50 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let nip07_signer = new Nip07Signer();
|
let nip07_signer = new Nip07Signer();
|
||||||
this.signer = ClientSigner.nip07(nip07_signer);
|
try{
|
||||||
|
this.signer = ClientSigner.nip07(nip07_signer);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
this.signer = ClientSigner.keys(Keys.generate())
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let database = await NostrDatabase.open("test.db")
|
||||||
|
let client = new ClientBuilder().database(database).signer(this.signer).build()
|
||||||
|
|
||||||
let client = new Client(this.signer);
|
|
||||||
|
|
||||||
//await client.addRelay("wss://relay.damus.io");
|
//await client.addRelay("wss://relay.damus.io");
|
||||||
//await client.addRelay("wss://nos.lol");
|
//await client.addRelay("wss://nos.lol");
|
||||||
await client.addRelay("wss://relay.nostr.band");
|
await client.addRelay("wss://relay.nostr.band");
|
||||||
await client.addRelay("wss://nostr-pub.wellorder.net")
|
await client.addRelay("wss://nostr-pub.wellorder.net")
|
||||||
|
|
||||||
const pubkey = await nip07_signer.getPublicKey()
|
const pubkey = await nip07_signer.getPublicKey();
|
||||||
await client.connect();
|
await client.connect();
|
||||||
|
|
||||||
|
|
||||||
|
const filter = new Filter().kind(6302).limit(20)
|
||||||
|
//TODO this next line breaks the code
|
||||||
|
//await client.reconcile(filter);
|
||||||
|
/*const filterl = new Filter().author(pubkey)
|
||||||
|
let test = dbclient.database().query([filterl])
|
||||||
|
for (let ev of test){
|
||||||
|
console.log(ev.as_json())
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
store.commit('set_client', client)
|
store.commit('set_client', client)
|
||||||
|
store.commit('set_pubkey', pubkey)
|
||||||
console.log("Client connected")
|
console.log("Client connected")
|
||||||
|
|
||||||
await this.get_user_info(pubkey)
|
|
||||||
|
|
||||||
//this.current_user = (await nip07_signer.getPublicKey()).toBech32()
|
|
||||||
//console.log( this.current_user)
|
await this.get_user_info(pubkey)
|
||||||
this.showSuccessMsg()
|
miniToastr.showMessage("Login successful!", "Logged in as " + this.current_user, VueNotifications.types.success)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -42,6 +42,7 @@ const author_placeholder = ref()
|
|||||||
const author_image_placeholder = ref()
|
const author_image_placeholder = ref()
|
||||||
const author_url_placeholder = ref()
|
const author_url_placeholder = ref()
|
||||||
|
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
|
||||||
|
|
||||||
@@ -52,7 +53,7 @@ onMounted(async () => {
|
|||||||
|
|
||||||
|
|
||||||
content_placeholder.value = props.content //TODO furher parse content
|
content_placeholder.value = props.content //TODO furher parse content
|
||||||
console.log(props.author)
|
console.log(props.author)
|
||||||
const profile = await get_user_info(props.author)
|
const profile = await get_user_info(props.author)
|
||||||
console.log(profile)
|
console.log(profile)
|
||||||
author_placeholder.value = profile["name"]
|
author_placeholder.value = profile["name"]
|
||||||
|
@@ -2,22 +2,28 @@
|
|||||||
<EasyDataTable v-if="store.state.results.length != 0" table-class-name="customize-table"
|
<EasyDataTable v-if="store.state.results.length != 0" table-class-name="customize-table"
|
||||||
:headers="headers"
|
:headers="headers"
|
||||||
:items="store.state.results">
|
:items="store.state.results">
|
||||||
<template #item-content="{ content, author}">
|
<template #item-content="{ content, author, authorurl}">
|
||||||
<NoteRender :content="content" :author="author"/>
|
<a :href="authorurl" target="_blank">{{ author }}</a>
|
||||||
|
<p>{{content}}</p>
|
||||||
|
<!-- <NoteRender :content="content" :author="author"/> -->
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
</EasyDataTable>
|
</EasyDataTable>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import type { Header, Item } from "vue3-easy-data-table";
|
import type { Header, Item } from "vue3-easy-data-table";
|
||||||
import store from '../store';
|
import store from '../store';
|
||||||
import NoteRender from "@/components/NoteRender.vue";
|
import NoteRender from "@/components/NoteRender.vue";
|
||||||
import {EventId, Filter} from "@rust-nostr/nostr-sdk";
|
import {EventId, Filter} from "@rust-nostr/nostr-sdk";
|
||||||
|
|
||||||
|
|
||||||
const headers: Header[] = [
|
const headers: Header[] = [
|
||||||
{ text: "Results:", value: "content", width: 400},
|
{ text: "Results:", value: "content", width: 400},
|
||||||
{ text: "Time", value: "indicator.time", sortable: true},
|
{ text: "Time", value: "indicator.time", sortable: true, width:100},
|
||||||
];
|
];
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@@ -1,22 +1,33 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import {Client, Filter, Timestamp, Event, Metadata, PublicKey, EventBuilder, Tag, EventId} from "@rust-nostr/nostr-sdk";
|
import {Client, Filter, Timestamp, Event, Metadata, PublicKey, EventBuilder, Tag, EventId} from "@rust-nostr/nostr-sdk";
|
||||||
import store from '../store';
|
import store from '../store';
|
||||||
|
import miniToastr from "mini-toastr";
|
||||||
|
import VueNotifications from "vue-notifications";
|
||||||
|
|
||||||
let items = []
|
let items = []
|
||||||
|
|
||||||
|
let listener = false
|
||||||
|
|
||||||
async function send_search_request(message) {
|
async function send_search_request(message) {
|
||||||
try {
|
try {
|
||||||
if (message === undefined){
|
if (message === undefined){
|
||||||
message = "Nostr"
|
message = "Nostr"
|
||||||
}
|
}
|
||||||
items = []
|
items = []
|
||||||
|
store.state.results = []
|
||||||
let client = store.state.client
|
let client = store.state.client
|
||||||
let tags = []
|
let tags = []
|
||||||
tags.push(Tag.parse(["i", message, "text"]))
|
tags.push(Tag.parse(["i", message, "text"]))
|
||||||
|
tags.push(Tag.parse(["param", "max_results", "100"]))
|
||||||
let evt = new EventBuilder(5302, "Search for me", tags)
|
let evt = new EventBuilder(5302, "Search for me", tags)
|
||||||
let res = await client.sendEventBuilder(evt)
|
let res = await client.sendEventBuilder(evt)
|
||||||
|
miniToastr.showMessage("Sent Request to DVMs", "Awaiting results", VueNotifications.types.info)
|
||||||
|
if (!listener){
|
||||||
|
listen()
|
||||||
|
}
|
||||||
|
|
||||||
console.log(res)
|
console.log(res)
|
||||||
await this.listen()
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
@@ -29,10 +40,13 @@ async function getEvents(eventids) {
|
|||||||
return await client.getEventsOf([event_filter], 5)
|
return await client.getEventsOf([event_filter], 5)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function listen() {
|
|
||||||
let client = store.state.client
|
|
||||||
|
|
||||||
const filter = new Filter().kinds([7000, 6302]).since(Timestamp.now());
|
async function listen() {
|
||||||
|
listener = true
|
||||||
|
let client = store.state.client
|
||||||
|
let pubkey = store.state.pubkey
|
||||||
|
|
||||||
|
const filter = new Filter().kinds([7000, 6302]).pubkey(pubkey).since(Timestamp.now());
|
||||||
await client.subscribe([filter]);
|
await client.subscribe([filter]);
|
||||||
|
|
||||||
const handle = {
|
const handle = {
|
||||||
@@ -42,6 +56,7 @@ async function listen() {
|
|||||||
if (event.kind === 7000) {
|
if (event.kind === 7000) {
|
||||||
try {
|
try {
|
||||||
console.log("7000:", event.content);
|
console.log("7000:", event.content);
|
||||||
|
miniToastr.showMessage("DVM replied", event.content, VueNotifications.types.info)
|
||||||
|
|
||||||
|
|
||||||
//if (content === "stop") {
|
//if (content === "stop") {
|
||||||
@@ -54,14 +69,21 @@ async function listen() {
|
|||||||
else if(event.kind === 6302) {
|
else if(event.kind === 6302) {
|
||||||
let entries = []
|
let entries = []
|
||||||
console.log("6302:", event.content);
|
console.log("6302:", event.content);
|
||||||
|
miniToastr.showMessage("DVM replied", "Received Results", VueNotifications.types.success)
|
||||||
let event_etags = JSON.parse(event.content)
|
let event_etags = JSON.parse(event.content)
|
||||||
for (let etag of event_etags){
|
for (let etag of event_etags){
|
||||||
const eventid = EventId.fromHex(etag[1])
|
const eventid = EventId.fromHex(etag[1])
|
||||||
entries.push(eventid)
|
entries.push(eventid)
|
||||||
}
|
}
|
||||||
const events = await getEvents(entries)
|
const events = await getEvents(entries)
|
||||||
|
let authors = []
|
||||||
for (const evt of events){
|
for (const evt of events){
|
||||||
items.push({ content: evt.content, author: evt.author.toHex(), indicator: {"time": evt.createdAt.toHumanDatetime()}})
|
authors.push(evt.author)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (const evt of events){
|
||||||
|
items.push({ content: evt.content, author: evt.author.toBech32(), authorurl: "https://njump.me/" + evt.author.toBech32(), indicator: {"time": evt.createdAt.toHumanDatetime()}})
|
||||||
}
|
}
|
||||||
|
|
||||||
store.commit('set_search_results', items)
|
store.commit('set_search_results', items)
|
||||||
@@ -76,6 +98,7 @@ async function listen() {
|
|||||||
client.handleNotifications(handle);
|
client.handleNotifications(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
defineProps({
|
defineProps({
|
||||||
msg: {
|
msg: {
|
||||||
type: String,
|
type: String,
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import {createStore} from "vuex";
|
import {createStore} from "vuex";
|
||||||
import {Client} from "@rust-nostr/nostr-sdk";
|
import {Client, ClientSigner, PublicKey} from "@rust-nostr/nostr-sdk";
|
||||||
|
|
||||||
const store = createStore({
|
const store = createStore({
|
||||||
state () {
|
state () {
|
||||||
@@ -7,6 +7,7 @@ const store = createStore({
|
|||||||
count: 0,
|
count: 0,
|
||||||
test: "hello",
|
test: "hello",
|
||||||
client: Client,
|
client: Client,
|
||||||
|
pubkey: PublicKey,
|
||||||
results: []
|
results: []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -16,6 +17,9 @@ const store = createStore({
|
|||||||
},
|
},
|
||||||
set_client (state, client) {
|
set_client (state, client) {
|
||||||
state.client = client
|
state.client = client
|
||||||
|
},
|
||||||
|
set_pubkey(state, pubkey) {
|
||||||
|
state.pubkey = pubkey
|
||||||
},
|
},
|
||||||
set_search_results(state, results){
|
set_search_results(state, results){
|
||||||
state.results = results
|
state.results = results
|
||||||
|
Reference in New Issue
Block a user