aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHJ <spam@hjkos.com>2019-01-22 17:46:08 +0000
committerHJ <spam@hjkos.com>2019-01-22 17:46:08 +0000
commit3a3cf1d48a67c82bb2c94cafb0150b1fa8e4de1a (patch)
tree5e39bb41c1e73191b2ff6222eee8720420f13dfd /src
parent7651290e2be72ed35d7582757251eb151fdce953 (diff)
parent92dedcd53e56562205e704eea2754f159eb9707d (diff)
Merge branch 'favorites' into 'develop'
Add Favorites TL to user profile, add some initial support for MastoAPI Closes #265 and #262 See merge request pleroma/pleroma-fe!462
Diffstat (limited to 'src')
-rw-r--r--src/components/conversation-page/conversation-page.js4
-rw-r--r--src/components/conversation/conversation.js16
-rw-r--r--src/components/status/status.js5
-rw-r--r--src/components/tab_switcher/tab_switcher.jsx28
-rw-r--r--src/components/user_profile/user_profile.js16
-rw-r--r--src/components/user_profile/user_profile.vue1
-rw-r--r--src/i18n/en.json1
-rw-r--r--src/i18n/ru.json1
-rw-r--r--src/modules/statuses.js118
-rw-r--r--src/modules/users.js66
-rw-r--r--src/services/api/api.service.js52
-rw-r--r--src/services/entity_normalizer/entity_normalizer.service.js263
-rw-r--r--src/services/notification_utils/notification_utils.js4
-rw-r--r--src/services/status_poster/status_poster.service.js1
14 files changed, 437 insertions, 139 deletions
diff --git a/src/components/conversation-page/conversation-page.js b/src/components/conversation-page/conversation-page.js
index beffa5bb..8f1ac3d9 100644
--- a/src/components/conversation-page/conversation-page.js
+++ b/src/components/conversation-page/conversation-page.js
@@ -1,5 +1,5 @@
import Conversation from '../conversation/conversation.vue'
-import { find, toInteger } from 'lodash'
+import { find } from 'lodash'
const conversationPage = {
components: {
@@ -7,7 +7,7 @@ const conversationPage = {
},
computed: {
statusoid () {
- const id = toInteger(this.$route.params.id)
+ const id = this.$route.params.id
const statuses = this.$store.state.statuses.allStatuses
const status = find(statuses, {id})
diff --git a/src/components/conversation/conversation.js b/src/components/conversation/conversation.js
index 9d9f7bbe..9bf5e136 100644
--- a/src/components/conversation/conversation.js
+++ b/src/components/conversation/conversation.js
@@ -1,9 +1,8 @@
import { reduce, filter, sortBy } from 'lodash'
-import { statusType } from '../../modules/statuses.js'
import Status from '../status/status.vue'
const sortAndFilterConversation = (conversation) => {
- conversation = filter(conversation, (status) => statusType(status) !== 'retweet')
+ conversation = filter(conversation, (status) => status.type !== 'retweet')
return sortBy(conversation, 'id')
}
@@ -18,10 +17,12 @@ const conversation = {
'collapsable'
],
computed: {
- status () { return this.statusoid },
+ status () {
+ return this.statusoid
+ },
conversation () {
if (!this.status) {
- return false
+ return []
}
const conversationId = this.status.statusnet_conversation_id
@@ -32,7 +33,9 @@ const conversation = {
replies () {
let i = 1
return reduce(this.conversation, (result, {id, in_reply_to_status_id}) => {
- const irid = Number(in_reply_to_status_id)
+ /* eslint-disable camelcase */
+ const irid = in_reply_to_status_id
+ /* eslint-enable camelcase */
if (irid) {
result[irid] = result[irid] || []
result[irid].push({
@@ -69,7 +72,6 @@ const conversation = {
}
},
getReplies (id) {
- id = Number(id)
return this.replies[id] || []
},
focused (id) {
@@ -80,7 +82,7 @@ const conversation = {
}
},
setHighlight (id) {
- this.highlight = Number(id)
+ this.highlight = id
}
}
}
diff --git a/src/components/status/status.js b/src/components/status/status.js
index 7d6acbac..105a736b 100644
--- a/src/components/status/status.js
+++ b/src/components/status/status.js
@@ -129,7 +129,7 @@ const Status = {
if (this.status.user.id === this.$store.state.users.currentUser.id) {
return false
}
- if (this.status.activity_type === 'repeat') {
+ if (this.status.type === 'retweet') {
return false
}
var checkFollowing = this.$store.state.config.replyVisibility === 'following'
@@ -258,7 +258,7 @@ const Status = {
},
replyEnter (id, event) {
this.showPreview = true
- const targetId = Number(id)
+ const targetId = id
const statuses = this.$store.state.statuses.allStatuses
if (!this.preview) {
@@ -283,7 +283,6 @@ const Status = {
},
watch: {
'highlight': function (id) {
- id = Number(id)
if (this.status.id === id) {
let rect = this.$el.getBoundingClientRect()
if (rect.top < 100) {
diff --git a/src/components/tab_switcher/tab_switcher.jsx b/src/components/tab_switcher/tab_switcher.jsx
index 2f362c4d..9038733c 100644
--- a/src/components/tab_switcher/tab_switcher.jsx
+++ b/src/components/tab_switcher/tab_switcher.jsx
@@ -6,18 +6,26 @@ export default Vue.component('tab-switcher', {
name: 'TabSwitcher',
data () {
return {
- active: 0
+ active: this.$slots.default.findIndex(_ => _.tag)
}
},
methods: {
- activateTab(index) {
- return () => this.active = index;
+ activateTab (index) {
+ return () => {
+ this.active = index
+ }
}
},
- render(h) {
+ beforeUpdate () {
+ const currentSlot = this.$slots.default[this.active]
+ if (!currentSlot.tag) {
+ this.active = this.$slots.default.findIndex(_ => _.tag)
+ }
+ },
+ render (h) {
const tabs = this.$slots.default
- .filter(slot => slot.data)
.map((slot, index) => {
+ if (!slot.tag) return
const classesTab = ['tab']
const classesWrapper = ['tab-wrapper']
@@ -25,20 +33,24 @@ export default Vue.component('tab-switcher', {
classesTab.push('active')
classesWrapper.push('active')
}
+
return (
<div class={ classesWrapper.join(' ')}>
<button onClick={this.activateTab(index)} class={ classesTab.join(' ') }>{slot.data.attrs.label}</button>
</div>
)
- });
- const contents = this.$slots.default.filter(_=>_.data).map(( slot, index ) => {
+ })
+
+ const contents = this.$slots.default.map((slot, index) => {
+ if (!slot.tag) return
const active = index === this.active
return (
<div class={active ? 'active' : 'hidden'}>
{slot}
</div>
)
- });
+ })
+
return (
<div class="tab-switcher">
<div class="tabs">
diff --git a/src/components/user_profile/user_profile.js b/src/components/user_profile/user_profile.js
index bde20707..c9197a1c 100644
--- a/src/components/user_profile/user_profile.js
+++ b/src/components/user_profile/user_profile.js
@@ -5,24 +5,33 @@ import Timeline from '../timeline/timeline.vue'
const UserProfile = {
created () {
this.$store.commit('clearTimeline', { timeline: 'user' })
+ this.$store.commit('clearTimeline', { timeline: 'favorites' })
this.$store.dispatch('startFetching', ['user', this.fetchBy])
+ this.$store.dispatch('startFetching', ['favorites', this.fetchBy])
if (!this.user.id) {
this.$store.dispatch('fetchUser', this.fetchBy)
}
},
destroyed () {
this.$store.dispatch('stopFetching', 'user')
+ this.$store.dispatch('stopFetching', 'favorites')
},
computed: {
timeline () {
return this.$store.state.statuses.timelines.user
},
+ favorites () {
+ return this.$store.state.statuses.timelines.favorites
+ },
userId () {
return this.$route.params.id || this.user.id
},
userName () {
return this.$route.params.name || this.user.screen_name
},
+ isUs () {
+ return this.userId === this.$store.state.users.currentUser.id
+ },
friends () {
return this.user.friends
},
@@ -62,21 +71,28 @@ const UserProfile = {
}
},
watch: {
+ // TODO get rid of this copypasta
userName () {
if (this.isExternal) {
return
}
this.$store.dispatch('stopFetching', 'user')
+ this.$store.dispatch('stopFetching', 'favorites')
this.$store.commit('clearTimeline', { timeline: 'user' })
+ this.$store.commit('clearTimeline', { timeline: 'favorites' })
this.$store.dispatch('startFetching', ['user', this.fetchBy])
+ this.$store.dispatch('startFetching', ['favorites', this.fetchBy])
},
userId () {
if (!this.isExternal) {
return
}
this.$store.dispatch('stopFetching', 'user')
+ this.$store.dispatch('stopFetching', 'favorites')
this.$store.commit('clearTimeline', { timeline: 'user' })
+ this.$store.commit('clearTimeline', { timeline: 'favorites' })
this.$store.dispatch('startFetching', ['user', this.fetchBy])
+ this.$store.dispatch('startFetching', ['favorites', this.fetchBy])
},
user () {
if (this.user.id && !this.user.followers) {
diff --git a/src/components/user_profile/user_profile.vue b/src/components/user_profile/user_profile.vue
index 50619026..d64ce277 100644
--- a/src/components/user_profile/user_profile.vue
+++ b/src/components/user_profile/user_profile.vue
@@ -20,6 +20,7 @@
<i class="icon-spin3 animate-spin"></i>
</div>
</div>
+ <Timeline v-if="isUs" :label="$t('user_card.favorites')" :embedded="true" :title="$t('user_profile.favorites_title')" timeline-name="favorites" :timeline="favorites"/>
</tab-switcher>
</div>
<div v-else class="panel user-profile-placeholder">
diff --git a/src/i18n/en.json b/src/i18n/en.json
index 1dd3462b..3c29a17e 100644
--- a/src/i18n/en.json
+++ b/src/i18n/en.json
@@ -324,6 +324,7 @@
"block": "Block",
"blocked": "Blocked!",
"deny": "Deny",
+ "favorites": "Favorites",
"follow": "Follow",
"follow_sent": "Request sent!",
"follow_progress": "Requesting…",
diff --git a/src/i18n/ru.json b/src/i18n/ru.json
index 249eab69..0887bb59 100644
--- a/src/i18n/ru.json
+++ b/src/i18n/ru.json
@@ -279,6 +279,7 @@
"user_card": {
"block": "Заблокировать",
"blocked": "Заблокирован",
+ "favorites": "Понравившиеся",
"follow": "Читать",
"follow_sent": "Запрос отправлен!",
"follow_progress": "Запрашиваем…",
diff --git a/src/modules/statuses.js b/src/modules/statuses.js
index f92239a9..83cf7256 100644
--- a/src/modules/statuses.js
+++ b/src/modules/statuses.js
@@ -1,8 +1,8 @@
-import { includes, remove, slice, sortBy, toInteger, each, find, flatten, maxBy, minBy, merge, last, isArray } from 'lodash'
+import { remove, slice, each, find, maxBy, minBy, merge, last, isArray } from 'lodash'
import apiService from '../services/api/api.service.js'
// import parse from '../services/status_parser/status_parser.js'
-const emptyTl = (userId = 0) => ({
+const emptyTl = () => ({
statuses: [],
statusesObject: {},
faves: [],
@@ -14,8 +14,8 @@ const emptyTl = (userId = 0) => ({
loading: false,
followers: [],
friends: [],
- flushMarker: 0,
- userId
+ userId: 0,
+ flushMarker: 0
})
export const defaultState = {
@@ -36,6 +36,7 @@ export const defaultState = {
mentions: emptyTl(),
public: emptyTl(),
user: emptyTl(),
+ favorites: emptyTl(),
publicAndExternal: emptyTl(),
friends: emptyTl(),
tag: emptyTl(),
@@ -43,20 +44,7 @@ export const defaultState = {
}
}
-const isNsfw = (status) => {
- const nsfwRegex = /#nsfw/i
- return includes(status.tags, 'nsfw') || !!status.text.match(nsfwRegex)
-}
-
export const prepareStatus = (status) => {
- // Parse nsfw tags
- if (status.nsfw === undefined) {
- status.nsfw = isNsfw(status)
- if (status.retweeted_status) {
- status.nsfw = status.retweeted_status.nsfw
- }
- }
-
// Set deleted flag
status.deleted = false
@@ -75,35 +63,6 @@ const visibleNotificationTypes = (rootState) => {
].filter(_ => _)
}
-export const statusType = (status) => {
- if (status.is_post_verb) {
- return 'status'
- }
-
- if (status.retweeted_status) {
- return 'retweet'
- }
-
- if ((typeof status.uri === 'string' && status.uri.match(/(fave|objectType=Favourite)/)) ||
- (typeof status.text === 'string' && status.text.match(/favorited/))) {
- return 'favorite'
- }
-
- if (status.text.match(/deleted notice {{tag/) || status.qvitter_delete_notice) {
- return 'deletion'
- }
-
- if (status.text.match(/started following/) || status.activity_type === 'follow') {
- return 'follow'
- }
-
- return 'unknown'
-}
-
-export const findMaxId = (...args) => {
- return (maxBy(flatten(args), 'id') || {}).id
-}
-
const mergeOrAdd = (arr, obj, item) => {
const oldItem = obj[item.id]
@@ -122,9 +81,11 @@ const mergeOrAdd = (arr, obj, item) => {
}
}
+const sortById = (a, b) => a.id > b.id ? -1 : 1
+
const sortTimeline = (timeline) => {
- timeline.visibleStatuses = sortBy(timeline.visibleStatuses, ({id}) => -id)
- timeline.statuses = sortBy(timeline.statuses, ({id}) => -id)
+ timeline.visibleStatuses = timeline.visibleStatuses.sort(sortById)
+ timeline.statuses = timeline.statuses.sort(sortById)
timeline.minVisibleId = (last(timeline.visibleStatuses) || {}).id
return timeline
}
@@ -153,13 +114,13 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
return
}
- const addStatus = (status, showImmediately, addToTimeline = true) => {
- const result = mergeOrAdd(allStatuses, allStatusesObject, status)
- status = result.item
+ const addStatus = (data, showImmediately, addToTimeline = true) => {
+ const result = mergeOrAdd(allStatuses, allStatusesObject, data)
+ const status = result.item
if (result.new) {
// We are mentioned in a post
- if (statusType(status) === 'status' && find(status.attentions, { id: user.id })) {
+ if (status.type === 'status' && find(status.attentions, { id: user.id })) {
const mentions = state.timelines.mentions
// Add the mention to the mentions timeline
@@ -200,7 +161,7 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
}
const favoriteStatus = (favorite, counter) => {
- const status = find(allStatuses, { id: toInteger(favorite.in_reply_to_status_id) })
+ const status = find(allStatuses, { id: favorite.in_reply_to_status_id })
if (status) {
// This is our favorite, so the relevant bit.
if (favorite.user.id === user.id) {
@@ -263,6 +224,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)
@@ -270,7 +234,7 @@ const addNewStatuses = (state, { statuses, showImmediately = false, timeline, us
}
each(statuses, (status) => {
- const type = statusType(status)
+ const type = status.type
const processor = processors[type] || processors['default']
processor(status)
})
@@ -288,42 +252,36 @@ const addNewNotifications = (state, { dispatch, notifications, older, visibleNot
const allStatuses = state.allStatuses
const allStatusesObject = state.allStatusesObject
each(notifications, (notification) => {
- const result = mergeOrAdd(allStatuses, allStatusesObject, notification.notice)
- const action = result.item
+ notification.action = mergeOrAdd(allStatuses, allStatusesObject, notification.action).item
+ notification.status = notification.status && mergeOrAdd(allStatuses, allStatusesObject, notification.status).item
+
// Only add a new notification if we don't have one for the same action
- if (!find(state.notifications.data, (oldNotification) => oldNotification.action.id === action.id)) {
- state.notifications.maxId = Math.max(notification.id, state.notifications.maxId)
- state.notifications.minId = Math.min(notification.id, state.notifications.minId)
-
- const fresh = !notification.is_seen
- const status = notification.ntype === 'like'
- ? action.favorited_status
- : action
-
- const result = {
- type: notification.ntype,
- status,
- action,
- seen: !fresh
- }
+ if (!state.notifications.idStore.hasOwnProperty(notification.id)) {
+ state.notifications.maxId = notification.id > state.notifications.maxId
+ ? notification.id
+ : state.notifications.maxId
+ state.notifications.minId = notification.id < state.notifications.minId
+ ? notification.id
+ : state.notifications.minId
- state.notifications.data.push(result)
- state.notifications.idStore[notification.id] = result
+ state.notifications.data.push(notification)
+ state.notifications.idStore[notification.id] = notification
if ('Notification' in window && window.Notification.permission === 'granted') {
+ const notifObj = {}
+ const action = notification.action
const title = action.user.name
- const result = {}
- result.icon = action.user.profile_image_url
- result.body = action.text // there's a problem that it doesn't put a space before links tho
+ notifObj.icon = action.user.profile_image_url
+ notifObj.body = action.text // there's a problem that it doesn't put a space before links tho
// Shows first attached non-nsfw image, if any. Should add configuration for this somehow...
if (action.attachments && action.attachments.length > 0 && !action.nsfw &&
action.attachments[0].mimetype.startsWith('image/')) {
- result.image = action.attachments[0].url
+ notifObj.image = action.attachments[0].url
}
- if (fresh && !state.notifications.desktopNotificationSilence && visibleNotificationTypes.includes(notification.ntype)) {
- let notification = new window.Notification(title, result)
+ if (notification.fresh && !state.notifications.desktopNotificationSilence && visibleNotificationTypes.includes(notification.ntype)) {
+ let notification = new window.Notification(title, notifObj)
// Chrome is known for not closing notifications automatically
// according to MDN, anyway.
setTimeout(notification.close.bind(notification), 5000)
@@ -346,7 +304,7 @@ export const mutations = {
each(oldTimeline.visibleStatuses, (status) => { oldTimeline.visibleStatusesObject[status.id] = status })
},
clearTimeline (state, { timeline }) {
- state.timelines[timeline] = emptyTl(state.timelines[timeline].userId)
+ state.timelines[timeline] = emptyTl()
},
setFavorited (state, { status, value }) {
const newStatus = state.allStatusesObject[status.id]
diff --git a/src/modules/users.js b/src/modules/users.js
index adbd37dd..d83f0dd8 100644
--- a/src/modules/users.js
+++ b/src/modules/users.js
@@ -68,6 +68,7 @@ export const mutations = {
},
setUserForNotification (state, notification) {
notification.action.user = state.usersObject[notification.action.user.id]
+ notification.from_profile = state.usersObject[notification.action.user.id]
},
setColor (state, { user: { id }, highlighted }) {
const user = state.usersObject[id]
@@ -149,8 +150,8 @@ const users = {
})
},
addNewNotifications (store, { notifications }) {
- const users = compact(map(notifications, 'from_profile'))
- const notificationIds = compact(notifications.map(_ => String(_.id)))
+ const users = map(notifications, 'from_profile')
+ const notificationIds = notifications.map(_ => _.id)
store.commit('addNewUsers', users)
const notificationsObject = store.rootState.statuses.notifications.idStore
@@ -206,39 +207,38 @@ const users = {
const commit = store.commit
commit('beginLogin')
store.rootState.api.backendInteractor.verifyCredentials(accessToken)
- .then((response) => {
- if (response.ok) {
- response.json()
- .then((user) => {
- // user.credentials = userCredentials
- user.credentials = accessToken
- commit('setCurrentUser', user)
- commit('addNewUsers', [user])
+ .then((data) => {
+ if (!data.error) {
+ const user = data
+ // user.credentials = userCredentials
+ user.credentials = accessToken
+ commit('setCurrentUser', user)
+ commit('addNewUsers', [user])
- getNotificationPermission()
- .then(permission => commit('setNotificationPermission', permission))
+ getNotificationPermission()
+ .then(permission => commit('setNotificationPermission', permission))
- // Set our new backend interactor
- commit('setBackendInteractor', backendInteractorService(accessToken))
+ // Set our new backend interactor
+ commit('setBackendInteractor', backendInteractorService(accessToken))
- if (user.token) {
- store.dispatch('initializeSocket', user.token)
- }
+ if (user.token) {
+ store.dispatch('initializeSocket', user.token)
+ }
- // Start getting fresh tweets.
- store.dispatch('startFetching', 'friends')
+ // Start getting fresh tweets.
+ store.dispatch('startFetching', 'friends')
- // Get user mutes and follower info
- store.rootState.api.backendInteractor.fetchMutes().then((mutedUsers) => {
- each(mutedUsers, (user) => { user.muted = true })
- store.commit('addNewUsers', mutedUsers)
- })
+ // Get user mutes and follower info
+ store.rootState.api.backendInteractor.fetchMutes().then((mutedUsers) => {
+ each(mutedUsers, (user) => { user.muted = true })
+ store.commit('addNewUsers', mutedUsers)
+ })
- // Fetch our friends
- store.rootState.api.backendInteractor.fetchFriends({ id: user.id })
- .then((friends) => commit('addNewUsers', friends))
- })
+ // Fetch our friends
+ store.rootState.api.backendInteractor.fetchFriends({ id: user.id })
+ .then((friends) => commit('addNewUsers', friends))
} else {
+ const response = data.error
// Authentication failed
commit('endLogin')
if (response.status === 401) {
@@ -250,11 +250,11 @@ const users = {
commit('endLogin')
resolve()
})
- .catch((error) => {
- console.log(error)
- commit('endLogin')
- reject('Failed to connect to server, try again')
- })
+ .catch((error) => {
+ console.log(error)
+ commit('endLogin')
+ reject('Failed to connect to server, try again')
+ })
})
}
}
diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js
index 4ee95bd1..2b1ef5df 100644
--- a/src/services/api/api.service.js
+++ b/src/services/api/api.service.js
@@ -41,7 +41,10 @@ const APPROVE_USER_URL = '/api/pleroma/friendships/approve'
const DENY_USER_URL = '/api/pleroma/friendships/deny'
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 '../entity_normalizer/entity_normalizer.service.js'
import 'whatwg-fetch'
const oldfetch = window.fetch
@@ -70,6 +73,7 @@ const updateAvatar = ({credentials, params}) => {
form.append(key, value)
}
})
+
return fetch(url, {
headers: authHeaders(credentials),
method: 'POST',
@@ -87,6 +91,7 @@ const updateBg = ({credentials, params}) => {
form.append(key, value)
}
})
+
return fetch(url, {
headers: authHeaders(credentials),
method: 'POST',
@@ -110,6 +115,7 @@ const updateBanner = ({credentials, params}) => {
form.append(key, value)
}
})
+
return fetch(url, {
headers: authHeaders(credentials),
method: 'POST',
@@ -237,24 +243,28 @@ const fetchUser = ({id, credentials}) => {
let url = `${USER_URL}?user_id=${id}`
return fetch(url, { headers: authHeaders(credentials) })
.then((data) => data.json())
+ .then((data) => parseUser(data))
}
const fetchFriends = ({id, credentials}) => {
let url = `${FRIENDS_URL}?user_id=${id}`
return fetch(url, { headers: authHeaders(credentials) })
.then((data) => data.json())
+ .then((data) => data.map(parseUser))
}
const fetchFollowers = ({id, credentials}) => {
let url = `${FOLLOWERS_URL}?user_id=${id}`
return fetch(url, { headers: authHeaders(credentials) })
.then((data) => data.json())
+ .then((data) => data.map(parseUser))
}
const fetchAllFollowing = ({username, credentials}) => {
const url = `${ALL_FOLLOWING_URL}/${username}.json`
return fetch(url, { headers: authHeaders(credentials) })
.then((data) => data.json())
+ .then((data) => data.map(parseUser))
}
const fetchFollowRequests = ({credentials}) => {
@@ -266,13 +276,27 @@ const fetchFollowRequests = ({credentials}) => {
const fetchConversation = ({id, credentials}) => {
let url = `${CONVERSATION_URL}/${id}.json?count=100`
return fetch(url, { headers: authHeaders(credentials) })
+ .then((data) => {
+ if (data.ok) {
+ return data
+ }
+ throw new Error('Error fetching timeline', data)
+ })
.then((data) => data.json())
+ .then((data) => data.map(parseStatus))
}
const fetchStatus = ({id, credentials}) => {
let url = `${STATUS_URL}/${id}.json`
return fetch(url, { headers: authHeaders(credentials) })
+ .then((data) => {
+ if (data.ok) {
+ return data
+ }
+ throw new Error('Error fetching timeline', data)
+ })
.then((data) => data.json())
+ .then((data) => parseStatus(data))
}
const setUserMute = ({id, credentials, muted = true}) => {
@@ -300,13 +324,14 @@ const fetchTimeline = ({timeline, credentials, since = false, until = false, use
notifications: QVITTER_USER_NOTIFICATIONS_URL,
'publicAndExternal': PUBLIC_AND_EXTERNAL_TIMELINE_URL,
user: QVITTER_USER_TIMELINE_URL,
+ favorites: MASTODON_USER_FAVORITES_TIMELINE_URL,
tag: TAG_TIMELINE_URL
}
+ const isNotifications = timeline === 'notifications'
+ const params = []
let url = timelineUrls[timeline]
- let params = []
-
if (since) {
params.push(['since_id', since])
}
@@ -330,9 +355,10 @@ const fetchTimeline = ({timeline, credentials, since = false, until = false, use
if (data.ok) {
return data
}
- throw new Error('Error fetching timeline')
+ throw new Error('Error fetching timeline', data)
})
.then((data) => data.json())
+ .then((data) => data.map(isNotifications ? parseNotification : parseStatus))
}
const verifyCredentials = (user) => {
@@ -340,6 +366,16 @@ const verifyCredentials = (user) => {
method: 'POST',
headers: authHeaders(user)
})
+ .then((response) => {
+ if (response.ok) {
+ return response.json()
+ } else {
+ return {
+ error: response
+ }
+ }
+ })
+ .then((data) => data.error ? data : parseUser(data))
}
const favorite = ({ id, credentials }) => {
@@ -391,6 +427,16 @@ const postStatus = ({credentials, status, spoilerText, visibility, sensitive, me
method: 'POST',
headers: authHeaders(credentials)
})
+ .then((response) => {
+ if (response.ok) {
+ return response.json()
+ } else {
+ return {
+ error: response
+ }
+ }
+ })
+ .then((data) => data.error ? data : parseStatus(data))
}
const deleteStatus = ({ id, credentials }) => {
diff --git a/src/services/entity_normalizer/entity_normalizer.service.js b/src/services/entity_normalizer/entity_normalizer.service.js
new file mode 100644
index 00000000..6fc6d152
--- /dev/null
+++ b/src/services/entity_normalizer/entity_normalizer.service.js
@@ -0,0 +1,263 @@
+const qvitterStatusType = (status) => {
+ if (status.is_post_verb) {
+ return 'status'
+ }
+
+ if (status.retweeted_status) {
+ return 'retweet'
+ }
+
+ if ((typeof status.uri === 'string' && status.uri.match(/(fave|objectType=Favourite)/)) ||
+ (typeof status.text === 'string' && status.text.match(/favorited/))) {
+ return 'favorite'
+ }
+
+ if (status.text.match(/deleted notice {{tag/) || status.qvitter_delete_notice) {
+ return 'deletion'
+ }
+
+ if (status.text.match(/started following/) || status.activity_type === 'follow') {
+ return 'follow'
+ }
+
+ return 'unknown'
+}
+
+export const parseUser = (data) => {
+ const output = {}
+ const masto = data.hasOwnProperty('acct')
+ // case for users in "mentions" property for statuses in MastoAPI
+ const mastoShort = masto && !data.hasOwnProperty('avatar')
+
+ output.id = String(data.id)
+
+ if (masto) {
+ output.screen_name = data.acct
+
+ // There's nothing else to get
+ if (mastoShort) {
+ return output
+ }
+
+ output.name = null // missing
+ output.name_html = data.display_name
+
+ output.description = null // missing
+ output.description_html = data.note
+
+ // Utilize avatar_static for gif avatars?
+ output.profile_image_url = data.avatar
+ output.profile_image_url_original = data.avatar
+
+ // Same, utilize header_static?
+ output.cover_photo = data.header
+
+ output.friends_count = data.following_count
+
+ output.bot = data.bot
+
+ output.statusnet_profile_url = data.url
+
+ if (data.pleroma) {
+ const pleroma = data.pleroma
+ output.follows_you = pleroma.follows_you
+ output.statusnet_blocking = pleroma.statusnet_blocking
+ output.muted = pleroma.muted
+ }
+
+ // Missing, trying to recover
+ output.is_local = !output.screen_name.includes('@')
+ } else {
+ output.screen_name = data.screen_name
+
+ output.name = data.name
+ output.name_html = data.name_html
+
+ output.description = data.description
+ output.description_html = data.description_html
+
+ output.profile_image_url = data.profile_image_url
+ output.profile_image_url_original = data.profile_image_url_original
+
+ output.cover_photo = data.cover_photo
+
+ output.friends_count = data.friends_count
+
+ output.bot = null // missing
+
+ output.statusnet_profile_url = data.statusnet_profile_url
+
+ output.statusnet_blocking = data.statusnet_blocking
+
+ output.is_local = data.is_local
+
+ output.follows_you = data.follows_you
+
+ output.muted = data.muted
+
+ // QVITTER ONLY FOR NOW
+ // Really only applies to logged in user, really.. I THINK
+ output.rights = data.rights
+ output.no_rich_text = data.no_rich_text
+ output.default_scope = data.default_scope
+ output.hide_network = data.hide_network
+ output.background_image = data.background_image
+ }
+
+ output.created_at = new Date(data.created_at)
+ output.locked = data.locked
+ output.followers_count = data.followers_count
+ output.statuses_count = data.statuses_count
+
+ return output
+}
+
+const parseAttachment = (data) => {
+ const output = {}
+ const masto = !data.hasOwnProperty('oembed')
+
+ if (masto) {
+ // Not exactly same...
+ output.mimetype = data.type
+ output.meta = data.meta // not present in BE yet
+ } else {
+ output.mimetype = data.mimetype
+ output.meta = null // missing
+ }
+
+ output.url = data.url
+ output.description = data.description
+
+ return output
+}
+
+export const parseStatus = (data) => {
+ const output = {}
+ const masto = data.hasOwnProperty('account')
+
+ if (masto) {
+ output.favorited = data.favourited
+ output.fave_num = data.favourites_count
+
+ output.repeated = data.reblogged
+ output.repeat_num = data.reblogs_count
+
+ output.type = data.reblog ? 'retweet' : 'status'
+ output.nsfw = data.sensitive
+
+ output.statusnet_html = data.content
+
+ // Not exactly the same but works?
+ output.text = data.content
+
+ output.in_reply_to_status_id = data.in_reply_to_id
+ output.in_reply_to_user_id = data.in_reply_to_account_id
+
+ // Missing!! fix in UI?
+ output.in_reply_to_screen_name = null
+
+ // Not exactly the same but works
+ output.statusnet_conversation_id = data.id
+
+ if (output.type === 'retweet') {
+ output.retweeted_status = parseStatus(data.reblog)
+ }
+
+ output.summary = data.spoiler_text
+ output.external_url = data.url
+
+ // FIXME missing!!
+ output.is_local = false
+ } else {
+ output.favorited = data.favorited
+ output.fave_num = data.fave_num
+
+ output.repeated = data.repeated
+ output.repeat_num = data.repeat_num
+
+ // catchall, temporary
+ // Object.assign(output, data)
+
+ output.type = qvitterStatusType(data)
+
+ if (data.nsfw === undefined) {
+ output.nsfw = isNsfw(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
+
+ output.in_reply_to_status_id = data.in_reply_to_status_id
+ output.in_reply_to_user_id = data.in_reply_to_user_id
+ output.in_reply_to_screen_name = data.in_reply_to_screen_name
+
+ output.statusnet_conversation_id = data.statusnet_conversation_id
+
+ if (output.type === 'retweet') {
+ output.retweeted_status = parseStatus(data.retweeted_status)
+ }
+
+ output.summary = data.summary
+ output.external_url = data.external_url
+ output.is_local = data.is_local
+ }
+
+ output.id = String(data.id)
+ output.visibility = data.visibility
+ output.created_at = new Date(data.created_at)
+
+ output.user = parseUser(masto ? data.account : data.user)
+
+ output.attentions = ((masto ? data.mentions : data.attentions) || []).map(parseUser)
+
+ output.attachments = ((masto ? data.media_attachments : data.attachments) || [])
+ .map(parseAttachment)
+
+ const retweetedStatus = masto ? data.reblog : data.retweeted_status
+ if (retweetedStatus) {
+ output.retweeted_status = parseStatus(retweetedStatus)
+ }
+
+ return output
+}
+
+export const parseNotification = (data) => {
+ const mastoDict = {
+ 'favourite': 'like',
+ 'reblog': 'repeat'
+ }
+ const masto = !data.hasOwnProperty('ntype')
+ const output = {}
+
+ if (masto) {
+ output.type = mastoDict[data.type] || data.type
+ output.seen = null // missing
+ output.status = parseStatus(data.status)
+ output.action = output.status // not sure
+ output.from_profile = parseUser(data.account)
+ } else {
+ const parsedNotice = parseStatus(data.notice)
+ output.type = data.ntype
+ output.seen = Boolean(data.is_seen)
+ output.status = output.type === 'like'
+ ? parseStatus(data.notice.favorited_status)
+ : parsedNotice
+ output.action = parsedNotice
+ output.from_profile = parseUser(data.from_profile)
+ }
+
+ output.created_at = new Date(data.created_at)
+ output.id = String(data.id)
+
+ return output
+}
+
+const isNsfw = (status) => {
+ const nsfwRegex = /#nsfw/i
+ return (status.tags || []).includes('nsfw') || !!status.text.match(nsfwRegex)
+}
diff --git a/src/services/notification_utils/notification_utils.js b/src/services/notification_utils/notification_utils.js
index f5ac0d47..c3879677 100644
--- a/src/services/notification_utils/notification_utils.js
+++ b/src/services/notification_utils/notification_utils.js
@@ -10,8 +10,8 @@ export const visibleTypes = store => ([
].filter(_ => _))
export const visibleNotificationsFromStore = store => {
- // Don't know why, but sortBy([seen, -action.id]) doesn't work.
- let sortedNotifications = sortBy(notificationsFromStore(store), ({action}) => -action.id)
+ // map is just to clone the array since sort mutates it and it causes some issues
+ let sortedNotifications = notificationsFromStore(store).map(_ => _).sort((a, b) => a.action.id > b.action.id ? -1 : 1)
sortedNotifications = sortBy(sortedNotifications, 'seen')
return sortedNotifications.filter((notification) => visibleTypes(store).includes(notification.type))
}
diff --git a/src/services/status_poster/status_poster.service.js b/src/services/status_poster/status_poster.service.js
index 1e20d336..f1932bb6 100644
--- a/src/services/status_poster/status_poster.service.js
+++ b/src/services/status_poster/status_poster.service.js
@@ -5,7 +5,6 @@ const postStatus = ({ store, status, spoilerText, visibility, sensitive, media =
const mediaIds = map(media, 'id')
return apiService.postStatus({credentials: store.state.users.currentUser.credentials, status, spoilerText, visibility, sensitive, mediaIds, inReplyToStatusId, contentType, noAttachmentLinks: store.state.instance.noAttachmentLinks})
- .then((data) => data.json())
.then((data) => {
if (!data.error) {
store.dispatch('addNewStatuses', {