diff --git a/src/routes/_actions/timeline.js b/src/routes/_actions/timeline.js index eb9d7581..ce25c0e4 100644 --- a/src/routes/_actions/timeline.js +++ b/src/routes/_actions/timeline.js @@ -273,3 +273,7 @@ export async function showMoreItemsForThread (instanceName, timelineName) { }) stop('showMoreItemsForThread') } + +if (process.browser) { + window.__database = database; +} diff --git a/static/fedilove-no-react.js b/static/fedilove-no-react.js index 461a81e9..ebe8a7ee 100644 --- a/static/fedilove-no-react.js +++ b/static/fedilove-no-react.js @@ -227,6 +227,32 @@ var fediloveUI = { $('div#chat-party-global > div#name > span').text(acct); if (accid != 0) $('div#chat-party-global > div#name > a').attr('href', `/accounts/${accid}`); }, + fillMeetRelationships: function() { + var countMax = 0; + const _this = setInterval(function() { + if (countMax > 100) { + return clearInterval(_this); + } + const items = window.__store.get().timelineItemSummaries; + if (items !== null && items.length > 0) { + var refIds = []; + for (var it of items) { + if (!refIds.includes(it.accountId)) + refIds.push(it.accountId); + } + for (var accId of refIds) { + window.__database.getRelationship(fediloveApi.getCurrentInstance(), accId+"").then(function(rel) { + if (rel !== undefined && fediloveData.meetRelationships[rel.id] === undefined) + fediloveData.meetRelationships[rel.id] = rel; + if (Object.keys(window.fediloveData.meetRelationships).length === refIds.length) + fediloveData.meetRelationshipsFilled = true; + }); + } + clearInterval(_this); + } + countMax++; + }, 100); + }, onAccountNope: function() { const accObj = fediloveApi.getMeetAccount(); if (accObj === undefined) return; @@ -240,8 +266,8 @@ var fediloveUI = { onAccountMatch: function() { const accObj = fediloveApi.getMeetAccount(); if (accObj === undefined) return; - if (!fediloveData.tmpDiscardedAccounts.includes(accObj.id)) - fediloveData.tmpDiscardedAccounts.push(accObj.id); + 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); @@ -328,6 +354,8 @@ var fediloveData = { currentAccountIsEmpty: false, currentIDMeetTimeline: null, tmpDiscardedAccounts: [], + meetRelationships: {}, + meetRelationshipsFilled: false, gotEmojifyTextFunction: false, composeTxtKeypressEvent: false }; @@ -650,10 +678,21 @@ function fedilove_customization() { it.attr('style', 'animation: fadeOut .5s linear infinite'); }, (i*250), elem); } + + fediloveData.meetRelationshipsFilled = false; + fediloveUI.fillMeetRelationships(); fediloveUI.registerSwipeOnElement('#meet-navigation #anim-swipe', function(swiperightBol) { fediloveUI.meetPageGoToCurrentAccount(swiperightBol) }); + const _discardAccountUI = function(accId) { + $('article[data-account='+accId+']').each(function() { + $(this).parent().addClass('meetnotshown'); + if ($(this)[0].id === fediloveData.currentIDMeetTimeline) + fediloveData.currentIDMeetTimeline = null; + }); + }; + // make sure only the wanted items in timeline are shown var prevItems; var itemsDrawnOnce = false; @@ -662,6 +701,9 @@ function fedilove_customization() { if (window.location.pathname !== '/meet') return clearInterval(_this); + if (!fediloveData.meetRelationshipsFilled) + return; + if ($('div#noone-to-meet').length === 0) $('div.timeline').parent().append(''); @@ -669,13 +711,16 @@ function fedilove_customization() { // if /meet is reloaded, blocked accounts won't show either) prevItems = $('div.virtual-list > div.virtual-list-item:visible'); - for (var accId of fediloveData.tmpDiscardedAccounts) { - $('article[data-account='+accId+']').each(function() { - $(this).parent().addClass('meetnotshown'); - if ($(this)[0].id === window.fediloveData.currentIDMeetTimeline) - window.fediloveData.currentIDMeetTimeline = null; - }); - } + + // discard temporary added accounts (by "Nope" action) + for (var accId of fediloveData.tmpDiscardedAccounts) + _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); + const items = $('div.virtual-list > div.virtual-list-item:visible'); if (items.length > 0) {