openvibers/openvibe.live Commits
openvibe.live/#vibes opens the Vibes window once (every site's account menu links its Vibes chip here, openvibe-shared 4.3) (#174)
Changes
@@@ -446,3 +446,15 @@ async function doCashout() {closeModal();} catch (e) { toast(e.message || 'Cashout failed', 'error'); }}++++// Every other OpenVibe site's account menu links its Vibes chip here (openvibe-shared 4.3: openvibe.live/#vibes): open++// the Vibes window once, then drop the hash so a reload or a shared link does not open it again.++(function openVibesFromLink() {++ if (location.hash !== '#vibes') return;++ const open = () => {++ try { history.replaceState(history.state, '', location.pathname + location.search); } catch { /* keep the hash */ }++ showModal('buy-funds');++ };++ if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', open, { once: true });++ else setTimeout(open, 0);++})();nnew file mode 100644@@@ -0,0 +1,33 @@++/**++ * openvibe-shared 4.3's account menu shows a person's Vibes on every OpenVibe site and links them to openvibe.live/#vibes.++ * Live opens its Vibes window for that link, once: the hash goes, so a reload does not open it again.++ *++ * node test/vibes-hash.test.js++ */++'use strict';++const assert = require('assert');++const fs = require('fs');++const path = require('path');++++const src = fs.readFileSync(path.join(__dirname, '..', 'public', 'js', 'vibes.js'), 'utf8');++const block = src.slice(src.indexOf('(function openVibesFromLink()'));++++function run(hash) {++ const opened = [];++ const replaced = [];++ const env = {++ location: { hash, pathname: '/@alex', search: '?x=1' },++ history: { state: null, replaceState: (s, t, url) => replaced.push(url) },++ document: { readyState: 'complete', addEventListener() {} },++ setTimeout: (fn) => fn(),++ showModal: (id) => opened.push(id),++ };++ // eslint-disable-next-line no-new-func++ new Function(...Object.keys(env), block)(...Object.values(env));++ return { opened, replaced };++}++++assert.deepStrictEqual(run('#vibes'), { opened: ['buy-funds'], replaced: ['/@alex?x=1'] }, 'the link opens the Vibes window and drops the hash');++assert.deepStrictEqual(run(''), { opened: [], replaced: [] }, 'nothing otherwise');++assert.deepStrictEqual(run('#chat'), { opened: [], replaced: [] });++console.log('vibes hash: all checks passed');
@@ -446,3 +446,15 @@ async function doCashout() {
@@ -446,3 +446,15 @@ async function doCashout() {
closeModal();
closeModal();
} catch (e) { toast(e.message || 'Cashout failed', 'error'); }
} catch (e) { toast(e.message || 'Cashout failed', 'error'); }
}
}
+
+// Every other OpenVibe site's account menu links its Vibes chip here (openvibe-shared 4.3: openvibe.live/#vibes): open
+// the Vibes window once, then drop the hash so a reload or a shared link does not open it again.
+(function openVibesFromLink() {
+ if (location.hash !== '#vibes') return;
+ const open = () => {
+ try { history.replaceState(history.state, '', location.pathname + location.search); } catch { /* keep the hash */ }
+ showModal('buy-funds');
+ };
+ if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', open, { once: true });
+ else setTimeout(open, 0);
+})();
new file mode 100644
new file mode 100644
@@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
+/**
+ * openvibe-shared 4.3's account menu shows a person's Vibes on every OpenVibe site and links them to openvibe.live/#vibes.
+ * Live opens its Vibes window for that link, once: the hash goes, so a reload does not open it again.
+ *
+ * node test/vibes-hash.test.js
+ */
+'use strict';
+const assert = require('assert');
+const fs = require('fs');
+const path = require('path');
+
+const src = fs.readFileSync(path.join(__dirname, '..', 'public', 'js', 'vibes.js'), 'utf8');
+const block = src.slice(src.indexOf('(function openVibesFromLink()'));
+
+function run(hash) {
+ const opened = [];
+ const replaced = [];
+ const env = {
+ location: { hash, pathname: '/@alex', search: '?x=1' },
+ history: { state: null, replaceState: (s, t, url) => replaced.push(url) },
+ document: { readyState: 'complete', addEventListener() {} },
+ setTimeout: (fn) => fn(),
+ showModal: (id) => opened.push(id),
+ };
+ // eslint-disable-next-line no-new-func
+ new Function(...Object.keys(env), block)(...Object.values(env));
+ return { opened, replaced };
+}
+
+assert.deepStrictEqual(run('#vibes'), { opened: ['buy-funds'], replaced: ['/@alex?x=1'] }, 'the link opens the Vibes window and drops the hash');
+assert.deepStrictEqual(run(''), { opened: [], replaced: [] }, 'nothing otherwise');
+assert.deepStrictEqual(run('#chat'), { opened: [], replaced: [] });
+console.log('vibes hash: all checks passed');