Browse Source

check needsPricePerMessage

feature/dockerfile-arm
Evan Feenstra 5 years ago
parent
commit
144ea0f70b
  1. 23
      api/network/receive.ts
  2. 25
      dist/api/network/receive.js
  3. 2
      dist/api/network/receive.js.map

23
api/network/receive.ts

@ -18,6 +18,9 @@ const typesToForward=[
const typesToModify=[
msgtypes.attachment
]
const typesThatNeedPricePerMessage = [
msgtypes.message, msgtypes.attachment
]
async function onReceive(payload){
console.log("=>>> onReceive",payload)
// if tribe, owner must forward to MQTT
@ -25,22 +28,26 @@ async function onReceive(payload){
const toAddIn:{[k:string]:any} = {}
const isTribe = payload.chat && payload.chat.type===constants.chat_types.tribe
if(isTribe && typesToForward.includes(payload.type)){
const needsPricePerJoin = typesThatNeedPricePerMessage.includes(payload.type)
const chat = await models.Chat.findOne({where:{uuid:payload.chat.uuid}})
const tribeOwnerPubKey = chat.ownerPubkey
const owner = await models.Contact.findOne({where: {isOwner:true}})
if(owner.publicKey===tribeOwnerPubKey){
// CHECK THEY ARE IN THE GROUP
const senderContact = await models.Contact.findOne({where:{publicKey:payload.sender.pub_key}})
const senderMember = senderContact && await models.ChatMember.findOne({where:{contactId:senderContact.id, chatId:chat.id}})
if(!senderMember) doAction=false
// CHECK PRICES
toAddIn.isTribeOwner = true
if(payload.type===msgtypes.group_join) {
if(payload.message.amount<chat.priceToJoin) doAction=false
// CHECK THEY ARE IN THE GROUP if message
if(needsPricePerJoin) {
const senderContact = await models.Contact.findOne({where:{publicKey:payload.sender.pub_key}})
const senderMember = senderContact && await models.ChatMember.findOne({where:{contactId:senderContact.id, chatId:chat.id}})
if(!senderMember) doAction=false
}
if(payload.type===msgtypes.message) {
// CHECK PRICES
if(needsPricePerJoin) {
if(payload.message.amount<chat.pricePerMessage) doAction=false
}
// check price to join
if(payload.type===msgtypes.group_join) {
if(payload.message.amount<chat.priceToJoin) doAction=false
}
if(doAction) forwardMessageToTribe(payload)
else console.log('=> insufficient payment for this action')
}

25
dist/api/network/receive.js

@ -27,6 +27,9 @@ const typesToForward = [
const typesToModify = [
msgtypes.attachment
];
const typesThatNeedPricePerMessage = [
msgtypes.message, msgtypes.attachment
];
function onReceive(payload) {
return __awaiter(this, void 0, void 0, function* () {
console.log("=>>> onReceive", payload);
@ -35,25 +38,29 @@ function onReceive(payload) {
const toAddIn = {};
const isTribe = payload.chat && payload.chat.type === constants.chat_types.tribe;
if (isTribe && typesToForward.includes(payload.type)) {
const needsPricePerJoin = typesThatNeedPricePerMessage.includes(payload.type);
const chat = yield models_1.models.Chat.findOne({ where: { uuid: payload.chat.uuid } });
const tribeOwnerPubKey = chat.ownerPubkey;
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
if (owner.publicKey === tribeOwnerPubKey) {
// CHECK THEY ARE IN THE GROUP
const senderContact = yield models_1.models.Contact.findOne({ where: { publicKey: payload.sender.pub_key } });
const senderMember = senderContact && (yield models_1.models.ChatMember.findOne({ where: { contactId: senderContact.id, chatId: chat.id } }));
if (!senderMember)
doAction = false;
// CHECK PRICES
toAddIn.isTribeOwner = true;
if (payload.type === msgtypes.group_join) {
if (payload.message.amount < chat.priceToJoin)
// CHECK THEY ARE IN THE GROUP if message
if (needsPricePerJoin) {
const senderContact = yield models_1.models.Contact.findOne({ where: { publicKey: payload.sender.pub_key } });
const senderMember = senderContact && (yield models_1.models.ChatMember.findOne({ where: { contactId: senderContact.id, chatId: chat.id } }));
if (!senderMember)
doAction = false;
}
if (payload.type === msgtypes.message) {
// CHECK PRICES
if (needsPricePerJoin) {
if (payload.message.amount < chat.pricePerMessage)
doAction = false;
}
// check price to join
if (payload.type === msgtypes.group_join) {
if (payload.message.amount < chat.priceToJoin)
doAction = false;
}
if (doAction)
forwardMessageToTribe(payload);
else

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

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