mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-09-26 17:56:47 +02:00
updates on noogle example
This commit is contained in:
@@ -24,10 +24,11 @@ import {
|
||||
Filter,
|
||||
initLogger,
|
||||
LogLevel,
|
||||
Timestamp
|
||||
Timestamp, Keys, NostrDatabase, ClientBuilder
|
||||
} from "@rust-nostr/nostr-sdk";
|
||||
import VueNotifications from "vue-notifications";
|
||||
import store from '../store';
|
||||
import miniToastr from "mini-toastr";
|
||||
|
||||
export default {
|
||||
data() {
|
||||
@@ -41,28 +42,7 @@ export default {
|
||||
async mounted() {
|
||||
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: {
|
||||
async sign_in() {
|
||||
|
||||
@@ -77,27 +57,50 @@ export default {
|
||||
}
|
||||
|
||||
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://nos.lol");
|
||||
await client.addRelay("wss://relay.nostr.band");
|
||||
await client.addRelay("wss://nostr-pub.wellorder.net")
|
||||
|
||||
const pubkey = await nip07_signer.getPublicKey()
|
||||
const pubkey = await nip07_signer.getPublicKey();
|
||||
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_pubkey', pubkey)
|
||||
console.log("Client connected")
|
||||
|
||||
await this.get_user_info(pubkey)
|
||||
|
||||
//this.current_user = (await nip07_signer.getPublicKey()).toBech32()
|
||||
//console.log( this.current_user)
|
||||
this.showSuccessMsg()
|
||||
|
||||
await this.get_user_info(pubkey)
|
||||
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_url_placeholder = ref()
|
||||
|
||||
|
||||
onMounted(async () => {
|
||||
|
||||
|
||||
@@ -52,7 +53,7 @@ onMounted(async () => {
|
||||
|
||||
|
||||
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)
|
||||
console.log(profile)
|
||||
author_placeholder.value = profile["name"]
|
||||
|
@@ -2,22 +2,28 @@
|
||||
<EasyDataTable v-if="store.state.results.length != 0" table-class-name="customize-table"
|
||||
:headers="headers"
|
||||
:items="store.state.results">
|
||||
<template #item-content="{ content, author}">
|
||||
<NoteRender :content="content" :author="author"/>
|
||||
<template #item-content="{ content, author, authorurl}">
|
||||
<a :href="authorurl" target="_blank">{{ author }}</a>
|
||||
<p>{{content}}</p>
|
||||
<!-- <NoteRender :content="content" :author="author"/> -->
|
||||
</template>
|
||||
|
||||
</EasyDataTable>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
|
||||
|
||||
|
||||
import type { Header, Item } from "vue3-easy-data-table";
|
||||
import store from '../store';
|
||||
import NoteRender from "@/components/NoteRender.vue";
|
||||
import {EventId, Filter} from "@rust-nostr/nostr-sdk";
|
||||
|
||||
|
||||
const headers: Header[] = [
|
||||
{ text: "Results:", value: "content", width: 400},
|
||||
{ text: "Time", value: "indicator.time", sortable: true},
|
||||
{ text: "Time", value: "indicator.time", sortable: true, width:100},
|
||||
];
|
||||
</script>
|
||||
|
||||
|
@@ -1,22 +1,33 @@
|
||||
<script setup>
|
||||
import {Client, Filter, Timestamp, Event, Metadata, PublicKey, EventBuilder, Tag, EventId} from "@rust-nostr/nostr-sdk";
|
||||
import store from '../store';
|
||||
import miniToastr from "mini-toastr";
|
||||
import VueNotifications from "vue-notifications";
|
||||
|
||||
let items = []
|
||||
|
||||
let listener = false
|
||||
|
||||
async function send_search_request(message) {
|
||||
try {
|
||||
if (message === undefined){
|
||||
message = "Nostr"
|
||||
}
|
||||
items = []
|
||||
store.state.results = []
|
||||
let client = store.state.client
|
||||
let tags = []
|
||||
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 res = await client.sendEventBuilder(evt)
|
||||
miniToastr.showMessage("Sent Request to DVMs", "Awaiting results", VueNotifications.types.info)
|
||||
if (!listener){
|
||||
listen()
|
||||
}
|
||||
|
||||
console.log(res)
|
||||
await this.listen()
|
||||
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
@@ -29,10 +40,13 @@ async function getEvents(eventids) {
|
||||
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]);
|
||||
|
||||
const handle = {
|
||||
@@ -42,6 +56,7 @@ async function listen() {
|
||||
if (event.kind === 7000) {
|
||||
try {
|
||||
console.log("7000:", event.content);
|
||||
miniToastr.showMessage("DVM replied", event.content, VueNotifications.types.info)
|
||||
|
||||
|
||||
//if (content === "stop") {
|
||||
@@ -54,14 +69,21 @@ async function listen() {
|
||||
else if(event.kind === 6302) {
|
||||
let entries = []
|
||||
console.log("6302:", event.content);
|
||||
miniToastr.showMessage("DVM replied", "Received Results", VueNotifications.types.success)
|
||||
let event_etags = JSON.parse(event.content)
|
||||
for (let etag of event_etags){
|
||||
const eventid = EventId.fromHex(etag[1])
|
||||
entries.push(eventid)
|
||||
}
|
||||
const events = await getEvents(entries)
|
||||
let authors = []
|
||||
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)
|
||||
@@ -76,6 +98,7 @@ async function listen() {
|
||||
client.handleNotifications(handle);
|
||||
}
|
||||
|
||||
|
||||
defineProps({
|
||||
msg: {
|
||||
type: String,
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import {createStore} from "vuex";
|
||||
import {Client} from "@rust-nostr/nostr-sdk";
|
||||
import {Client, ClientSigner, PublicKey} from "@rust-nostr/nostr-sdk";
|
||||
|
||||
const store = createStore({
|
||||
state () {
|
||||
@@ -7,6 +7,7 @@ const store = createStore({
|
||||
count: 0,
|
||||
test: "hello",
|
||||
client: Client,
|
||||
pubkey: PublicKey,
|
||||
results: []
|
||||
}
|
||||
},
|
||||
@@ -16,6 +17,9 @@ const store = createStore({
|
||||
},
|
||||
set_client (state, client) {
|
||||
state.client = client
|
||||
},
|
||||
set_pubkey(state, pubkey) {
|
||||
state.pubkey = pubkey
|
||||
},
|
||||
set_search_results(state, results){
|
||||
state.results = results
|
||||
|
Reference in New Issue
Block a user