Implementing APIs for the matches control screen + some tweaks to current discard/match feature

* Now the discard/match function call reject/authorize respectively to the follow requests (if any)
 this causes 404 error when there is none, but it is OK. This is a feature, not a bug.
* Mastodon API improved to check callback is null
* Matches pages cleared out to start from scratch
This commit is contained in:
Bofh 2021-01-14 00:36:49 +01:00
parent 92cb0668d0
commit 6d599f1b4d
2 changed files with 19 additions and 22 deletions

View File

@ -1,20 +1,4 @@
<DynamicPageBanner title="{intl.follows}" /> <div id="manage-matches">
<AccountsListPage {accountsFetcher} /> </div>
<script> <script>
import { getFollows } from '../../_api/followsAndFollowers'
import AccountsListPage from '../../_components/AccountsListPage.html'
import { store } from '../../_store/store'
import DynamicPageBanner from '../../_components/DynamicPageBanner.html'
export default {
computed: {
accountId: ({ params }) => params.accountId,
accountsFetcher: ({ $currentInstance, $accessToken, accountId }) => () => getFollows($currentInstance, $accessToken, accountId)
},
store: () => store,
components: {
AccountsListPage,
DynamicPageBanner
}
}
</script> </script>

View File

@ -8,12 +8,13 @@
const fediloveMastodon = { const fediloveMastodon = {
request: function(method, path, payload, callbk) { request: function(method, path, payload, callbk) {
payload = payload || null; payload = payload || null;
callbk = callbk || null;
const ACCESS_TOKEN = window.fediloveApi.getAccessToken(); const ACCESS_TOKEN = window.fediloveApi.getAccessToken();
if (ACCESS_TOKEN === undefined) if (ACCESS_TOKEN === undefined)
return callbk(undefined); return callbk(undefined);
const API_URL = 'https://'+fediloveApi.getCurrentInstance()+path; const API_URL = 'https://'+fediloveApi.getCurrentInstance()+path;
const oReq = new XMLHttpRequest(); const oReq = new XMLHttpRequest();
oReq.addEventListener("load", function() { callbk(this.responseText); }); oReq.addEventListener("load", function() { if (callbk) callbk(this.responseText) });
oReq.open(method, API_URL); oReq.open(method, API_URL);
oReq.setRequestHeader('Authorization', 'Bearer '+ACCESS_TOKEN); oReq.setRequestHeader('Authorization', 'Bearer '+ACCESS_TOKEN);
oReq.send(payload); oReq.send(payload);
@ -27,15 +28,27 @@ const fediloveMastodon = {
API: { API: {
discardAccount: function(account_id, cback) { discardAccount: function(account_id, cback) {
fediloveMastodon.post(`/api/v1/accounts/${account_id}/block`, null, function(data) { cback() }); fediloveMastodon.post(`/api/v1/accounts/${account_id}/block`, null, function(data) { cback() });
fediloveMastodon.post(`/api/v1/follow_requests/${account_id}/reject`);
}, },
matchAccount: function(account_id, cback) { matchAccount: function(account_id, cback) {
fediloveMastodon.post(`/api/v1/accounts/${account_id}/follow`, {'reblogs': true}, fediloveMastodon.post(`/api/v1/accounts/${account_id}/follow`, {'reblogs': true}, function(data) { cback() });
function(data) { cback() } fediloveMastodon.post(`/api/v1/follow_requests/${account_id}/authorize`);
);
}, },
getRelationship: function(account_id, cback) { getRelationship: function(account_id, cback) {
fediloveMastodon.get(`/api/v1/accounts/relationships?id=${account_id}`, null, cback); fediloveMastodon.get(`/api/v1/accounts/relationships?id=${account_id}`, null, cback);
}, },
getMyFollowing: function(cback) {
fediloveMastodon.get(`/api/v1/accounts/${fediloveData.myAccountId}/following`, null, cback);
},
getMyRequestsToFollow: function(cback) {
// to-do: find out how to list my own matches (follow requests)
},
getMyFollowers: function(cback) {
fediloveMastodon.get(`/api/v1/accounts/${fediloveData.myAccountId}/followers`, null, cback);
},
getRequestsToFollowMe: function(cback) {
fediloveMastodon.get('/api/v1/follow_requests', null, cback);
},
statusFav: function(dom, status_id) { statusFav: function(dom, status_id) {
var dislike = false; var dislike = false;
var path = `/api/v1/statuses/${status_id}/favourite`; var path = `/api/v1/statuses/${status_id}/favourite`;