Browse Source

cleanup

feature/dockerfile-arm
Evan Feenstra 5 years ago
parent
commit
409ff02ba4
  1. 18
      api/network/modify.ts
  2. 5
      api/network/receive.ts
  3. 16
      dist/api/network/modify.js
  4. 2
      dist/api/network/modify.js.map
  5. 5
      dist/api/network/receive.js
  6. 2
      dist/api/network/receive.js.map

18
api/network/modify.ts

@ -42,7 +42,6 @@ export async function purchaseFromOriginalSender(payload, chat, purchaser){
const owner = await models.Contact.findOne({where: {isOwner:true}})
if(mediaKey) { // ALREADY BEEN PURHCASED! simply send
console.log("MEDIA KEY EXISTS ALREADY",mediaKey)
// send back the new mediaToken and key
const mediaTerms: {[k:string]:any} = {
muid:mediaKey.muid, ttl:31536000, host:'',
@ -55,7 +54,6 @@ export async function purchaseFromOriginalSender(payload, chat, purchaser){
originalMuid:mediaKey.originalMuid,
mediaType:mediaKey.mediaType
}
console.log("SEND PURCHASE ACCEPT FROM STORED KEY")
sendMessage({
chat: {...chat.dataValues, contactIds:[purchaser.id]},
sender: owner,
@ -65,11 +63,9 @@ export async function purchaseFromOriginalSender(payload, chat, purchaser){
failure: ()=>{}
})
} else {
console.log("NO MEDIA KEY EXISTS YET")
const ogmsg = await models.Message.findOne({where:{chatId:chat.id,mediaToken:mt}})
// purchase it from creator (send "purchase")
const msg={amount, mediaToken:mt}
console.log("GO AHEARD AND BUY!!!")
sendMessage({
chat: {...chat.dataValues, contactIds:[ogmsg.sender]},
sender: {
@ -88,8 +84,6 @@ export async function purchaseFromOriginalSender(payload, chat, purchaser){
export async function sendFinalMemeIfFirstPurchaser(payload, chat, sender){
if(payload.type!==msgtypes.purchase_accept) return
console.log("PURCHASE ACCEPT!!!!!")
const mt = payload.message && payload.message.mediaToken
const typ = payload.message && payload.message.mediaType
if(!mt) return
@ -107,11 +101,8 @@ export async function sendFinalMemeIfFirstPurchaser(payload, chat, sender){
const termsAndKey = await downloadAndUploadAndSaveReturningTermsAndKey(payload,chat,sender,ogPurchaseMessage.amount)
console.log('ogPurchaseMessage',ogPurchaseMessage.dataValues)
// send it to the purchaser
const owner = await models.Contact.findOne({where: {isOwner:true}})
console.log("SEND firST PURHCASE ACCEPT MSG!")
sendMessage({
sender: {
...owner.dataValues,
@ -203,15 +194,6 @@ export async function downloadAndUploadAndSaveReturningTermsAndKey(payload, chat
var date = new Date()
date.setMilliseconds(0)
console.log('[modify] save media key!',{
muid:json.muid,
chatId:chat.id,
key: encKey,
messageId: (payload.message&&payload.message.id)||0,
receiver: 0,
sender: sender.id, // the og sender
createdAt: date,
})
await sleep(1)
await models.MediaKey.create({
muid:json.muid,

5
api/network/receive.ts

@ -64,9 +64,9 @@ async function onReceive(payload){
mediaToken: mt, sender: 1, type:msgtypes.attachment
} })
if(!myMediaMessage) { // someone else's attachment
console.log("=> NO MEDIA MESSAGE BY ME, purchaseFromOriginalSender")
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
}
}
if(isTribeOwner && payload.type===msgtypes.purchase_accept) {
@ -79,10 +79,9 @@ async function onReceive(payload){
sender: 1,
}})
if(!ogPurchaseMessage) { // for someone else
console.log("=> NO OG PURCHASE MESSAGE BY ME, sendFinalMemeIfFirstPurchaser")
const senderContact = await models.Contact.findOne({where:{publicKey:payload.sender.pub_key}})
sendFinalMemeIfFirstPurchaser(payload, chat, senderContact)
doAction = false
doAction = false // skip this! we dont need it
}
}
if(doAction) doTheAction({...payload, ...toAddIn})

16
dist/api/network/modify.js

@ -54,7 +54,6 @@ function purchaseFromOriginalSender(payload, chat, purchaser) {
return; // not enough sats
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
if (mediaKey) { // ALREADY BEEN PURHCASED! simply send
console.log("MEDIA KEY EXISTS ALREADY", mediaKey);
// send back the new mediaToken and key
const mediaTerms = {
muid: mediaKey.muid, ttl: 31536000, host: '',
@ -67,7 +66,6 @@ function purchaseFromOriginalSender(payload, chat, purchaser) {
originalMuid: mediaKey.originalMuid,
mediaType: mediaKey.mediaType
};
console.log("SEND PURCHASE ACCEPT FROM STORED KEY");
send_1.sendMessage({
chat: Object.assign(Object.assign({}, chat.dataValues), { contactIds: [purchaser.id] }),
sender: owner,
@ -78,11 +76,9 @@ function purchaseFromOriginalSender(payload, chat, purchaser) {
});
}
else {
console.log("NO MEDIA KEY EXISTS YET");
const ogmsg = yield models_1.models.Message.findOne({ where: { chatId: chat.id, mediaToken: mt } });
// purchase it from creator (send "purchase")
const msg = { amount, mediaToken: mt };
console.log("GO AHEARD AND BUY!!!");
send_1.sendMessage({
chat: Object.assign(Object.assign({}, chat.dataValues), { contactIds: [ogmsg.sender] }),
sender: Object.assign(Object.assign({}, owner.dataValues), purchaser && purchaser.alias && { alias: purchaser.alias }),
@ -100,7 +96,6 @@ function sendFinalMemeIfFirstPurchaser(payload, chat, sender) {
return __awaiter(this, void 0, void 0, function* () {
if (payload.type !== msgtypes.purchase_accept)
return;
console.log("PURCHASE ACCEPT!!!!!");
const mt = payload.message && payload.message.mediaToken;
const typ = payload.message && payload.message.mediaType;
if (!mt)
@ -117,10 +112,8 @@ function sendFinalMemeIfFirstPurchaser(payload, chat, sender) {
type: msgtypes.purchase,
} });
const termsAndKey = yield downloadAndUploadAndSaveReturningTermsAndKey(payload, chat, sender, ogPurchaseMessage.amount);
console.log('ogPurchaseMessage', ogPurchaseMessage.dataValues);
// send it to the purchaser
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
console.log("SEND firST PURHCASE ACCEPT MSG!");
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] }),
@ -186,15 +179,6 @@ function downloadAndUploadAndSaveReturningTermsAndKey(payload, chat, sender, inj
const encKey = rsa.encrypt(chat.groupKey, newKey.slice());
var date = new Date();
date.setMilliseconds(0);
console.log('[modify] save media key!', {
muid: json.muid,
chatId: chat.id,
key: encKey,
messageId: (payload.message && payload.message.id) || 0,
receiver: 0,
sender: sender.id,
createdAt: date,
});
yield sleep(1);
yield models_1.models.MediaKey.create({
muid: json.muid,

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

File diff suppressed because one or more lines are too long

5
dist/api/network/receive.js

@ -80,9 +80,9 @@ function onReceive(payload) {
mediaToken: mt, sender: 1, type: msgtypes.attachment
} });
if (!myMediaMessage) { // someone else's attachment
console.log("=> NO MEDIA MESSAGE BY ME, purchaseFromOriginalSender");
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
}
}
if (isTribeOwner && payload.type === msgtypes.purchase_accept) {
@ -95,10 +95,9 @@ function onReceive(payload) {
sender: 1,
} });
if (!ogPurchaseMessage) { // for someone else
console.log("=> NO OG PURCHASE MESSAGE BY ME, sendFinalMemeIfFirstPurchaser");
const senderContact = yield models_1.models.Contact.findOne({ where: { publicKey: payload.sender.pub_key } });
modify_1.sendFinalMemeIfFirstPurchaser(payload, chat, senderContact);
doAction = false;
doAction = false; // skip this! we dont need it
}
}
if (doAction)

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

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