|
@@ -158,11 +158,30 @@ const seenChat = async (req, res, next) => {
|
|
|
const id = req.body.id;
|
|
|
const userId = req.user.id;
|
|
|
const isChat = await ChatModel.getByField(id, userId);
|
|
|
+ const isCompanionChat = await ChatModel.getByField(userId, id);
|
|
|
const isMessage = await MessageModel.getList(userId, {});
|
|
|
- if (isChat && isMessage) {
|
|
|
- const { _id } = isChat;
|
|
|
+ if (isChat && isMessage && isCompanionChat) {
|
|
|
const { total } = isMessage;
|
|
|
- await ChatModel.update(_id, { seen: total });
|
|
|
+ await ChatModel.update(isChat._id, { seen: total, watched: false });
|
|
|
+ await ChatModel.update(isCompanionChat._id, { watched: true });
|
|
|
+ return res.status(200).json({
|
|
|
+ status: 'success',
|
|
|
+ code: 200,
|
|
|
+ data: {},
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ next(e);
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+const typingChat = async (req, res, next) => {
|
|
|
+ try {
|
|
|
+ const { id, typing } = req.body;
|
|
|
+ const userId = req.user.id;
|
|
|
+ const isCompanionChat = await ChatModel.getByField(userId, id);
|
|
|
+ if (isCompanionChat) {
|
|
|
+ await ChatModel.update(isCompanionChat._id, { typing });
|
|
|
return res.status(200).json({
|
|
|
status: 'success',
|
|
|
code: 200,
|
|
@@ -189,6 +208,8 @@ const chatById = async (req, res, next) => {
|
|
|
mute,
|
|
|
seen,
|
|
|
total,
|
|
|
+ watched,
|
|
|
+ typing,
|
|
|
number,
|
|
|
_id,
|
|
|
companionId,
|
|
@@ -209,6 +230,8 @@ const chatById = async (req, res, next) => {
|
|
|
mute,
|
|
|
seen,
|
|
|
total,
|
|
|
+ watched,
|
|
|
+ typing,
|
|
|
number,
|
|
|
_id,
|
|
|
companionId,
|
|
@@ -229,5 +252,6 @@ module.exports = {
|
|
|
startChat,
|
|
|
muteChat,
|
|
|
seenChat,
|
|
|
+ typingChat,
|
|
|
chatById,
|
|
|
};
|