Basic functionality for relay optoins

This commit is contained in:
Ryan Breen
2023-01-24 22:44:34 -05:00
parent 03af8e71ad
commit 84a8d5ddeb
4 changed files with 140 additions and 1 deletions

View File

@@ -89,6 +89,14 @@ browser.runtime.onMessage.addListener(
case 'getRelays':
sendResponse({});
break;
case 'getRelaysForProfile':
let profileRelays = await getRelaysForProfile(message.payload);
sendResponse(profileRelays);
break;
case 'saveRelaysForProfile':
let [srfpIndex, srfpRelays] = message.payload;
await saveRelaysForProfile(srfpIndex, srfpRelays);
break;
default:
break;
}
@@ -217,3 +225,16 @@ async function nip04Decrypt({ pubKey, cipherText }) {
let privKey = await getPrivKey();
return nip04.decrypt(privKey, pubKey, cipherText);
}
async function getRelaysForProfile(profileIndex) {
let profiles = await get('profiles');
let profile = profiles[profileIndex];
return profile.relays || [];
}
async function saveRelaysForProfile(profileIndex, relays) {
let profiles = await get('profiles');
let profile = profiles[profileIndex];
profile.relays = relays;
await storage.set({ profiles });
}