The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/app/threads/server/functions.js

49 lines
1.4 KiB

import { Messages, Subscriptions } from '../../models/server';
export const reply = ({ tmid }, { rid, ts, u, editedAt }, parentMessage) => {
if (!tmid || editedAt) {
return false;
}
Messages.updateRepliesByThreadId(tmid, [parentMessage.u._id, u._id], ts);
const replies = Messages.getThreadFollowsByThreadId(tmid);
// doesnt need to update the sender (u._id) subscription, so filter it
Subscriptions.addUnreadThreadByRoomIdAndUserIds(rid, replies.filter((userId) => userId !== u._id), tmid);
};
export const undoReply = ({ tmid }) => {
if (!tmid) {
return false;
}
const { ts } = Messages.getFirstReplyTsByThreadId(tmid) || {};
if (!ts) {
return Messages.unsetThreadByThreadId(tmid);
}
return Messages.updateThreadLastMessageAndCountByThreadId(tmid, ts, -1);
};
export const follow = ({ tmid, uid }) => {
if (!tmid || !uid) {
return false;
}
Messages.addThreadFollowerByThreadId(tmid, uid);
};
export const unfollow = ({ tmid, rid, uid }) => {
if (!tmid || !uid) {
return false;
}
Subscriptions.removeUnreadThreadByRoomIdAndUserId(rid, uid, tmid);
return Messages.removeThreadFollowerByThreadId(tmid, uid);
};
export const readThread = ({ userId, rid, tmid }) => Subscriptions.removeUnreadThreadByRoomIdAndUserId(rid, userId, tmid);
export const readAllThreads = (rid, userId) => Subscriptions.removeAllUnreadThreadsByRoomIdAndUserId(rid, userId);