diff options
10 files changed, 178 insertions, 61 deletions
diff --git a/src/components/notification/notification.vue b/src/components/notification/notification.vue index 5e9cef97..7d88c90b 100644 --- a/src/components/notification/notification.vue +++ b/src/components/notification/notification.vue @@ -1,15 +1,20 @@ <template> - <status v-if="notification.type === 'mention'" :compact="true" :statusoid="notification.status"></status> + <status + v-if="notification.type === 'mention'" + :compact="true" + :statusoid="notification.status" + > + </status> <div class="non-mention" :class="[userClass, { highlighted: userStyle }]" :style="[ userStyle ]"v-else> - <a class='avatar-container' :href="notification.action.user.statusnet_profile_url" @click.stop.prevent.capture="toggleUserExpanded"> - <UserAvatar :compact="true" :betterShadow="betterShadow" :src="notification.action.user.profile_image_url_original"/> + <a class='avatar-container' :href="notification.action.account.statusnet_profile_url" @click.stop.prevent.capture="toggleUserExpanded"> + <UserAvatar :compact="true" :betterShadow="betterShadow" :src="notification.action.account.profile_image_url_original"/> </a> <div class='notification-right'> - <UserCard :user="notification.action.user" :rounded="true" :bordered="true" v-if="userExpanded"/> + <UserCard :user="notification.action.account" :rounded="true" :bordered="true" v-if="userExpanded"/> <span class="notification-details"> <div class="name-and-action"> - <span class="username" v-if="!!notification.action.user.name_html" :title="'@'+notification.action.user.screen_name" v-html="notification.action.user.name_html"></span> - <span class="username" v-else :title="'@'+notification.action.user.screen_name">{{ notification.action.user.name }}</span> + <span class="username" v-if="!!notification.action.account.name_html" :title="'@'+notification.action.account.screen_name" v-html="notification.action.account.name_html"></span> + <span class="username" v-else :title="'@'+notification.action.account.screen_name">{{ notification.action.account.name }}</span> <span v-if="notification.type === 'like'"> <i class="fa icon-star lit"></i> <small>{{$t('notifications.favorited_you')}}</small> @@ -23,15 +28,20 @@ <small>{{$t('notifications.followed_you')}}</small> </span> </div> - <div class="timeago"> + <div class="timeago" v-if="notification.type === 'follow'"> + <span class="faint"> + <timeago :since="notification.action.notified_at" :auto-update="240"></timeago> + </span> + </div> + <div class="timeago" v-else> <router-link v-if="notification.status" :to="{ name: 'conversation', params: { id: notification.status.id } }" class="faint-link"> - <timeago :since="notification.action.created_at" :auto-update="240"></timeago> + <timeago :since="notification.action.notified_at" :auto-update="240"></timeago> </router-link> </div> </span> <div class="follow-text" v-if="notification.type === 'follow'"> <router-link :to="userProfileLink(notification.action.user)"> - @{{notification.action.user.screen_name}} + @{{notification.action.account.screen_name}} </router-link> </div> <template v-else> diff --git a/src/components/notifications/notifications.js b/src/components/notifications/notifications.js index 9fc5e38a..e1c53c58 100644 --- a/src/components/notifications/notifications.js +++ b/src/components/notifications/notifications.js @@ -53,7 +53,7 @@ const Notifications = { }, methods: { markAsSeen () { - this.$store.dispatch('markNotificationsAsSeen', this.visibleNotifications) + this.$store.dispatch('markNotificationsAsSeen') }, fetchOlderNotifications () { const store = this.$store diff --git a/src/components/notifications/notifications.vue b/src/components/notifications/notifications.vue index 6f162b62..37104b90 100644 --- a/src/components/notifications/notifications.vue +++ b/src/components/notifications/notifications.vue @@ -12,7 +12,7 @@ <button v-if="unseenCount" @click.prevent="markAsSeen" class="read-button">{{$t('notifications.read')}}</button> </div> <div class="panel-body"> - <div v-for="notification in visibleNotifications" :key="notification.action.id" class="notification" :class='{"unseen": !notification.seen}'> + <div v-for="notification in visibleNotifications" :key="notification.id" class="notification" :class='{"unseen": !notification.seen}'> <div class="notification-overlay"></div> <notification :notification="notification"></notification> </div> diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 3a4f21a6..2f54d508 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -22,7 +22,6 @@ const BG_UPDATE_URL = '/api/qvitter/update_background_image.json' const BANNER_UPDATE_URL = '/api/account/update_profile_banner.json' const PROFILE_UPDATE_URL = '/api/account/update_profile.json' const EXTERNAL_PROFILE_URL = '/api/externalprofile/show.json' -const QVITTER_USER_NOTIFICATIONS_URL = '/api/qvitter/statuses/notifications.json' const QVITTER_USER_NOTIFICATIONS_READ_URL = '/api/qvitter/statuses/notifications/read.json' const FOLLOW_IMPORT_URL = '/api/pleroma/follow_import' const DELETE_ACCOUNT_URL = '/api/pleroma/delete_account' @@ -33,6 +32,7 @@ const DENY_USER_URL = '/api/pleroma/friendships/deny' const SUGGESTIONS_URL = '/api/v1/suggestions' const MASTODON_USER_FAVORITES_TIMELINE_URL = '/api/v1/favourites' +const MASTODON_USER_NOTIFICATIONS_URL = '/api/v1/notifications' const MASTODON_STATUS_URL = id => `/api/v1/statuses/${id}` const MASTODON_STATUS_CONTEXT_URL = id => `/api/v1/statuses/${id}/context` const MASTODON_USER_URL = '/api/v1/accounts' @@ -351,7 +351,7 @@ const fetchTimeline = ({timeline, credentials, since = false, until = false, use friends: FRIENDS_TIMELINE_URL, mentions: MENTIONS_URL, dms: DM_TIMELINE_URL, - notifications: QVITTER_USER_NOTIFICATIONS_URL, + notifications: MASTODON_USER_NOTIFICATIONS_URL, 'publicAndExternal': PUBLIC_AND_EXTERNAL_TIMELINE_URL, user: MASTODON_USER_TIMELINE_URL, media: MASTODON_USER_TIMELINE_URL, diff --git a/src/services/entity_normalizer/entity_normalizer.service.js b/src/services/entity_normalizer/entity_normalizer.service.js index 5cac3463..249e99b4 100644 --- a/src/services/entity_normalizer/entity_normalizer.service.js +++ b/src/services/entity_normalizer/entity_normalizer.service.js @@ -69,7 +69,7 @@ export const parseUser = (data) => { } } - // Missing, trying to recover + // TODO: handle is_local output.is_local = !output.screen_name.includes('@') } else { output.screen_name = data.screen_name @@ -181,8 +181,8 @@ export const parseStatus = (data) => { // Missing!! fix in UI? // output.in_reply_to_screen_name = ??? - // Not exactly the same but works - output.statusnet_conversation_id = data.id + // It breaks the conversation when combined with notification + // output.statusnet_conversation_id = data.id if (output.type === 'retweet') { output.retweeted_status = parseStatus(data.reblog) @@ -191,8 +191,7 @@ export const parseStatus = (data) => { output.summary = data.spoiler_text output.summary_html = addEmojis(data.spoiler_text, data.emojis) output.external_url = data.url - - // output.is_local = ??? missing + output.is_local = data.pleroma.local } else { output.favorited = data.favorited output.fave_num = data.fave_num @@ -220,7 +219,6 @@ export const parseStatus = (data) => { 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') { @@ -261,6 +259,19 @@ export const parseStatus = (data) => { return output } +// This is for masto API only. +export const parseFollow = (data) => { + const output = {} + output.id = String(data.id) + output.visibility = true + output.created_at = new Date(data.created_at) + output.user = parseUser(data.account) + output.notified_at = output.created_at + output.account = output.user + + return output +} + export const parseNotification = (data) => { const mastoDict = { 'favourite': 'like', @@ -271,8 +282,15 @@ export const parseNotification = (data) => { if (masto) { output.type = mastoDict[data.type] || data.type - // output.seen = ??? missing - output.status = parseStatus(data.status) + output.seen = data.pleroma.is_seen + output.status = output.type === 'follow' + ? parseFollow(data) + : parseStatus(data.status) + if (data.type === 'reblog' || data.type === 'favourite') { + output.status.user = parseUser(data.account) + output.status.account = parseUser(data.account) + output.status.notified_at = new Date(data.created_at) + } output.action = output.status // not sure output.from_profile = parseUser(data.account) } else { diff --git a/src/services/notification_utils/notification_utils.js b/src/services/notification_utils/notification_utils.js index cd8f3f9e..8afd114e 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(_ => _)) const sortById = (a, b) => { - const seqA = Number(a.action.id) - const seqB = Number(b.action.id) + const seqA = Number(a.id) + const seqB = Number(b.id) const isSeqA = !Number.isNaN(seqA) const isSeqB = !Number.isNaN(seqB) if (isSeqA && isSeqB) { @@ -21,7 +21,7 @@ const sortById = (a, b) => { } else if (!isSeqA && isSeqB) { return -1 } else { - return a.action.id > b.action.id ? -1 : 1 + return a.id > b.id ? -1 : 1 } } diff --git a/src/services/notifications_fetcher/notifications_fetcher.service.js b/src/services/notifications_fetcher/notifications_fetcher.service.js index 3ecdae6a..60c497ae 100644 --- a/src/services/notifications_fetcher/notifications_fetcher.service.js +++ b/src/services/notifications_fetcher/notifications_fetcher.service.js @@ -11,29 +11,35 @@ const fetchAndUpdate = ({store, credentials, older = false}) => { const rootState = store.rootState || store.state const timelineData = rootState.statuses.notifications + args['timeline'] = 'notifications' if (older) { if (timelineData.minId !== Number.POSITIVE_INFINITY) { args['until'] = timelineData.minId } + return fetchNotifications({ store, args, older }) } else { - // load unread notifications repeadedly to provide consistency between browser tabs + // fetch new notifications + if (timelineData.maxId !== Number.POSITIVE_INFINITY) { + args['since'] = timelineData.maxId + } + const result = fetchNotifications({ store, args, older }) + + // load unread notifications repeatedly to provide consistency between browser tabs const notifications = timelineData.data const unread = notifications.filter(n => !n.seen).map(n => n.id) - if (!unread.length) { - args['since'] = timelineData.maxId - } else { - args['since'] = Math.min(...unread) - 1 - if (timelineData.maxId !== Math.max(...unread)) { - args['until'] = Math.max(...unread, args['since'] + 20) - } + if (unread.length) { + args['since'] = Math.min(...unread) + fetchNotifications({ store, args, older }) } - } - args['timeline'] = 'notifications' + return result + } +} +const fetchNotifications = ({ store, args, older }) => { return apiService.fetchTimeline(args) .then((notifications) => { - update({store, notifications, older}) + update({ store, notifications, older }) return notifications }, () => store.dispatch('setNotificationsError', { value: true })) .catch(() => store.dispatch('setNotificationsError', { value: true })) diff --git a/test/fixtures/mastoapi.json b/test/fixtures/mastoapi.json index 858d7a0d..887fb83e 100644 --- a/test/fixtures/mastoapi.json +++ b/test/fixtures/mastoapi.json @@ -58,7 +58,10 @@ "tags": [], "uri": "https://shigusegubu.club/objects/16033fbb-97c0-4f0e-b834-7abb92fb8639", "url": "https://shigusegubu.club/objects/16033fbb-97c0-4f0e-b834-7abb92fb8639", - "visibility": "public" + "visibility": "public", + "pleroma": { + "local": true + } }, { "account": { "acct": "hj", @@ -127,7 +130,10 @@ "tags": [], "uri": "https://shigusegubu.club/objects/6634d32b-96a8-4852-a3db-ac8730715779", "url": "https://shigusegubu.club/objects/6634d32b-96a8-4852-a3db-ac8730715779", - "visibility": "public" + "visibility": "public", + "pleroma": { + "local": true + } }, { "account": { "acct": "hj", @@ -250,7 +256,10 @@ "tags": [], "uri": "https://pleroma.soykaf.com/objects/bf7e43d4-5048-4176-8519-58e3e1014f8b", "url": "https://pleroma.soykaf.com/objects/bf7e43d4-5048-4176-8519-58e3e1014f8b", - "visibility": "public" + "visibility": "public", + "pleroma": { + "local": true + } }, "reblogged": false, "reblogs_count": 0, @@ -260,7 +269,10 @@ "tags": [], "uri": "https://pleroma.soykaf.com/objects/bf7e43d4-5048-4176-8519-58e3e1014f8b", "url": "https://pleroma.soykaf.com/objects/bf7e43d4-5048-4176-8519-58e3e1014f8b", - "visibility": "public" + "visibility": "public", + "pleroma": { + "local": true + } }, { "account": { "acct": "hj", @@ -329,7 +341,10 @@ "tags": [], "uri": "https://shigusegubu.club/objects/0f963ca1-a263-41ca-a43c-b5d26d0a08e9", "url": "https://shigusegubu.club/objects/0f963ca1-a263-41ca-a43c-b5d26d0a08e9", - "visibility": "public" + "visibility": "public", + "pleroma": { + "local": true + } }, { "account": { "acct": "hj", @@ -390,7 +405,10 @@ "tags": [], "uri": "https://shigusegubu.club/objects/3f809bd8-656f-4a29-81d4-80eed6916eb0", "url": "https://shigusegubu.club/objects/3f809bd8-656f-4a29-81d4-80eed6916eb0", - "visibility": "public" + "visibility": "public", + "pleroma": { + "local": true + } }, { "account": { "acct": "hj", @@ -516,7 +534,10 @@ }], "uri": "tag:social.super-niche.club,2019-01-17:noticeId=2353002:objectType=note", "url": "https://social.super-niche.club/notice/2353002", - "visibility": "public" + "visibility": "public", + "pleroma": { + "local": true + } }, "reblogged": false, "reblogs_count": 0, @@ -529,7 +550,10 @@ }], "uri": "tag:social.super-niche.club,2019-01-17:noticeId=2353002:objectType=note", "url": "tag:social.super-niche.club,2019-01-17:noticeId=2353002:objectType=note", - "visibility": "public" + "visibility": "public", + "pleroma": { + "local": true + } }, { "account": { "acct": "hj", @@ -657,7 +681,10 @@ "tags": [], "uri": "https://miniwa.moe/objects/448e2944-0ecd-457f-92c3-cb454f2b0fab", "url": "https://miniwa.moe/objects/448e2944-0ecd-457f-92c3-cb454f2b0fab", - "visibility": "public" + "visibility": "public", + "pleroma": { + "local": true + } }, "reblogged": false, "reblogs_count": 0, @@ -667,7 +694,10 @@ "tags": [], "uri": "https://miniwa.moe/objects/448e2944-0ecd-457f-92c3-cb454f2b0fab", "url": "https://miniwa.moe/objects/448e2944-0ecd-457f-92c3-cb454f2b0fab", - "visibility": "public" + "visibility": "public", + "pleroma": { + "local": true + } }, { "account": { "acct": "hj", @@ -733,7 +763,10 @@ "tags": [], "uri": "https://shigusegubu.club/objects/38b1bc44-15d8-40dd-b1aa-937e0ff4a86d", "url": "https://shigusegubu.club/objects/38b1bc44-15d8-40dd-b1aa-937e0ff4a86d", - "visibility": "public" + "visibility": "public", + "pleroma": { + "local": true + } }, { "account": { "acct": "hj", @@ -794,7 +827,10 @@ "tags": [], "uri": "https://shigusegubu.club/objects/fbff5da4-a517-42a9-bca9-17cae8cf2542", "url": "https://shigusegubu.club/objects/fbff5da4-a517-42a9-bca9-17cae8cf2542", - "visibility": "public" + "visibility": "public", + "pleroma": { + "local": true + } }, { "account": { "acct": "hj", @@ -850,7 +886,10 @@ "tags": [], "uri": "https://shigusegubu.club/objects/4007d659-27c6-4577-be10-fd134f5e4e7e", "url": "https://shigusegubu.club/objects/4007d659-27c6-4577-be10-fd134f5e4e7e", - "visibility": "public" + "visibility": "public", + "pleroma": { + "local": true + } }, { "account": { "acct": "hj", @@ -906,7 +945,10 @@ "tags": [], "uri": "https://shigusegubu.club/objects/59912d51-1cc6-4dc7-828c-f167e6c8b391", "url": "https://shigusegubu.club/objects/59912d51-1cc6-4dc7-828c-f167e6c8b391", - "visibility": "public" + "visibility": "public", + "pleroma": { + "local": true + } }, { "account": { "acct": "hj", @@ -962,7 +1004,10 @@ "tags": [], "uri": "https://shigusegubu.club/objects/62690bce-3f49-4047-9c8e-8941f2f79e10", "url": "https://shigusegubu.club/objects/62690bce-3f49-4047-9c8e-8941f2f79e10", - "visibility": "public" + "visibility": "public", + "pleroma": { + "local": true + } }, { "account": { "acct": "hj", @@ -1023,7 +1068,10 @@ "tags": [], "uri": "https://shigusegubu.club/objects/818f3dd0-2ff8-4def-a170-e4d4c405f387", "url": "https://shigusegubu.club/objects/818f3dd0-2ff8-4def-a170-e4d4c405f387", - "visibility": "public" + "visibility": "public", + "pleroma": { + "local": true + } }, { "account": { "acct": "hj", @@ -1084,7 +1132,10 @@ "tags": [], "uri": "https://shigusegubu.club/objects/0783a193-c097-488d-8944-47df9372cd6e", "url": "https://shigusegubu.club/objects/0783a193-c097-488d-8944-47df9372cd6e", - "visibility": "public" + "visibility": "public", + "pleroma": { + "local": true + } }, { "account": { "acct": "hj", @@ -1145,7 +1196,10 @@ "tags": [], "uri": "https://shigusegubu.club/objects/145d5252-7b8e-467d-9f36-1db0818f452f", "url": "https://shigusegubu.club/objects/145d5252-7b8e-467d-9f36-1db0818f452f", - "visibility": "public" + "visibility": "public", + "pleroma": { + "local": true + } }, { "account": { "acct": "hj", @@ -1252,7 +1306,10 @@ "tags": [], "uri": "https://pleroma.site/objects/3076c055-0e34-4cf9-86ca-2d148b9b694a", "url": "https://pleroma.site/objects/3076c055-0e34-4cf9-86ca-2d148b9b694a", - "visibility": "public" + "visibility": "public", + "pleroma": { + "local": true + } }, "reblogged": false, "reblogs_count": 0, @@ -1262,7 +1319,10 @@ "tags": [], "uri": "https://pleroma.site/objects/3076c055-0e34-4cf9-86ca-2d148b9b694a", "url": "https://pleroma.site/objects/3076c055-0e34-4cf9-86ca-2d148b9b694a", - "visibility": "public" + "visibility": "public", + "pleroma": { + "local": true + } }, { "account": { "acct": "hj", @@ -1323,7 +1383,10 @@ "tags": [], "uri": "https://shigusegubu.club/objects/d4eb7c46-02f9-4b1f-83af-926cefa21f33", "url": "https://shigusegubu.club/objects/d4eb7c46-02f9-4b1f-83af-926cefa21f33", - "visibility": "public" + "visibility": "public", + "pleroma": { + "local": true + } }, { "account": { "acct": "hj", @@ -1446,7 +1509,10 @@ "tags": [], "uri": "https://pleroma.soykaf.com/objects/338b6bd2-3c2d-40fe-93a3-28b688782733", "url": "https://pleroma.soykaf.com/objects/338b6bd2-3c2d-40fe-93a3-28b688782733", - "visibility": "public" + "visibility": "public", + "pleroma": { + "local": true + } }, "reblogged": false, "reblogs_count": 0, @@ -1456,7 +1522,10 @@ "tags": [], "uri": "https://pleroma.soykaf.com/objects/338b6bd2-3c2d-40fe-93a3-28b688782733", "url": "https://pleroma.soykaf.com/objects/338b6bd2-3c2d-40fe-93a3-28b688782733", - "visibility": "public" + "visibility": "public", + "pleroma": { + "local": true + } }, { "account": { "acct": "hj", @@ -1517,7 +1586,10 @@ "tags": [], "uri": "https://shigusegubu.club/objects/f472f4ed-8b0b-492f-9d53-d69eda79629d", "url": "https://shigusegubu.club/objects/f472f4ed-8b0b-492f-9d53-d69eda79629d", - "visibility": "public" + "visibility": "public", + "pleroma": { + "local": true + } }, { "account": { "acct": "hj", @@ -1578,5 +1650,8 @@ "tags": [], "uri": "https://shigusegubu.club/objects/d6fb4fd2-1f6a-4446-a1a6-5edd34050096", "url": "https://shigusegubu.club/objects/d6fb4fd2-1f6a-4446-a1a6-5edd34050096", - "visibility": "public" + "visibility": "public", + "pleroma": { + "local": true + } }] diff --git a/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js b/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js index 2b0b0d6d..bae890f8 100644 --- a/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js +++ b/test/unit/specs/services/entity_normalizer/entity_normalizer.spec.js @@ -129,7 +129,10 @@ const makeMockStatusMasto = (overrides = {}) => { tags: [], uri: 'https://shigusegubu.club/objects/16033fbb-97c0-4f0e-b834-7abb92fb8639', url: 'https://shigusegubu.club/objects/16033fbb-97c0-4f0e-b834-7abb92fb8639', - visibility: 'public' + visibility: 'public', + pleroma: { + local: true + } }, overrides) } diff --git a/test/unit/specs/services/notification_utils/notification_utils.spec.js b/test/unit/specs/services/notification_utils/notification_utils.spec.js index e945459e..1baa5fc9 100644 --- a/test/unit/specs/services/notification_utils/notification_utils.spec.js +++ b/test/unit/specs/services/notification_utils/notification_utils.spec.js @@ -9,14 +9,17 @@ describe('NotificationUtils', () => { notifications: { data: [ { + id: 1, action: { id: '1' }, type: 'like' }, { + id: 2, action: { id: '2' }, type: 'mention' }, { + id: 3, action: { id: '3' }, type: 'repeat' } @@ -35,10 +38,12 @@ describe('NotificationUtils', () => { const expected = [ { action: { id: '3' }, + id: 3, type: 'repeat' }, { action: { id: '1' }, + id: 1, type: 'like' } ] |
