Browse Source

record amts in all msgs, boost msg, if admin sends boost send separat keysend

dependabot/npm_and_yarn/ini-1.3.7
Evan Feenstra 4 years ago
parent
commit
626a3d69e9
  1. 39
      dist/src/controllers/messages.js
  2. 2
      dist/src/controllers/messages.js.map
  3. 7
      dist/src/network/receive.js
  4. 2
      dist/src/network/receive.js.map
  5. 39
      src/controllers/messages.ts
  6. 6
      src/network/receive.ts

39
dist/src/controllers/messages.js

@ -22,6 +22,7 @@ const confirmations_1 = require("./confirmations");
const network = require("../network");
const short = require("short-uuid");
const constants_1 = require("../constants");
const receive_1 = require("../network/receive");
exports.getMessages = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const dateToReturn = req.query.date;
if (!dateToReturn) {
@ -184,10 +185,40 @@ exports.sendMessage = (req, res) => __awaiter(void 0, void 0, void 0, function*
type: msgtype,
message: msgToSend,
});
const isTribe = chat.type === constants_1.default.chat_types.tribe;
const isTribeOwner = isTribe && owner.publicKey === chat.ownerPubkey;
if (isTribeOwner && reply_uuid && boost && amount) {
processTribeAdminBoost(chat, reply_uuid, amount);
}
});
function processTribeAdminBoost(chat, reply_uuid, amount) {
return __awaiter(this, void 0, void 0, function* () {
const ogMsg = yield models_1.models.Message.findOne({ where: {
uuid: reply_uuid,
} });
if (ogMsg && ogMsg.sender && ogMsg.sender !== 1) {
receive_1.forwardBoostSatsToContact(chat, ogMsg.sender, amount);
var date = new Date();
date.setMilliseconds(0);
models_1.models.Message.create({
chatId: 0,
type: constants_1.default.message_types.keysend,
sender: 1,
amount,
amountMsat: amount * 1000,
paymentHash: '',
date: date,
messageContent: '!',
status: constants_1.default.statuses.confirmed,
createdAt: date,
updatedAt: date
});
}
});
}
exports.receiveMessage = (payload) => __awaiter(void 0, void 0, void 0, function* () {
// console.log('received message', { payload })
const { owner, sender, chat, content, remote_content, msg_id, chat_type, sender_alias, msg_uuid, date_string, reply_uuid } = yield helpers.parseReceiveParams(payload);
const { owner, sender, chat, content, remote_content, msg_id, chat_type, sender_alias, msg_uuid, date_string, reply_uuid, amount } = yield helpers.parseReceiveParams(payload);
if (!owner || !sender || !chat) {
return console.log('=> no group chat!');
}
@ -202,7 +233,7 @@ exports.receiveMessage = (payload) => __awaiter(void 0, void 0, void 0, function
type: constants_1.default.message_types.message,
sender: sender.id,
date: date,
// amount: amount||0,
amount: amount || 0,
messageContent: text,
createdAt: date,
updatedAt: date,
@ -227,7 +258,7 @@ exports.receiveMessage = (payload) => __awaiter(void 0, void 0, void 0, function
});
exports.receiveBoost = (payload) => __awaiter(void 0, void 0, void 0, function* () {
console.log('received boost', { payload });
const { owner, sender, chat, content, remote_content, chat_type, sender_alias, msg_uuid, date_string, reply_uuid } = yield helpers.parseReceiveParams(payload);
const { owner, sender, chat, content, remote_content, chat_type, sender_alias, msg_uuid, date_string, reply_uuid, amount } = yield helpers.parseReceiveParams(payload);
if (!owner || !sender || !chat) {
return console.log('=> no group chat!');
}
@ -242,7 +273,7 @@ exports.receiveBoost = (payload) => __awaiter(void 0, void 0, void 0, function*
type: constants_1.default.message_types.boost,
sender: sender.id,
date: date,
// amount: amount||0,
amount: amount || 0,
messageContent: text,
createdAt: date,
updatedAt: date,

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

File diff suppressed because one or more lines are too long

7
dist/src/network/receive.js

@ -143,7 +143,7 @@ function onReceive(payload) {
if (ogMsg && ogMsg.sender && ogMsg.sender !== 1) {
const amtToForward = payload.message.amount - (chat.pricePerMessage || 0) - (chat.escrowAmount || 0);
if (amtToForward > 0) {
forwardSatsToContact(chat, ogMsg.sender, amtToForward);
forwardBoostSatsToContact(chat, ogMsg.sender, amtToForward);
}
}
}
@ -203,9 +203,9 @@ function doTheAction(data) {
}
});
}
function forwardSatsToContact(chat, contactId, amount) {
function forwardBoostSatsToContact(chat, contactId, amount) {
return __awaiter(this, void 0, void 0, function* () {
console.log('=> forwardSatsToContact', contactId);
console.log('=> forwardBoostSatsToContact', contactId);
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
send_1.sendMessage({
chat: Object.assign(Object.assign({}, chat.dataValues), { contactIds: [contactId] }),
@ -218,6 +218,7 @@ function forwardSatsToContact(chat, contactId, amount) {
});
});
}
exports.forwardBoostSatsToContact = forwardBoostSatsToContact;
function forwardMessageToTribe(ogpayload, sender) {
return __awaiter(this, void 0, void 0, function* () {
// console.log('forwardMessageToTribe')

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

File diff suppressed because one or more lines are too long

39
src/controllers/messages.ts

@ -11,6 +11,7 @@ import {sendConfirmation} from './confirmations'
import * as network from '../network'
import * as short from 'short-uuid'
import constants from '../constants'
import {forwardBoostSatsToContact} from '../network/receive'
export const getMessages = async (req, res) => {
const dateToReturn = req.query.date;
@ -206,12 +207,42 @@ export const sendMessage = async (req, res) => {
type: msgtype,
message: msgToSend,
})
const isTribe = chat.type===constants.chat_types.tribe
const isTribeOwner = isTribe && owner.publicKey===chat.ownerPubkey
if(isTribeOwner && reply_uuid && boost && amount) {
processTribeAdminBoost(chat, reply_uuid, amount)
}
}
async function processTribeAdminBoost(chat, reply_uuid, amount){
const ogMsg = await models.Message.findOne({where:{
uuid: reply_uuid,
}})
if(ogMsg && ogMsg.sender && ogMsg.sender!==1) {
forwardBoostSatsToContact(chat,ogMsg.sender,amount)
var date = new Date();
date.setMilliseconds(0)
models.Message.create({ // gen keysend record on owner side
chatId: 0,
type: constants.message_types.keysend,
sender: 1,
amount,
amountMsat: amount*1000,
paymentHash: '',
date: date,
messageContent: '!',
status: constants.statuses.confirmed,
createdAt: date,
updatedAt: date
})
}
}
export const receiveMessage = async (payload) => {
// console.log('received message', { payload })
const {owner, sender, chat, content, remote_content, msg_id, chat_type, sender_alias, msg_uuid, date_string, reply_uuid} = await helpers.parseReceiveParams(payload)
const {owner, sender, chat, content, remote_content, msg_id, chat_type, sender_alias, msg_uuid, date_string, reply_uuid, amount} = await helpers.parseReceiveParams(payload)
if(!owner || !sender || !chat) {
return console.log('=> no group chat!')
}
@ -227,7 +258,7 @@ export const receiveMessage = async (payload) => {
type: constants.message_types.message,
sender: sender.id,
date: date,
// amount: amount||0,
amount: amount||0,
messageContent: text,
createdAt: date,
updatedAt: date,
@ -255,7 +286,7 @@ export const receiveMessage = async (payload) => {
export const receiveBoost = async (payload) => {
console.log('received boost', { payload })
const {owner, sender, chat, content, remote_content, chat_type, sender_alias, msg_uuid, date_string, reply_uuid} = await helpers.parseReceiveParams(payload)
const {owner, sender, chat, content, remote_content, chat_type, sender_alias, msg_uuid, date_string, reply_uuid, amount} = await helpers.parseReceiveParams(payload)
if(!owner || !sender || !chat) {
return console.log('=> no group chat!')
}
@ -271,7 +302,7 @@ export const receiveBoost = async (payload) => {
type: constants.message_types.boost,
sender: sender.id,
date: date,
// amount: amount||0,
amount: amount||0,
messageContent: text,
createdAt: date,
updatedAt: date,

6
src/network/receive.ts

@ -129,7 +129,7 @@ async function onReceive(payload){
if(ogMsg && ogMsg.sender && ogMsg.sender!==1) {
const amtToForward = payload.message.amount - (chat.pricePerMessage||0) - (chat.escrowAmount||0)
if(amtToForward>0) {
forwardSatsToContact(chat,ogMsg.sender,amtToForward)
forwardBoostSatsToContact(chat,ogMsg.sender,amtToForward)
}
}
}
@ -183,8 +183,8 @@ async function doTheAction(data){
}
}
async function forwardSatsToContact(chat,contactId:number,amount:number) {
console.log('=> forwardSatsToContact',contactId)
export async function forwardBoostSatsToContact(chat,contactId:number,amount:number) {
console.log('=> forwardBoostSatsToContact',contactId)
const owner = await models.Contact.findOne({where:{isOwner:true}})
sendMessage({
chat: {...chat.dataValues, contactIds:[contactId]},

Loading…
Cancel
Save