Browse Source

forward boost sats to original msg poster if tribe admin, receiveBoost and send boost

dependabot/npm_and_yarn/ini-1.3.7
Evan Feenstra 4 years ago
parent
commit
30efccdbf3
  1. 1
      dist/src/constants.js
  2. 2
      dist/src/constants.js.map
  3. 1
      dist/src/controllers/index.js
  4. 2
      dist/src/controllers/index.js.map
  5. 54
      dist/src/controllers/messages.js
  6. 2
      dist/src/controllers/messages.js.map
  7. 33
      dist/src/network/receive.js
  8. 2
      dist/src/network/receive.js.map
  9. 1
      src/constants.ts
  10. 1
      src/controllers/index.ts
  11. 56
      src/controllers/messages.ts
  12. 32
      src/network/receive.ts

1
dist/src/constants.js

@ -58,6 +58,7 @@ const constants = {
"heartbeat": 26, "heartbeat": 26,
"heartbeat_confirmation": 27, "heartbeat_confirmation": 27,
"keysend": 28, "keysend": 28,
"boost": 29,
}, },
payment_errors: { payment_errors: {
"timeout": "Timed Out", "timeout": "Timed Out",

2
dist/src/constants.js.map

@ -1 +1 @@
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;AAAA,MAAM,SAAS,GAAG;IAChB,cAAc,EAAE,CAAC;IACjB,eAAe,EAAE;QACf,SAAS,EAAE,CAAC;QACZ,OAAO,EAAE,CAAC;QACV,WAAW,EAAE,CAAC;QACd,aAAa,EAAE,CAAC;QAChB,UAAU,EAAE,CAAC;QACb,SAAS,EAAE,CAAC;QACZ,iBAAiB,EAAE,CAAC;KACrB;IACD,gBAAgB,EAAE;QAChB,SAAS,EAAE,CAAC;QACZ,WAAW,EAAE,CAAC;KACf;IACD,QAAQ,EAAE;QACR,SAAS,EAAE,CAAC;QACZ,WAAW,EAAE,CAAC;QACd,WAAW,EAAE,CAAC;QACd,UAAU,EAAE,CAAC;QACb,QAAQ,EAAE,CAAC;QACX,SAAS,EAAE,CAAC;KACb;IACD,aAAa,EAAE;QACb,UAAU,EAAE,CAAC;QACb,SAAS,EAAE,CAAC;QACZ,UAAU,EAAE,CAAC;KACd;IACD,aAAa,EAAE;QACb,SAAS,EAAE,CAAC;QACZ,cAAc,EAAE,CAAC;QACjB,SAAS,EAAE,CAAC;QACZ,SAAS,EAAE,CAAC;QACZ,cAAc,EAAE,CAAC;QACjB,gBAAgB,EAAE,CAAC;QACnB,YAAY,EAAE,CAAC;QACf,UAAU,EAAE,CAAC;QACb,iBAAiB,EAAE,CAAC;QACpB,eAAe,EAAE,CAAC;QAClB,aAAa,EAAE,EAAE;QACjB,0BAA0B,EAAE,EAAE;QAC9B,cAAc,EAAE,EAAE;QAClB,cAAc,EAAE,EAAE;QAClB,YAAY,EAAE,EAAE;QAChB,aAAa,EAAE,EAAE;QACjB,YAAY,EAAE,EAAE;QAChB,QAAQ,EAAE,EAAE;QACZ,WAAW,EAAE,EAAE;QACf,gBAAgB,EAAE,EAAE;QACpB,gBAAgB,EAAE,EAAE;QACpB,eAAe,EAAE,EAAE;QACnB,cAAc,EAAE,EAAE;QAClB,aAAa,EAAE,EAAE;QACjB,SAAS,EAAE,EAAE;QACb,SAAS,EAAE,EAAE;QACb,WAAW,EAAE,EAAE;QACf,wBAAwB,EAAE,EAAE;QAC5B,SAAS,EAAE,EAAE;KACd;IACD,cAAc,EAAE;QACd,SAAS,EAAE,WAAW;QACtB,UAAU,EAAE,sBAAsB;QAClC,OAAO,EAAE,OAAO;QAChB,2BAA2B,EAAE,2BAA2B;QACxD,SAAS,EAAE,SAAS;KACrB;IACD,UAAU,EAAE;QACV,cAAc,EAAE,CAAC;QACjB,OAAO,EAAE,CAAC;QACV,OAAO,EAAE,CAAC;KACX;IACD,SAAS,EAAE;QACT,SAAS,EAAE,CAAC;QACZ,OAAO,EAAE,CAAC;QACV,QAAQ,EAAE,CAAC;KACZ;IACD,UAAU,EAAE;QACV,GAAG,EAAE,CAAC;QACN,OAAO,EAAE,CAAC;QACV,OAAO,EAAE,CAAC;QACV,KAAK,EAAE,CAAC;QACR,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE,CAAC;KACZ;CACF,CAAA;AAED,kBAAe,SAAS,CAAA"} {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;AAAA,MAAM,SAAS,GAAG;IAChB,cAAc,EAAE,CAAC;IACjB,eAAe,EAAE;QACf,SAAS,EAAE,CAAC;QACZ,OAAO,EAAE,CAAC;QACV,WAAW,EAAE,CAAC;QACd,aAAa,EAAE,CAAC;QAChB,UAAU,EAAE,CAAC;QACb,SAAS,EAAE,CAAC;QACZ,iBAAiB,EAAE,CAAC;KACrB;IACD,gBAAgB,EAAE;QAChB,SAAS,EAAE,CAAC;QACZ,WAAW,EAAE,CAAC;KACf;IACD,QAAQ,EAAE;QACR,SAAS,EAAE,CAAC;QACZ,WAAW,EAAE,CAAC;QACd,WAAW,EAAE,CAAC;QACd,UAAU,EAAE,CAAC;QACb,QAAQ,EAAE,CAAC;QACX,SAAS,EAAE,CAAC;KACb;IACD,aAAa,EAAE;QACb,UAAU,EAAE,CAAC;QACb,SAAS,EAAE,CAAC;QACZ,UAAU,EAAE,CAAC;KACd;IACD,aAAa,EAAE;QACb,SAAS,EAAE,CAAC;QACZ,cAAc,EAAE,CAAC;QACjB,SAAS,EAAE,CAAC;QACZ,SAAS,EAAE,CAAC;QACZ,cAAc,EAAE,CAAC;QACjB,gBAAgB,EAAE,CAAC;QACnB,YAAY,EAAE,CAAC;QACf,UAAU,EAAE,CAAC;QACb,iBAAiB,EAAE,CAAC;QACpB,eAAe,EAAE,CAAC;QAClB,aAAa,EAAE,EAAE;QACjB,0BAA0B,EAAE,EAAE;QAC9B,cAAc,EAAE,EAAE;QAClB,cAAc,EAAE,EAAE;QAClB,YAAY,EAAE,EAAE;QAChB,aAAa,EAAE,EAAE;QACjB,YAAY,EAAE,EAAE;QAChB,QAAQ,EAAE,EAAE;QACZ,WAAW,EAAE,EAAE;QACf,gBAAgB,EAAE,EAAE;QACpB,gBAAgB,EAAE,EAAE;QACpB,eAAe,EAAE,EAAE;QACnB,cAAc,EAAE,EAAE;QAClB,aAAa,EAAE,EAAE;QACjB,SAAS,EAAE,EAAE;QACb,SAAS,EAAE,EAAE;QACb,WAAW,EAAE,EAAE;QACf,wBAAwB,EAAE,EAAE;QAC5B,SAAS,EAAE,EAAE;QACb,OAAO,EAAE,EAAE;KACZ;IACD,cAAc,EAAE;QACd,SAAS,EAAE,WAAW;QACtB,UAAU,EAAE,sBAAsB;QAClC,OAAO,EAAE,OAAO;QAChB,2BAA2B,EAAE,2BAA2B;QACxD,SAAS,EAAE,SAAS;KACrB;IACD,UAAU,EAAE;QACV,cAAc,EAAE,CAAC;QACjB,OAAO,EAAE,CAAC;QACV,OAAO,EAAE,CAAC;KACX;IACD,SAAS,EAAE;QACT,SAAS,EAAE,CAAC;QACZ,OAAO,EAAE,CAAC;QACV,QAAQ,EAAE,CAAC;KACZ;IACD,UAAU,EAAE;QACV,GAAG,EAAE,CAAC;QACN,OAAO,EAAE,CAAC;QACV,OAAO,EAAE,CAAC;QACV,KAAK,EAAE,CAAC;QACR,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE,CAAC;KACZ;CACF,CAAA;AAED,kBAAe,SAAS,CAAA"}

1
dist/src/controllers/index.js

@ -150,5 +150,6 @@ exports.ACTIONS = {
[msgtypes.bot_res]: bots.receiveBotRes, [msgtypes.bot_res]: bots.receiveBotRes,
[msgtypes.heartbeat]: confirmations.receiveHeartbeat, [msgtypes.heartbeat]: confirmations.receiveHeartbeat,
[msgtypes.heartbeat_confirmation]: confirmations.receiveHeartbeatConfirmation, [msgtypes.heartbeat_confirmation]: confirmations.receiveHeartbeatConfirmation,
[msgtypes.boost]: messages.receiveBoost,
}; };
//# sourceMappingURL=index.js.map //# sourceMappingURL=index.js.map

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

