mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-15 18:26:15 +01:00
feat: GET /api/v3/chats/:roomId/messages
This commit is contained in:
@@ -144,6 +144,8 @@ paths:
|
||||
$ref: 'write/chats/roomId/users.yaml'
|
||||
/chats/{roomId}/users/{uid}:
|
||||
$ref: 'write/chats/roomId/users/uid.yaml'
|
||||
/chats/{roomId}/messages:
|
||||
$ref: 'write/chats/roomId/messages.yaml'
|
||||
/chats/{roomId}/messages/{mid}:
|
||||
$ref: 'write/chats/roomId/messages/mid.yaml'
|
||||
/flags/:
|
||||
|
||||
54
public/openapi/write/chats/roomId/messages.yaml
Normal file
54
public/openapi/write/chats/roomId/messages.yaml
Normal file
@@ -0,0 +1,54 @@
|
||||
get:
|
||||
tags:
|
||||
- chats
|
||||
summary: get chat room messages
|
||||
description: This operation retrieves the messages in a chat room, with pagination options accepted
|
||||
parameters:
|
||||
- in: path
|
||||
name: roomId
|
||||
schema:
|
||||
type: number
|
||||
required: true
|
||||
description: a valid chat room id
|
||||
example: 1
|
||||
- in: query
|
||||
name: uid
|
||||
schema:
|
||||
type: number
|
||||
description: a valid user id
|
||||
example: 1
|
||||
- in: query
|
||||
name: start
|
||||
schema:
|
||||
type: number
|
||||
description: At which chat message index to start returning messages from
|
||||
example: 0
|
||||
responses:
|
||||
'200':
|
||||
description: Messages successfully retrieved
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
status:
|
||||
$ref: ../../../components/schemas/Status.yaml#/Status
|
||||
response:
|
||||
type: object
|
||||
properties:
|
||||
messages:
|
||||
type: array
|
||||
items:
|
||||
allOf:
|
||||
- $ref: ../../../components/schemas/Chats.yaml#/MessageObject
|
||||
- type: object
|
||||
description: Optional properties that may or may not be present (except for `messageId`, which is always present, and is only here as a hack to pass validation)
|
||||
properties:
|
||||
messageId:
|
||||
type: number
|
||||
index:
|
||||
type: number
|
||||
isOwner:
|
||||
type: boolean
|
||||
required:
|
||||
- messageId
|
||||
@@ -122,14 +122,9 @@ define('forum/chats', [
|
||||
}
|
||||
loading = true;
|
||||
const start = parseInt(el.children('[data-mid]').length, 10);
|
||||
socket.emit('modules.chats.getMessages', {
|
||||
roomId: roomId,
|
||||
uid: uid,
|
||||
start: start,
|
||||
}, function (err, data) {
|
||||
if (err) {
|
||||
return alerts.error(err);
|
||||
}
|
||||
api.get(`/chats/${roomId}/messages`, { uid, start }).then((data) => {
|
||||
data = data.messages;
|
||||
|
||||
if (!data) {
|
||||
loading = false;
|
||||
return;
|
||||
@@ -151,7 +146,7 @@ define('forum/chats', [
|
||||
el.scrollTop((el[0].scrollHeight - previousHeight) + currentScrollTop);
|
||||
loading = false;
|
||||
});
|
||||
});
|
||||
}).catch(alerts.error);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -89,6 +89,18 @@ Chats.kickUser = async (req, res) => {
|
||||
};
|
||||
|
||||
Chats.messages = {};
|
||||
Chats.messages.list = async (req, res) => {
|
||||
const messages = await messaging.getMessages({
|
||||
callerUid: req.uid,
|
||||
uid: req.query.uid || req.uid,
|
||||
roomId: req.params.roomId,
|
||||
start: parseInt(req.query.start, 10) || 0,
|
||||
count: 50,
|
||||
});
|
||||
|
||||
helpers.formatApiResponse(200, res, { messages });
|
||||
};
|
||||
|
||||
Chats.messages.get = async (req, res) => {
|
||||
const messages = await messaging.getMessagesData([req.params.mid], req.uid, req.params.roomId, false);
|
||||
helpers.formatApiResponse(200, res, messages.pop());
|
||||
|
||||
@@ -24,6 +24,7 @@ module.exports = function () {
|
||||
setupApiRoute(router, 'delete', '/:roomId/users', [...middlewares, middleware.assert.room, middleware.checkRequired.bind(null, ['uids'])], controllers.write.chats.kick);
|
||||
setupApiRoute(router, 'delete', '/:roomId/users/:uid', [...middlewares, middleware.assert.room, middleware.assert.user], controllers.write.chats.kickUser);
|
||||
|
||||
setupApiRoute(router, 'get', '/:roomId/messages', [...middlewares, middleware.assert.room], controllers.write.chats.messages.list);
|
||||
setupApiRoute(router, 'get', '/:roomId/messages/:mid', [...middlewares, middleware.assert.room, middleware.assert.message], controllers.write.chats.messages.get);
|
||||
setupApiRoute(router, 'put', '/:roomId/messages/:mid', [...middlewares, middleware.assert.room, middleware.assert.message], controllers.write.chats.messages.edit);
|
||||
setupApiRoute(router, 'post', '/:roomId/messages/:mid', [...middlewares, middleware.assert.room, middleware.assert.message], controllers.write.chats.messages.restore);
|
||||
|
||||
@@ -232,6 +232,8 @@ SocketModules.chats.hasPrivateChat = async function (socket, uid) {
|
||||
};
|
||||
|
||||
SocketModules.chats.getMessages = async function (socket, data) {
|
||||
sockets.warnDeprecated(socket, 'GET /api/v3/chats/:roomId/messages');
|
||||
|
||||
if (!socket.uid || !data || !data.uid || !data.roomId) {
|
||||
throw new Error('[[error:invalid-data]]');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user