noogle: fixes for subscription/cancel, add aber support for subscriptions

This commit is contained in:
Believethehype 2024-03-19 23:40:46 +01:00
parent 79164f356e
commit b1f62609a2

View File

@ -33,6 +33,13 @@ import Newnote from "@/components/Newnote.vue";
import SummarizationGeneration from "@/components/SummarizationGeneration.vue" import SummarizationGeneration from "@/components/SummarizationGeneration.vue"
import {post_note, schedule, copyurl, copyinvoice, sleep, getEvents, get_user_infos, get_zaps, get_reactions, nextInput, getEventsOriginalOrder, parseandreplacenpubsName} from "../components/helper/Helper.vue" import {post_note, schedule, copyurl, copyinvoice, sleep, getEvents, get_user_infos, get_zaps, get_reactions, nextInput, getEventsOriginalOrder, parseandreplacenpubsName} from "../components/helper/Helper.vue"
import {zap, createBolt11Lud16, zaprequest} from "../components/helper/Zap.vue" import {zap, createBolt11Lud16, zaprequest} from "../components/helper/Zap.vue"
import { ref } from "vue";
import ModalComponent from "../components/Newnote.vue";
import VueDatePicker from "@vuepic/vue-datepicker";
import {timestamp} from "@vueuse/core";
import NoteTable from "@/components/NoteTable.vue";
import {webln} from "@getalby/sdk";
import amberSignerService from "./android-signer/AndroidSigner"; import amberSignerService from "./android-signer/AndroidSigner";
import StringUtil from "@/components/helper/string.ts"; import StringUtil from "@/components/helper/string.ts";
@ -51,18 +58,17 @@ await addAllContentDVMs()
}) })
const current_subscription_amount = ref("")
const current_subscription_cadence = ref("")
const current_subscription_dvm = ref(null)
const current_subscription_nwc = ref("")
function set_subscription_props(amount, cadence, dvm) { function set_subscription_props(amount, cadence, dvm) {
this.current_subscription_amount = amount console.log(dvm)
this.current_subscription_cadence = cadence current_subscription_dvm.value = dvm
this.current_subscription_dvm = dvm current_subscription_amount.value = amount
this.nwcalby = "" current_subscription_cadence.value = cadence
this.nwcmutiny = "" current_subscription_nwc.value = ""
this.nwc = "" nwcalby.value = ""
nwcmutiny.value = ""
nwc.value = ""
} }
@ -495,23 +501,44 @@ async function addDVM(event){
async function cancelSubscription(kind7001, recipent){ async function cancelSubscription(kind7001, recipent){
console.log(kind7001) console.log(kind7001)
console.log(recipent) console.log(recipent)
let client = store.state.client
let res;
let requestid;
let content = "Canceled from Noogle" let content = "Canceled from Noogle"
let kind = 7002 let kind = 7002
let tags = [ let tags = [
["p", recipent], ["p", recipent],
["e", kind7001] ["e", kind7001]
] ]
if (localStorage.getItem('nostr-key-method') === 'android-signer') {
let draft = {
content: content,
kind: kind,
pubkey: store.state.pubkey.toHex(),
tags: tags,
createdAt: Date.now()
};
res = await amberSignerService.signEvent(draft)
await client.sendEvent(Event.fromJson(JSON.stringify(res)))
requestid = res.id;
console.log(requestid)
}
else{
let tags_t = [] let tags_t = []
for (let tag of tags){ for (let tag of tags){
tags_t.push(Tag.parse(tag)) tags_t.push(Tag.parse(tag))
} }
let evt = new EventBuilder(kind, content, tags_t) let evt = new EventBuilder(kind, content, tags_t)
let client = store.state.client res = await client.sendEventBuilder(evt);
let res = await client.sendEventBuilder(evt); requestid = res.toHex();
let requestid = res.toHex(); console.log(requestid)
dvms.find(x => x.nip88.eventid === this.current_subscription_dvm.nip88.eventid).nip88.hasActiveSubscription = true }
dvms.find(x => x.nip88.eventid === this.current_subscription_dvm.nip88.eventid).nip88.expires = true
dvms.find(x => x.nip88.eventid === current_subscription_dvm.value.nip88.eventid).nip88.hasActiveSubscription = true
dvms.find(x => x.nip88.eventid === current_subscription_dvm.value.nip88.eventid).nip88.expires = true
} }
async function subscribe_to_dvm() { async function subscribe_to_dvm() {
@ -523,26 +550,50 @@ async function subscribe_to_dvm() {
// We only arrive here if no subscription exists, we might create a 7001 if it doesnt exist and we zap it // We only arrive here if no subscription exists, we might create a 7001 if it doesnt exist and we zap it
let client = store.state.client let client = store.state.client
if (this.current_subscription_dvm.nip88.subscriptionId === ""){ if (current_subscription_dvm.value.nip88.subscriptionId === ""){
console.log("Creating 7001 event") let res;
let requestid;
let kind = 7001
let content = "Subscription from noogle.lol"
let tags = [ let tags = [
Tag.parse([ "p", this.current_subscription_dvm.id]), [ "p", this.current_subscription_dvm.id],
Tag.parse([ "e" , this.current_subscription_dvm.nip88.eventid]), [ "e" , this.current_subscription_dvm.nip88.eventid],
Tag.parse([ "event", JSON.stringify(this.current_subscription_dvm.nip88.event)]), [ "event", JSON.stringify(this.current_subscription_dvm.nip88.event)],
Tag.parse([ "amount", (this.current_subscription_amount).toString(), "msats", this.current_subscription_cadence]), [ "amount", (current_subscription_amount.value).toString(), "msats", current_subscription_cadence.value],
] ]
for(let zap of current_subscription_dvm.value.nip88.zaps){
console.log(this.current_subscription_dvm.nip88.zaps) let zaptag = [ "zap", zap.key, zap.split]
for(let zap of this.current_subscription_dvm.nip88.zaps){
let zaptag = Tag.parse([ "zap", zap.key, zap.split])
tags.push(zaptag) tags.push(zaptag)
} }
let evt = new EventBuilder(7001, "Subscription from noogle.lol", tags) console.log("Creating 7001 event")
let res = await client.sendEventBuilder(evt); if (localStorage.getItem('nostr-key-method') === 'android-signer') {
let draft = {
content: content,
kind: kind,
pubkey: store.state.pubkey.toHex(),
tags: tags,
createdAt: Date.now()
};
res = await amberSignerService.signEvent(draft)
await client.sendEvent(Event.fromJson(JSON.stringify(res)))
requestid = res.id;
console.log(requestid)
}
else{
let tags_t = []
for (let tag of tags){
tags_t.push(Tag.parse(tag))
}
let evt = new EventBuilder(kind, content, tags)
res = await client.sendEventBuilder(evt);
requestid = res.id
console.log(res) console.log(res)
this.current_subscription_dvm.nip88.subscriptionId = res.toHex() }
current_subscription_dvm.value.nip88.subscriptionId = requestid
} }
@ -557,32 +608,32 @@ async function subscribe_to_dvm() {
await nclient.connect() await nclient.connect()
let encnwc = nip44_encrypt(SecretKey.parse(store.state.nooglekey), PublicKey.parse(store.state.subscription_verifier_pubkey), let encnwc = nip44_encrypt(SecretKey.parse(store.state.nooglekey), PublicKey.parse(store.state.subscription_verifier_pubkey),
this.current_subscription_nwc, NIP44Version.V2) current_subscription_nwc.value, NIP44Version.V2)
let content = { let content = {
"subscribe_event": this.current_subscription_dvm.nip88.subscriptionId, "subscribe_event": current_subscription_dvm.value.nip88.subscriptionId,
"nwc": encnwc, "nwc": encnwc,
"cadence" : this.current_subscription_cadence, "cadence" : current_subscription_cadence.value,
"overall_amount" : this.current_subscription_amount, "overall_amount" : current_subscription_amount.value,
"tier_dtag" : this.current_subscription_dvm.nip88.d, "tier_dtag" : current_subscription_dvm.value.nip88.d,
"recipient" : this.current_subscription_dvm.id, "recipient" : current_subscription_dvm.value.id,
"subscriber" : store.state.pubkey.toHex(), "subscriber" : store.state.pubkey.toHex(),
"zaps" : this.current_subscription_dvm.nip88.zaps "zaps" : current_subscription_dvm.value.nip88.zaps
} }
// TODO this is only for viewing, check event (happens on page reload now) // TODO this is only for viewing, check event (happens on page reload now)
let subscribeduntil = Timestamp.now().asSecs() let subscribeduntil = Timestamp.now().asSecs()
if (this.current_subscription_cadence === "daily"){ if (current_subscription_cadence.value === "daily"){
subscribeduntil = Timestamp.now().asSecs() + 60*60*24 subscribeduntil = Timestamp.now().asSecs() + 60*60*24
} }
else if (this.current_subscription_cadence === "weekly"){ else if (current_subscription_cadence.value === "weekly"){
subscribeduntil = Timestamp.now().asSecs() + 60*60*24 * 7 subscribeduntil = Timestamp.now().asSecs() + 60*60*24 * 7
} }
else if (this.current_subscription_cadence === "monthly"){ else if (current_subscription_cadence.value === "monthly"){
subscribeduntil = Timestamp.now().asSecs() + 60*60*24 * 31 subscribeduntil = Timestamp.now().asSecs() + 60*60*24 * 31
} }
else if (this.current_subscription_cadence === "yearly"){ else if (current_subscription_cadence.value === "yearly"){
subscribeduntil = Timestamp.now().asSecs() + 60*60*24 * 365 subscribeduntil = Timestamp.now().asSecs() + 60*60*24 * 365
} }
console.log(content) console.log(content)
@ -591,9 +642,9 @@ async function subscribe_to_dvm() {
let id = await nclient.sendDirectMsg(receiver, msg) let id = await nclient.sendDirectMsg(receiver, msg)
console.log(id) console.log(id)
dvms.find(x => x.nip88.eventid === this.current_subscription_dvm.nip88.eventid).nip88.hasActiveSubscription = true dvms.find(x => x.nip88.eventid === current_subscription_dvm.value.nip88.eventid).nip88.hasActiveSubscription = true
dvms.find(x => x.nip88.eventid === this.current_subscription_dvm.nip88.eventid).nip88.expires = false dvms.find(x => x.nip88.eventid === current_subscription_dvm.value.nip88.eventid).nip88.expires = false
dvms.find(x => x.nip88.eventid === this.current_subscription_dvm.nip88.eventid).nip88.subscribedUntil = subscribeduntil dvms.find(x => x.nip88.eventid === current_subscription_dvm.value.nip88.eventid).nip88.subscribedUntil = subscribeduntil
} }
@ -615,17 +666,17 @@ async function zap_local(invoice) {
async function store_nwc(){ async function store_nwc(){
if (this.nwcalby.startsWith("nostr")){ if (nwcalby.value.startsWith("nostr")){
this.current_subscription_nwc = this.nwcalby current_subscription_nwc.value = nwcalby.value
} }
else if (this.nwcmutiny.startsWith("nostr") ){ else if (nwcmutiny.value.startsWith("nostr") ){
this.current_subscription_nwc = this.nwcmutiny current_subscription_nwc.value = nwcmutiny.value
} }
else{ else{
this.current_subscription_nwc = this.nwc current_subscription_nwc.value = nwc.value
} }
} }
@ -637,8 +688,8 @@ let result = await alby.client.initNWC({
}); });
if (result.payload.success){ if (result.payload.success){
this.nwcalby = alby.client.getNostrWalletConnectUrl(true); nwcalby.value = alby.client.getNostrWalletConnectUrl(true);
await this.store_nwc() await store_nwc()
} }
} }
@ -650,12 +701,8 @@ defineProps({
}, },
}) })
import { ref } from "vue";
import ModalComponent from "../components/Newnote.vue";
import VueDatePicker from "@vuepic/vue-datepicker";
import {timestamp} from "@vueuse/core";
import NoteTable from "@/components/NoteTable.vue";
import {webln} from "@getalby/sdk";
@ -668,7 +715,10 @@ const datetopost = ref(Date.now());
const nwc = ref(""); const nwc = ref("");
const nwcmutiny = ref(""); const nwcmutiny = ref("");
const nwcalby= ref(""); const nwcalby= ref("");
const nwcconnector= ref("user"); const current_subscription_amount = ref(0)
const current_subscription_cadence = ref("")
const current_subscription_dvm = ref(null)
const current_subscription_nwc = ref("")
const openModal = result => { const openModal = result => {