mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: PUT /api/v3/chats/:roomId
This commit is contained in:
@@ -80,3 +80,60 @@ MessageObject:
|
|||||||
example: Not Banned
|
example: Not Banned
|
||||||
deleted:
|
deleted:
|
||||||
type: boolean
|
type: boolean
|
||||||
|
RoomObjectFull:
|
||||||
|
# Messaging.loadRoom
|
||||||
|
allOf:
|
||||||
|
- $ref: '#/RoomObject'
|
||||||
|
- $ref: '#/MessageObject'
|
||||||
|
- type: object
|
||||||
|
properties:
|
||||||
|
isOwner:
|
||||||
|
type: boolean
|
||||||
|
users:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
uid:
|
||||||
|
type: number
|
||||||
|
description: A user identifier
|
||||||
|
username:
|
||||||
|
type: string
|
||||||
|
description: A friendly name for a given user account
|
||||||
|
picture:
|
||||||
|
nullable: true
|
||||||
|
type: string
|
||||||
|
status:
|
||||||
|
type: string
|
||||||
|
displayname:
|
||||||
|
type: string
|
||||||
|
description: This is either username or fullname depending on forum and user settings
|
||||||
|
icon:text:
|
||||||
|
type: string
|
||||||
|
description: A single-letter representation of a username. This is used in the
|
||||||
|
auto-generated icon given to users
|
||||||
|
without an avatar
|
||||||
|
icon:bgColor:
|
||||||
|
type: string
|
||||||
|
description: A six-character hexadecimal colour code assigned to the user. This
|
||||||
|
value is used in conjunction with
|
||||||
|
`icon:text` for the user's
|
||||||
|
auto-generated icon
|
||||||
|
example: "#f44336"
|
||||||
|
isOwner:
|
||||||
|
type: boolean
|
||||||
|
canReply:
|
||||||
|
type: boolean
|
||||||
|
groupChat:
|
||||||
|
type: boolean
|
||||||
|
usernames:
|
||||||
|
type: string
|
||||||
|
description: User-friendly depiction of the users within the chat room
|
||||||
|
maximumUsersInChatRoom:
|
||||||
|
type: number
|
||||||
|
maximumChatMessageLength:
|
||||||
|
type: number
|
||||||
|
showUserInput:
|
||||||
|
type: boolean
|
||||||
|
isAdminOrGlobalMod:
|
||||||
|
type: boolean
|
||||||
@@ -39,61 +39,7 @@ get:
|
|||||||
status:
|
status:
|
||||||
$ref: ../../components/schemas/Status.yaml#/Status
|
$ref: ../../components/schemas/Status.yaml#/Status
|
||||||
response:
|
response:
|
||||||
allOf:
|
$ref: ../../components/schemas/Chats.yaml#/RoomObjectFull
|
||||||
- $ref: ../../components/schemas/Chats.yaml#/RoomObject
|
|
||||||
- $ref: ../../components/schemas/Chats.yaml#/MessageObject
|
|
||||||
- type: object
|
|
||||||
properties:
|
|
||||||
isOwner:
|
|
||||||
type: boolean
|
|
||||||
users:
|
|
||||||
type: array
|
|
||||||
items:
|
|
||||||
type: object
|
|
||||||
properties:
|
|
||||||
uid:
|
|
||||||
type: number
|
|
||||||
description: A user identifier
|
|
||||||
username:
|
|
||||||
type: string
|
|
||||||
description: A friendly name for a given user account
|
|
||||||
picture:
|
|
||||||
nullable: true
|
|
||||||
type: string
|
|
||||||
status:
|
|
||||||
type: string
|
|
||||||
displayname:
|
|
||||||
type: string
|
|
||||||
description: This is either username or fullname depending on forum and user settings
|
|
||||||
icon:text:
|
|
||||||
type: string
|
|
||||||
description: A single-letter representation of a username. This is used in the
|
|
||||||
auto-generated icon given to users
|
|
||||||
without an avatar
|
|
||||||
icon:bgColor:
|
|
||||||
type: string
|
|
||||||
description: A six-character hexadecimal colour code assigned to the user. This
|
|
||||||
value is used in conjunction with
|
|
||||||
`icon:text` for the user's
|
|
||||||
auto-generated icon
|
|
||||||
example: "#f44336"
|
|
||||||
isOwner:
|
|
||||||
type: boolean
|
|
||||||
canReply:
|
|
||||||
type: boolean
|
|
||||||
groupChat:
|
|
||||||
type: boolean
|
|
||||||
usernames:
|
|
||||||
type: string
|
|
||||||
description: User-friendly depiction of the users within the chat room
|
|
||||||
maximumUsersInChatRoom:
|
|
||||||
type: number
|
|
||||||
maximumChatMessageLength:
|
|
||||||
type: number
|
|
||||||
showUserInput:
|
|
||||||
type: boolean
|
|
||||||
isAdminOrGlobalMod:
|
|
||||||
type: boolean
|
|
||||||
post:
|
post:
|
||||||
tags:
|
tags:
|
||||||
- chats
|
- chats
|
||||||
@@ -144,3 +90,39 @@ post:
|
|||||||
type: string
|
type: string
|
||||||
mid:
|
mid:
|
||||||
type: number
|
type: number
|
||||||
|
put:
|
||||||
|
tags:
|
||||||
|
- chats
|
||||||
|
summary: rename a chat room
|
||||||
|
description: This operation renames a chat room.
|
||||||
|
parameters:
|
||||||
|
- in: path
|
||||||
|
name: roomId
|
||||||
|
schema:
|
||||||
|
type: number
|
||||||
|
required: true
|
||||||
|
description: a valid room id
|
||||||
|
example: 1
|
||||||
|
requestBody:
|
||||||
|
required: true
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
description: the new name of the room
|
||||||
|
example: 'casper the friendly room'
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: Chat room renamed
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
status:
|
||||||
|
$ref: ../../components/schemas/Status.yaml#/Status
|
||||||
|
response:
|
||||||
|
$ref: ../../components/schemas/Chats.yaml#/RoomObjectFull
|
||||||
@@ -13,10 +13,12 @@ define('forum/chats', [
|
|||||||
'bootbox',
|
'bootbox',
|
||||||
'alerts',
|
'alerts',
|
||||||
'chat',
|
'chat',
|
||||||
|
'api',
|
||||||
], function (
|
], function (
|
||||||
components, translator, mousetrap,
|
components, translator, mousetrap,
|
||||||
recentChats, search, messages,
|
recentChats, search, messages,
|
||||||
autocomplete, hooks, bootbox, alerts, chatModule
|
autocomplete, hooks, bootbox, alerts, chatModule,
|
||||||
|
api
|
||||||
) {
|
) {
|
||||||
const Chats = {
|
const Chats = {
|
||||||
initialised: false,
|
initialised: false,
|
||||||
@@ -345,14 +347,9 @@ define('forum/chats', [
|
|||||||
});
|
});
|
||||||
|
|
||||||
function submit() {
|
function submit() {
|
||||||
socket.emit('modules.chats.renameRoom', {
|
api.put(`/chats/${roomId}`, {
|
||||||
roomId: roomId,
|
name: modal.find('#roomName').val(),
|
||||||
newName: modal.find('#roomName').val(),
|
}).catch(alerts.error);
|
||||||
}, function (err) {
|
|
||||||
if (err) {
|
|
||||||
alerts.error(err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const validator = require('validator');
|
||||||
|
|
||||||
const user = require('../user');
|
const user = require('../user');
|
||||||
const meta = require('../meta');
|
const meta = require('../meta');
|
||||||
const messaging = require('../messaging');
|
const messaging = require('../messaging');
|
||||||
const plugins = require('../plugins');
|
const plugins = require('../plugins');
|
||||||
|
|
||||||
// const websockets = require('../socket.io');
|
// const websockets = require('../socket.io');
|
||||||
// const socketHelpers = require('../socket.io/helpers');
|
const socketHelpers = require('../socket.io/helpers');
|
||||||
|
|
||||||
const chatsAPI = module.exports;
|
const chatsAPI = module.exports;
|
||||||
|
|
||||||
@@ -59,3 +61,14 @@ chatsAPI.post = async (caller, data) => {
|
|||||||
|
|
||||||
return message;
|
return message;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
chatsAPI.rename = async (caller, data) => {
|
||||||
|
await messaging.renameRoom(caller.uid, data.roomId, data.name);
|
||||||
|
const uids = await messaging.getUidsInRoom(data.roomId, 0, -1);
|
||||||
|
const eventData = { roomId: data.roomId, newName: validator.escape(String(data.name)) };
|
||||||
|
|
||||||
|
socketHelpers.emitToUids('event:chats.roomRename', eventData, uids);
|
||||||
|
return messaging.loadRoom(caller.uid, {
|
||||||
|
roomId: data.roomId,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -44,6 +44,15 @@ Chats.post = async (req, res) => {
|
|||||||
helpers.formatApiResponse(200, res, messageObj);
|
helpers.formatApiResponse(200, res, messageObj);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Chats.rename = async (req, res) => {
|
||||||
|
const roomObj = await api.chats.rename(req, {
|
||||||
|
...req.body,
|
||||||
|
roomId: req.params.roomId,
|
||||||
|
});
|
||||||
|
|
||||||
|
helpers.formatApiResponse(200, res, roomObj);
|
||||||
|
};
|
||||||
|
|
||||||
Chats.users = async (req, res) => {
|
Chats.users = async (req, res) => {
|
||||||
// ...
|
// ...
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ module.exports = function () {
|
|||||||
setupApiRoute(router, 'head', '/:roomId', [...middlewares, middleware.assert.room], controllers.write.chats.exists);
|
setupApiRoute(router, 'head', '/:roomId', [...middlewares, middleware.assert.room], controllers.write.chats.exists);
|
||||||
setupApiRoute(router, 'get', '/:roomId', [...middlewares, middleware.assert.room], controllers.write.chats.get);
|
setupApiRoute(router, 'get', '/:roomId', [...middlewares, middleware.assert.room], controllers.write.chats.get);
|
||||||
setupApiRoute(router, 'post', '/:roomId', [...middlewares, middleware.assert.room, middleware.checkRequired.bind(null, ['message'])], controllers.write.chats.post);
|
setupApiRoute(router, 'post', '/:roomId', [...middlewares, middleware.assert.room, middleware.checkRequired.bind(null, ['message'])], controllers.write.chats.post);
|
||||||
// // no route for room deletion, reserved just in case...
|
setupApiRoute(router, 'put', '/:roomId', [...middlewares, middleware.assert.room, middleware.checkRequired.bind(null, ['name'])], controllers.write.chats.rename);
|
||||||
|
// no route for room deletion, noted here just in case...
|
||||||
|
|
||||||
// setupApiRoute(router, 'get', '/:roomId/users', [...middlewares, middleware.assert.room], controllers.write.chats.users);
|
// setupApiRoute(router, 'get', '/:roomId/users', [...middlewares, middleware.assert.room], controllers.write.chats.users);
|
||||||
// setupApiRoute(router, 'put', '/:roomId/users', [...middlewares, middleware.assert.room, middleware.checkRequired.bind(null, ['uids'])], controllers.write.chats.invite);
|
// setupApiRoute(router, 'put', '/:roomId/users', [...middlewares, middleware.assert.room, middleware.checkRequired.bind(null, ['uids'])], controllers.write.chats.invite);
|
||||||
|
|||||||
@@ -203,15 +203,15 @@ SocketModules.chats.markAllRead = async function (socket) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SocketModules.chats.renameRoom = async function (socket, data) {
|
SocketModules.chats.renameRoom = async function (socket, data) {
|
||||||
|
sockets.warnDeprecated(socket, 'PUT /api/v3/chats/:roomId');
|
||||||
|
|
||||||
if (!data || !data.roomId || !data.newName) {
|
if (!data || !data.roomId || !data.newName) {
|
||||||
throw new Error('[[error:invalid-data]]');
|
throw new Error('[[error:invalid-data]]');
|
||||||
}
|
}
|
||||||
await Messaging.renameRoom(socket.uid, data.roomId, data.newName);
|
|
||||||
const uids = await Messaging.getUidsInRoom(data.roomId, 0, -1);
|
data.name = data.newName;
|
||||||
const eventData = { roomId: data.roomId, newName: validator.escape(String(data.newName)) };
|
delete data.newName;
|
||||||
uids.forEach((uid) => {
|
await api.chats.rename(socket, data);
|
||||||
server.in(`uid_${uid}`).emit('event:chats.roomRename', eventData);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketModules.chats.getRecentChats = async function (socket, data) {
|
SocketModules.chats.getRecentChats = async function (socket, data) {
|
||||||
|
|||||||
Reference in New Issue
Block a user