diff --git a/static/fedilove-no-react.js b/static/fedilove-no-react.js index cdff3b80..ab2f0cea 100644 --- a/static/fedilove-no-react.js +++ b/static/fedilove-no-react.js @@ -268,14 +268,17 @@ var fediloveUI = { countMax++; }, 100); }, + animateMainContentSwipe: function(animName, cback) { + $('div.virtual-list')[0].style.animation = `${animName} .25s linear 1`; + setTimeout(cback, 220); + }, onAccountNope: function() { const accObj = fediloveApi.getMeetAccount(); if (accObj === undefined) return; if (!fediloveData.tmpDiscardedAccounts.includes(accObj.id)) fediloveData.tmpDiscardedAccounts.push(accObj.id); fediloveMastodon.API.discardAccount(accObj.id, function() { - $('div.virtual-list')[0].style.animation = 'nopeMeet .25s linear 1'; - setTimeout(function() { window.history.back() }, 220); + fediloveUI.animateMainContentSwipe('nopeMeet', function() { window.history.back() }); }); }, onAccountMatch: function() { @@ -284,11 +287,22 @@ var fediloveUI = { if (fediloveData.meetRelationships[accObj.id] !== undefined) fediloveData.meetRelationships[accObj.id] = { 'id': accObj.id, 'requested': true } fediloveMastodon.API.matchAccount(accObj.id, function() { - $('div.virtual-list')[0].style.animation = 'yepMeet .25s linear 1'; - setTimeout(function() { window.history.back() }, 220); + fediloveUI.animateMainContentSwipe('yepMeet', function() { window.history.back() }); }); }, - onAccountMaybe: function() {} + onAccountMaybe: function() { + const accObj = fediloveApi.getMeetAccount(); + if (accObj === undefined) return; + + const expire = 24 * (60*60*1000); // hours. Expire the maybe after 24 hours + var accounts = {}; + if (window.localStorage.store_maybeAccounts !== undefined) + accounts = JSON.parse(window.localStorage.store_maybeAccounts); + accounts[accObj.id] = Date.now() + expire; + window.localStorage.store_maybeAccounts = JSON.stringify(accounts); + + fediloveUI.animateMainContentSwipe('acceptMeet', function() { window.history.back() }); + } }; // objects to access from React code @@ -459,16 +473,8 @@ function fedilove_customization() { return; } - // get the userAccountId to check against the href /account/NUM on the messages - // so we can apply different style to my messages - if (fediloveData.myAccountId === undefined) { - fediloveMastodon.get('/api/v1/accounts/verify_credentials', {}, function(data) { - const json = JSON.parse(data); - if (json !== undefined) { - fediloveData.myAccountId = json.id; - } - }); - } + if (fediloveData.myAccountId === undefined && window.__store.get().verifyCredentials !== undefined) + fediloveData.myAccountId = window.__store.get().verifyCredentials[fediloveApi.getCurrentInstance()].id; if (document.querySelector('#main-nav > div#dummy-nav') != null) { document.querySelector('#main-nav > div#dummy-nav').remove(); @@ -715,6 +721,12 @@ function fedilove_customization() { }); }; + // "maybe" Accounts are stored on localStorage + // as there is no way to save this on Mastodon + const nowDate = Date.now(); + const maybeAccounts = localStorage.store_maybeAccounts !== undefined ? + JSON.parse(localStorage.store_maybeAccounts) : []; + // make sure only the wanted items in timeline are shown var prevItems; var itemsDrawnOnce = false; @@ -726,6 +738,7 @@ function fedilove_customization() { if (!fediloveData.meetRelationshipsFilled) return; + // added when there is no more profiles to Meet if ($('div#noone-to-meet').length === 0) $('div.timeline').parent().append('
'); @@ -738,12 +751,18 @@ function fedilove_customization() { for (var accId of fediloveData.tmpDiscardedAccounts) _discardAccountUI(accId); + // discard localStorage powered maybe accounts (by "Maybe" action) + for (var accId of Object.keys(maybeAccounts)) + if (maybeAccounts[accId] !== undefined && maybeAccounts[accId] > nowDate) + _discardAccountUI(accId); + // discard the ones we "matched" (by "Match" action for (var accId of Object.keys(fediloveData.meetRelationships)) if (fediloveData.meetRelationships[accId].requested) _discardAccountUI(accId); + // paint the current Meet account, after adding classes to hide what we want const items = $('div.virtual-list > div.virtual-list-item:visible'); if (items.length > 0) { if (window.fediloveData.currentIDMeetTimeline === null ||