Browse Source

fix saveMediaKeys

feature/dockerfile-arm
Evan Feenstra 5 years ago
parent
commit
b53f1c9afd
  1. 15
      api/controllers/media.ts
  2. 15
      dist/api/controllers/media.js
  3. 2
      dist/api/controllers/media.js.map

15
api/controllers/media.ts

@ -135,11 +135,14 @@ function saveMediaKeys(muid, mediaKeyMap, chatId, messageId){
var date = new Date();
date.setMilliseconds(0)
for (let [contactId, key] of Object.entries(mediaKeyMap)) {
if(parseInt(contactId)!==1) {
models.MediaKey.create({
muid, chatId, contactId, key, messageId,
muid, chatId, key, messageId,
receiver: parseInt(contactId),
createdAt: date,
})
}
}
}
const purchase = async (req, res) => {
@ -196,7 +199,7 @@ const purchase = async (req, res) => {
/* RECEIVERS */
const receivePurchase = async (payload) => {
console.log('received purchase', { payload })
console.log('=> received purchase', { payload })
var date = new Date();
date.setMilliseconds(0)
@ -231,6 +234,7 @@ const receivePurchase = async (payload) => {
const mediaKey = models.MediaKey.findOne({where:{
muid, receiver: sender.id,
}})
console.log('mediaKey found!',mediaKey)
const terms = parseLDAT(mediaToken)
// get info
@ -265,6 +269,11 @@ const receivePurchase = async (payload) => {
muid, ttl: TTL,
meta: {amt:amount},
}
console.log("SEND THIS!", {
mediaTerms: acceptTerms, // converted to token in utils/msg.ts
mediaKey: mediaKey.key,
mediaType: ogMessage.mediaType,
})
helpers.sendMessage({
chat: {...chat.dataValues, contactIds:[sender.id]}, // only to sender
sender: owner,
@ -282,6 +291,7 @@ const receivePurchase = async (payload) => {
}
const receivePurchaseAccept = async (payload) => {
console.log('=> receivePurchaseAccept')
var date = new Date();
date.setMilliseconds(0)
@ -325,6 +335,7 @@ const receivePurchaseAccept = async (payload) => {
}
const receivePurchaseDeny = async (payload) => {
console.log('=> receivePurchaseDeny')
var date = new Date();
date.setMilliseconds(0)
const {owner, sender, chat, amount, mediaToken} = await helpers.parseReceiveParams(payload)

15
dist/api/controllers/media.js

@ -123,11 +123,14 @@ function saveMediaKeys(muid, mediaKeyMap, chatId, messageId) {
var date = new Date();
date.setMilliseconds(0);
for (let [contactId, key] of Object.entries(mediaKeyMap)) {
if (parseInt(contactId) !== 1) {
models_1.models.MediaKey.create({
muid, chatId, contactId, key, messageId,
muid, chatId, key, messageId,
receiver: parseInt(contactId),
createdAt: date,
});
}
}
}
const purchase = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const { chat_id, contact_id, amount, media_token, } = req.body;
@ -174,7 +177,7 @@ const purchase = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
exports.purchase = purchase;
/* RECEIVERS */
const receivePurchase = (payload) => __awaiter(void 0, void 0, void 0, function* () {
console.log('received purchase', { payload });
console.log('=> received purchase', { payload });
var date = new Date();
date.setMilliseconds(0);
const { owner, sender, chat, amount, mediaToken } = yield helpers.parseReceiveParams(payload);
@ -204,6 +207,7 @@ const receivePurchase = (payload) => __awaiter(void 0, void 0, void 0, function*
const mediaKey = models_1.models.MediaKey.findOne({ where: {
muid, receiver: sender.id,
} });
console.log('mediaKey found!', mediaKey);
const terms = ldat_1.parseLDAT(mediaToken);
// get info
let TTL = terms.meta && terms.meta.ttl;
@ -237,6 +241,11 @@ const receivePurchase = (payload) => __awaiter(void 0, void 0, void 0, function*
muid, ttl: TTL,
meta: { amt: amount },
};
console.log("SEND THIS!", {
mediaTerms: acceptTerms,
mediaKey: mediaKey.key,
mediaType: ogMessage.mediaType,
});
helpers.sendMessage({
chat: Object.assign(Object.assign({}, chat.dataValues), { contactIds: [sender.id] }),
sender: owner,
@ -254,6 +263,7 @@ const receivePurchase = (payload) => __awaiter(void 0, void 0, void 0, function*
});
exports.receivePurchase = receivePurchase;
const receivePurchaseAccept = (payload) => __awaiter(void 0, void 0, void 0, function* () {
console.log('=> receivePurchaseAccept');
var date = new Date();
date.setMilliseconds(0);
const { owner, sender, chat, mediaToken, mediaKey, mediaType } = yield helpers.parseReceiveParams(payload);
@ -294,6 +304,7 @@ const receivePurchaseAccept = (payload) => __awaiter(void 0, void 0, void 0, fun
});
exports.receivePurchaseAccept = receivePurchaseAccept;
const receivePurchaseDeny = (payload) => __awaiter(void 0, void 0, void 0, function* () {
console.log('=> receivePurchaseDeny');
var date = new Date();
date.setMilliseconds(0);
const { owner, sender, chat, amount, mediaToken } = yield helpers.parseReceiveParams(payload);

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

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