Files
NodeBB/src/socket.io/modules.js

226 lines
6.2 KiB
JavaScript
Raw Normal View History

2017-02-18 01:56:23 -07:00
'use strict';
2017-02-18 02:28:54 -07:00
2023-11-15 10:36:39 -05:00
/**
* v4 note all methods here are deprecated and can be removed except for:
* - SocketModules.chats.(enter|leave)(Public)? => related to socket.io rooms
*/
2019-09-15 02:14:51 -04:00
const Messaging = require('../messaging');
const utils = require('../utils');
const user = require('../user');
2023-07-12 20:43:53 -04:00
const groups = require('../groups');
const api = require('../api');
const sockets = require('.');
2019-09-15 02:14:51 -04:00
const SocketModules = module.exports;
2017-05-20 20:03:41 -04:00
SocketModules.chats = {};
SocketModules.settings = {};
2014-01-10 16:00:03 -05:00
/* Chat */
2019-09-15 02:14:51 -04:00
SocketModules.chats.getRaw = async function (socket, data) {
sockets.warnDeprecated(socket, 'GET /api/v3/chats/:roomId/messages/:mid/raw');
2017-11-29 11:46:30 -05:00
if (!data || !data.hasOwnProperty('mid')) {
2019-09-15 02:14:51 -04:00
throw new Error('[[error:invalid-data]]');
Squashed commit of the following: Closes #2668 commit 3d4f494ed3257bceda8f6f82057cab83f0f252b3 Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 12:06:42 2015 -0500 theme minvers for #2668 commit b608ce61854f8195143685bb9753b80d32b26e95 Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 12:01:03 2015 -0500 Allowing chat modal to edit and delete messages re: #2668 commit 0104db90a4070582f3938b6929dae35f985bac35 Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 11:51:23 2015 -0500 Fixed issue where newSet calculations were off ... sometimes. Also, rendering of edited messages now parses a template partial, instead of just replacing the content. commit 5cb6ca600425ca9320c599b32306e93dcc5aa4ce Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 11:07:12 2015 -0500 If edited content matches existing content... ... then edit is aborted. commit 6e7495247b1895589c716db29f919a934087b924 Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 11:05:08 2015 -0500 some linting and fixed issue where new msgs when deleted would crash server commit db4a9e40d6dff44569c2437378121db8fdf75cf8 Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 17:25:56 2015 -0500 Message deletion for #2668, and fixed bug Fixed bug where chat modal would spawn even though user was sitting on the /chats page. commit a5aa2498ab4a8bba02a6daa43a9dbed7b3e37976 Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 14:55:23 2015 -0500 wiring up the edit button, #2668 commit 5f2afdcf6f2b9eae6b5873ca100149e65e3d385d Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 14:20:39 2015 -0500 added indicator to show if and when a message had been edited commit e8301132d525c1b9fd46c98cdb282ac7ea7a0d7f Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 14:06:39 2015 -0500 Allowing editing of chat messages commit bfd991be1cb1769599f7d5d2b1638e313c3c2dcb Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 10:33:49 2015 -0500 Added messageId to messages object return commit 0306ee6657b3288dd4547c66869d7d4ece0b31ad Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 08:20:17 2015 -0500 WIP #2668
2015-12-11 12:07:02 -05:00
}
2019-09-15 02:14:51 -04:00
const roomId = await Messaging.getMessageField(data.mid, 'roomId');
const { content } = await api.chats.getRawMessage(socket, {
mid: data.mid,
roomId,
});
return content;
Squashed commit of the following: Closes #2668 commit 3d4f494ed3257bceda8f6f82057cab83f0f252b3 Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 12:06:42 2015 -0500 theme minvers for #2668 commit b608ce61854f8195143685bb9753b80d32b26e95 Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 12:01:03 2015 -0500 Allowing chat modal to edit and delete messages re: #2668 commit 0104db90a4070582f3938b6929dae35f985bac35 Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 11:51:23 2015 -0500 Fixed issue where newSet calculations were off ... sometimes. Also, rendering of edited messages now parses a template partial, instead of just replacing the content. commit 5cb6ca600425ca9320c599b32306e93dcc5aa4ce Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 11:07:12 2015 -0500 If edited content matches existing content... ... then edit is aborted. commit 6e7495247b1895589c716db29f919a934087b924 Author: Julian Lam <julian@designcreateplay.com> Date: Fri Dec 11 11:05:08 2015 -0500 some linting and fixed issue where new msgs when deleted would crash server commit db4a9e40d6dff44569c2437378121db8fdf75cf8 Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 17:25:56 2015 -0500 Message deletion for #2668, and fixed bug Fixed bug where chat modal would spawn even though user was sitting on the /chats page. commit a5aa2498ab4a8bba02a6daa43a9dbed7b3e37976 Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 14:55:23 2015 -0500 wiring up the edit button, #2668 commit 5f2afdcf6f2b9eae6b5873ca100149e65e3d385d Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 14:20:39 2015 -0500 added indicator to show if and when a message had been edited commit e8301132d525c1b9fd46c98cdb282ac7ea7a0d7f Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 14:06:39 2015 -0500 Allowing editing of chat messages commit bfd991be1cb1769599f7d5d2b1638e313c3c2dcb Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 10:33:49 2015 -0500 Added messageId to messages object return commit 0306ee6657b3288dd4547c66869d7d4ece0b31ad Author: Julian Lam <julian@designcreateplay.com> Date: Tue Dec 8 08:20:17 2015 -0500 WIP #2668
2015-12-11 12:07:02 -05:00
};
2019-09-15 02:14:51 -04:00
SocketModules.chats.isDnD = async function (socket, uid) {
sockets.warnDeprecated(socket, 'GET /api/v3/users/:uid/status OR HEAD /api/v3/users/:uid/status/:status');
const { status } = await api.users.getStatus(socket, { uid });
2019-09-15 02:14:51 -04:00
return status === 'dnd';
2017-04-14 10:08:50 -04:00
};
2019-09-15 02:14:51 -04:00
SocketModules.chats.canMessage = async function (socket, roomId) {
sockets.warnDeprecated(socket);
2019-09-15 02:14:51 -04:00
await Messaging.canMessageRoom(socket.uid, roomId);
2014-01-10 16:00:03 -05:00
};
2019-09-15 02:14:51 -04:00
SocketModules.chats.markAllRead = async function (socket) {
sockets.warnDeprecated(socket);
2019-09-15 02:14:51 -04:00
await Messaging.markAllRead(socket.uid);
Messaging.pushUnreadCount(socket.uid);
2016-03-11 13:38:52 +02:00
};
2019-09-15 02:14:51 -04:00
SocketModules.chats.getRecentChats = async function (socket, data) {
sockets.warnDeprecated(socket, 'GET /api/v3/chats');
2016-10-03 20:35:36 +03:00
if (!data || !utils.isNumber(data.after) || !utils.isNumber(data.uid)) {
2019-09-15 02:14:51 -04:00
throw new Error('[[error:invalid-data]]');
2014-09-15 16:26:25 -04:00
}
2019-09-15 02:14:51 -04:00
const start = parseInt(data.after, 10);
const stop = start + 9;
const { uid } = data;
return api.chats.list(socket, { uid, start, stop });
2014-01-10 16:00:03 -05:00
};
2019-09-15 02:14:51 -04:00
SocketModules.chats.hasPrivateChat = async function (socket, uid) {
sockets.warnDeprecated(socket, 'GET /api/v3/users/:uid/chat');
2018-11-17 22:31:39 -05:00
if (socket.uid <= 0 || uid <= 0) {
2019-09-15 02:14:51 -04:00
throw new Error('[[error:invalid-data]]');
2016-01-18 15:35:24 +02:00
}
// despite the `has` prefix, this method actually did return the roomId.
const { roomId } = await api.users.getPrivateRoomId(socket, { uid });
return roomId;
2016-01-18 15:35:24 +02:00
};
2014-01-10 16:00:03 -05:00
2019-09-15 02:14:51 -04:00
SocketModules.chats.getIP = async function (socket, mid) {
sockets.warnDeprecated(socket, 'GET /api/v3/chats/:roomId/messages/:mid/ip');
const { ip } = await api.chats.getIpAddress(socket, { mid });
return ip;
2018-05-31 15:05:12 -04:00
};
Chat refactor (#11779) * first part of chat refactor remove per user chat zsets & store all mids in chat:room:<roomId>:mids reverse uids in getUidsInRoom * feat: create room button public groups wip * feat: public rooms create chats:room zset chat room deletion * join socket.io room * get rid of some calls that load all users in room * dont load all users when loadRoom is called * mange room users infinitescroll dont load all members in api call * IS for user list ability to change groups field for public rooms update groups field if group is renamed * test: test fixes * wip * keep 150 messages * fix extra awaits fix dupe code in chat toggleReadState * unread state for public rooms * feat: faster push unread * test: spec * change base to harmony * test: lint fixes * fix language of chat with message * add 2 methods for perf messaging.getTeasers and getUsers(roomIds) instead of loading one by one * refactor: cleaner conditional * test fix upgrade script fix save timestamp of room creation in room object * set progress.total * don't check for guests/spiders * public room unread fix * add public unread counts * mark read on send * ignore instead of throwing * doggy.gif * fix: restore delete * prevent entering chat rooms with meta.enter * fix self message causing mark unread * ability to sort public rooms * dont init sortable on mobile * move chat-loaded class to core * test: fix spec * add missing keys * use ajaxify * refactor: store some refs * fix: when user is deleted remove from public rooms as well * feat: change how unread count is calculated * get rid of cleaned content get rid of mid * add help text * test: fix tests, add back mid to prevent breaking change * ability to search members of chat rooms * remove * derp * perf: switch with partial data fix tests * more fixes if user leaves a group leave public rooms is he is no longer part of any of the groups that have access fix the cache key used to get all public room ids dont allow joining chat socket.io room if user is no longer part of group * fix: lint * fix: js error when trying to delete room after switching * add isRoomPublic
2023-07-12 13:03:54 -04:00
SocketModules.chats.getUnreadCount = async function (socket) {
sockets.warnDeprecated(socket, 'GET /api/v3/chats/unread');
const { count } = await api.chats.getUnread(socket);
return count;
Chat refactor (#11779) * first part of chat refactor remove per user chat zsets & store all mids in chat:room:<roomId>:mids reverse uids in getUidsInRoom * feat: create room button public groups wip * feat: public rooms create chats:room zset chat room deletion * join socket.io room * get rid of some calls that load all users in room * dont load all users when loadRoom is called * mange room users infinitescroll dont load all members in api call * IS for user list ability to change groups field for public rooms update groups field if group is renamed * test: test fixes * wip * keep 150 messages * fix extra awaits fix dupe code in chat toggleReadState * unread state for public rooms * feat: faster push unread * test: spec * change base to harmony * test: lint fixes * fix language of chat with message * add 2 methods for perf messaging.getTeasers and getUsers(roomIds) instead of loading one by one * refactor: cleaner conditional * test fix upgrade script fix save timestamp of room creation in room object * set progress.total * don't check for guests/spiders * public room unread fix * add public unread counts * mark read on send * ignore instead of throwing * doggy.gif * fix: restore delete * prevent entering chat rooms with meta.enter * fix self message causing mark unread * ability to sort public rooms * dont init sortable on mobile * move chat-loaded class to core * test: fix spec * add missing keys * use ajaxify * refactor: store some refs * fix: when user is deleted remove from public rooms as well * feat: change how unread count is calculated * get rid of cleaned content get rid of mid * add help text * test: fix tests, add back mid to prevent breaking change * ability to search members of chat rooms * remove * derp * perf: switch with partial data fix tests * more fixes if user leaves a group leave public rooms is he is no longer part of any of the groups that have access fix the cache key used to get all public room ids dont allow joining chat socket.io room if user is no longer part of group * fix: lint * fix: js error when trying to delete room after switching * add isRoomPublic
2023-07-12 13:03:54 -04:00
};
SocketModules.chats.enter = async function (socket, roomIds) {
await joinLeave(socket, roomIds, 'join');
};
SocketModules.chats.leave = async function (socket, roomIds) {
await joinLeave(socket, roomIds, 'leave');
};
SocketModules.chats.enterPublic = async function (socket, roomIds) {
await joinLeave(socket, roomIds, 'join', 'chat_room_public');
};
SocketModules.chats.leavePublic = async function (socket, roomIds) {
await joinLeave(socket, roomIds, 'leave', 'chat_room_public');
};
async function joinLeave(socket, roomIds, method, prefix = 'chat_room') {
if (!(socket.uid > 0)) {
throw new Error('[[error:not-allowed]]');
}
if (!Array.isArray(roomIds)) {
roomIds = [roomIds];
}
if (roomIds.length) {
const [isAdmin, inRooms, roomData] = await Promise.all([
user.isAdministrator(socket.uid),
Messaging.isUserInRoom(socket.uid, roomIds),
Messaging.getRoomsData(roomIds, ['public', 'groups']),
]);
2023-07-14 13:01:41 -04:00
Chat refactor (#11779) * first part of chat refactor remove per user chat zsets & store all mids in chat:room:<roomId>:mids reverse uids in getUidsInRoom * feat: create room button public groups wip * feat: public rooms create chats:room zset chat room deletion * join socket.io room * get rid of some calls that load all users in room * dont load all users when loadRoom is called * mange room users infinitescroll dont load all members in api call * IS for user list ability to change groups field for public rooms update groups field if group is renamed * test: test fixes * wip * keep 150 messages * fix extra awaits fix dupe code in chat toggleReadState * unread state for public rooms * feat: faster push unread * test: spec * change base to harmony * test: lint fixes * fix language of chat with message * add 2 methods for perf messaging.getTeasers and getUsers(roomIds) instead of loading one by one * refactor: cleaner conditional * test fix upgrade script fix save timestamp of room creation in room object * set progress.total * don't check for guests/spiders * public room unread fix * add public unread counts * mark read on send * ignore instead of throwing * doggy.gif * fix: restore delete * prevent entering chat rooms with meta.enter * fix self message causing mark unread * ability to sort public rooms * dont init sortable on mobile * move chat-loaded class to core * test: fix spec * add missing keys * use ajaxify * refactor: store some refs * fix: when user is deleted remove from public rooms as well * feat: change how unread count is calculated * get rid of cleaned content get rid of mid * add help text * test: fix tests, add back mid to prevent breaking change * ability to search members of chat rooms * remove * derp * perf: switch with partial data fix tests * more fixes if user leaves a group leave public rooms is he is no longer part of any of the groups that have access fix the cache key used to get all public room ids dont allow joining chat socket.io room if user is no longer part of group * fix: lint * fix: js error when trying to delete room after switching * add isRoomPublic
2023-07-12 13:03:54 -04:00
await Promise.all(roomIds.map(async (roomId, idx) => {
const isPublic = roomData[idx] && roomData[idx].public;
2023-07-12 20:43:53 -04:00
const roomGroups = roomData[idx] && roomData[idx].groups;
if (isAdmin ||
(
inRooms[idx] &&
(!isPublic || !roomGroups.length || await groups.isMemberOfAny(socket.uid, roomGroups))
)
) {
Chat refactor (#11779) * first part of chat refactor remove per user chat zsets & store all mids in chat:room:<roomId>:mids reverse uids in getUidsInRoom * feat: create room button public groups wip * feat: public rooms create chats:room zset chat room deletion * join socket.io room * get rid of some calls that load all users in room * dont load all users when loadRoom is called * mange room users infinitescroll dont load all members in api call * IS for user list ability to change groups field for public rooms update groups field if group is renamed * test: test fixes * wip * keep 150 messages * fix extra awaits fix dupe code in chat toggleReadState * unread state for public rooms * feat: faster push unread * test: spec * change base to harmony * test: lint fixes * fix language of chat with message * add 2 methods for perf messaging.getTeasers and getUsers(roomIds) instead of loading one by one * refactor: cleaner conditional * test fix upgrade script fix save timestamp of room creation in room object * set progress.total * don't check for guests/spiders * public room unread fix * add public unread counts * mark read on send * ignore instead of throwing * doggy.gif * fix: restore delete * prevent entering chat rooms with meta.enter * fix self message causing mark unread * ability to sort public rooms * dont init sortable on mobile * move chat-loaded class to core * test: fix spec * add missing keys * use ajaxify * refactor: store some refs * fix: when user is deleted remove from public rooms as well * feat: change how unread count is calculated * get rid of cleaned content get rid of mid * add help text * test: fix tests, add back mid to prevent breaking change * ability to search members of chat rooms * remove * derp * perf: switch with partial data fix tests * more fixes if user leaves a group leave public rooms is he is no longer part of any of the groups that have access fix the cache key used to get all public room ids dont allow joining chat socket.io room if user is no longer part of group * fix: lint * fix: js error when trying to delete room after switching * add isRoomPublic
2023-07-12 13:03:54 -04:00
socket[method](`${prefix}_${roomId}`);
}
}));
}
}
SocketModules.chats.sortPublicRooms = async function (socket, data) {
sockets.warnDeprecated(socket, 'PUT /api/v3/chats/sort');
if (!data) {
Chat refactor (#11779) * first part of chat refactor remove per user chat zsets & store all mids in chat:room:<roomId>:mids reverse uids in getUidsInRoom * feat: create room button public groups wip * feat: public rooms create chats:room zset chat room deletion * join socket.io room * get rid of some calls that load all users in room * dont load all users when loadRoom is called * mange room users infinitescroll dont load all members in api call * IS for user list ability to change groups field for public rooms update groups field if group is renamed * test: test fixes * wip * keep 150 messages * fix extra awaits fix dupe code in chat toggleReadState * unread state for public rooms * feat: faster push unread * test: spec * change base to harmony * test: lint fixes * fix language of chat with message * add 2 methods for perf messaging.getTeasers and getUsers(roomIds) instead of loading one by one * refactor: cleaner conditional * test fix upgrade script fix save timestamp of room creation in room object * set progress.total * don't check for guests/spiders * public room unread fix * add public unread counts * mark read on send * ignore instead of throwing * doggy.gif * fix: restore delete * prevent entering chat rooms with meta.enter * fix self message causing mark unread * ability to sort public rooms * dont init sortable on mobile * move chat-loaded class to core * test: fix spec * add missing keys * use ajaxify * refactor: store some refs * fix: when user is deleted remove from public rooms as well * feat: change how unread count is calculated * get rid of cleaned content get rid of mid * add help text * test: fix tests, add back mid to prevent breaking change * ability to search members of chat rooms * remove * derp * perf: switch with partial data fix tests * more fixes if user leaves a group leave public rooms is he is no longer part of any of the groups that have access fix the cache key used to get all public room ids dont allow joining chat socket.io room if user is no longer part of group * fix: lint * fix: js error when trying to delete room after switching * add isRoomPublic
2023-07-12 13:03:54 -04:00
throw new Error('[[error:invalid-data]]');
}
await api.chats.sortPublicRooms(socket, data);
Chat refactor (#11779) * first part of chat refactor remove per user chat zsets & store all mids in chat:room:<roomId>:mids reverse uids in getUidsInRoom * feat: create room button public groups wip * feat: public rooms create chats:room zset chat room deletion * join socket.io room * get rid of some calls that load all users in room * dont load all users when loadRoom is called * mange room users infinitescroll dont load all members in api call * IS for user list ability to change groups field for public rooms update groups field if group is renamed * test: test fixes * wip * keep 150 messages * fix extra awaits fix dupe code in chat toggleReadState * unread state for public rooms * feat: faster push unread * test: spec * change base to harmony * test: lint fixes * fix language of chat with message * add 2 methods for perf messaging.getTeasers and getUsers(roomIds) instead of loading one by one * refactor: cleaner conditional * test fix upgrade script fix save timestamp of room creation in room object * set progress.total * don't check for guests/spiders * public room unread fix * add public unread counts * mark read on send * ignore instead of throwing * doggy.gif * fix: restore delete * prevent entering chat rooms with meta.enter * fix self message causing mark unread * ability to sort public rooms * dont init sortable on mobile * move chat-loaded class to core * test: fix spec * add missing keys * use ajaxify * refactor: store some refs * fix: when user is deleted remove from public rooms as well * feat: change how unread count is calculated * get rid of cleaned content get rid of mid * add help text * test: fix tests, add back mid to prevent breaking change * ability to search members of chat rooms * remove * derp * perf: switch with partial data fix tests * more fixes if user leaves a group leave public rooms is he is no longer part of any of the groups that have access fix the cache key used to get all public room ids dont allow joining chat socket.io room if user is no longer part of group * fix: lint * fix: js error when trying to delete room after switching * add isRoomPublic
2023-07-12 13:03:54 -04:00
};
SocketModules.chats.searchMembers = async function (socket, data) {
sockets.warnDeprecated(socket, 'GET /api/v3/search/chats/:roomId/users?query=');
Chat refactor (#11779) * first part of chat refactor remove per user chat zsets & store all mids in chat:room:<roomId>:mids reverse uids in getUidsInRoom * feat: create room button public groups wip * feat: public rooms create chats:room zset chat room deletion * join socket.io room * get rid of some calls that load all users in room * dont load all users when loadRoom is called * mange room users infinitescroll dont load all members in api call * IS for user list ability to change groups field for public rooms update groups field if group is renamed * test: test fixes * wip * keep 150 messages * fix extra awaits fix dupe code in chat toggleReadState * unread state for public rooms * feat: faster push unread * test: spec * change base to harmony * test: lint fixes * fix language of chat with message * add 2 methods for perf messaging.getTeasers and getUsers(roomIds) instead of loading one by one * refactor: cleaner conditional * test fix upgrade script fix save timestamp of room creation in room object * set progress.total * don't check for guests/spiders * public room unread fix * add public unread counts * mark read on send * ignore instead of throwing * doggy.gif * fix: restore delete * prevent entering chat rooms with meta.enter * fix self message causing mark unread * ability to sort public rooms * dont init sortable on mobile * move chat-loaded class to core * test: fix spec * add missing keys * use ajaxify * refactor: store some refs * fix: when user is deleted remove from public rooms as well * feat: change how unread count is calculated * get rid of cleaned content get rid of mid * add help text * test: fix tests, add back mid to prevent breaking change * ability to search members of chat rooms * remove * derp * perf: switch with partial data fix tests * more fixes if user leaves a group leave public rooms is he is no longer part of any of the groups that have access fix the cache key used to get all public room ids dont allow joining chat socket.io room if user is no longer part of group * fix: lint * fix: js error when trying to delete room after switching * add isRoomPublic
2023-07-12 13:03:54 -04:00
if (!data || !data.roomId) {
throw new Error('[[error:invalid-data]]');
}
// parameter renamed; backwards compatibility
data.query = data.username;
delete data.username;
return await api.search.roomUsers(socket, data);
Chat refactor (#11779) * first part of chat refactor remove per user chat zsets & store all mids in chat:room:<roomId>:mids reverse uids in getUidsInRoom * feat: create room button public groups wip * feat: public rooms create chats:room zset chat room deletion * join socket.io room * get rid of some calls that load all users in room * dont load all users when loadRoom is called * mange room users infinitescroll dont load all members in api call * IS for user list ability to change groups field for public rooms update groups field if group is renamed * test: test fixes * wip * keep 150 messages * fix extra awaits fix dupe code in chat toggleReadState * unread state for public rooms * feat: faster push unread * test: spec * change base to harmony * test: lint fixes * fix language of chat with message * add 2 methods for perf messaging.getTeasers and getUsers(roomIds) instead of loading one by one * refactor: cleaner conditional * test fix upgrade script fix save timestamp of room creation in room object * set progress.total * don't check for guests/spiders * public room unread fix * add public unread counts * mark read on send * ignore instead of throwing * doggy.gif * fix: restore delete * prevent entering chat rooms with meta.enter * fix self message causing mark unread * ability to sort public rooms * dont init sortable on mobile * move chat-loaded class to core * test: fix spec * add missing keys * use ajaxify * refactor: store some refs * fix: when user is deleted remove from public rooms as well * feat: change how unread count is calculated * get rid of cleaned content get rid of mid * add help text * test: fix tests, add back mid to prevent breaking change * ability to search members of chat rooms * remove * derp * perf: switch with partial data fix tests * more fixes if user leaves a group leave public rooms is he is no longer part of any of the groups that have access fix the cache key used to get all public room ids dont allow joining chat socket.io room if user is no longer part of group * fix: lint * fix: js error when trying to delete room after switching * add isRoomPublic
2023-07-12 13:03:54 -04:00
};
SocketModules.chats.toggleOwner = async (socket, data) => {
sockets.warnDeprecated(socket, 'PUT/DELETE /api/v3/chats/:roomId/owners/:uid');
if (!data || !data.uid || !data.roomId) {
throw new Error('[[error:invalid-data]]');
}
await api.chats.toggleOwner(socket, data);
};
SocketModules.chats.setNotificationSetting = async (socket, data) => {
sockets.warnDeprecated(socket, 'PUT/DELETE /api/v3/chats/:roomId/watch');
if (!data || !utils.isNumber(data.value) || !data.roomId) {
throw new Error('[[error:invalid-data]]');
}
await api.chats.watch(socket, data);
};
2023-07-28 10:56:25 -04:00
SocketModules.chats.searchMessages = async (socket, data) => {
sockets.warnDeprecated(socket, 'GET /api/v3/search/chats/:roomId/messages');
2023-07-28 10:56:25 -04:00
if (!data || !utils.isNumber(data.roomId) || !data.content) {
throw new Error('[[error:invalid-data]]');
}
// parameter renamed; backwards compatibility
data.query = data.content;
delete data.content;
return await api.search.roomMessages(socket, data);
2023-07-28 10:56:25 -04:00
};
2023-08-28 15:57:30 -04:00
SocketModules.chats.loadPinnedMessages = async (socket, data) => {
sockets.warnDeprecated(socket, 'GET /api/v3/chats/:roomId/messages/pinned');
2023-08-28 15:57:30 -04:00
if (!data || !data.roomId || !utils.isNumber(data.start)) {
throw new Error('[[error:invalid-data]]');
}
const { messages } = await api.chats.getPinnedMessages(socket, data);
return messages;
2023-08-28 15:57:30 -04:00
};
2023-09-02 21:18:00 -04:00
SocketModules.chats.typing = async (socket, data) => {
sockets.warnDeprecated(socket, 'PUT /api/v3/chats/:roomId/typing');
if (!data) {
2023-09-02 21:18:00 -04:00
throw new Error('[[error:invalid-data]]');
}
// `username` is now inferred from caller uid
delete data.username;
await api.chats.toggleTyping(socket, data);
2023-09-02 21:18:00 -04:00
};
2023-08-28 15:57:30 -04:00
2019-09-15 02:14:51 -04:00
require('../promisify')(SocketModules);