diff --git a/client/components/modals/ListeningSessionModal.vue b/client/components/modals/ListeningSessionModal.vue index ecf00f78..0a6b556e 100644 --- a/client/components/modals/ListeningSessionModal.vue +++ b/client/components/modals/ListeningSessionModal.vue @@ -81,7 +81,7 @@

{{ $strings.LabelUser }}

-

{{ _session.userId }}

+

{{ username }}

{{ $strings.LabelMediaPlayer }}

{{ playMethodName }}

@@ -132,6 +132,9 @@ export default { _session() { return this.session || {} }, + username() { + return this._session.user?.username || this._session.userId || '' + }, deviceInfo() { return this._session.deviceInfo || {} }, diff --git a/server/controllers/SessionController.js b/server/controllers/SessionController.js index 8cebdd35..7160eace 100644 --- a/server/controllers/SessionController.js +++ b/server/controllers/SessionController.js @@ -57,26 +57,24 @@ class SessionController { } let where = null - const include = [ - { - model: Database.models.device - } - ] if (userId) { where = { userId } - } else { - include.push({ - model: Database.userModel, - attributes: ['id', 'username'] - }) } const { rows, count } = await Database.playbackSessionModel.findAndCountAll({ where, - include, + include: [ + { + model: Database.deviceModel + }, + { + model: Database.userModel, + attributes: ['id', 'username'] + } + ], order: [[orderKey, orderDesc]], limit: itemsPerPage, offset: itemsPerPage * page diff --git a/server/controllers/UserController.js b/server/controllers/UserController.js index e72293cb..3ec10539 100644 --- a/server/controllers/UserController.js +++ b/server/controllers/UserController.js @@ -439,7 +439,16 @@ class UserController { const page = toNumber(req.query.page, 0) const start = page * itemsPerPage - const sessions = listeningSessions.slice(start, start + itemsPerPage) + // Map user to sessions to match the format of the sessions endpoint + const sessions = listeningSessions.slice(start, start + itemsPerPage).map((session) => { + return { + ...session, + user: { + id: req.reqUser.id, + username: req.reqUser.username + } + } + }) const payload = { total: listeningSessions.length,