Skip to content

Commit

Permalink
Merge pull request #111 from stakwork/fixboost
Browse files Browse the repository at this point in the history
Fixboost
  • Loading branch information
Evanfeenstra authored Nov 25, 2020
2 parents 45820a3 + c01033f commit b13aec5
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 8 deletions.
8 changes: 6 additions & 2 deletions dist/src/controllers/messages.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/src/controllers/messages.js.map

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion dist/src/network/receive.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/src/network/receive.js.map

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions src/controllers/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export const sendMessage = async (req, res) => {
amount,
reply_uuid,
boost,
message_price,
} = req.body

let msgtype = constants.message_types.message
Expand All @@ -182,19 +183,23 @@ export const sendMessage = async (req, res) => {
}})
if(ogMsg && ogMsg.sender) {
realSatsContactId = ogMsg.sender
}
}
}

const hasRealAmount = amount && amount>constants.min_sat_amount

const remoteMessageContent = remote_text_map?JSON.stringify(remote_text_map) : remote_text
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}={
chatId: chat.id,
uuid: uuid,
type: msgtype,
sender: owner.id,
amount: amount||0,
amount: amtToStore,
date: date,
messageContent: text,
remoteMessageContent,
Expand Down
5 changes: 4 additions & 1 deletion src/network/receive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,14 @@ async function onReceive(payload){
const ogMsg = await models.Message.findOne({where:{
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)
if(theAmtToForward>0) {
realSatsContactId = ogMsg.sender
amtToForward = theAmtToForward
if(amtToForward && payload.message && payload.message.amount) {
payload.message.amount = amtToForward // mutate the payload amount
}
}
}
}
Expand Down

0 comments on commit b13aec5

Please sign in to comment.