mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
refactor(socket.io): deprecate SocketModules.chat.getUnreadCount in favour of api.chats.getUnread
This commit is contained in:
@@ -192,6 +192,8 @@ paths:
|
||||
$ref: 'write/posts/pid/replies.yaml'
|
||||
/chats/:
|
||||
$ref: 'write/chats.yaml'
|
||||
/chats/unread:
|
||||
$ref: 'write/chats/unread.yaml'
|
||||
/chats/{roomId}:
|
||||
$ref: 'write/chats/roomId.yaml'
|
||||
/chats/{roomId}/state:
|
||||
|
||||
24
public/openapi/write/chats/unread.yaml
Normal file
24
public/openapi/write/chats/unread.yaml
Normal file
@@ -0,0 +1,24 @@
|
||||
get:
|
||||
tags:
|
||||
- chats
|
||||
summary: get unread count
|
||||
description: >
|
||||
This operation retrieves the calling user's count of unread chat rooms.
|
||||
|
||||
Note that this API call is open-ended.
|
||||
It currently only returns the unread count, but can be expanded upon in the future.
|
||||
responses:
|
||||
'200':
|
||||
description: Count of unread chat rooms successfully retrieved.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
status:
|
||||
$ref: ../../components/schemas/Status.yaml#/Status
|
||||
response:
|
||||
type: object
|
||||
properties:
|
||||
count:
|
||||
type: number
|
||||
@@ -1,8 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
define('forum/header/chat', [
|
||||
'components', 'hooks',
|
||||
], function (components, hooks) {
|
||||
'components', 'hooks', 'api',
|
||||
], function (components, hooks, api) {
|
||||
const chat = {};
|
||||
|
||||
chat.prepareDOM = function () {
|
||||
@@ -44,7 +44,7 @@ define('forum/header/chat', [
|
||||
chatPage.markChatPageElUnread(data);
|
||||
}
|
||||
|
||||
let count = await socket.emit('modules.chats.getUnreadCount', {});
|
||||
let { count } = await api.get('/chats/unread');
|
||||
const chatIcon = components.get('chat/icon');
|
||||
count = Math.max(0, count);
|
||||
chatIcon.toggleClass('fa-comment', count > 0)
|
||||
|
||||
@@ -79,6 +79,11 @@ chatsAPI.create = async function (caller, data) {
|
||||
return await messaging.getRoomData(roomId);
|
||||
};
|
||||
|
||||
chatsAPI.getUnread = async (caller) => {
|
||||
const count = await messaging.getUnreadCount(caller.uid);
|
||||
return { count };
|
||||
};
|
||||
|
||||
chatsAPI.get = async (caller, { uid, roomId }) => await messaging.loadRoom(caller.uid, { uid, roomId });
|
||||
|
||||
chatsAPI.post = async (caller, data) => {
|
||||
|
||||
@@ -29,6 +29,9 @@ Chats.create = async (req, res) => {
|
||||
helpers.formatApiResponse(200, res, roomObj);
|
||||
};
|
||||
|
||||
// currently only returns unread count, but open-ended for future additions if warranted.
|
||||
Chats.getUnread = async (req, res) => helpers.formatApiResponse(200, res, await api.chats.getUnread(req));
|
||||
|
||||
Chats.exists = async (req, res) => {
|
||||
// yes, this is fine. Room existence is checked via middleware :)
|
||||
helpers.formatApiResponse(200, res);
|
||||
|
||||
@@ -13,6 +13,8 @@ module.exports = function () {
|
||||
setupApiRoute(router, 'get', '/', [...middlewares], controllers.write.chats.list);
|
||||
setupApiRoute(router, 'post', '/', [...middlewares, middleware.checkRequired.bind(null, ['uids'])], controllers.write.chats.create);
|
||||
|
||||
setupApiRoute(router, 'get', '/unread', [...middlewares], controllers.write.chats.getUnread);
|
||||
|
||||
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, 'post', '/:roomId', [...middlewares, middleware.assert.room, middleware.checkRequired.bind(null, ['message'])], controllers.write.chats.post);
|
||||
|
||||
@@ -90,7 +90,10 @@ SocketModules.chats.getIP = async function (socket, mid) {
|
||||
};
|
||||
|
||||
SocketModules.chats.getUnreadCount = async function (socket) {
|
||||
return await Messaging.getUnreadCount(socket.uid);
|
||||
sockets.warnDeprecated(socket, 'GET /api/v3/chats/unread');
|
||||
|
||||
const { count } = await api.chats.getUnread(socket);
|
||||
return count;
|
||||
};
|
||||
|
||||
SocketModules.chats.enter = async function (socket, roomIds) {
|
||||
|
||||
Reference in New Issue
Block a user