mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
refactor(socket.io): deprecate SocketModules.chats.hasPrivateChat in favour of api.users.getPrivateRoomId
This commit is contained in:
@@ -68,6 +68,8 @@ paths:
|
|||||||
$ref: 'write/users/uid/status.yaml'
|
$ref: 'write/users/uid/status.yaml'
|
||||||
/users/{uid}/status/{status}:
|
/users/{uid}/status/{status}:
|
||||||
$ref: 'write/users/uid/status/status.yaml'
|
$ref: 'write/users/uid/status/status.yaml'
|
||||||
|
/users/{uid}/chat:
|
||||||
|
$ref: 'write/users/uid/chat.yaml'
|
||||||
/users/{uid}/settings:
|
/users/{uid}/settings:
|
||||||
$ref: 'write/users/uid/settings.yaml'
|
$ref: 'write/users/uid/settings.yaml'
|
||||||
/users/{uid}/password:
|
/users/{uid}/password:
|
||||||
|
|||||||
27
public/openapi/write/users/uid/chat.yaml
Normal file
27
public/openapi/write/users/uid/chat.yaml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- users
|
||||||
|
summary: get chat room
|
||||||
|
parameters:
|
||||||
|
- in: path
|
||||||
|
name: uid
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
required: true
|
||||||
|
description: uid of the user to query
|
||||||
|
example: 2
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: successfully retrieved private chat room with user
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
status:
|
||||||
|
$ref: ../../../components/schemas/Status.yaml#/Status
|
||||||
|
response:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
roomId:
|
||||||
|
type: number
|
||||||
@@ -32,7 +32,7 @@ define('forum/account/header', [
|
|||||||
components.get('account/unfollow').on('click', () => toggleFollow('unfollow'));
|
components.get('account/unfollow').on('click', () => toggleFollow('unfollow'));
|
||||||
|
|
||||||
components.get('account/chat').on('click', async function () {
|
components.get('account/chat').on('click', async function () {
|
||||||
const roomId = await socket.emit('modules.chats.hasPrivateChat', ajaxify.data.uid);
|
const { roomId } = await api.get(`/users/${ajaxify.data.uid}/chat`);
|
||||||
const chat = await app.require('chat');
|
const chat = await app.require('chat');
|
||||||
if (roomId) {
|
if (roomId) {
|
||||||
chat.openChat(roomId);
|
chat.openChat(roomId);
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ const db = require('../database');
|
|||||||
const user = require('../user');
|
const user = require('../user');
|
||||||
const groups = require('../groups');
|
const groups = require('../groups');
|
||||||
const meta = require('../meta');
|
const meta = require('../meta');
|
||||||
|
const messaging = require('../messaging');
|
||||||
const flags = require('../flags');
|
const flags = require('../flags');
|
||||||
const privileges = require('../privileges');
|
const privileges = require('../privileges');
|
||||||
const notifications = require('../notifications');
|
const notifications = require('../notifications');
|
||||||
@@ -147,6 +148,15 @@ usersAPI.getStatus = async (caller, { uid }) => {
|
|||||||
return { status };
|
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) {
|
usersAPI.changePassword = async function (caller, data) {
|
||||||
await user.changePassword(caller.uid, Object.assign(data, { ip: caller.ip }));
|
await user.changePassword(caller.uid, Object.assign(data, { ip: caller.ip }));
|
||||||
await events.log({
|
await events.log({
|
||||||
|
|||||||
@@ -77,6 +77,10 @@ Users.checkStatus = async (req, res) => {
|
|||||||
helpers.formatApiResponse(current === status ? 200 : 404, 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) => {
|
Users.updateSettings = async (req, res) => {
|
||||||
const settings = await api.users.updateSettings(req, { ...req.body, uid: req.params.uid });
|
const settings = await api.users.updateSettings(req, { ...req.body, uid: req.params.uid });
|
||||||
helpers.formatApiResponse(200, res, settings);
|
helpers.formatApiResponse(200, res, settings);
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ function authenticatedRoutes() {
|
|||||||
setupApiRoute(router, 'get', '/:uid/status', [], controllers.write.users.getStatus);
|
setupApiRoute(router, 'get', '/:uid/status', [], controllers.write.users.getStatus);
|
||||||
setupApiRoute(router, 'head', '/:uid/status/:status', [], controllers.write.users.checkStatus);
|
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/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);
|
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) {
|
SocketModules.chats.hasPrivateChat = async function (socket, uid) {
|
||||||
|
sockets.warnDeprecated(socket, 'GET /api/v3/users/:uid/chat');
|
||||||
|
|
||||||
if (socket.uid <= 0 || uid <= 0) {
|
if (socket.uid <= 0 || uid <= 0) {
|
||||||
throw new Error('[[error:invalid-data]]');
|
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) {
|
SocketModules.chats.getIP = async function (socket, mid) {
|
||||||
|
|||||||
Reference in New Issue
Block a user