diff --git a/changelog.d/show-recent-scrobble.skip b/changelog.d/show-recent-scrobble.skip
new file mode 100644
index 00000000..9227de06
--- /dev/null
+++ b/changelog.d/show-recent-scrobble.skip
@@ -0,0 +1 @@
+Shows the most recent scrobble under each post when available
diff --git a/src/components/settings_modal/tabs/filtering_tab.vue b/src/components/settings_modal/tabs/filtering_tab.vue
index 41d1b54f..89fdef1a 100644
--- a/src/components/settings_modal/tabs/filtering_tab.vue
+++ b/src/components/settings_modal/tabs/filtering_tab.vue
@@ -91,6 +91,11 @@
{{ $t('settings.hide_attachments_in_convo') }}
+
+
+ {{ $t('settings.hide_scrobbles') }}
+
+
name.charAt(0).toUpperCase() + name.slice(1)
@@ -415,6 +417,12 @@ const Status = {
},
shouldDisplayQuote () {
return this.quotedStatus && this.displayQuote
+ },
+ scrobblePresent () {
+ return !this.mergedConfig.hideScrobbles && this.status.user.latestScrobble && this.status.user.latestScrobble.artist
+ },
+ scrobble () {
+ return this.status.user.latestScrobble
}
},
methods: {
diff --git a/src/components/status/status.vue b/src/components/status/status.vue
index c49a9e7b..ad625643 100644
--- a/src/components/status/status.vue
+++ b/src/components/status/status.vue
@@ -249,6 +249,25 @@
+
+
+ {{ scrobble.artist }} — {{ scrobble.title }}
+
+
+
+
+
+
-
({
export const defaultState = () => ({
allStatuses: [],
+ scrobblesNextFetch: {},
allStatusesObject: {},
conversationsObject: {},
maxId: 0,
@@ -120,8 +121,24 @@ const sortTimeline = (timeline) => {
return timeline
}
+const getLatestScrobble = (state, user) => {
+ if (state.scrobblesNextFetch[user.id] && state.scrobblesNextFetch[user.id] > Date.now()) {
+ return
+ }
+
+ state.scrobblesNextFetch[user.id] = Date.now() + 24 * 60 * 60 * 1000
+ apiService.fetchScrobbles({ accountId: user.id }).then((scrobbles) => {
+ if (scrobbles.length > 0) {
+ user.latestScrobble = scrobbles[0]
+
+ state.scrobblesNextFetch[user.id] = Date.now() + 60 * 1000
+ }
+ })
+}
+
// Add status to the global storages (arrays and objects maintaining statuses) except timelines
const addStatusToGlobalStorage = (state, data) => {
+ getLatestScrobble(state, data.user)
const result = mergeOrAdd(state.allStatuses, state.allStatusesObject, data)
if (result.new) {
// Add to conversation
diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js
index c6bca10b..f45e3958 100644
--- a/src/services/api/api.service.js
+++ b/src/services/api/api.service.js
@@ -107,6 +107,7 @@ const PLEROMA_ANNOUNCEMENTS_URL = '/api/v1/pleroma/admin/announcements'
const PLEROMA_POST_ANNOUNCEMENT_URL = '/api/v1/pleroma/admin/announcements'
const PLEROMA_EDIT_ANNOUNCEMENT_URL = id => `/api/v1/pleroma/admin/announcements/${id}`
const PLEROMA_DELETE_ANNOUNCEMENT_URL = id => `/api/v1/pleroma/admin/announcements/${id}`
+const PLEROMA_SCROBBLES_URL = id => `/api/v1/pleroma/accounts/${id}/scrobbles`
const PLEROMA_ADMIN_CONFIG_URL = '/api/pleroma/admin/config'
const PLEROMA_ADMIN_DESCRIPTIONS_URL = '/api/pleroma/admin/config/descriptions'
@@ -1765,6 +1766,23 @@ const installFrontend = ({ credentials, payload }) => {
})
}
+const fetchScrobbles = ({ accountId, limit = 1 }) => {
+ let url = PLEROMA_SCROBBLES_URL(accountId)
+ const params = [['limit', limit]]
+ const queryString = map(params, (param) => `${param[0]}=${param[1]}`).join('&')
+ url += `?${queryString}`
+ return fetch(url, {})
+ .then((response) => {
+ if (response.ok) {
+ return response.json()
+ } else {
+ return {
+ error: response
+ }
+ }
+ })
+}
+
const apiService = {
verifyCredentials,
fetchTimeline,
@@ -1878,6 +1896,7 @@ const apiService = {
postAnnouncement,
editAnnouncement,
deleteAnnouncement,
+ fetchScrobbles,
adminFetchAnnouncements,
fetchInstanceDBConfig,
fetchInstanceConfigDescriptions,