Files
NodeBB/src/controllers/write/chats.js

76 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-12-10 17:16:54 -05:00
'use strict';
const api = require('../../api');
2021-12-13 11:47:48 -05:00
const messaging = require('../../messaging');
2021-12-10 17:16:54 -05:00
const helpers = require('../helpers');
const Chats = module.exports;
Chats.list = async (req, res) => {
2021-12-13 11:47:48 -05:00
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 });
2021-12-10 17:16:54 -05:00
};
Chats.create = async (req, res) => {
const roomObj = await api.chats.create(req, req.body);
helpers.formatApiResponse(200, res, roomObj);
2021-12-10 17:16:54 -05:00
};
Chats.exists = async (req, res) => {
helpers.formatApiResponse(200, res);
};
Chats.get = async (req, res) => {
2021-12-14 10:32:41 -05:00
const roomObj = await messaging.loadRoom(req.uid, {
uid: req.query.uid || req.uid,
roomId: req.params.roomId,
});
helpers.formatApiResponse(200, res, roomObj);
2021-12-10 17:16:54 -05:00
};
Chats.post = async (req, res) => {
2021-12-14 11:01:05 -05:00
const messageObj = await api.chats.post(req, {
...req.body,
roomId: req.params.roomId,
});
helpers.formatApiResponse(200, res, messageObj);
2021-12-10 17:16:54 -05:00
};
2021-12-15 10:59:58 -05:00
Chats.rename = async (req, res) => {
const roomObj = await api.chats.rename(req, {
...req.body,
roomId: req.params.roomId,
});
helpers.formatApiResponse(200, res, roomObj);
};
2021-12-10 17:16:54 -05:00
Chats.users = async (req, res) => {
// ...
};
Chats.invite = async (req, res) => {
// ...
};
Chats.kick = async (req, res) => {
// ...
};
2021-12-13 11:47:48 -05:00
Chats.messages = {};
2021-12-10 17:16:54 -05:00
Chats.messages.edit = async (req, res) => {
// ...
};
Chats.messages.delete = async (req, res) => {
// ...
};