diff --git a/src/controllers/write/chats.js b/src/controllers/write/chats.js index 8e4061036c..d80ff20864 100644 --- a/src/controllers/write/chats.js +++ b/src/controllers/write/chats.js @@ -1,14 +1,20 @@ -/* eslint-disable */ 'use strict'; const api = require('../../api'); +const messaging = require('../../messaging'); const helpers = require('../helpers'); const Chats = module.exports; Chats.list = async (req, res) => { - // ... + const page = (isFinite(req.query.page) && parseInt(req.query.page, 10)) || 1; + const perPage = (isFinite(req.query.perPage) && parseInt(req.query.perPage, 10)) || 20; + const start = Math.max(0, page - 1) * perPage; + const stop = start + perPage; + const { rooms } = await messaging.getRecentChats(req.uid, req.uid, start, stop); + + helpers.formatApiResponse(200, res, { rooms }); }; Chats.create = async (req, res) => { @@ -39,7 +45,7 @@ Chats.kick = async (req, res) => { // ... }; -Chats.message = {}; +Chats.messages = {}; Chats.messages.edit = async (req, res) => { // ... }; diff --git a/src/controllers/write/index.js b/src/controllers/write/index.js index a8b6dc99d7..ad797c212c 100644 --- a/src/controllers/write/index.js +++ b/src/controllers/write/index.js @@ -7,6 +7,7 @@ Write.groups = require('./groups'); Write.categories = require('./categories'); Write.topics = require('./topics'); Write.posts = require('./posts'); +Write.chats = require('./chats'); Write.flags = require('./flags'); Write.admin = require('./admin'); Write.files = require('./files'); diff --git a/src/routes/write/chats.js b/src/routes/write/chats.js index c52fb48692..489004b3b1 100644 --- a/src/routes/write/chats.js +++ b/src/routes/write/chats.js @@ -11,19 +11,19 @@ module.exports = function () { const middlewares = [middleware.ensureLoggedIn, middleware.canChat]; setupApiRoute(router, 'get', '/', [...middlewares], controllers.write.chats.list); - setupApiRoute(router, 'post', '/', [...middlewares, middleware.checkRequired.bind(null, ['uids'])], controllers.write.chats.create); + // setupApiRoute(router, 'post', '/', [...middlewares, middleware.checkRequired.bind(null, ['uids'])], controllers.write.chats.create); setupApiRoute(router, 'head', '/:roomId', [...middlewares, middleware.assert.room], controllers.write.chats.exists); - setupApiRoute(router, 'get', '/:roomId', [...middlewares, middleware.assert.room], controllers.write.chats.get); - setupApiRoute(router, 'post', '/:roomId', [...middlewares, middleware.assert.room], controllers.write.chats.post); - // no route for room deletion, reserved just in case... + // setupApiRoute(router, 'get', '/:roomId', [...middlewares, middleware.assert.room], controllers.write.chats.get); + // setupApiRoute(router, 'post', '/:roomId', [...middlewares, middleware.assert.room], controllers.write.chats.post); + // // no route for room deletion, reserved just in case... - setupApiRoute(router, 'get', '/:roomId/users', [...middlewares, middleware.assert.room], controllers.write.chats.users); - setupApiRoute(router, 'put', '/:roomId/users', [...middlewares, middleware.assert.room, middleware.checkRequired.bind(null, ['uids'])], controllers.write.chats.invite); - setupApiRoute(router, 'delete', '/:roomId/users', [...middlewares, middleware.assert.room, middleware.checkRequired.bind(null, ['uids'])], controllers.write.chats.kick); + // setupApiRoute(router, 'get', '/:roomId/users', [...middlewares, middleware.assert.room], controllers.write.chats.users); + // setupApiRoute(router, 'put', '/:roomId/users', [...middlewares, middleware.assert.room, middleware.checkRequired.bind(null, ['uids'])], controllers.write.chats.invite); + // setupApiRoute(router, 'delete', '/:roomId/users', [...middlewares, middleware.assert.room, middleware.checkRequired.bind(null, ['uids'])], controllers.write.chats.kick); - setupApiRoute(router, 'put', '/:roomId/:mid', [...middlewares, middleware.assert.room], controllers.write.chats.messages.edit); - setupApiRoute(router, 'delete', '/:roomId/:mid', [...middlewares, middleware.assert.room], controllers.write.chats.messages.delete); + // setupApiRoute(router, 'put', '/:roomId/:mid', [...middlewares, middleware.assert.room], controllers.write.chats.messages.edit); + // setupApiRoute(router, 'delete', '/:roomId/:mid', [...middlewares, middleware.assert.room], controllers.write.chats.messages.delete); return router; };