Browse Source

Merge pull request #111 from stakwork/fixboost

Fixboost
dependabot/npm_and_yarn/ini-1.3.7 v1.1.0
Evan Feenstra 4 years ago
committed by GitHub
parent
commit
b13aec53f2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      dist/src/controllers/messages.js
  2. 2
      dist/src/controllers/messages.js.map
  3. 5
      dist/src/network/receive.js
  4. 2
      dist/src/network/receive.js.map
  5. 9
      src/controllers/messages.ts
  6. 5
      src/network/receive.ts

8
dist/src/controllers/messages.js

@ -139,7 +139,7 @@ exports.sendMessage = (req, res) => __awaiter(void 0, void 0, void 0, function*
// } catch(e) { // } catch(e) {
// return failure(res, e.message) // return failure(res, e.message)
// } // }
const { contact_id, text, remote_text, chat_id, remote_text_map, amount, reply_uuid, boost, } = req.body; const { contact_id, text, remote_text, chat_id, remote_text_map, amount, reply_uuid, boost, message_price, } = req.body;
let msgtype = constants_1.default.message_types.message; let msgtype = constants_1.default.message_types.message;
if (boost) if (boost)
msgtype = constants_1.default.message_types.boost; msgtype = constants_1.default.message_types.boost;
@ -165,12 +165,16 @@ exports.sendMessage = (req, res) => __awaiter(void 0, void 0, void 0, function*
const hasRealAmount = amount && amount > constants_1.default.min_sat_amount; const hasRealAmount = amount && amount > constants_1.default.min_sat_amount;
const remoteMessageContent = remote_text_map ? JSON.stringify(remote_text_map) : remote_text; const remoteMessageContent = remote_text_map ? JSON.stringify(remote_text_map) : remote_text;
const uuid = short.generate(); const uuid = short.generate();
let amtToStore = amount || 0;
if (boost && message_price && typeof message_price === 'number' && amount && message_price < amount) {
amtToStore = amount - message_price;
}
const msg = { const msg = {
chatId: chat.id, chatId: chat.id,
uuid: uuid, uuid: uuid,
type: msgtype, type: msgtype,
sender: owner.id, sender: owner.id,
amount: amount || 0, amount: amtToStore,
date: date, date: date,
messageContent: text, messageContent: text,
remoteMessageContent, remoteMessageContent,

2
dist/src/controllers/messages.js.map

File diff suppressed because one or more lines are too long

5
dist/src/network/receive.js

@ -143,11 +143,14 @@ function onReceive(payload) {
const ogMsg = yield models_1.models.Message.findOne({ where: { const ogMsg = yield models_1.models.Message.findOne({ where: {
uuid: payload.message.replyUuid, uuid: payload.message.replyUuid,
} }); } });
if (ogMsg && ogMsg.sender && ogMsg.sender !== 1) { if (ogMsg && ogMsg.sender) { // even include "me"
const theAmtToForward = payload.message.amount - (chat.pricePerMessage || 0) - (chat.escrowAmount || 0); const theAmtToForward = payload.message.amount - (chat.pricePerMessage || 0) - (chat.escrowAmount || 0);
if (theAmtToForward > 0) { if (theAmtToForward > 0) {
realSatsContactId = ogMsg.sender; realSatsContactId = ogMsg.sender;
amtToForward = theAmtToForward; amtToForward = theAmtToForward;
if (amtToForward && payload.message && payload.message.amount) {
payload.message.amount = amtToForward; // mutate the payload amount
}
} }
} }
} }

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

File diff suppressed because one or more lines are too long

9
src/controllers/messages.ts

@ -158,6 +158,7 @@ export const sendMessage = async (req, res) => {
amount, amount,
reply_uuid, reply_uuid,
boost, boost,
message_price,
} = req.body } = req.body
let msgtype = constants.message_types.message let msgtype = constants.message_types.message
@ -182,19 +183,23 @@ export const sendMessage = async (req, res) => {
}}) }})
if(ogMsg && ogMsg.sender) { if(ogMsg && ogMsg.sender) {
realSatsContactId = ogMsg.sender realSatsContactId = ogMsg.sender
} }
} }
const hasRealAmount = amount && amount>constants.min_sat_amount const hasRealAmount = amount && amount>constants.min_sat_amount
const remoteMessageContent = remote_text_map?JSON.stringify(remote_text_map) : remote_text const remoteMessageContent = remote_text_map?JSON.stringify(remote_text_map) : remote_text
const uuid = short.generate() const uuid = short.generate()
let amtToStore = amount || 0
if(boost && message_price && typeof message_price==='number' && amount && message_price<amount) {
amtToStore = amount - message_price
}
const msg:{[k:string]:any}={ const msg:{[k:string]:any}={
chatId: chat.id, chatId: chat.id,
uuid: uuid, uuid: uuid,
type: msgtype, type: msgtype,
sender: owner.id, sender: owner.id,
amount: amount||0, amount: amtToStore,
date: date, date: date,
messageContent: text, messageContent: text,
remoteMessageContent, remoteMessageContent,

5
src/network/receive.ts

@ -130,11 +130,14 @@ async function onReceive(payload){
const ogMsg = await models.Message.findOne({where:{ const ogMsg = await models.Message.findOne({where:{
uuid: payload.message.replyUuid, uuid: payload.message.replyUuid,
}}) }})
if(ogMsg && ogMsg.sender && ogMsg.sender!==1) { if(ogMsg && ogMsg.sender) { // even include "me"
const theAmtToForward = payload.message.amount - (chat.pricePerMessage||0) - (chat.escrowAmount||0) const theAmtToForward = payload.message.amount - (chat.pricePerMessage||0) - (chat.escrowAmount||0)
if(theAmtToForward>0) { if(theAmtToForward>0) {
realSatsContactId = ogMsg.sender realSatsContactId = ogMsg.sender
amtToForward = theAmtToForward amtToForward = theAmtToForward
if(amtToForward && payload.message && payload.message.amount) {
payload.message.amount = amtToForward // mutate the payload amount
}
} }
} }
} }

Loading…
Cancel
Save