File diff suppressed because one or more lines are too long

54
dist/src/controllers/messages.js

@ -139,7 +139,10 @@ 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, } = req.body; const { contact_id, text, remote_text, chat_id, remote_text_map, amount, reply_uuid, boost, } = req.body;
let msgtype = constants_1.default.message_types.message;
if (boost)
msgtype = constants_1.default.message_types.boost;
var date = new Date(); var date = new Date();
date.setMilliseconds(0); date.setMilliseconds(0);
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } }); const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
@ -152,7 +155,7 @@ exports.sendMessage = (req, res) => __awaiter(void 0, void 0, void 0, function*
const msg = { const msg = {
chatId: chat.id, chatId: chat.id,
uuid: short.generate(), uuid: short.generate(),
type: constants_1.default.message_types.message, type: msgtype,
sender: owner.id, sender: owner.id,
amount: amount || 0, amount: amount || 0,
date: date, date: date,
@ -178,18 +181,17 @@ exports.sendMessage = (req, res) => __awaiter(void 0, void 0, void 0, function*
chat: chat, chat: chat,
sender: owner, sender: owner,
amount: amount || 0, amount: amount || 0,
type: constants_1.default.message_types.message, type: msgtype,
message: msgToSend, message: msgToSend,
}); });
}); });
exports.receiveMessage = (payload) => __awaiter(void 0, void 0, void 0, function* () { exports.receiveMessage = (payload) => __awaiter(void 0, void 0, void 0, function* () {
// console.log('received message', { payload }) // console.log('received message', { payload })
const total_spent = 1; const { owner, sender, chat, content, remote_content, msg_id, chat_type, sender_alias, msg_uuid, date_string, reply_uuid, amount } = yield helpers.parseReceiveParams(payload);
const { owner, sender, chat, content, remote_content, msg_id, chat_type, sender_alias, msg_uuid, date_string, reply_uuid } = yield helpers.parseReceiveParams(payload);
if (!owner || !sender || !chat) { if (!owner || !sender || !chat) {
return console.log('=> no group chat!'); return console.log('=> no group chat!');
} }
const text = content; const text = content || '';
var date = new Date(); var date = new Date();
date.setMilliseconds(0); date.setMilliseconds(0);
if (date_string) if (date_string)
@ -198,9 +200,9 @@ exports.receiveMessage = (payload) => __awaiter(void 0, void 0, void 0, function
chatId: chat.id, chatId: chat.id,
uuid: msg_uuid, uuid: msg_uuid,
type: constants_1.default.message_types.message, type: constants_1.default.message_types.message,
asciiEncodedTotal: total_spent,
sender: sender.id, sender: sender.id,
date: date, date: date,
amount: amount || 0,
messageContent: text, messageContent: text,
createdAt: date, createdAt: date,
updatedAt: date, updatedAt: date,
@ -215,7 +217,6 @@ exports.receiveMessage = (payload) => __awaiter(void 0, void 0, void 0, function
if (reply_uuid) if (reply_uuid)
msg.replyUuid = reply_uuid; msg.replyUuid = reply_uuid;
const message = yield models_1.models.Message.create(msg); const message = yield models_1.models.Message.create(msg);
// console.log('saved message', message.dataValues)
socket.sendJson({ socket.sendJson({
type: 'message', type: 'message',
response: jsonUtils.messageToJson(message, chat, sender) response: jsonUtils.messageToJson(message, chat, sender)
@ -224,6 +225,43 @@ exports.receiveMessage = (payload) => __awaiter(void 0, void 0, void 0, function
const theChat = Object.assign(Object.assign({}, chat.dataValues), { contactIds: [sender.id] }); const theChat = Object.assign(Object.assign({}, chat.dataValues), { contactIds: [sender.id] });
confirmations_1.sendConfirmation({ chat: theChat, sender: owner, msg_id }); confirmations_1.sendConfirmation({ chat: theChat, sender: owner, msg_id });
}); });
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, amount } = yield helpers.parseReceiveParams(payload);
if (!owner || !sender || !chat) {
return console.log('=> no group chat!');
}
const text = content;
var date = new Date();
date.setMilliseconds(0);
if (date_string)
date = new Date(date_string);
const msg = {
chatId: chat.id,
uuid: msg_uuid,
type: constants_1.default.message_types.boost,
sender: sender.id,
date: date,
amount: amount || 0,
messageContent: text,
createdAt: date,
updatedAt: date,
status: constants_1.default.statuses.received
};
const isTribe = chat_type === constants_1.default.chat_types.tribe;
if (isTribe) {
msg.senderAlias = sender_alias;
if (remote_content)
msg.remoteMessageContent = remote_content;
}
if (reply_uuid)
msg.replyUuid = reply_uuid;
const message = yield models_1.models.Message.create(msg);
socket.sendJson({
type: 'boost',
response: jsonUtils.messageToJson(message, chat, sender)
});
});
exports.receiveDeleteMessage = (payload) => __awaiter(void 0, void 0, void 0, function* () { exports.receiveDeleteMessage = (payload) => __awaiter(void 0, void 0, void 0, function* () {
console.log('=> received delete message'); console.log('=> received delete message');
const { owner, sender, chat, chat_type, msg_uuid } = yield helpers.parseReceiveParams(payload); const { owner, sender, chat, chat_type, msg_uuid } = yield helpers.parseReceiveParams(payload);

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

File diff suppressed because one or more lines are too long

33
dist/src/network/receive.js

@ -33,13 +33,13 @@ in receiveDeleteMessage check the deleter is og sender?
const msgtypes = constants_1.default.message_types; const msgtypes = constants_1.default.message_types;
exports.typesToForward = [ exports.typesToForward = [
msgtypes.message, msgtypes.group_join, msgtypes.group_leave, msgtypes.message, msgtypes.group_join, msgtypes.group_leave,
msgtypes.attachment, msgtypes.delete, msgtypes.attachment, msgtypes.delete, msgtypes.boost,
]; ];
const typesToModify = [ const typesToModify = [
msgtypes.attachment msgtypes.attachment
]; ];
const typesThatNeedPricePerMessage = [ const typesThatNeedPricePerMessage = [
msgtypes.message, msgtypes.attachment msgtypes.message, msgtypes.attachment, msgtypes.boost
]; ];
exports.typesToReplay = [ exports.typesToReplay = [
msgtypes.message, msgtypes.message,
@ -135,6 +135,18 @@ function onReceive(payload) {
doAction = true; doAction = true;
} }
} }
// forward boost sats to recipient
if (payload.type === msgtypes.boost && payload.message.replyUuid) {
const ogMsg = yield models_1.models.Message.findOne({ where: {
uuid: payload.message.replyUuid,
} });
if (ogMsg) {
const amtToForward = payload.message.amount - (chat.pricePerMessage || 0) - (chat.escrowAmount || 0);
if (amtToForward > 0) {
forwardSatsToContact(chat, ogMsg.sender, amtToForward, payload.message.replyUuid);
}
}
}
if (doAction) if (doAction)
forwardMessageToTribe(payload, senderContact); forwardMessageToTribe(payload, senderContact);
else else
@ -170,7 +182,8 @@ function onReceive(payload) {
function doTheAction(data) { function doTheAction(data) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let payload = data; let payload = data;
if (payload.isTribeOwner) { if (payload.isTribeOwner) { // this is only for storing locally, my own messages as tribe owner
// actual encryption for tribe happens in personalizeMessage
const ogContent = data.message && data.message.content; const ogContent = data.message && data.message.content;
// const ogMediaKey = data.message && data.message.mediaKey // const ogMediaKey = data.message && data.message.mediaKey
/* decrypt and re-encrypt with phone's pubkey for storage */ /* decrypt and re-encrypt with phone's pubkey for storage */
@ -190,6 +203,20 @@ function doTheAction(data) {
} }
}); });
} }
function forwardSatsToContact(chat, contactId, amount, theuuid) {
return __awaiter(this, void 0, void 0, function* () {
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
send_1.sendMessage({
chat: Object.assign(Object.assign({}, chat.dataValues), { contactIds: [contactId] }),
sender: owner,
type: constants_1.default.message_types.keysend,
amount: amount,
message: { content: '!' },
success: () => { },
failure: () => { }
});
});
}
function forwardMessageToTribe(ogpayload, sender) { function forwardMessageToTribe(ogpayload, sender) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
// console.log('forwardMessageToTribe') // console.log('forwardMessageToTribe')

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

File diff suppressed because one or more lines are too long

1
src/constants.ts

@ -56,6 +56,7 @@ const constants = {
"heartbeat": 26, "heartbeat": 26,
"heartbeat_confirmation": 27, "heartbeat_confirmation": 27,
"keysend": 28, // no e2e "keysend": 28, // no e2e
"boost": 29,
}, },
payment_errors: { payment_errors: {
"timeout": "Timed Out", "timeout": "Timed Out",

1
src/controllers/index.ts

@ -151,4 +151,5 @@ export const ACTIONS = {
[msgtypes.bot_res]: bots.receiveBotRes, [msgtypes.bot_res]: bots.receiveBotRes,
[msgtypes.heartbeat]: confirmations.receiveHeartbeat, [msgtypes.heartbeat]: confirmations.receiveHeartbeat,
[msgtypes.heartbeat_confirmation]: confirmations.receiveHeartbeatConfirmation, [msgtypes.heartbeat_confirmation]: confirmations.receiveHeartbeatConfirmation,
[msgtypes.boost]: messages.receiveBoost,
} }

56
src/controllers/messages.ts

@ -157,8 +157,12 @@ export const sendMessage = async (req, res) => {
remote_text_map, remote_text_map,
amount, amount,
reply_uuid, reply_uuid,
boost,
} = req.body } = req.body
let msgtype = constants.message_types.message
if(boost) msgtype = constants.message_types.boost
var date = new Date() var date = new Date()
date.setMilliseconds(0) date.setMilliseconds(0)
@ -173,7 +177,7 @@ export const sendMessage = async (req, res) => {
const msg:{[k:string]:any}={ const msg:{[k:string]:any}={
chatId: chat.id, chatId: chat.id,
uuid: short.generate(), uuid: short.generate(),
type: constants.message_types.message, type: msgtype,
sender: owner.id, sender: owner.id,
amount: amount||0, amount: amount||0,
date: date, date: date,
@ -199,7 +203,7 @@ export const sendMessage = async (req, res) => {
chat: chat, chat: chat,
sender: owner, sender: owner,
amount: amount||0, amount: amount||0,
type: constants.message_types.message, type: msgtype,
message: msgToSend, message: msgToSend,
}) })
} }
@ -207,12 +211,11 @@ export const sendMessage = async (req, res) => {
export const receiveMessage = async (payload) => { export const receiveMessage = async (payload) => {
// console.log('received message', { payload }) // console.log('received message', { payload })
const total_spent = 1 const {owner, sender, chat, content, remote_content, msg_id, chat_type, sender_alias, msg_uuid, date_string, reply_uuid, amount} = await helpers.parseReceiveParams(payload)
const {owner, sender, chat, content, remote_content, msg_id, chat_type, sender_alias, msg_uuid, date_string, reply_uuid} = await helpers.parseReceiveParams(payload)
if(!owner || !sender || !chat) { if(!owner || !sender || !chat) {
return console.log('=> no group chat!') return console.log('=> no group chat!')
} }
const text = content const text = content||''
var date = new Date(); var date = new Date();
date.setMilliseconds(0) date.setMilliseconds(0)
@ -222,9 +225,9 @@ export const receiveMessage = async (payload) => {
chatId: chat.id, chatId: chat.id,
uuid: msg_uuid, uuid: msg_uuid,
type: constants.message_types.message, type: constants.message_types.message,
asciiEncodedTotal: total_spent,
sender: sender.id, sender: sender.id,
date: date, date: date,
amount: amount||0,
messageContent: text, messageContent: text,
createdAt: date, createdAt: date,
updatedAt: date, updatedAt: date,
@ -238,8 +241,6 @@ export const receiveMessage = async (payload) => {
if(reply_uuid) msg.replyUuid = reply_uuid if(reply_uuid) msg.replyUuid = reply_uuid
const message = await models.Message.create(msg) const message = await models.Message.create(msg)
// console.log('saved message', message.dataValues)
socket.sendJson({ socket.sendJson({
type: 'message', type: 'message',
response: jsonUtils.messageToJson(message, chat, sender) response: jsonUtils.messageToJson(message, chat, sender)
@ -251,6 +252,45 @@ export const receiveMessage = async (payload) => {
sendConfirmation({ chat:theChat, sender: owner, msg_id }) sendConfirmation({ chat:theChat, sender: owner, msg_id })
} }
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, amount} = await helpers.parseReceiveParams(payload)
if(!owner || !sender || !chat) {
return console.log('=> no group chat!')
}
const text = content
var date = new Date();
date.setMilliseconds(0)
if(date_string) date=new Date(date_string)
const msg:{[k:string]:any} = {
chatId: chat.id,
uuid: msg_uuid,
type: constants.message_types.boost,
sender: sender.id,
date: date,
amount: amount||0,
messageContent: text,
createdAt: date,
updatedAt: date,
status: constants.statuses.received
}
const isTribe = chat_type===constants.chat_types.tribe
if(isTribe) {
msg.senderAlias = sender_alias
if(remote_content) msg.remoteMessageContent=remote_content
}
if(reply_uuid) msg.replyUuid = reply_uuid
const message = await models.Message.create(msg)
socket.sendJson({
type: 'boost',
response: jsonUtils.messageToJson(message, chat, sender)
})
}
export const receiveDeleteMessage = async (payload) => { export const receiveDeleteMessage = async (payload) => {
console.log('=> received delete message') console.log('=> received delete message')
const {owner, sender, chat, chat_type, msg_uuid} = await helpers.parseReceiveParams(payload) const {owner, sender, chat, chat_type, msg_uuid} = await helpers.parseReceiveParams(payload)

32
src/network/receive.ts

@ -25,13 +25,13 @@ const msgtypes = constants.message_types
export const typesToForward=[ export const typesToForward=[
msgtypes.message, msgtypes.group_join, msgtypes.group_leave, msgtypes.message, msgtypes.group_join, msgtypes.group_leave,
msgtypes.attachment, msgtypes.delete, msgtypes.attachment, msgtypes.delete, msgtypes.boost,
] ]
const typesToModify=[ const typesToModify=[
msgtypes.attachment msgtypes.attachment
] ]
const typesThatNeedPricePerMessage = [ const typesThatNeedPricePerMessage = [
msgtypes.message, msgtypes.attachment msgtypes.message, msgtypes.attachment, msgtypes.boost
] ]
export const typesToReplay=[ // should match typesToForward export const typesToReplay=[ // should match typesToForward
msgtypes.message, msgtypes.message,
@ -121,6 +121,18 @@ async function onReceive(payload){
if(ogMsg) doAction = true if(ogMsg) doAction = true
} }
} }
// forward boost sats to recipient
if(payload.type===msgtypes.boost && payload.message.replyUuid) {
const ogMsg = await models.Message.findOne({where:{
uuid: payload.message.replyUuid,
}})
if(ogMsg) {
const amtToForward = payload.message.amount - (chat.pricePerMessage||0) - (chat.escrowAmount||0)
if(amtToForward>0) {
forwardSatsToContact(chat,ogMsg.sender,amtToForward,payload.message.replyUuid)
}
}
}
if(doAction) forwardMessageToTribe(payload, senderContact) if(doAction) forwardMessageToTribe(payload, senderContact)
else console.log('=> insufficient payment for this action') else console.log('=> insufficient payment for this action')
} }
@ -152,7 +164,8 @@ async function onReceive(payload){
async function doTheAction(data){ async function doTheAction(data){
let payload = data let payload = data
if(payload.isTribeOwner) { if(payload.isTribeOwner) { // this is only for storing locally, my own messages as tribe owner
// actual encryption for tribe happens in personalizeMessage
const ogContent = data.message && data.message.content const ogContent = data.message && data.message.content
// const ogMediaKey = data.message && data.message.mediaKey // const ogMediaKey = data.message && data.message.mediaKey
/* decrypt and re-encrypt with phone's pubkey for storage */ /* decrypt and re-encrypt with phone's pubkey for storage */
@ -170,6 +183,19 @@ async function doTheAction(data){
} }
} }
async function forwardSatsToContact(chat,contactId:number,amount:number,theuuid) {
const owner = await models.Contact.findOne({where:{isOwner:true}})
sendMessage({
chat: {...chat.dataValues, contactIds:[contactId]},
sender: owner,
type: constants.message_types.keysend,
amount: amount,
message: { content:'!' },
success: ()=>{},
failure: ()=>{}
})
}
async function forwardMessageToTribe(ogpayload, sender){ async function forwardMessageToTribe(ogpayload, sender){
// console.log('forwardMessageToTribe') // console.log('forwardMessageToTribe')
const chat = await models.Chat.findOne({where:{uuid:ogpayload.chat.uuid}}) const chat = await models.Chat.findOne({where:{uuid:ogpayload.chat.uuid}})

Loading…
Cancel
Save