diff options
| author | HJ <30-hj@users.noreply.git.pleroma.social> | 2023-11-10 13:31:45 +0000 |
|---|---|---|
| committer | HJ <30-hj@users.noreply.git.pleroma.social> | 2023-11-10 13:31:45 +0000 |
| commit | 60cb173b61a9ffa4336a0ace7c90622834efd98e (patch) | |
| tree | e93c8fcd0e2b99233659c0f3d204bce4bf13fb68 /src | |
| parent | 954d03150f1dc097b9950cfef2fed2e4f55b6442 (diff) | |
| parent | 55d4ea3643a3bdb9e350c559d2d9a5f8608a7910 (diff) | |
Merge branch 'neetzsche/display-latest-scrobble' into 'develop'
Display the latest scrobble under a user's name
See merge request pleroma/pleroma-fe!1865
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/settings_modal/tabs/filtering_tab.vue | 5 | ||||
| -rw-r--r-- | src/components/status/status.js | 12 | ||||
| -rw-r--r-- | src/components/status/status.vue | 18 | ||||
| -rw-r--r-- | src/i18n/en.json | 1 | ||||
| -rw-r--r-- | src/modules/config.js | 1 | ||||
| -rw-r--r-- | src/modules/statuses.js | 17 | ||||
| -rw-r--r-- | src/services/api/api.service.js | 19 |
7 files changed, 71 insertions, 2 deletions
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') }} </BooleanSetting> </li> + <li> + <BooleanSetting path="hideScrobbles"> + {{ $t('settings.hide_scrobbles') }} + </BooleanSetting> + </li> </ul> </div> <div diff --git a/src/components/status/status.js b/src/components/status/status.js index e722a635..a339694d 100644 --- a/src/components/status/status.js +++ b/src/components/status/status.js @@ -39,7 +39,8 @@ import { faThumbtack, faChevronUp, faChevronDown, - faAngleDoubleRight + faAngleDoubleRight, + faPlay } from '@fortawesome/free-solid-svg-icons' library.add( @@ -59,7 +60,8 @@ library.add( faThumbtack, faChevronUp, faChevronDown, - faAngleDoubleRight + faAngleDoubleRight, + faPlay ) const camelCase = name => 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..d66de562 100644 --- a/src/components/status/status.vue +++ b/src/components/status/status.vue @@ -249,6 +249,24 @@ </button> </span> </div> + <div class="status-rich-presence" v-if="scrobblePresent"> + <FAIcon + class="fa-scale-110 fa-old-padding" + icon="music" + /> + {{ scrobble.artist }} — {{ scrobble.title }} + <FAIcon + class="fa-scale-110 fa-old-padding" + icon="play" + /> + <span class="status-rich-presence-time"> + <Timeago + template-key="time.in_past" + :time="scrobble.created_at" + :auto-update="60" + /> + </span> + </div> <div v-if="isReply || hasMentionsLine" class="heading-reply-row" diff --git a/src/i18n/en.json b/src/i18n/en.json index 1658a25d..031771dd 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -495,6 +495,7 @@ "hide_muted_posts": "Hide posts of muted users", "mute_bot_posts": "Mute bot posts", "hide_bot_indication": "Hide bot indication in posts", + "hide_scrobbles": "Hide scrobbles", "hide_all_muted_posts": "Hide muted posts", "max_thumbnails": "Maximum amount of thumbnails per post (empty = no limit)", "hide_isp": "Hide instance-specific panel", diff --git a/src/modules/config.js b/src/modules/config.js index dda3d221..49e9b2df 100644 --- a/src/modules/config.js +++ b/src/modules/config.js @@ -40,6 +40,7 @@ export const defaultState = { padEmoji: true, hideAttachments: false, hideAttachmentsInConv: false, + hideScrobbles: false, maxThumbnails: 16, hideNsfw: true, preloadImage: true, diff --git a/src/modules/statuses.js b/src/modules/statuses.js index 186bba3c..9b4cd175 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -47,6 +47,7 @@ const emptyNotifications = () => ({ 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, |
