Browse Source

delete_messages in getMessages

bugfix/timeout-logging
Evan Feenstra 5 years ago
parent
commit
f0006f153a
  1. 14
      api/controllers/messages.ts
  2. 14
      dist/api/controllers/messages.js
  3. 2
      dist/api/controllers/messages.js.map

14
api/controllers/messages.ts

@ -36,6 +36,13 @@ const getMessages = async (req, res) => {
updated_at: { [Op.gte]: dateToReturn },
status: {[Op.or]: [
constants.statuses.received,
]},
sender: owner.id
}
let deletedMessagesWhere = {
updated_at: { [Op.gte]: dateToReturn },
status: {[Op.or]: [
constants.statuses.deleted
]},
sender: owner.id
@ -48,6 +55,7 @@ const getMessages = async (req, res) => {
const newMessages = await models.Message.findAll({ where: newMessagesWhere })
const confirmedMessages = await models.Message.findAll({ where: confirmedMessagesWhere })
const deletedMessages = await models.Message.findAll({ where: deletedMessagesWhere })
const chatIds: number[] = []
newMessages.forEach(m => {
@ -56,6 +64,9 @@ const getMessages = async (req, res) => {
confirmedMessages.forEach(m => {
if(!chatIds.includes(m.chatId)) chatIds.push(m.chatId)
})
deletedMessages.forEach(m => {
if(!chatIds.includes(m.chatId)) chatIds.push(m.chatId)
})
let chats = chatIds.length > 0 ? await models.Chat.findAll({ where: {deleted:false, id: chatIds} }) : []
const chatsById = indexBy(chats, 'id')
@ -68,6 +79,9 @@ const getMessages = async (req, res) => {
),
confirmed_messages: confirmedMessages.map(message =>
jsonUtils.messageToJson(message, chatsById[parseInt(message.chatId)])
),
deleted_messages: deletedMessages.map(message =>
jsonUtils.messageToJson(message, chatsById[parseInt(message.chatId)])
)
}
});

14
dist/api/controllers/messages.js

@ -42,6 +42,12 @@ const getMessages = (req, res) => __awaiter(void 0, void 0, void 0, function* ()
updated_at: { [sequelize_1.Op.gte]: dateToReturn },
status: { [sequelize_1.Op.or]: [
constants.statuses.received,
] },
sender: owner.id
};
let deletedMessagesWhere = {
updated_at: { [sequelize_1.Op.gte]: dateToReturn },
status: { [sequelize_1.Op.or]: [
constants.statuses.deleted
] },
sender: owner.id
@ -52,6 +58,7 @@ const getMessages = (req, res) => __awaiter(void 0, void 0, void 0, function* ()
// }
const newMessages = yield models_1.models.Message.findAll({ where: newMessagesWhere });
const confirmedMessages = yield models_1.models.Message.findAll({ where: confirmedMessagesWhere });
const deletedMessages = yield models_1.models.Message.findAll({ where: deletedMessagesWhere });
const chatIds = [];
newMessages.forEach(m => {
if (!chatIds.includes(m.chatId))
@ -61,13 +68,18 @@ const getMessages = (req, res) => __awaiter(void 0, void 0, void 0, function* ()
if (!chatIds.includes(m.chatId))
chatIds.push(m.chatId);
});
deletedMessages.forEach(m => {
if (!chatIds.includes(m.chatId))
chatIds.push(m.chatId);
});
let chats = chatIds.length > 0 ? yield models_1.models.Chat.findAll({ where: { deleted: false, id: chatIds } }) : [];
const chatsById = underscore_1.indexBy(chats, 'id');
res.json({
success: true,
response: {
new_messages: newMessages.map(message => jsonUtils.messageToJson(message, chatsById[parseInt(message.chatId)])),
confirmed_messages: confirmedMessages.map(message => jsonUtils.messageToJson(message, chatsById[parseInt(message.chatId)]))
confirmed_messages: confirmedMessages.map(message => jsonUtils.messageToJson(message, chatsById[parseInt(message.chatId)])),
deleted_messages: deletedMessages.map(message => jsonUtils.messageToJson(message, chatsById[parseInt(message.chatId)]))
}
});
res.status(200);

2
dist/api/controllers/messages.js.map

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save