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

15
dist/api/controllers/media.js

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