mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
refactor(socket.io): deprecate SocketModules.chats.getIP in favour of api.chats.getIpAddress
This commit is contained in:
@@ -208,6 +208,8 @@ paths:
|
||||
$ref: 'write/chats/roomId/messages/mid/pin.yaml'
|
||||
/chats/{roomId}/messages/{mid}/raw:
|
||||
$ref: 'write/chats/roomId/messages/mid/raw.yaml'
|
||||
/chats/{roomId}/messages/{mid}/ip:
|
||||
$ref: 'write/chats/roomId/messages/mid/ip.yaml'
|
||||
/flags/:
|
||||
$ref: 'write/flags.yaml'
|
||||
/flags/{flagId}:
|
||||
|
||||
35
public/openapi/write/chats/roomId/messages/mid/ip.yaml
Normal file
35
public/openapi/write/chats/roomId/messages/mid/ip.yaml
Normal file
@@ -0,0 +1,35 @@
|
||||
get:
|
||||
tags:
|
||||
- chats
|
||||
summary: get message ip address
|
||||
description: This operation retrieves the ip address recorded when a message was saved
|
||||
parameters:
|
||||
- in: path
|
||||
name: roomId
|
||||
schema:
|
||||
type: string
|
||||
required: true
|
||||
description: a valid chat room id
|
||||
example: 1
|
||||
- in: path
|
||||
name: mid
|
||||
schema:
|
||||
type: string
|
||||
required: true
|
||||
description: a valid chat message id
|
||||
example: 5
|
||||
responses:
|
||||
'200':
|
||||
description: Chat message ip address retrieved
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
status:
|
||||
$ref: ../../../../../components/schemas/Status.yaml#/Status
|
||||
response:
|
||||
type: object
|
||||
properties:
|
||||
ip:
|
||||
type: string
|
||||
@@ -236,7 +236,7 @@ define('forum/chats', [
|
||||
return;
|
||||
}
|
||||
const mid = ipEl.parents('[data-mid]').attr('data-mid');
|
||||
ip = await socket.emit('modules.chats.getIP', mid);
|
||||
({ ip } = await api.get(`/chats/${ajaxify.data.roomId}/messages/${mid}/ip`));
|
||||
ipEl.text(ip).attr('data-ip', ip);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -8,6 +8,7 @@ const user = require('../user');
|
||||
const meta = require('../meta');
|
||||
const messaging = require('../messaging');
|
||||
const notifications = require('../notifications');
|
||||
const privileges = require('../privileges');
|
||||
const plugins = require('../plugins');
|
||||
|
||||
const socketHelpers = require('../socket.io/helpers');
|
||||
@@ -295,6 +296,15 @@ chatsAPI.getRawMessage = async (caller, { mid, roomId }) => {
|
||||
return { content };
|
||||
};
|
||||
|
||||
chatsAPI.getIpAddress = async (caller, { mid }) => {
|
||||
const allowed = await privileges.global.can('view:users:info', caller.uid);
|
||||
if (!allowed) {
|
||||
throw new Error('[[error:no-privileges]]');
|
||||
}
|
||||
const ip = await messaging.getMessageField(mid, 'ip');
|
||||
return { ip };
|
||||
};
|
||||
|
||||
chatsAPI.editMessage = async (caller, { mid, roomId, message }) => {
|
||||
await messaging.canEdit(mid, caller.uid);
|
||||
await messaging.editMessage(caller.uid, mid, roomId, message);
|
||||
|
||||
@@ -139,6 +139,10 @@ Chats.messages.getRaw = async (req, res) => {
|
||||
helpers.formatApiResponse(200, res, await api.chats.getRawMessage(req, { ...req.params }));
|
||||
};
|
||||
|
||||
Chats.messages.getIpAddress = async (req, res) => {
|
||||
helpers.formatApiResponse(200, res, await api.chats.getIpAddress(req, { ...req.params }));
|
||||
};
|
||||
|
||||
Chats.messages.edit = async (req, res) => {
|
||||
const { mid, roomId } = req.params;
|
||||
const { message } = req.body;
|
||||
|
||||
@@ -33,6 +33,7 @@ module.exports = function () {
|
||||
setupApiRoute(router, 'delete', '/:roomId/messages/:mid', [...middlewares, middleware.assert.room, middleware.assert.message], controllers.write.chats.messages.delete);
|
||||
|
||||
setupApiRoute(router, 'get', '/:roomId/messages/:mid/raw', [...middlewares, middleware.assert.room], controllers.write.chats.messages.getRaw);
|
||||
setupApiRoute(router, 'get', '/:roomId/messages/:mid/ip', [...middlewares, middleware.assert.room], controllers.write.chats.messages.getIpAddress);
|
||||
|
||||
setupApiRoute(router, 'put', '/:roomId/messages/:mid/pin', [...middlewares, middleware.assert.room, middleware.assert.message], controllers.write.chats.messages.pin);
|
||||
setupApiRoute(router, 'delete', '/:roomId/messages/:mid/pin', [...middlewares, middleware.assert.room, middleware.assert.message], controllers.write.chats.messages.unpin);
|
||||
|
||||
@@ -83,11 +83,10 @@ SocketModules.chats.hasPrivateChat = async function (socket, uid) {
|
||||
};
|
||||
|
||||
SocketModules.chats.getIP = async function (socket, mid) {
|
||||
const allowed = await privileges.global.can('view:users:info', socket.uid);
|
||||
if (!allowed) {
|
||||
throw new Error('[[error:no-privilege]]');
|
||||
}
|
||||
return await Messaging.getMessageField(mid, 'ip');
|
||||
sockets.warnDeprecated(socket, 'GET /api/v3/chats/:roomId/messages/:mid/ip');
|
||||
|
||||
const { ip } = await api.chats.getIpAddress(socket, { mid });
|
||||
return ip;
|
||||
};
|
||||
|
||||
SocketModules.chats.getUnreadCount = async function (socket) {
|
||||
|
||||
Reference in New Issue
Block a user