mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-09-02 01:57:38 +02:00
refactor(socket.io): deprecate SocketModules.chats.hasPrivateChat in favour of api.users.getPrivateRoomId
This commit is contained in:
@@ -11,6 +11,7 @@ const db = require('../database');
|
||||
const user = require('../user');
|
||||
const groups = require('../groups');
|
||||
const meta = require('../meta');
|
||||
const messaging = require('../messaging');
|
||||
const flags = require('../flags');
|
||||
const privileges = require('../privileges');
|
||||
const notifications = require('../notifications');
|
||||
@@ -147,6 +148,15 @@ usersAPI.getStatus = async (caller, { uid }) => {
|
||||
return { status };
|
||||
};
|
||||
|
||||
usersAPI.getPrivateRoomId = async (caller, { uid }) => {
|
||||
let roomId = await messaging.hasPrivateChat(caller.uid, uid);
|
||||
roomId = parseInt(roomId, 10);
|
||||
|
||||
return {
|
||||
roomId: roomId > 0 ? roomId : null,
|
||||
};
|
||||
};
|
||||
|
||||
usersAPI.changePassword = async function (caller, data) {
|
||||
await user.changePassword(caller.uid, Object.assign(data, { ip: caller.ip }));
|
||||
await events.log({
|
||||
|
||||
@@ -77,6 +77,10 @@ Users.checkStatus = async (req, res) => {
|
||||
helpers.formatApiResponse(current === status ? 200 : 404, res);
|
||||
};
|
||||
|
||||
Users.getPrivateRoomId = async (req, res) => {
|
||||
helpers.formatApiResponse(200, res, await api.users.getPrivateRoomId(req, { ...req.params }));
|
||||
};
|
||||
|
||||
Users.updateSettings = async (req, res) => {
|
||||
const settings = await api.users.updateSettings(req, { ...req.body, uid: req.params.uid });
|
||||
helpers.formatApiResponse(200, res, settings);
|
||||
|
||||
@@ -29,6 +29,8 @@ function authenticatedRoutes() {
|
||||
setupApiRoute(router, 'get', '/:uid/status', [], controllers.write.users.getStatus);
|
||||
setupApiRoute(router, 'head', '/:uid/status/:status', [], controllers.write.users.checkStatus);
|
||||
|
||||
setupApiRoute(router, 'get', '/:uid/chat', [...middlewares], controllers.write.users.getPrivateRoomId);
|
||||
|
||||
setupApiRoute(router, 'put', '/:uid/settings', [...middlewares, middleware.checkRequired.bind(null, ['settings'])], controllers.write.users.updateSettings);
|
||||
|
||||
setupApiRoute(router, 'put', '/:uid/password', [...middlewares, middleware.checkRequired.bind(null, ['newPassword']), middleware.assert.user], controllers.write.users.changePassword);
|
||||
|
||||
@@ -71,10 +71,15 @@ SocketModules.chats.getRecentChats = async function (socket, data) {
|
||||
};
|
||||
|
||||
SocketModules.chats.hasPrivateChat = async function (socket, uid) {
|
||||
sockets.warnDeprecated(socket, 'GET /api/v3/users/:uid/chat');
|
||||
|
||||
if (socket.uid <= 0 || uid <= 0) {
|
||||
throw new Error('[[error:invalid-data]]');
|
||||
}
|
||||
return await Messaging.hasPrivateChat(socket.uid, uid);
|
||||
|
||||
// despite the `has` prefix, this method actually did return the roomId.
|
||||
const { roomId } = await api.users.getPrivateRoomId(socket, { uid });
|
||||
return roomId;
|
||||
};
|
||||
|
||||
SocketModules.chats.getIP = async function (socket, mid) {
|
||||
|
||||
Reference in New Issue
Block a user