mirror of
https://github.com/believethehype/nostrdvm.git
synced 2025-11-19 22:36:25 +01:00
noogle: get profiles on login
This commit is contained in:
@@ -183,9 +183,10 @@ export default {
|
|||||||
localStorage.setItem('nostr-key', '')
|
localStorage.setItem('nostr-key', '')
|
||||||
console.log("Client Nip46 connected")
|
console.log("Client Nip46 connected")
|
||||||
await this.get_user_info(pubkey)
|
await this.get_user_info(pubkey)
|
||||||
|
await this.reconcile_all_profiles(pubkey)
|
||||||
console.log(pubkey.toBech32())
|
console.log(pubkey.toBech32())
|
||||||
//await this.reconcile_all_profiles()
|
//await this.reconcile_all_profiles()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -296,6 +297,7 @@ export default {
|
|||||||
localStorage.setItem('nostr-key', pubkey.toHex())
|
localStorage.setItem('nostr-key', pubkey.toHex())
|
||||||
console.log("Client Nip07 connected")
|
console.log("Client Nip07 connected")
|
||||||
await this.get_user_info(pubkey)
|
await this.get_user_info(pubkey)
|
||||||
|
await this.reconcile_all_profiles(pubkey)
|
||||||
//await this.reconcile_all_profiles()
|
//await this.reconcile_all_profiles()
|
||||||
//miniToastr.showMessage("Login successful!", "Logged in as " + this.current_user, VueNotifications.types.success)
|
//miniToastr.showMessage("Login successful!", "Logged in as " + this.current_user, VueNotifications.types.success)
|
||||||
|
|
||||||
@@ -361,7 +363,10 @@ export default {
|
|||||||
localStorage.setItem('nostr-key-method', "nip46")
|
localStorage.setItem('nostr-key-method', "nip46")
|
||||||
localStorage.setItem('nostr-key', connectionstring)
|
localStorage.setItem('nostr-key', connectionstring)
|
||||||
console.log("Client connected")
|
console.log("Client connected")
|
||||||
|
|
||||||
await this.get_user_info(pubkey)
|
await this.get_user_info(pubkey)
|
||||||
|
await this.reconcile_all_profiles(pubkey)
|
||||||
|
|
||||||
//miniToastr.showMessage("Login successful!", "Logged in as " + this.current_user, VueNotifications.types.success)
|
//miniToastr.showMessage("Login successful!", "Logged in as " + this.current_user, VueNotifications.types.success)
|
||||||
|
|
||||||
|
|
||||||
@@ -415,7 +420,9 @@ export default {
|
|||||||
store.commit('set_hasEventListener', false)
|
store.commit('set_hasEventListener', false)
|
||||||
localStorage.setItem('nostr-key-method', "android-signer")
|
localStorage.setItem('nostr-key-method', "android-signer")
|
||||||
localStorage.setItem('nostr-key', hexKey)
|
localStorage.setItem('nostr-key', hexKey)
|
||||||
|
|
||||||
await this.get_user_info(publicKey)
|
await this.get_user_info(publicKey)
|
||||||
|
await this.reconcile_all_profiles(publicKey)
|
||||||
}
|
}
|
||||||
catch (error){
|
catch (error){
|
||||||
alert(error)
|
alert(error)
|
||||||
@@ -479,6 +486,42 @@ export default {
|
|||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async reconcile_all_profiles(publicKey) {
|
||||||
|
{
|
||||||
|
let dbclient = Client
|
||||||
|
let keys = Keys.fromSkStr("ece3c0aa759c3e895ecb3c13ab3813c0f98430c6d4bd22160b9c2219efc9cf0e")
|
||||||
|
let db = NostrDatabase.indexeddb("profiles");
|
||||||
|
let signer = ClientSigner.keys(keys) //TODO store keys
|
||||||
|
dbclient = new ClientBuilder().signer(signer).database(await db).build()
|
||||||
|
|
||||||
|
await dbclient.addRelay("wss://relay.damus.io");
|
||||||
|
await dbclient.connect();
|
||||||
|
store.commit('set_dbclient', dbclient)
|
||||||
|
let direction = NegentropyDirection.Down;
|
||||||
|
let opts = new NegentropyOptions().direction(direction);
|
||||||
|
|
||||||
|
|
||||||
|
let followings = []
|
||||||
|
let followers_filter = new Filter().author(publicKey).kind(3).limit(1)
|
||||||
|
let followers = await dbclient.getEventsOf([followers_filter], 10)
|
||||||
|
|
||||||
|
if (followers.length > 0){
|
||||||
|
for (let tag of followers[0].tags) {
|
||||||
|
if (tag.asVec()[0] === "p") {
|
||||||
|
let following = tag.asVec()[1]
|
||||||
|
followings.push(PublicKey.fromHex(following))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
console.log("Followings: " + (followings.length).toString())
|
||||||
|
|
||||||
|
|
||||||
|
let filter = new Filter().kind(0).authors(followings)
|
||||||
|
await dbclient.reconcile(filter, opts);
|
||||||
|
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
async get_user_info(pubkey){
|
async get_user_info(pubkey){
|
||||||
let client = store.state.client
|
let client = store.state.client
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ let searching = false
|
|||||||
const message = ref("");
|
const message = ref("");
|
||||||
const fromuser = ref("");
|
const fromuser = ref("");
|
||||||
|
|
||||||
let dbclient = Client
|
|
||||||
let usernames = []
|
let usernames = []
|
||||||
|
|
||||||
|
|
||||||
@@ -46,8 +46,7 @@ onMounted(async () => {
|
|||||||
await send_search_request(message.value)
|
await send_search_request(message.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
await sleep(1000)
|
await sleep(2000)
|
||||||
await reconcile_all_profiles()
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -64,40 +63,7 @@ const sleep = (ms) => {
|
|||||||
return new Promise(resolve => setTimeout(resolve, ms))
|
return new Promise(resolve => setTimeout(resolve, ms))
|
||||||
}
|
}
|
||||||
|
|
||||||
async function reconcile_all_profiles() {
|
|
||||||
if (store.state.pubkey !== undefined){
|
|
||||||
|
|
||||||
let keys = Keys.fromSkStr("ece3c0aa759c3e895ecb3c13ab3813c0f98430c6d4bd22160b9c2219efc9cf0e")
|
|
||||||
let db = NostrDatabase.indexeddb("profiles");
|
|
||||||
let signer = ClientSigner.keys(keys) //TODO store keys
|
|
||||||
dbclient = new ClientBuilder().signer(signer).database(await db).build()
|
|
||||||
|
|
||||||
await dbclient.addRelay("wss://relay.damus.io");
|
|
||||||
await dbclient.connect();
|
|
||||||
let direction = NegentropyDirection.Down;
|
|
||||||
let opts = new NegentropyOptions().direction(direction);
|
|
||||||
|
|
||||||
|
|
||||||
let followings = []
|
|
||||||
let followers_filter = new Filter().author(store.state.pubkey).kind(3).limit(1)
|
|
||||||
let followers = await dbclient.getEventsOf([followers_filter], 10)
|
|
||||||
|
|
||||||
if (followers.length > 0){
|
|
||||||
for (let tag of followers[0].tags) {
|
|
||||||
if (tag.asVec()[0] === "p") {
|
|
||||||
let following = tag.asVec()[1]
|
|
||||||
followings.push(PublicKey.fromHex(following))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
console.log("Followings: " + (followings.length).toString())
|
|
||||||
|
|
||||||
|
|
||||||
let filter = new Filter().kind(0).authors(followings)
|
|
||||||
await dbclient.reconcile(filter, opts);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async function send_search_request(msg) {
|
async function send_search_request(msg) {
|
||||||
@@ -447,6 +413,7 @@ async function checkuser(msg){
|
|||||||
|
|
||||||
async function get_user_from_search(name){
|
async function get_user_from_search(name){
|
||||||
name = "\"name\":" + name
|
name = "\"name\":" + name
|
||||||
|
let dbclient = store.state.dbclient
|
||||||
let profiles = []
|
let profiles = []
|
||||||
let filter1 = new Filter().kind(0).search(name)
|
let filter1 = new Filter().kind(0).search(name)
|
||||||
let evts = await dbclient.database.query([filter1])
|
let evts = await dbclient.database.query([filter1])
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ const store = createStore({
|
|||||||
count: 0,
|
count: 0,
|
||||||
test: "hello",
|
test: "hello",
|
||||||
client: Client,
|
client: Client,
|
||||||
|
dbclient: Client,
|
||||||
pubkey: PublicKey,
|
pubkey: PublicKey,
|
||||||
requestidSearch: String,
|
requestidSearch: String,
|
||||||
requestidImage: String,
|
requestidImage: String,
|
||||||
@@ -32,6 +33,9 @@ const store = createStore({
|
|||||||
},
|
},
|
||||||
set_client (state, client) {
|
set_client (state, client) {
|
||||||
state.client = client
|
state.client = client
|
||||||
|
},
|
||||||
|
set_dbclient (state, dbclient) {
|
||||||
|
state.dbclient = dbclient
|
||||||
},
|
},
|
||||||
set_pubkey(state, pubkey) {
|
set_pubkey(state, pubkey) {
|
||||||
state.pubkey = pubkey
|
state.pubkey = pubkey
|
||||||
|
|||||||
Reference in New Issue
Block a user