aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/users.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/users.ts')
-rw-r--r--server/controllers/api/users.ts17
1 files changed, 14 insertions, 3 deletions
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts
index d37813595..ef2b63f51 100644
--- a/server/controllers/api/users.ts
+++ b/server/controllers/api/users.ts
@@ -8,6 +8,7 @@ import { retryTransactionWrapper } from '../../helpers/database-utils'
8import { logger } from '../../helpers/logger' 8import { logger } from '../../helpers/logger'
9import { createReqFiles, getFormattedObjects } from '../../helpers/utils' 9import { createReqFiles, getFormattedObjects } from '../../helpers/utils'
10import { AVATAR_MIMETYPE_EXT, AVATARS_SIZE, CONFIG, sequelizeTypescript } from '../../initializers' 10import { AVATAR_MIMETYPE_EXT, AVATARS_SIZE, CONFIG, sequelizeTypescript } from '../../initializers'
11import { sendUpdateUser } from '../../lib/activitypub/send'
11import { createUserAccountAndChannel } from '../../lib/user' 12import { createUserAccountAndChannel } from '../../lib/user'
12import { 13import {
13 asyncMiddleware, authenticate, ensureUserHasRight, ensureUserRegistrationAllowed, paginationValidator, setPagination, setUsersSort, 14 asyncMiddleware, authenticate, ensureUserHasRight, ensureUserRegistrationAllowed, paginationValidator, setPagination, setUsersSort,
@@ -217,7 +218,6 @@ async function removeUser (req: express.Request, res: express.Response, next: ex
217async function updateMe (req: express.Request, res: express.Response, next: express.NextFunction) { 218async function updateMe (req: express.Request, res: express.Response, next: express.NextFunction) {
218 const body: UserUpdateMe = req.body 219 const body: UserUpdateMe = req.body
219 220
220 // FIXME: user is not already a Sequelize instance?
221 const user = res.locals.oauth.token.user 221 const user = res.locals.oauth.token.user
222 222
223 if (body.password !== undefined) user.password = body.password 223 if (body.password !== undefined) user.password = body.password
@@ -226,13 +226,15 @@ async function updateMe (req: express.Request, res: express.Response, next: expr
226 if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo 226 if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo
227 227
228 await user.save() 228 await user.save()
229 await sendUpdateUser(user, undefined)
229 230
230 return res.sendStatus(204) 231 return res.sendStatus(204)
231} 232}
232 233
233async function updateMyAvatar (req: express.Request, res: express.Response, next: express.NextFunction) { 234async function updateMyAvatar (req: express.Request, res: express.Response, next: express.NextFunction) {
234 const avatarPhysicalFile = req.files['avatarfile'][0] 235 const avatarPhysicalFile = req.files['avatarfile'][0]
235 const actor = res.locals.oauth.token.user.Account.Actor 236 const user = res.locals.oauth.token.user
237 const actor = user.Account.Actor
236 238
237 const avatarDir = CONFIG.STORAGE.AVATARS_DIR 239 const avatarDir = CONFIG.STORAGE.AVATARS_DIR
238 const source = join(avatarDir, avatarPhysicalFile.filename) 240 const source = join(avatarDir, avatarPhysicalFile.filename)
@@ -252,12 +254,19 @@ async function updateMyAvatar (req: express.Request, res: express.Response, next
252 }, { transaction: t }) 254 }, { transaction: t })
253 255
254 if (actor.Avatar) { 256 if (actor.Avatar) {
255 await actor.Avatar.destroy({ transaction: t }) 257 try {
258 await actor.Avatar.destroy({ transaction: t })
259 } catch (err) {
260 logger.error('Cannot remove old avatar of user %s.', user.username, err)
261 }
256 } 262 }
257 263
258 actor.set('avatarId', avatar.id) 264 actor.set('avatarId', avatar.id)
265 actor.Avatar = avatar
259 await actor.save({ transaction: t }) 266 await actor.save({ transaction: t })
260 267
268 await sendUpdateUser(user, undefined)
269
261 return { actor, avatar } 270 return { actor, avatar }
262 }) 271 })
263 272
@@ -278,6 +287,8 @@ async function updateUser (req: express.Request, res: express.Response, next: ex
278 287
279 await user.save() 288 await user.save()
280 289
290 // Don't need to send this update to followers, these attributes are not propagated
291
281 return res.sendStatus(204) 292 return res.sendStatus(204)
282} 293}
283 294