From ff93d1edeefae88cc1b9e9efe4f22c8787e5f792 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sun, 27 Nov 2016 18:54:17 +0100 Subject: [PATCH] Parse mastodon favorites. --- src/modules/statuses.js | 4 ++-- test/unit/specs/modules/statuses.spec.js | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/modules/statuses.js b/src/modules/statuses.js index fee47558..cee249e2 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -62,7 +62,7 @@ export const updateTimestampsInStatuses = (statuses) => { }) } -const statusType = (status) => { +export const statusType = (status) => { if (status.is_post_verb) { return 'status' } @@ -71,7 +71,7 @@ const statusType = (status) => { return 'retweet' } - if (typeof status.uri === 'string' && status.uri.match(/fave/)) { + if (typeof status.uri === 'string' && status.uri.match(/(fave|objectType=Favourite)/)) { return 'favorite' } diff --git a/test/unit/specs/modules/statuses.spec.js b/test/unit/specs/modules/statuses.spec.js index f068bb92..e6abbd91 100644 --- a/test/unit/specs/modules/statuses.spec.js +++ b/test/unit/specs/modules/statuses.spec.js @@ -1,5 +1,5 @@ import { cloneDeep } from 'lodash' -import { defaultState, mutations, findMaxId, prepareStatus } from '../../../../src/modules/statuses.js' +import { defaultState, mutations, findMaxId, prepareStatus, statusType } from '../../../../src/modules/statuses.js' const makeMockStatus = ({id, text, is_post_verb = true}) => { return { @@ -13,6 +13,21 @@ const makeMockStatus = ({id, text, is_post_verb = true}) => { } } +describe('Statuses.statusType', () => { + it('identifies favorites', () => { + const fav = { + uri: 'tag:soykaf.com,2016-08-21:fave:2558:note:339495:2016-08-21T16:54:04+00:00' + } + + const mastoFav = { + uri: 'tag:mastodon.social,2016-11-27:objectId=73903:objectType=Favourite' + } + + expect(statusType(fav)).to.eql('favorite') + expect(statusType(mastoFav)).to.eql('favorite') + }) +}) + describe('Statuses.prepareStatus', () => { it('sets nsfw for statuses with the #nsfw tag', () => { const safe = makeMockStatus({id: 1, text: 'Hello oniichan'})