Mitra: handle status context endpoint as a list of statuses
This commit is contained in:
parent
69712baa02
commit
c084a7a232
3 changed files with 148 additions and 4 deletions
107
app/soapbox/__fixtures__/mitra-context.json
Normal file
107
app/soapbox/__fixtures__/mitra-context.json
Normal file
|
@ -0,0 +1,107 @@
|
|||
[
|
||||
{
|
||||
"id": "017ed503-bc96-301a-e871-2c23b30ddd05",
|
||||
"uri": "https://mitra.social/objects/017ed503-bc96-301a-e871-2c23b30ddd05",
|
||||
"created_at": "2022-02-07T16:28:18.966874Z",
|
||||
"account": {
|
||||
"id": "017ed4f9-c121-2ae6-0805-15516cce02c3",
|
||||
"username": "alex",
|
||||
"acct": "alex",
|
||||
"url": "https://mitra.social/users/alex",
|
||||
"display_name": null,
|
||||
"created_at": "2022-02-07T16:17:24.769229Z",
|
||||
"note": null,
|
||||
"avatar": null,
|
||||
"header": null,
|
||||
"fields": [],
|
||||
"followers_count": 1,
|
||||
"following_count": 1,
|
||||
"statuses_count": 3,
|
||||
"source": null,
|
||||
"wallet_address": null
|
||||
},
|
||||
"content": "<span class=\"h-card\"><a class=\"u-url mention\" href=\"https://mitra.social/users/silverpill\">@silverpill</a></span> sup!",
|
||||
"in_reply_to_id": null,
|
||||
"reblog": null,
|
||||
"visibility": "public",
|
||||
"replies_count": 1,
|
||||
"favourites_count": 0,
|
||||
"reblogs_count": 0,
|
||||
"media_attachments": [],
|
||||
"mentions": [
|
||||
{
|
||||
"id": "dd4ebc18-269d-4c7b-a310-03d29c6ab551",
|
||||
"username": "silverpill",
|
||||
"acct": "silverpill",
|
||||
"url": "https://mitra.social/users/silverpill"
|
||||
}
|
||||
],
|
||||
"tags": [],
|
||||
"favourited": false,
|
||||
"reblogged": false,
|
||||
"ipfs_cid": null,
|
||||
"token_id": null,
|
||||
"token_tx_id": null
|
||||
},
|
||||
{
|
||||
"id": "017ed505-5926-392f-256a-f86d5075df70",
|
||||
"uri": "https://mitra.social/objects/017ed505-5926-392f-256a-f86d5075df70",
|
||||
"created_at": "2022-02-07T16:30:04.582771Z",
|
||||
"account": {
|
||||
"id": "dd4ebc18-269d-4c7b-a310-03d29c6ab551",
|
||||
"username": "silverpill",
|
||||
"acct": "silverpill",
|
||||
"url": "https://mitra.social/users/silverpill",
|
||||
"display_name": "silverpill",
|
||||
"created_at": "2021-11-06T21:08:57.441927Z",
|
||||
"note": "Admin of <a href=\"https://mitra.social/\" rel=\"noopener noreferrer\">mitra.social</a> instance. It is running experimental ActivityPub server <a href=\"https://codeberg.org/silverpill/mitra\" rel=\"noopener noreferrer\">Mitra</a>.",
|
||||
"avatar": "https://mitra.social/media/6a785bf7dd05f61c3590e8935aa49156a499ac30fd1e402f79e7e164adb36e2c.png",
|
||||
"header": null,
|
||||
"fields": [
|
||||
{
|
||||
"name": "Matrix",
|
||||
"value": "@silverpill:poa.st"
|
||||
},
|
||||
{
|
||||
"name": "Alt",
|
||||
"value": "@silverpill@poa.st"
|
||||
},
|
||||
{
|
||||
"name": "Code",
|
||||
"value": "<a href=\"https://codeberg.org/silverpill/\" rel=\"noopener noreferrer\">https://codeberg.org/silverpill/</a>"
|
||||
},
|
||||
{
|
||||
"name": "$XMR",
|
||||
"value": "884y9LmsWY7PQNsyR7bJy1dvj91tuF5spVabyCnPk4KfQtSuzFbQobTFC7xSemJgVW1FWAwnJbjTZX5zZWbBrfkv62DB62d"
|
||||
}
|
||||
],
|
||||
"followers_count": 27,
|
||||
"following_count": 15,
|
||||
"statuses_count": 110,
|
||||
"source": null,
|
||||
"wallet_address": null
|
||||
},
|
||||
"content": "<span class=\"h-card\"><a class=\"u-url mention\" href=\"https://mitra.social/users/alex\">@alex</a></span> welcome",
|
||||
"in_reply_to_id": "017ed503-bc96-301a-e871-2c23b30ddd05",
|
||||
"reblog": null,
|
||||
"visibility": "public",
|
||||
"replies_count": 0,
|
||||
"favourites_count": 1,
|
||||
"reblogs_count": 0,
|
||||
"media_attachments": [],
|
||||
"mentions": [
|
||||
{
|
||||
"id": "017ed4f9-c121-2ae6-0805-15516cce02c3",
|
||||
"username": "alex",
|
||||
"acct": "alex",
|
||||
"url": "https://mitra.social/users/alex"
|
||||
}
|
||||
],
|
||||
"tags": [],
|
||||
"favourited": true,
|
||||
"reblogged": false,
|
||||
"ipfs_cid": null,
|
||||
"token_id": null,
|
||||
"token_tx_id": null
|
||||
}
|
||||
]
|
29
app/soapbox/actions/__tests__/statuses-test.js
Normal file
29
app/soapbox/actions/__tests__/statuses-test.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
import { Map as ImmutableMap } from 'immutable';
|
||||
|
||||
import { STATUSES_IMPORT } from 'soapbox/actions/importer';
|
||||
import { __stub } from 'soapbox/api';
|
||||
import { mockStore } from 'soapbox/test_helpers';
|
||||
|
||||
import { fetchContext } from '../statuses';
|
||||
|
||||
describe('fetchContext()', () => {
|
||||
it('handles Mitra context', done => {
|
||||
const statuses = require('soapbox/__fixtures__/mitra-context.json');
|
||||
|
||||
__stub(mock => {
|
||||
mock.onGet('/api/v1/statuses/017ed505-5926-392f-256a-f86d5075df70/context')
|
||||
.reply(200, statuses);
|
||||
});
|
||||
|
||||
const store = mockStore(ImmutableMap());
|
||||
|
||||
store.dispatch(fetchContext('017ed505-5926-392f-256a-f86d5075df70')).then(context => {
|
||||
const actions = store.getActions();
|
||||
|
||||
expect(actions[3].type).toEqual(STATUSES_IMPORT);
|
||||
expect(actions[3].statuses[0].id).toEqual('017ed503-bc96-301a-e871-2c23b30ddd05');
|
||||
|
||||
done();
|
||||
}).catch(console.error);
|
||||
});
|
||||
});
|
|
@ -143,10 +143,18 @@ export function fetchContext(id) {
|
|||
dispatch({ type: CONTEXT_FETCH_REQUEST, id });
|
||||
|
||||
return api(getState).get(`/api/v1/statuses/${id}/context`).then(({ data: context }) => {
|
||||
const { ancestors, descendants } = context;
|
||||
const statuses = ancestors.concat(descendants);
|
||||
dispatch(importFetchedStatuses(statuses));
|
||||
dispatch({ type: CONTEXT_FETCH_SUCCESS, id, ancestors, descendants });
|
||||
if (Array.isArray(context)) {
|
||||
// Mitra: returns a list of statuses
|
||||
dispatch(importFetchedStatuses(context));
|
||||
} else if (typeof context === 'object') {
|
||||
// Standard Mastodon API returns a map with `ancestors` and `descendants`
|
||||
const { ancestors, descendants } = context;
|
||||
const statuses = ancestors.concat(descendants);
|
||||
dispatch(importFetchedStatuses(statuses));
|
||||
dispatch({ type: CONTEXT_FETCH_SUCCESS, id, ancestors, descendants });
|
||||
} else {
|
||||
throw context;
|
||||
}
|
||||
return context;
|
||||
}).catch(error => {
|
||||
if (error.response && error.response.status === 404) {
|
||||
|
|
Loading…
Reference in a new issue