noogle: get profiles on login

This commit is contained in:
Believethehype 2024-02-14 12:14:56 +01:00
parent f7c66c7593
commit 20c605e245
3 changed files with 51 additions and 37 deletions

View File

@ -183,9 +183,10 @@ export default {
localStorage.setItem('nostr-key', '')
console.log("Client Nip46 connected")
await this.get_user_info(pubkey)
await this.reconcile_all_profiles(pubkey)
console.log(pubkey.toBech32())
//await this.reconcile_all_profiles()
} catch (error) {
@ -296,6 +297,7 @@ export default {
localStorage.setItem('nostr-key', pubkey.toHex())
console.log("Client Nip07 connected")
await this.get_user_info(pubkey)
await this.reconcile_all_profiles(pubkey)
//await this.reconcile_all_profiles()
//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', connectionstring)
console.log("Client connected")
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)
@ -415,7 +420,9 @@ export default {
store.commit('set_hasEventListener', false)
localStorage.setItem('nostr-key-method', "android-signer")
localStorage.setItem('nostr-key', hexKey)
await this.get_user_info(publicKey)
await this.reconcile_all_profiles(publicKey)
}
catch (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){
let client = store.state.client

View File

@ -30,7 +30,7 @@ let searching = false
const message = ref("");
const fromuser = ref("");
let dbclient = Client
let usernames = []
@ -46,8 +46,7 @@ onMounted(async () => {
await send_search_request(message.value)
}
await sleep(1000)
await reconcile_all_profiles()
await sleep(2000)
})
@ -64,40 +63,7 @@ const sleep = (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) {
@ -447,6 +413,7 @@ async function checkuser(msg){
async function get_user_from_search(name){
name = "\"name\":" + name
let dbclient = store.state.dbclient
let profiles = []
let filter1 = new Filter().kind(0).search(name)
let evts = await dbclient.database.query([filter1])

View File

@ -7,6 +7,7 @@ const store = createStore({
count: 0,
test: "hello",
client: Client,
dbclient: Client,
pubkey: PublicKey,
requestidSearch: String,
requestidImage: String,
@ -32,6 +33,9 @@ const store = createStore({
},
set_client (state, client) {
state.client = client
},
set_dbclient (state, dbclient) {
state.dbclient = dbclient
},
set_pubkey(state, pubkey) {
state.pubkey = pubkey