mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
feat: POST /chats/:roomId/:mid and DELETE /chats/:roomId/:mid
This commit is contained in:
@@ -52,8 +52,16 @@ MessageObject:
|
|||||||
example: dragon-fruit
|
example: dragon-fruit
|
||||||
picture:
|
picture:
|
||||||
type: string
|
type: string
|
||||||
|
nullable: true
|
||||||
description: A URL pointing to a picture to be used as the user's avatar
|
description: A URL pointing to a picture to be used as the user's avatar
|
||||||
example: 'https://images.unsplash.com/photo-1560070094-e1f2ddec4337?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=256&h=256&q=80'
|
example: 'https://images.unsplash.com/photo-1560070094-e1f2ddec4337?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=256&h=256&q=80'
|
||||||
|
status:
|
||||||
|
type: string
|
||||||
|
enum:
|
||||||
|
- online
|
||||||
|
- offline
|
||||||
|
- dnd
|
||||||
|
- away
|
||||||
banned:
|
banned:
|
||||||
type: boolean
|
type: boolean
|
||||||
description: Whether a user is banned or not
|
description: Whether a user is banned or not
|
||||||
@@ -80,6 +88,12 @@ MessageObject:
|
|||||||
example: Not Banned
|
example: Not Banned
|
||||||
deleted:
|
deleted:
|
||||||
type: boolean
|
type: boolean
|
||||||
|
self:
|
||||||
|
type: number
|
||||||
|
newSet:
|
||||||
|
type: boolean
|
||||||
|
cleanedContent:
|
||||||
|
type: string
|
||||||
RoomObjectFull:
|
RoomObjectFull:
|
||||||
# Messaging.loadRoom
|
# Messaging.loadRoom
|
||||||
allOf:
|
allOf:
|
||||||
|
|||||||
@@ -140,6 +140,8 @@ paths:
|
|||||||
$ref: 'write/chats.yaml'
|
$ref: 'write/chats.yaml'
|
||||||
/chats/{roomId}:
|
/chats/{roomId}:
|
||||||
$ref: 'write/chats/roomId.yaml'
|
$ref: 'write/chats/roomId.yaml'
|
||||||
|
/chats/{roomId}/{mid}:
|
||||||
|
$ref: 'write/chats/roomId/mid.yaml'
|
||||||
/flags/:
|
/flags/:
|
||||||
$ref: 'write/flags.yaml'
|
$ref: 'write/flags.yaml'
|
||||||
/flags/{flagId}:
|
/flags/{flagId}:
|
||||||
|
|||||||
141
public/openapi/write/chats/roomId/mid.yaml
Normal file
141
public/openapi/write/chats/roomId/mid.yaml
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- chats
|
||||||
|
summary: get a chat message
|
||||||
|
description: This operation retrieves a single chat room message, by its id
|
||||||
|
parameters:
|
||||||
|
- in: path
|
||||||
|
name: roomId
|
||||||
|
schema:
|
||||||
|
type: number
|
||||||
|
required: true
|
||||||
|
description: a valid chat room id
|
||||||
|
example: 1
|
||||||
|
- in: path
|
||||||
|
name: mid
|
||||||
|
schema:
|
||||||
|
type: number
|
||||||
|
required: true
|
||||||
|
description: a valid message id
|
||||||
|
example: 1
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: Message successfully retrieved
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
status:
|
||||||
|
$ref: ../../../components/schemas/Status.yaml#/Status
|
||||||
|
response:
|
||||||
|
$ref: ../../../components/schemas/Chats.yaml#/MessageObject
|
||||||
|
put:
|
||||||
|
tags:
|
||||||
|
- chats
|
||||||
|
summary: edit a chat message
|
||||||
|
description: This operation edits a chat message.
|
||||||
|
parameters:
|
||||||
|
- in: path
|
||||||
|
name: roomId
|
||||||
|
schema:
|
||||||
|
type: number
|
||||||
|
required: true
|
||||||
|
description: a valid chat room id
|
||||||
|
example: 1
|
||||||
|
- in: path
|
||||||
|
name: mid
|
||||||
|
schema:
|
||||||
|
type: number
|
||||||
|
required: true
|
||||||
|
description: a valid message id
|
||||||
|
example: 5
|
||||||
|
requestBody:
|
||||||
|
required: true
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
description: message content
|
||||||
|
example: 'edited message'
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: Message successfully edited
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
status:
|
||||||
|
$ref: ../../../components/schemas/Status.yaml#/Status
|
||||||
|
response:
|
||||||
|
$ref: ../../../components/schemas/Chats.yaml#/MessageObject
|
||||||
|
delete:
|
||||||
|
tags:
|
||||||
|
- chats
|
||||||
|
summary: delete a chat message
|
||||||
|
description: This operation deletes a chat message
|
||||||
|
parameters:
|
||||||
|
- in: path
|
||||||
|
name: roomId
|
||||||
|
schema:
|
||||||
|
type: number
|
||||||
|
required: true
|
||||||
|
description: a valid chat room id
|
||||||
|
example: 1
|
||||||
|
- in: path
|
||||||
|
name: mid
|
||||||
|
schema:
|
||||||
|
type: number
|
||||||
|
required: true
|
||||||
|
description: a valid message id
|
||||||
|
example: 5
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: Message successfully deleted
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
status:
|
||||||
|
$ref: ../../../components/schemas/Status.yaml#/Status
|
||||||
|
response:
|
||||||
|
type: object
|
||||||
|
properties: {}
|
||||||
|
post:
|
||||||
|
tags:
|
||||||
|
- chats
|
||||||
|
summary: restore a chat message
|
||||||
|
description: This operation restores a delete chat message
|
||||||
|
parameters:
|
||||||
|
- in: path
|
||||||
|
name: roomId
|
||||||
|
schema:
|
||||||
|
type: number
|
||||||
|
required: true
|
||||||
|
description: a valid chat room id
|
||||||
|
example: 1
|
||||||
|
- in: path
|
||||||
|
name: mid
|
||||||
|
schema:
|
||||||
|
type: number
|
||||||
|
required: true
|
||||||
|
description: a valid message id
|
||||||
|
example: 5
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: message successfully restored
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
status:
|
||||||
|
$ref: ../../../components/schemas/Status.yaml#/Status
|
||||||
|
response:
|
||||||
|
type: object
|
||||||
|
properties: {}
|
||||||
@@ -190,31 +190,17 @@ define('forum/chats/messages', [
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.emit('modules.chats.delete', {
|
api.delete(`/chats/${roomId}/${messageId}`, {}).then(() => {
|
||||||
messageId: messageId,
|
|
||||||
roomId: roomId,
|
|
||||||
}, function (err) {
|
|
||||||
if (err) {
|
|
||||||
return alerts.error(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
components.get('chat/message', messageId).toggleClass('deleted', true);
|
components.get('chat/message', messageId).toggleClass('deleted', true);
|
||||||
});
|
}).catch(alerts.error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
messages.restore = function (messageId, roomId) {
|
messages.restore = function (messageId, roomId) {
|
||||||
socket.emit('modules.chats.restore', {
|
api.post(`/chats/${roomId}/${messageId}`, {}).then(() => {
|
||||||
messageId: messageId,
|
|
||||||
roomId: roomId,
|
|
||||||
}, function (err) {
|
|
||||||
if (err) {
|
|
||||||
return alerts.error(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
components.get('chat/message', messageId).toggleClass('deleted', false);
|
components.get('chat/message', messageId).toggleClass('deleted', false);
|
||||||
});
|
}).catch(alerts.error);
|
||||||
};
|
};
|
||||||
|
|
||||||
return messages;
|
return messages;
|
||||||
|
|||||||
@@ -80,5 +80,15 @@ Chats.messages.edit = async (req, res) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Chats.messages.delete = async (req, res) => {
|
Chats.messages.delete = async (req, res) => {
|
||||||
// ...
|
await messaging.canDelete(req.params.mid, req.uid);
|
||||||
|
await messaging.deleteMessage(req.params.mid, req.uid);
|
||||||
|
|
||||||
|
helpers.formatApiResponse(200, res);
|
||||||
|
};
|
||||||
|
|
||||||
|
Chats.messages.restore = async (req, res) => {
|
||||||
|
await messaging.canDelete(req.params.mid, req.uid);
|
||||||
|
await messaging.restoreMessage(req.params.mid, req.uid);
|
||||||
|
|
||||||
|
helpers.formatApiResponse(200, res);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ module.exports = function () {
|
|||||||
|
|
||||||
setupApiRoute(router, 'get', '/:roomId/:mid', [...middlewares, middleware.assert.room, middleware.assert.message], controllers.write.chats.messages.get);
|
setupApiRoute(router, 'get', '/:roomId/:mid', [...middlewares, middleware.assert.room, middleware.assert.message], controllers.write.chats.messages.get);
|
||||||
setupApiRoute(router, 'put', '/:roomId/:mid', [...middlewares, middleware.assert.room, middleware.assert.message], controllers.write.chats.messages.edit);
|
setupApiRoute(router, 'put', '/:roomId/:mid', [...middlewares, middleware.assert.room, middleware.assert.message], controllers.write.chats.messages.edit);
|
||||||
// setupApiRoute(router, 'delete', '/:roomId/:mid', [...middlewares, middleware.assert.room], controllers.write.chats.messages.delete);
|
setupApiRoute(router, 'post', '/:roomId/:mid', [...middlewares, middleware.assert.room, middleware.assert.message], controllers.write.chats.messages.restore);
|
||||||
|
setupApiRoute(router, 'delete', '/:roomId/:mid', [...middlewares, middleware.assert.room, middleware.assert.message], controllers.write.chats.messages.delete);
|
||||||
|
|
||||||
return router;
|
return router;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -156,6 +156,8 @@ SocketModules.chats.edit = async function (socket, data) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SocketModules.chats.delete = async function (socket, data) {
|
SocketModules.chats.delete = async function (socket, data) {
|
||||||
|
sockets.warnDeprecated(socket, 'DELETE /api/v3/chats/:roomId/:mid');
|
||||||
|
|
||||||
if (!data || !data.roomId || !data.messageId) {
|
if (!data || !data.roomId || !data.messageId) {
|
||||||
throw new Error('[[error:invalid-data]]');
|
throw new Error('[[error:invalid-data]]');
|
||||||
}
|
}
|
||||||
@@ -164,6 +166,8 @@ SocketModules.chats.delete = async function (socket, data) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SocketModules.chats.restore = async function (socket, data) {
|
SocketModules.chats.restore = async function (socket, data) {
|
||||||
|
sockets.warnDeprecated(socket, 'POST /api/v3/chats/:roomId/:mid');
|
||||||
|
|
||||||
if (!data || !data.roomId || !data.messageId) {
|
if (!data || !data.roomId || !data.messageId) {
|
||||||
throw new Error('[[error:invalid-data]]');
|
throw new Error('[[error:invalid-data]]');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user