Browse Source

dont store each purchase msg on admins side, extract buyer buykey from media token

feature/dockerfile-arm
Evan Feenstra 4 years ago
parent
commit
3a1cb5484f
  1. 25
      api/network/modify.ts
  2. 2
      api/network/receive.ts
  3. 22
      dist/api/network/modify.js
  4. 2
      dist/api/network/modify.js.map
  5. 2
      dist/api/network/receive.js
  6. 2
      dist/api/network/receive.js.map

25
api/network/modify.ts

@ -8,7 +8,7 @@ import * as FormData from 'form-data'
import { models } from '../models'
import * as RNCryptor from 'jscryptor'
import {sendMessage} from './send'
import { Op } from 'sequelize'
// import { Op } from 'sequelize'
const constants = require(path.join(__dirname,'../../config/constants.json'))
const msgtypes = constants.message_types
@ -106,13 +106,24 @@ export async function sendFinalMemeIfFirstPurchaser(payload, chat, sender){
const existingMediaKey = await models.MediaKey.findOne({where:{muid}})
if(existingMediaKey) return // no need, its already been sent
const host = mt.split('.')[0]
const ogPurchaseMessage = await models.Message.findOne({where:{
mediaToken: {[Op.like]: `${host}.${muid}%`},
type: msgtypes.purchase,
// const host = mt.split('.')[0]
const terms = parseLDAT(mt)
const ogPurchaser = await models.Concat.findOne({where:{
publicKey: terms.pubkey
}})
console.log("OG PURCHASER", ogPurchaser.dataValues)
if(!ogPurchaser) return
const amt = (terms.meta&&terms.meta.amt)||0
// const ogPurchaseMessage = await models.Message.findOne({where:{
// mediaToken: {[Op.like]: `${host}.${muid}%`},
// type: msgtypes.purchase,
// }})
const termsAndKey = await downloadAndUploadAndSaveReturningTermsAndKey(payload,chat,sender,ogPurchaseMessage.amount)
const termsAndKey = await downloadAndUploadAndSaveReturningTermsAndKey(payload,chat,sender,amt)
// send it to the purchaser
const owner = await models.Contact.findOne({where: {isOwner:true}})
@ -123,7 +134,7 @@ export async function sendFinalMemeIfFirstPurchaser(payload, chat, sender){
},
chat:{
...chat.dataValues,
contactIds:[ogPurchaseMessage.sender],
contactIds:[ogPurchaser.id],
},
type:msgtypes.purchase_accept,
message:{

2
api/network/receive.ts

@ -28,6 +28,7 @@ export const typesToReplay=[ // should match typesToForward
]
async function onReceive(payload){
// if tribe, owner must forward to MQTT
console.log('======> ON RECEIVE',payload.chat&&payload.chat.type)
let doAction = true
const toAddIn:{[k:string]:any} = {}
const isTribe = payload.chat && payload.chat.type===constants.chat_types.tribe
@ -70,6 +71,7 @@ async function onReceive(payload){
const senderContact = await models.Contact.findOne({where:{publicKey:payload.sender.pub_key}})
purchaseFromOriginalSender(payload, chat, senderContact)
// we do pass thru, to store... so that we know who the og purchaser was
doAction = false
}
}
if(isTribeOwner && payload.type===msgtypes.purchase_accept) {

22
dist/api/network/modify.js

@ -19,7 +19,7 @@ const FormData = require("form-data");
const models_1 = require("../models");
const RNCryptor = require("jscryptor");
const send_1 = require("./send");
const sequelize_1 = require("sequelize");
// import { Op } from 'sequelize'
const constants = require(path.join(__dirname, '../../config/constants.json'));
const msgtypes = constants.message_types;
function modifyPayloadAndSaveMediaKey(payload, chat, sender) {
@ -119,17 +119,25 @@ function sendFinalMemeIfFirstPurchaser(payload, chat, sender) {
const existingMediaKey = yield models_1.models.MediaKey.findOne({ where: { muid } });
if (existingMediaKey)
return; // no need, its already been sent
const host = mt.split('.')[0];
const ogPurchaseMessage = yield models_1.models.Message.findOne({ where: {
mediaToken: { [sequelize_1.Op.like]: `${host}.${muid}%` },
type: msgtypes.purchase,
// const host = mt.split('.')[0]
const terms = ldat_1.parseLDAT(mt);
const ogPurchaser = yield models_1.models.Concat.findOne({ where: {
publicKey: terms.pubkey
} });
const termsAndKey = yield downloadAndUploadAndSaveReturningTermsAndKey(payload, chat, sender, ogPurchaseMessage.amount);
console.log("OG PURCHASER", ogPurchaser.dataValues);
if (!ogPurchaser)
return;
const amt = (terms.meta && terms.meta.amt) || 0;
// const ogPurchaseMessage = await models.Message.findOne({where:{
// mediaToken: {[Op.like]: `${host}.${muid}%`},
// type: msgtypes.purchase,
// }})
const termsAndKey = yield downloadAndUploadAndSaveReturningTermsAndKey(payload, chat, sender, amt);
// send it to the purchaser
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
send_1.sendMessage({
sender: Object.assign(Object.assign({}, owner.dataValues), sender && sender.alias && { alias: sender.alias }),
chat: Object.assign(Object.assign({}, chat.dataValues), { contactIds: [ogPurchaseMessage.sender] }),
chat: Object.assign(Object.assign({}, chat.dataValues), { contactIds: [ogPurchaser.id] }),
type: msgtypes.purchase_accept,
message: Object.assign(Object.assign({}, termsAndKey), { mediaType: typ, originalMuid: muid }),
success: () => { },

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

File diff suppressed because one or more lines are too long

2
dist/api/network/receive.js

@ -38,6 +38,7 @@ exports.typesToReplay = [
function onReceive(payload) {
return __awaiter(this, void 0, void 0, function* () {
// if tribe, owner must forward to MQTT
console.log('======> ON RECEIVE', payload.chat && payload.chat.type);
let doAction = true;
const toAddIn = {};
const isTribe = payload.chat && payload.chat.type === constants.chat_types.tribe;
@ -86,6 +87,7 @@ function onReceive(payload) {
const senderContact = yield models_1.models.Contact.findOne({ where: { publicKey: payload.sender.pub_key } });
modify_1.purchaseFromOriginalSender(payload, chat, senderContact);
// we do pass thru, to store... so that we know who the og purchaser was
doAction = false;
}
}
if (isTribeOwner && payload.type === msgtypes.purchase_accept) {

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

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