Browse Source

change del msg route

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

19
api/controllers/messages.ts

@ -92,20 +92,26 @@ const getAllMessages = async (req, res) => {
async function deleteMessage(req, res){
const id = parseInt(req.params.id)
const {chat_id} = req.body
const message = await models.Message.findOne({where:{id}})
const uuid = message.uuid
await message.update({status: constants.statuses.deleted})
success(res, {id})
const chat_id = message.chatId
let chat
if(chat_id) {
const chat = await models.Chat.findOne({where:{id:chat_id}})
chat = await models.Chat.findOne({where:{id:chat_id}})
}
success(res, jsonUtils.messageToJson(message, chat))
if(!chat) return
const isTribe = chat.type===constants.chat_types.tribe
if(isTribe){
if(!isTribe) return
const owner = await models.Contact.findOne({ where: { isOwner: true }})
const isTribeOwner = owner.publicKey===chat.ownerPubkey
if(isTribeOwner) {
if(!isTribeOwner) return
timers.removeTimerByMsgId(id)
network.sendMessage({
chat: chat,
@ -114,9 +120,6 @@ async function deleteMessage(req, res){
message: {id,uuid},
})
}
}
}
}
const sendMessage = async (req, res) => {
// try {

19
dist/api/controllers/messages.js

@ -88,18 +88,24 @@ exports.getAllMessages = getAllMessages;
function deleteMessage(req, res) {
return __awaiter(this, void 0, void 0, function* () {
const id = parseInt(req.params.id);
const { chat_id } = req.body;
const message = yield models_1.models.Message.findOne({ where: { id } });
const uuid = message.uuid;
yield message.update({ status: constants.statuses.deleted });
res_1.success(res, { id });
const chat_id = message.chatId;
let chat;
if (chat_id) {
const chat = yield models_1.models.Chat.findOne({ where: { id: chat_id } });
chat = yield models_1.models.Chat.findOne({ where: { id: chat_id } });
}
res_1.success(res, jsonUtils.messageToJson(message, chat));
if (!chat)
return;
const isTribe = chat.type === constants.chat_types.tribe;
if (isTribe) {
if (!isTribe)
return;
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
const isTribeOwner = owner.publicKey === chat.ownerPubkey;
if (isTribeOwner) {
if (!isTribeOwner)
return;
timers.removeTimerByMsgId(id);
network.sendMessage({
chat: chat,
@ -107,9 +113,6 @@ function deleteMessage(req, res) {
type: constants.message_types.delete,
message: { id, uuid },
});
}
}
}
});
}
exports.deleteMessage = deleteMessage;

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

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