aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/modules/statuses.js3
-rw-r--r--src/services/api/api.service.js2
-rw-r--r--src/services/entity_normalizer/entity_normalizer.service.js (renamed from src/services/status_normalizer/status_normalizer.service.js)3
-rw-r--r--test/unit/specs/modules/statuses.spec.js64
-rw-r--r--test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js102
5 files changed, 128 insertions, 46 deletions
diff --git a/src/modules/statuses.js b/src/modules/statuses.js
index fde019b7..2ece12ba 100644
--- a/src/modules/statuses.js
+++ b/src/modules/statuses.js
@@ -225,6 +225,9 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
remove(timelineObject.visibleStatuses, { uri })
}
},
+ 'follow': (follow) => {
+ // NOOP, it is known status but we don't do anything about it for now
+ },
'default': (unknown) => {
console.log('unknown status type')
console.log(unknown)
diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js
index e82f4f81..14a526ef 100644
--- a/src/services/api/api.service.js
+++ b/src/services/api/api.service.js
@@ -44,7 +44,7 @@ const SUGGESTIONS_URL = '/api/v1/suggestions'
const MASTODON_USER_FAVORITES_TIMELINE_URL = '/api/v1/favourites'
import { each, map } from 'lodash'
-import { parseStatus, parseUser, parseNotification } from '../status_normalizer/status_normalizer.service.js'
+import { parseStatus, parseUser, parseNotification } from '../entity_normalizer/entity_normalizer.service.js'
import 'whatwg-fetch'
const oldfetch = window.fetch
diff --git a/src/services/status_normalizer/status_normalizer.service.js b/src/services/entity_normalizer/entity_normalizer.service.js
index 784c7f20..adc7f047 100644
--- a/src/services/status_normalizer/status_normalizer.service.js
+++ b/src/services/entity_normalizer/entity_normalizer.service.js
@@ -139,7 +139,10 @@ export const parseStatus = (data) => {
if (data.retweeted_status) {
output.nsfw = data.retweeted_status.nsfw
}
+ } else {
+ output.nsfw = data.nsfw
}
+
output.statusnet_html = data.statusnet_html
output.text = data.text
diff --git a/test/unit/specs/modules/statuses.spec.js b/test/unit/specs/modules/statuses.spec.js
index 7d403312..0b511b80 100644
--- a/test/unit/specs/modules/statuses.spec.js
+++ b/test/unit/specs/modules/statuses.spec.js
@@ -1,8 +1,8 @@
import { cloneDeep } from 'lodash'
-import { defaultState, mutations, findMaxId, prepareStatus, statusType } from '../../../../src/modules/statuses.js'
+import { defaultState, mutations, findMaxId, prepareStatus } from '../../../../src/modules/statuses.js'
// eslint-disable-next-line camelcase
-const makeMockStatus = ({id, text, is_post_verb = true}) => {
+const makeMockStatus = ({id, text, type = 'status'}) => {
return {
id,
user: {id: 0},
@@ -10,42 +10,12 @@ const makeMockStatus = ({id, text, is_post_verb = true}) => {
text: text || `Text number ${id}`,
fave_num: 0,
uri: '',
- is_post_verb,
+ type,
attentions: []
}
}
-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'})
- const nsfw = makeMockStatus({id: 1, text: 'Hello oniichan #nsfw'})
-
- expect(prepareStatus(safe).nsfw).to.eq(false)
- expect(prepareStatus(nsfw).nsfw).to.eq(true)
- })
-
- it('leaves existing nsfw settings alone', () => {
- const nsfw = makeMockStatus({id: 1, text: 'Hello oniichan #nsfw'})
- nsfw.nsfw = false
-
- expect(prepareStatus(nsfw).nsfw).to.eq(false)
- })
-
it('sets deleted flag to false', () => {
const aStatus = makeMockStatus({id: 1, text: 'Hello oniichan'})
expect(prepareStatus(aStatus).deleted).to.eq(false)
@@ -127,7 +97,7 @@ describe('The Statuses module', () => {
const status = makeMockStatus({id: 1})
const otherStatus = makeMockStatus({id: 3})
status.uri = 'xxx'
- const deletion = makeMockStatus({id: 2, is_post_verb: false})
+ const deletion = makeMockStatus({id: 2, type: 'deletion'})
deletion.text = 'Dolus deleted notice {{tag:gs.smuglo.li,2016-11-18:noticeId=1038007:objectType=note}}.'
deletion.uri = 'xxx'
@@ -177,7 +147,7 @@ describe('The Statuses module', () => {
it('splits retweets from their status and links them', () => {
const state = cloneDeep(defaultState)
const status = makeMockStatus({id: 1})
- const retweet = makeMockStatus({id: 2, is_post_verb: false})
+ const retweet = makeMockStatus({id: 2, type: 'retweet'})
const modStatus = makeMockStatus({id: 1, text: 'something else'})
retweet.retweeted_status = status
@@ -220,7 +190,7 @@ describe('The Statuses module', () => {
const state = cloneDeep(defaultState)
const status = makeMockStatus({id: 1})
const modStatus = makeMockStatus({id: 1, text: 'something else'})
- const retweet = makeMockStatus({id: 2, is_post_verb: false})
+ const retweet = makeMockStatus({id: 2, type: 'retweet'})
retweet.retweeted_status = modStatus
// Add original status
@@ -243,7 +213,7 @@ describe('The Statuses module', () => {
const favorite = {
id: 2,
- is_post_verb: false,
+ type: 'favorite',
in_reply_to_status_id: '1', // The API uses strings here...
uri: 'tag:shitposter.club,2016-08-21:fave:3895:note:773501:2016-08-21T16:52:15+00:00',
text: 'a favorited something by b',
@@ -271,7 +241,7 @@ describe('The Statuses module', () => {
const ownFavorite = {
id: 3,
- is_post_verb: false,
+ type: 'favorite',
in_reply_to_status_id: '1', // The API uses strings here...
uri: 'tag:shitposter.club,2016-08-21:fave:3895:note:773501:2016-08-21T16:52:15+00:00',
text: 'a favorited something by b',
@@ -296,7 +266,7 @@ describe('The Statuses module', () => {
mentionedStatus.uri = 'xxx'
otherStatus.attentions = [user]
- const deletion = makeMockStatus({id: 4, is_post_verb: false})
+ const deletion = makeMockStatus({id: 4, type: 'deletion'})
deletion.text = 'Dolus deleted notice {{tag:gs.smuglo.li,2016-11-18:noticeId=1038007:objectType=note}}.'
deletion.uri = 'xxx'
@@ -305,10 +275,12 @@ describe('The Statuses module', () => {
state,
{
notifications: [{
- ntype: 'mention',
+ from_profile: { id: 2 },
+ id: 998,
+ type: 'mention',
status: otherStatus,
- notice: otherStatus,
- is_seen: false
+ action: otherStatus,
+ seen: false
}]
})
@@ -317,10 +289,12 @@ describe('The Statuses module', () => {
state,
{
notifications: [{
- ntype: 'mention',
+ from_profile: { id: 2 },
+ id: 999,
+ type: 'mention',
status: mentionedStatus,
- notice: mentionedStatus,
- is_seen: false
+ action: mentionedStatus,
+ seen: false
}]
})
diff --git a/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js b/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js
new file mode 100644
index 00000000..e5882725
--- /dev/null
+++ b/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js
@@ -0,0 +1,102 @@
+import { parseStatus, parseUser, parseNotification } from '../../../../../src/services/entity_normalizer/entity_normalizer.service.js'
+
+const makeMockStatusQvitter = (overrides = {}) => {
+ return Object.assign({
+ activity_type: 'post',
+ attachments: [],
+ attentions: [],
+ created_at: 'Tue Jan 15 13:57:56 +0000 2019',
+ external_url: 'https://ap.example/whatever',
+ fave_num: 1,
+ favorited: false,
+ id: 10335970,
+ in_reply_to_ostatus_uri: null,
+ in_reply_to_profileurl: null,
+ in_reply_to_screen_name: null,
+ in_reply_to_status_id: null,
+ in_reply_to_user_id: null,
+ is_local: false,
+ is_post_verb: true,
+ possibly_sensitive: false,
+ repeat_num: 0,
+ repeated: false,
+ statusnet_conversation_id: 16300488,
+ statusnet_html: '<p>haha benis</p>',
+ summary: null,
+ tags: [],
+ text: 'haha benis',
+ uri: 'https://ap.example/whatever',
+ user: makeMockUserQvitter(),
+ visibility: 'public'
+ }, overrides)
+}
+
+const makeMockUserQvitter = (overrides = {}) => {
+ return Object.assign({
+ background_image: null,
+ cover_photo: '',
+ created_at: 'Mon Jan 14 13:56:51 +0000 2019',
+ default_scope: 'public',
+ description: 'ebin',
+ description_html: '<p>ebin</p>',
+ favourites_count: 0,
+ fields: [],
+ followers_count: 1,
+ following: true,
+ follows_you: true,
+ friends_count: 1,
+ id: 60717,
+ is_local: false,
+ locked: false,
+ name: 'Spurdo :ebin:',
+ name_html: 'Spurdo <img src="whatever">',
+ no_rich_text: false,
+ pleroma: { confirmation_pending: false, tags: [] },
+ profile_image_url: 'https://ap.example/whatever',
+ profile_image_url_https: 'https://ap.example/whatever',
+ profile_image_url_original: 'https://ap.example/whatever',
+ profile_image_url_profile_size: 'https://ap.example/whatever',
+ rights: { delete_others_notice: false },
+ screen_name: 'spurdo@ap.example',
+ statuses_count: 46,
+ statusnet_blocking: false,
+ statusnet_profile_url: ''
+ }, overrides)
+}
+
+parseNotification
+parseUser
+parseStatus
+makeMockStatusQvitter
+makeMockUserQvitter
+
+describe('QVitter preprocessing', () => {
+ it('identifies favorites', () => {
+ const fav = {
+ uri: 'tag:soykaf.com,2016-08-21:fave:2558:note:339495:2016-08-21T16:54:04+00:00',
+ is_post_verb: false
+ }
+
+ const mastoFav = {
+ uri: 'tag:mastodon.social,2016-11-27:objectId=73903:objectType=Favourite',
+ is_post_verb: false
+ }
+
+ expect(parseStatus(makeMockStatusQvitter(fav))).to.have.property('type', 'favorite')
+ expect(parseStatus(makeMockStatusQvitter(mastoFav))).to.have.property('type', 'favorite')
+ })
+
+ it('sets nsfw for statuses with the #nsfw tag', () => {
+ const safe = makeMockStatusQvitter({id: 1, text: 'Hello oniichan'})
+ const nsfw = makeMockStatusQvitter({id: 1, text: 'Hello oniichan #nsfw'})
+
+ expect(parseStatus(safe).nsfw).to.eq(false)
+ expect(parseStatus(nsfw).nsfw).to.eq(true)
+ })
+
+ it('leaves existing nsfw settings alone', () => {
+ const nsfw = makeMockStatusQvitter({id: 1, text: 'Hello oniichan #nsfw', nsfw: false})
+
+ expect(parseStatus(nsfw).nsfw).to.eq(false)
+ })
+})