Browse Source

only forward delete if from og poster

bugfix/timeout-logging
Evan Feenstra 5 years ago
parent
commit
7975c9fba2
  1. 17
      api/network/receive.ts
  2. 18
      dist/api/network/receive.js
  3. 2
      dist/api/network/receive.js.map

17
api/network/receive.ts

@ -23,7 +23,7 @@ const constants = require(path.join(__dirname,'../../config/constants.json'))
const msgtypes = constants.message_types const msgtypes = constants.message_types
export const typesToForward=[ export const typesToForward=[
msgtypes.message, msgtypes.group_join, msgtypes.group_leave, msgtypes.attachment msgtypes.message, msgtypes.group_join, msgtypes.group_leave, msgtypes.attachment, msgtypes.delete
] ]
const typesToModify=[ const typesToModify=[
msgtypes.attachment msgtypes.attachment
@ -76,6 +76,17 @@ async function onReceive(payload){
if(payload.type===msgtypes.group_join) { if(payload.type===msgtypes.group_join) {
if(payload.message.amount<chat.priceToJoin) doAction=false if(payload.message.amount<chat.priceToJoin) doAction=false
} }
// check that the sender is the og poster
if(payload.type===msgtypes.delete) {
doAction = false
if(payload.message.uuid) {
const ogMsg = await models.Message.findOne({where:{
uuid: payload.message.uuid,
sender: senderContact.id,
}})
if(ogMsg) doAction = true
}
}
if(doAction) forwardMessageToTribe(payload, senderContact) if(doAction) forwardMessageToTribe(payload, senderContact)
else console.log('=> insufficient payment for this action') else console.log('=> insufficient payment for this action')
} }
@ -126,13 +137,11 @@ async function doTheAction(data){
} }
async function forwardMessageToTribe(ogpayload, sender){ async function forwardMessageToTribe(ogpayload, sender){
console.log('forwardMessageToTribe',ogpayload) // console.log('forwardMessageToTribe')
const chat = await models.Chat.findOne({where:{uuid:ogpayload.chat.uuid}}) const chat = await models.Chat.findOne({where:{uuid:ogpayload.chat.uuid}})
console.log('chat.contactIds',chat.contactIds)
let contactIds = JSON.parse(chat.contactIds||'[]') let contactIds = JSON.parse(chat.contactIds||'[]')
contactIds = contactIds.filter(cid=>cid!==sender.id) contactIds = contactIds.filter(cid=>cid!==sender.id)
console.log('contactIds',contactIds)
if(contactIds.length===0) { if(contactIds.length===0) {
return // totally skip if only send is in tribe return // totally skip if only send is in tribe
} }

18
dist/api/network/receive.js

@ -31,7 +31,7 @@ in receiveDeleteMessage check the deleter is og sender?
const constants = require(path.join(__dirname, '../../config/constants.json')); const constants = require(path.join(__dirname, '../../config/constants.json'));
const msgtypes = constants.message_types; const msgtypes = constants.message_types;
exports.typesToForward = [ exports.typesToForward = [
msgtypes.message, msgtypes.group_join, msgtypes.group_leave, msgtypes.attachment msgtypes.message, msgtypes.group_join, msgtypes.group_leave, msgtypes.attachment, msgtypes.delete
]; ];
const typesToModify = [ const typesToModify = [
msgtypes.attachment msgtypes.attachment
@ -89,6 +89,18 @@ function onReceive(payload) {
if (payload.message.amount < chat.priceToJoin) if (payload.message.amount < chat.priceToJoin)
doAction = false; doAction = false;
} }
// check that the sender is the og poster
if (payload.type === msgtypes.delete) {
doAction = false;
if (payload.message.uuid) {
const ogMsg = yield models_1.models.Message.findOne({ where: {
uuid: payload.message.uuid,
sender: senderContact.id,
} });
if (ogMsg)
doAction = true;
}
}
if (doAction) if (doAction)
forwardMessageToTribe(payload, senderContact); forwardMessageToTribe(payload, senderContact);
else else
@ -146,12 +158,10 @@ function doTheAction(data) {
} }
function forwardMessageToTribe(ogpayload, sender) { function forwardMessageToTribe(ogpayload, sender) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
console.log('forwardMessageToTribe', ogpayload); // console.log('forwardMessageToTribe')
const chat = yield models_1.models.Chat.findOne({ where: { uuid: ogpayload.chat.uuid } }); const chat = yield models_1.models.Chat.findOne({ where: { uuid: ogpayload.chat.uuid } });
console.log('chat.contactIds', chat.contactIds);
let contactIds = JSON.parse(chat.contactIds || '[]'); let contactIds = JSON.parse(chat.contactIds || '[]');
contactIds = contactIds.filter(cid => cid !== sender.id); contactIds = contactIds.filter(cid => cid !== sender.id);
console.log('contactIds', contactIds);
if (contactIds.length === 0) { if (contactIds.length === 0) {
return; // totally skip if only send is in tribe return; // totally skip if only send is in tribe
} }

2
dist/api/network/receive.js.map

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