Permit user to reload relationship states by refreshing the URL

This commit is contained in:
Bofh 2021-01-11 19:42:00 +01:00
parent 9deba874e1
commit 0a9d739269
1 changed files with 34 additions and 12 deletions

View File

@ -26,13 +26,16 @@ const fediloveMastodon = {
},
API: {
discardAccount: function(account_id, cback) {
fediloveMastodon.post(`/api/v1/accounts/${account_id}/block`, {}, function(data) { cback() });
fediloveMastodon.post(`/api/v1/accounts/${account_id}/block`, null, function(data) { cback() });
},
matchAccount: function(account_id, cback) {
fediloveMastodon.post(`/api/v1/accounts/${account_id}/follow`, {'reblogs': true},
function(data) { cback() }
);
},
getRelationship: function(account_id, cback) {
fediloveMastodon.get(`/api/v1/accounts/relationships?id=${account_id}`, null, cback);
},
statusFav: function(dom, status_id) {
var dislike = false;
var path = `/api/v1/statuses/${status_id}/favourite`;
@ -233,20 +236,32 @@ var fediloveUI = {
if (countMax > 100) {
return clearInterval(_this);
}
const items = window.__store.get().timelineItemSummaries;
const items = window.fediloveFunctions.filterItemsForFedilove(window.__store.get().timelineItemSummaries);
if (items !== null && items.length > 0) {
var refIds = [];
for (var it of items) {
if (!refIds.includes(it.accountId))
if (it.accountId !== undefined && !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;
});
if (fediloveData.pagesLoaded['meet']) {
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;
});
}
} else {
for (var accId of refIds) {
fediloveMastodon.API.getRelationship(accId+"", function(data) {
const json = JSON.parse(data)[0];
if (json && fediloveData.meetRelationships[json.id] === undefined)
fediloveData.meetRelationships[json.id] = json;
fediloveData.meetRelationshipsFilled = true;
fediloveData.pagesLoaded['meet'] = true;
});
}
}
clearInterval(_this);
}
@ -333,10 +348,16 @@ var fediloveApi = {
};
var fediloveFunctions = {
filterItemsForFedilove: function(items) {
if (items === null || items === undefined)
return null;
let newItems = [];
for (var item of items) {
if (item.account === undefined)
if (item.account === undefined) {
if (item.accountId !== undefined &&
item.accountId !== window.fediloveData.myAccountId)
newItems.push(item);
continue;
}
if (item.account.display_name.toLowerCase().includes('#fedilove') &&
item.content.replace(/<[^<>]+>/g, '').toLowerCase().includes('#fedilove') &&
item.account.id != window.fediloveData.myAccountId) {
@ -357,7 +378,8 @@ var fediloveData = {
meetRelationships: {},
meetRelationshipsFilled: false,
gotEmojifyTextFunction: false,
composeTxtKeypressEvent: false
composeTxtKeypressEvent: false,
pagesLoaded: {}
};
var fediloveEvents = {
onGotEmojifyTextFunction: function() {