Browse Source

network_type migration, include network_type in all recieved messages, boosts are auto forwarded, choose network in network.sendMessage

dependabot/npm_and_yarn/ini-1.3.7
Evan Feenstra 4 years ago
parent
commit
c59d8a489e
  1. 4
      dist/src/constants.js
  2. 2
      dist/src/constants.js.map
  3. 2
      dist/src/controllers/bots.js
  4. 2
      dist/src/controllers/bots.js.map
  5. 20
      dist/src/controllers/chatTribes.js
  6. 2
      dist/src/controllers/chatTribes.js.map
  7. 13
      dist/src/controllers/chats.js
  8. 2
      dist/src/controllers/chats.js.map
  9. 4
      dist/src/controllers/invoices.js
  10. 2
      dist/src/controllers/invoices.js.map
  11. 21
      dist/src/controllers/media.js
  12. 2
      dist/src/controllers/media.js.map
  13. 46
      dist/src/controllers/messages.js
  14. 2
      dist/src/controllers/messages.js.map
  15. 17
      dist/src/controllers/payment.js
  16. 2
      dist/src/controllers/payment.js.map
  17. 3
      dist/src/helpers.js
  18. 2
      dist/src/helpers.js.map
  19. 4
      dist/src/models/ts/message.js
  20. 2
      dist/src/models/ts/message.js.map
  21. 2
      dist/src/network/modify.js
  22. 2
      dist/src/network/modify.js.map
  23. 29
      dist/src/network/receive.js
  24. 2
      dist/src/network/receive.js.map
  25. 7
      dist/src/network/send.js
  26. 2
      dist/src/network/send.js.map
  27. 1
      dist/src/utils/setup.js
  28. 2
      dist/src/utils/setup.js.map
  29. 4
      src/constants.ts
  30. 3
      src/controllers/bots.ts
  31. 20
      src/controllers/chatTribes.ts
  32. 13
      src/controllers/chats.ts
  33. 4
      src/controllers/invoices.ts
  34. 21
      src/controllers/media.ts
  35. 49
      src/controllers/messages.ts
  36. 23
      src/controllers/payment.ts
  37. 3
      src/helpers.ts
  38. 3
      src/models/ts/message.ts
  39. 2
      src/network/modify.ts
  40. 29
      src/network/receive.ts
  41. 10
      src/network/send.ts
  42. 2
      src/utils/setup.ts

4
dist/src/constants.js

@ -60,6 +60,10 @@ const constants = {
"keysend": 28,
"boost": 29,
},
network_types: {
"lightning": 0,
"mqtt": 1,
},
payment_errors: {
"timeout": "Timed Out",
"no_route": "No Route To Receiver",

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;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"}
{"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,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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"}

2
dist/src/controllers/bots.js

@ -309,6 +309,7 @@ function receiveBotRes(payload) {
const bot_name = dat.bot_name;
const sender_alias = dat.sender.alias;
const date_string = dat.message.date;
const network_type = dat.network_type || 0;
if (!chat_uuid)
return console.log('=> receiveBotRes Error no chat_uuid');
const chat = yield models_1.models.Chat.findOne({ where: { uuid: chat_uuid } });
@ -349,6 +350,7 @@ function receiveBotRes(payload) {
createdAt: date,
updatedAt: date,
senderAlias: sender_alias || 'Bot',
network_type
};
const message = yield models_1.models.Message.create(msg);
socket.sendJson({

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

File diff suppressed because one or more lines are too long

20
dist/src/controllers/chatTribes.js

@ -119,7 +119,7 @@ exports.joinTribe = joinTribe;
function receiveMemberRequest(payload) {
return __awaiter(this, void 0, void 0, function* () {
console.log('=> receiveMemberRequest');
const { sender_pub_key, sender_alias, chat_uuid, chat_members, chat_type, isTribeOwner } = yield helpers.parseReceiveParams(payload);
const { sender_pub_key, sender_alias, chat_uuid, chat_members, chat_type, isTribeOwner, network_type } = yield helpers.parseReceiveParams(payload);
const chat = yield models_1.models.Chat.findOne({ where: { uuid: chat_uuid } });
if (!chat)
return console.log('no chat');
@ -173,7 +173,8 @@ function receiveMemberRequest(payload) {
sender: (theSender && theSender.id) || 0,
messageContent: '', remoteMessageContent: '',
status: constants_1.default.statuses.confirmed,
date: date, createdAt: date, updatedAt: date
date: date, createdAt: date, updatedAt: date,
network_type
};
if (isTribe) {
msg.senderAlias = sender_alias;
@ -314,7 +315,7 @@ exports.approveOrRejectMember = approveOrRejectMember;
function receiveMemberApprove(payload) {
return __awaiter(this, void 0, void 0, function* () {
console.log('=> receiveMemberApprove');
const { owner, chat, chat_name, sender } = yield helpers.parseReceiveParams(payload);
const { owner, chat, chat_name, sender, network_type } = yield helpers.parseReceiveParams(payload);
if (!chat)
return console.log('no chat');
yield chat.update({ status: constants_1.default.chat_statuses.approved });
@ -326,7 +327,8 @@ function receiveMemberApprove(payload) {
sender: (sender && sender.id) || 0,
messageContent: '', remoteMessageContent: '',
status: constants_1.default.statuses.confirmed,
date: date, createdAt: date, updatedAt: date
date: date, createdAt: date, updatedAt: date,
network_type
};
const message = yield models_1.models.Message.create(msg);
socket.sendJson({
@ -358,7 +360,7 @@ exports.receiveMemberApprove = receiveMemberApprove;
function receiveMemberReject(payload) {
return __awaiter(this, void 0, void 0, function* () {
console.log('=> receiveMemberReject');
const { chat, sender, chat_name } = yield helpers.parseReceiveParams(payload);
const { chat, sender, chat_name, network_type } = yield helpers.parseReceiveParams(payload);
if (!chat)
return console.log('no chat');
yield chat.update({ status: constants_1.default.chat_statuses.rejected });
@ -371,7 +373,8 @@ function receiveMemberReject(payload) {
sender: (sender && sender.id) || 0,
messageContent: '', remoteMessageContent: '',
status: constants_1.default.statuses.confirmed,
date: date, createdAt: date, updatedAt: date
date: date, createdAt: date, updatedAt: date,
network_type
};
const message = yield models_1.models.Message.create(msg);
socket.sendJson({
@ -388,7 +391,7 @@ exports.receiveMemberReject = receiveMemberReject;
function receiveTribeDelete(payload) {
return __awaiter(this, void 0, void 0, function* () {
console.log('=> receiveTribeDelete');
const { chat, sender } = yield helpers.parseReceiveParams(payload);
const { chat, sender, network_type } = yield helpers.parseReceiveParams(payload);
if (!chat)
return console.log('no chat');
// await chat.update({status: constants.chat_statuses.rejected})
@ -401,7 +404,8 @@ function receiveTribeDelete(payload) {
sender: (sender && sender.id) || 0,
messageContent: '', remoteMessageContent: '',
status: constants_1.default.statuses.confirmed,
date: date, createdAt: date, updatedAt: date
date: date, createdAt: date, updatedAt: date,
network_type
};
const message = yield models_1.models.Message.create(msg);
socket.sendJson({

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

File diff suppressed because one or more lines are too long

13
dist/src/controllers/chats.js

@ -79,7 +79,7 @@ exports.kickChatMember = kickChatMember;
function receiveGroupKick(payload) {
return __awaiter(this, void 0, void 0, function* () {
console.log('=> receiveGroupKick');
const { chat, sender, date_string } = yield helpers.parseReceiveParams(payload);
const { chat, sender, date_string, network_type } = yield helpers.parseReceiveParams(payload);
if (!chat)
return;
// const owner = await models.Contact.findOne({where:{isOwner:true}})
@ -104,6 +104,7 @@ function receiveGroupKick(payload) {
messageContent: '', remoteMessageContent: '',
status: constants_1.default.statuses.confirmed,
date: date, createdAt: date, updatedAt: date,
network_type
};
const message = yield models_1.models.Message.create(msg);
socket.sendJson({
@ -318,7 +319,7 @@ exports.deleteChat = (req, res) => __awaiter(void 0, void 0, void 0, function* (
function receiveGroupJoin(payload) {
return __awaiter(this, void 0, void 0, function* () {
console.log('=> receiveGroupJoin');
const { sender_pub_key, sender_alias, chat_uuid, chat_members, chat_type, isTribeOwner, date_string } = yield helpers.parseReceiveParams(payload);
const { sender_pub_key, sender_alias, chat_uuid, chat_members, chat_type, isTribeOwner, date_string, network_type } = yield helpers.parseReceiveParams(payload);
const chat = yield models_1.models.Chat.findOne({ where: { uuid: chat_uuid } });
if (!chat)
return;
@ -386,7 +387,8 @@ function receiveGroupJoin(payload) {
sender: (theSender && theSender.id) || 0,
messageContent: '', remoteMessageContent: '',
status: constants_1.default.statuses.confirmed,
date: date, createdAt: date, updatedAt: date
date: date, createdAt: date, updatedAt: date,
network_type
};
if (isTribe) {
msg.senderAlias = sender_alias;
@ -407,7 +409,7 @@ exports.receiveGroupJoin = receiveGroupJoin;
function receiveGroupLeave(payload) {
return __awaiter(this, void 0, void 0, function* () {
console.log('=> receiveGroupLeave');
const { sender_pub_key, chat_uuid, chat_type, sender_alias, isTribeOwner, date_string } = yield helpers.parseReceiveParams(payload);
const { sender_pub_key, chat_uuid, chat_type, sender_alias, isTribeOwner, date_string, network_type } = yield helpers.parseReceiveParams(payload);
const chat = yield models_1.models.Chat.findOne({ where: { uuid: chat_uuid } });
if (!chat)
return;
@ -446,7 +448,8 @@ function receiveGroupLeave(payload) {
sender: (sender && sender.id) || 0,
messageContent: '', remoteMessageContent: '',
status: constants_1.default.statuses.confirmed,
date: date, createdAt: date, updatedAt: date
date: date, createdAt: date, updatedAt: date,
network_type
};
if (isTribe) {
msg.senderAlias = sender_alias;

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

File diff suppressed because one or more lines are too long

4
dist/src/controllers/invoices.js

@ -204,6 +204,7 @@ exports.receiveInvoice = (payload) => __awaiter(void 0, void 0, void 0, function
const total_spent = 1;
const dat = payload.content || payload;
const payment_request = dat.message.invoice;
const network_type = dat.network_type || 0;
var date = new Date();
date.setMilliseconds(0);
const { owner, sender, chat, msg_id, chat_type, sender_alias, msg_uuid } = yield helpers.parseReceiveParams(payload);
@ -226,7 +227,8 @@ exports.receiveInvoice = (payload) => __awaiter(void 0, void 0, void 0, function
date: new Date(invoiceDate),
status: constants_1.default.statuses.pending,
createdAt: date,
updatedAt: date
updatedAt: date,
network_type: network_type,
};
const isTribe = chat_type === constants_1.default.chat_types.tribe;
if (isTribe) {

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

File diff suppressed because one or more lines are too long

21
dist/src/controllers/media.js

@ -185,6 +185,7 @@ exports.purchase = (req, res) => __awaiter(void 0, void 0, void 0, function* ()
chat: Object.assign(Object.assign({}, chat.dataValues), { contactIds: [contact_id] }),
sender: owner,
type: constants_1.default.message_types.purchase,
realSatsContactId: contact_id,
message: msg,
amount: amount,
success: (data) => __awaiter(void 0, void 0, void 0, function* () {
@ -199,7 +200,7 @@ exports.receivePurchase = (payload) => __awaiter(void 0, void 0, void 0, functio
console.log('=> received purchase', { payload });
var date = new Date();
date.setMilliseconds(0);
const { owner, sender, chat, amount, mediaToken, msg_uuid, chat_type, skip_payment_processing, purchaser_id } = yield helpers.parseReceiveParams(payload);
const { owner, sender, chat, amount, mediaToken, msg_uuid, chat_type, skip_payment_processing, purchaser_id, network_type } = yield helpers.parseReceiveParams(payload);
if (!owner || !sender || !chat) {
return console.log('=> group chat not found!');
}
@ -212,7 +213,8 @@ exports.receivePurchase = (payload) => __awaiter(void 0, void 0, void 0, functio
mediaToken: mediaToken,
date: date,
createdAt: date,
updatedAt: date
updatedAt: date,
network_type
});
socket.sendJson({
type: 'purchase',
@ -319,7 +321,7 @@ exports.receivePurchaseAccept = (payload) => __awaiter(void 0, void 0, void 0, f
console.log('=> receivePurchaseAccept');
var date = new Date();
date.setMilliseconds(0);
const { owner, sender, chat, mediaToken, mediaKey, mediaType, originalMuid } = yield helpers.parseReceiveParams(payload);
const { owner, sender, chat, mediaToken, mediaKey, mediaType, originalMuid, network_type } = yield helpers.parseReceiveParams(payload);
if (!owner || !sender || !chat) {
return console.log('=> no group chat!');
}
@ -349,7 +351,8 @@ exports.receivePurchaseAccept = (payload) => __awaiter(void 0, void 0, void 0, f
originalMuid: originalMuid || '',
date: date,
createdAt: date,
updatedAt: date
updatedAt: date,
network_type
});
socket.sendJson({
type: 'purchase_accept',
@ -360,7 +363,7 @@ exports.receivePurchaseDeny = (payload) => __awaiter(void 0, void 0, void 0, fun
console.log('=> receivePurchaseDeny');
var date = new Date();
date.setMilliseconds(0);
const { owner, sender, chat, amount, mediaToken } = yield helpers.parseReceiveParams(payload);
const { owner, sender, chat, amount, mediaToken, network_type } = yield helpers.parseReceiveParams(payload);
if (!owner || !sender || !chat) {
return console.log('=> no group chat!');
}
@ -375,7 +378,8 @@ exports.receivePurchaseDeny = (payload) => __awaiter(void 0, void 0, void 0, fun
mediaToken,
date: date,
createdAt: date,
updatedAt: date
updatedAt: date,
network_type
});
socket.sendJson({
type: 'purchase_deny',
@ -386,7 +390,7 @@ exports.receiveAttachment = (payload) => __awaiter(void 0, void 0, void 0, funct
// console.log('received attachment', { payload })
var date = new Date();
date.setMilliseconds(0);
const { owner, sender, chat, mediaToken, mediaKey, mediaType, content, msg_id, chat_type, sender_alias, msg_uuid, reply_uuid } = yield helpers.parseReceiveParams(payload);
const { owner, sender, chat, mediaToken, mediaKey, mediaType, content, msg_id, chat_type, sender_alias, msg_uuid, reply_uuid, network_type } = yield helpers.parseReceiveParams(payload);
if (!owner || !sender || !chat) {
return console.log('=> no group chat!');
}
@ -397,7 +401,8 @@ exports.receiveAttachment = (payload) => __awaiter(void 0, void 0, void 0, funct
sender: sender.id,
date: date,
createdAt: date,
updatedAt: date
updatedAt: date,
network_type
};
if (content)
msg.messageContent = content;

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

File diff suppressed because one or more lines are too long

46
dist/src/controllers/messages.js

@ -22,7 +22,6 @@ 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) {
@ -178,47 +177,30 @@ exports.sendMessage = (req, res) => __awaiter(void 0, void 0, void 0, function*
};
if (reply_uuid)
msgToSend.replyUuid = reply_uuid;
network.sendMessage({
const sendMessageParams = {
chat: chat,
sender: owner,
amount: amount || 0,
type: msgtype,
message: msgToSend,
});
};
// IF BOOST AND TRIBE OWNER NEED TO SEND ACTUAL SATS TO OG POSTER
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
});
if (ogMsg && ogMsg.sender) {
sendMessageParams.realSatsContactId = 123;
}
});
}
}
// final send
network.sendMessage(sendMessageParams);
});
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, amount } = yield helpers.parseReceiveParams(payload);
const { owner, sender, chat, content, remote_content, msg_id, chat_type, sender_alias, msg_uuid, date_string, reply_uuid, amount, network_type } = yield helpers.parseReceiveParams(payload);
if (!owner || !sender || !chat) {
return console.log('=> no group chat!');
}
@ -237,7 +219,8 @@ exports.receiveMessage = (payload) => __awaiter(void 0, void 0, void 0, function
messageContent: text,
createdAt: date,
updatedAt: date,
status: constants_1.default.statuses.received
status: constants_1.default.statuses.received,
network_type: network_type,
};
const isTribe = chat_type === constants_1.default.chat_types.tribe;
if (isTribe) {
@ -258,7 +241,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, amount } = yield helpers.parseReceiveParams(payload);
const { owner, sender, chat, content, remote_content, chat_type, sender_alias, msg_uuid, date_string, reply_uuid, amount, network_type } = yield helpers.parseReceiveParams(payload);
if (!owner || !sender || !chat) {
return console.log('=> no group chat!');
}
@ -277,7 +260,8 @@ exports.receiveBoost = (payload) => __awaiter(void 0, void 0, void 0, function*
messageContent: text,
createdAt: date,
updatedAt: date,
status: constants_1.default.statuses.received
status: constants_1.default.statuses.received,
network_type
};
const isTribe = chat_type === constants_1.default.chat_types.tribe;
if (isTribe) {

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

File diff suppressed because one or more lines are too long

17
dist/src/controllers/payment.js

@ -115,7 +115,7 @@ exports.receivePayment = (payload) => __awaiter(void 0, void 0, void 0, function
console.log('received payment', { payload });
var date = new Date();
date.setMilliseconds(0);
const { owner, sender, chat, amount, content, mediaType, mediaToken, chat_type, sender_alias, msg_uuid, reply_uuid } = yield helpers.parseReceiveParams(payload);
const { owner, sender, chat, amount, content, mediaType, mediaToken, chat_type, sender_alias, msg_uuid, reply_uuid, network_type } = yield helpers.parseReceiveParams(payload);
if (!owner || !sender || !chat) {
return console.log('=> no group chat!');
}
@ -128,7 +128,8 @@ exports.receivePayment = (payload) => __awaiter(void 0, void 0, void 0, function
amountMsat: parseFloat(amount) * 1000,
date: date,
createdAt: date,
updatedAt: date
updatedAt: date,
network_type
};
if (content)
msg.messageContent = content;
@ -152,7 +153,7 @@ exports.receivePayment = (payload) => __awaiter(void 0, void 0, void 0, function
exports.listPayments = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
const limit = (req.query.limit && parseInt(req.query.limit)) || 100;
const offset = (req.query.offset && parseInt(req.query.offset)) || 0;
// const MIN_VAL=constants.min_sat_amount
const MIN_VAL = constants_1.default.min_sat_amount;
try {
const msgs = yield models_1.models.Message.findAll({
where: {
@ -164,6 +165,16 @@ exports.listPayments = (req, res) => __awaiter(void 0, void 0, void 0, function*
constants_1.default.message_types.keysend,
] }
},
{
type: { [sequelize_1.Op.or]: [
constants_1.default.message_types.message,
constants_1.default.message_types.boost,
] },
amount: {
[sequelize_1.Op.gt]: MIN_VAL // greater than
},
network_type: constants_1.default.network_types.lightning
}
],
},
order: [['createdAt', 'desc']],

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

File diff suppressed because one or more lines are too long

3
dist/src/helpers.js

@ -168,6 +168,7 @@ function parseReceiveParams(payload) {
const skip_payment_processing = dat.message.skipPaymentProcessing;
const reply_uuid = dat.message.replyUuid;
const purchaser_id = dat.message.purchaser;
const network_type = dat.network_type || 0;
const isTribeOwner = dat.isTribeOwner ? true : false;
const isConversation = !chat_type || (chat_type && chat_type == constants_1.default.chat_types.conversation);
let sender;
@ -188,7 +189,7 @@ function parseReceiveParams(payload) {
}
chat = yield models_1.models.Chat.findOne({ where: { uuid: chat_uuid } });
}
return { owner, sender, chat, sender_pub_key, sender_alias, isTribeOwner, chat_uuid, amount, content, mediaToken, mediaKey, mediaType, originalMuid, chat_type, msg_id, chat_members, chat_name, chat_host, chat_key, remote_content, msg_uuid, date_string, reply_uuid, skip_payment_processing, purchaser_id, sender_photo_url };
return { owner, sender, chat, sender_pub_key, sender_alias, isTribeOwner, chat_uuid, amount, content, mediaToken, mediaKey, mediaType, originalMuid, chat_type, msg_id, chat_members, chat_name, chat_host, chat_key, remote_content, msg_uuid, date_string, reply_uuid, skip_payment_processing, purchaser_id, sender_photo_url, network_type };
});
}
exports.parseReceiveParams = parseReceiveParams;

2
dist/src/helpers.js.map

File diff suppressed because one or more lines are too long

4
dist/src/models/ts/message.js

@ -129,6 +129,10 @@ __decorate([
sequelize_typescript_1.Column,
__metadata("design:type", String)
], Message.prototype, "replyUuid", void 0);
__decorate([
sequelize_typescript_1.Column(sequelize_typescript_1.DataType.INTEGER),
__metadata("design:type", Number)
], Message.prototype, "network_type", void 0);
Message = __decorate([
sequelize_typescript_1.Table({ tableName: 'sphinx_messages', underscored: true })
], Message);

2
dist/src/models/ts/message.js.map

@ -1 +1 @@
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../../../src/models/ts/message.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+DAAsE;AAGtE,IAAqB,OAAO,GAA5B,MAAqB,OAAQ,SAAQ,4BAAc;CA2FlD,CAAA;AAnFC;IANC,6BAAM,CAAC;QACN,IAAI,EAAE,+BAAQ,CAAC,MAAM;QACrB,UAAU,EAAE,IAAI;QAChB,MAAM,EAAE,IAAI;QACZ,aAAa,EAAE,IAAI;KACpB,CAAC;;mCACQ;AAGV;IADC,6BAAM;;qCACK;AAGZ;IADC,6BAAM,CAAC,+BAAQ,CAAC,MAAM,CAAC;;uCACV;AAGd;IADC,6BAAM,CAAC,+BAAQ,CAAC,MAAM,CAAC;;qC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;IADC,6BAAM;;yCACS;AAGhB;IADC,6BAAM;;0CACU;AAGjB;IADC,6BAAM;;2CACW;AAOlB;IALC,6BAAM,CAAC;QACN,IAAI,EAAE,+BAAQ,CAAC,OAAO;QACtB,YAAY,EAAE,KAAK;QACnB,SAAS,EAAE,KAAK;KACjB,CAAC;;qCACW;AAGb;IADC,6BAAM;8BACI,IAAI;0CAAA;AAGf;IADC,6BAAM;8BACI,IAAI;0CAAA;AAGf;IADC,6BAAM;;4CACY;AAGnB;IADC,6BAAM;;6CACa;AAGpB;IADC,6BAAM;;0CACU;AAGjB;IADC,6BAAM,CAAC,+BAAQ,CAAC,OAAO,CAAC;;6CACL;AA7FD,OAAO;IAD3B,4BAAK,CAAC,EAAC,SAAS,EAAE,iBAAiB,EAAE,WAAW,EAAE,IAAI,EAAC,CAAC;GACpC,OAAO,CA8F3B;kBA9FoB,OAAO"}

2
dist/src/network/modify.js

@ -79,6 +79,7 @@ function purchaseFromOriginalSender(payload, chat, purchaser) {
sender: owner,
type: constants_1.default.message_types.purchase,
amount: amount,
realSatsContactId: mediaKey.sender,
message: {
mediaToken: mt,
skipPaymentProcessing: true,
@ -97,6 +98,7 @@ function purchaseFromOriginalSender(payload, chat, purchaser) {
chat: Object.assign(Object.assign({}, chat.dataValues), { contactIds: [ogmsg.sender] }),
sender: Object.assign(Object.assign(Object.assign({}, owner.dataValues), purchaser && purchaser.alias && { alias: purchaser.alias }), { role: constants_1.default.chat_roles.reader }),
type: constants_1.default.message_types.purchase,
realSatsContactId: ogmsg.sender,
message: msg,
amount: amount,
success: () => { },

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

File diff suppressed because one or more lines are too long

29
dist/src/network/receive.js

@ -136,6 +136,7 @@ function onReceive(payload) {
}
}
// forward boost sats to recipient
let realSatsContactId = null;
if (payload.type === msgtypes.boost && payload.message.replyUuid) {
const ogMsg = yield models_1.models.Message.findOne({ where: {
uuid: payload.message.replyUuid,
@ -143,12 +144,12 @@ function onReceive(payload) {
if (ogMsg && ogMsg.sender && ogMsg.sender !== 1) {
const amtToForward = payload.message.amount - (chat.pricePerMessage || 0) - (chat.escrowAmount || 0);
if (amtToForward > 0) {
forwardBoostSatsToContact(chat, ogMsg.sender, amtToForward);
realSatsContactId = ogMsg.sender;
}
}
}
if (doAction)
forwardMessageToTribe(payload, senderContact);
forwardMessageToTribe(payload, senderContact, realSatsContactId);
else
console.log('=> insufficient payment for this action');
}
@ -203,23 +204,7 @@ function doTheAction(data) {
}
});
}
function forwardBoostSatsToContact(chat, contactId, amount) {
return __awaiter(this, void 0, void 0, function* () {
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] }),
sender: owner,
type: constants_1.default.message_types.keysend,
amount: amount,
message: { content: '!' },
success: () => { },
failure: () => { }
});
});
}
exports.forwardBoostSatsToContact = forwardBoostSatsToContact;
function forwardMessageToTribe(ogpayload, sender) {
function forwardMessageToTribe(ogpayload, sender, realSatsContactId) {
return __awaiter(this, void 0, void 0, function* () {
// console.log('forwardMessageToTribe')
const chat = yield models_1.models.Chat.findOne({ where: { uuid: ogpayload.chat.uuid } });
@ -242,6 +227,7 @@ function forwardMessageToTribe(ogpayload, sender) {
sender: Object.assign(Object.assign(Object.assign({}, owner.dataValues), payload.sender && payload.sender.alias && { alias: payload.sender.alias }), { role: constants_1.default.chat_roles.reader }),
chat: chat,
skipPubKey: payload.sender.pub_key,
realSatsContactId: realSatsContactId,
success: () => { },
receive: () => { },
isForwarded: true,
@ -267,6 +253,7 @@ function initTribesSubscriptions() {
const msg = message.toString();
// check topic is signed by sender?
const payload = yield parseAndVerifyPayload(msg);
payload.network_type = constants_1.default.network_types.mqtt;
onReceive(payload);
}
catch (e) { }
@ -339,7 +326,8 @@ function saveAnonymousKeysend(response, memo, sender_pubkey) {
messageContent: memo || '',
status: constants_1.default.statuses.confirmed,
createdAt: new Date(settleDate),
updatedAt: new Date(settleDate)
updatedAt: new Date(settleDate),
network_type: constants_1.default.network_types.lightning
});
socket.sendJson({
type: 'keysend',
@ -396,6 +384,7 @@ function parseKeysendInvoice(i) {
if (value && dat && dat.message) {
dat.message.amount = value; // ADD IN TRUE VALUE
}
dat.network_type = constants_1.default.network_types.lightning;
onReceive(dat);
}
});

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

File diff suppressed because one or more lines are too long

7
dist/src/network/send.js

@ -20,7 +20,7 @@ const intercept = require("./intercept");
const constants_1 = require("../constants");
function sendMessage(params) {
return __awaiter(this, void 0, void 0, function* () {
const { type, chat, message, sender, amount, success, failure, skipPubKey, isForwarded } = params;
const { type, chat, message, sender, amount, success, failure, skipPubKey, isForwarded, realSatsContactId } = params;
if (!chat || !sender)
return;
const isTribe = chat.type === constants_1.default.chat_types.tribe;
@ -88,9 +88,8 @@ function sendMessage(params) {
console.log('-> sending to ', contact.id, destkey);
let mqttTopic = networkType === 'mqtt' ? `${destkey}/${chatUUID}` : '';
// sending a payment to one subscriber, buying a pic from OG poster
// or keysend such as forwarding boost to og poster
if (isTribeOwner && contactIds.length === 1 && amount && amount > constants_1.default.min_sat_amount &&
(msg.type === constants_1.default.message_types.purchase || msg.type === constants_1.default.message_types.keysend)) {
// or boost to og poster
if (isTribeOwner && amount && realSatsContactId === contactId) {
mqttTopic = ''; // FORCE KEYSEND!!!
}
const m = yield msg_1.personalizeMessage(msg, contact, isTribeOwner);

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

File diff suppressed because one or more lines are too long

1
dist/src/utils/setup.js

@ -49,6 +49,7 @@ function setVersion() {
}
function migrate() {
return __awaiter(this, void 0, void 0, function* () {
addTableColumn('sphinx_messages', 'network_type', 'INTEGER');
addTableColumn('sphinx_chats', 'meta');
addTableColumn('sphinx_contacts', 'tip_amount', 'BIGINT');
addTableColumn('sphinx_contacts', 'last_active', 'DATETIME');

2
dist/src/utils/setup.js.map

File diff suppressed because one or more lines are too long

4
src/constants.ts

@ -58,6 +58,10 @@ const constants = {
"keysend": 28, // no e2e
"boost": 29,
},
network_types: {
"lightning": 0,
"mqtt": 1,
},
payment_errors: {
"timeout": "Timed Out",
"no_route": "No Route To Receiver",

3
src/controllers/bots.ts

@ -176,6 +176,7 @@ export async function receiveBotInstall(payload) {
const sender_pub_key = dat.sender && dat.sender.pub_key
const bot_uuid = dat.bot_uuid
const chat_uuid = dat.chat && dat.chat.uuid
if(!chat_uuid || !sender_pub_key) return console.log('no chat uuid or sender pub key')
const owner = await models.Contact.findOne({ where: { isOwner: true } })
@ -298,6 +299,7 @@ export async function receiveBotRes(payload) {
const bot_name = dat.bot_name
const sender_alias = dat.sender.alias
const date_string = dat.message.date
const network_type = dat.network_type||0
if(!chat_uuid) return console.log('=> receiveBotRes Error no chat_uuid')
@ -339,6 +341,7 @@ export async function receiveBotRes(payload) {
createdAt: date,
updatedAt: date,
senderAlias: sender_alias || 'Bot',
network_type
}
const message = await models.Message.create(msg)
socket.sendJson({

20
src/controllers/chatTribes.ts

@ -114,7 +114,7 @@ export async function joinTribe(req, res){
export async function receiveMemberRequest(payload) {
console.log('=> receiveMemberRequest')
const { sender_pub_key, sender_alias, chat_uuid, chat_members, chat_type, isTribeOwner } = await helpers.parseReceiveParams(payload)
const { sender_pub_key, sender_alias, chat_uuid, chat_members, chat_type, isTribeOwner, network_type } = await helpers.parseReceiveParams(payload)
const chat = await models.Chat.findOne({ where: { uuid: chat_uuid } })
if (!chat) return console.log('no chat')
@ -170,7 +170,8 @@ export async function receiveMemberRequest(payload) {
sender: (theSender && theSender.id) || 0,
messageContent:'', remoteMessageContent:'',
status: constants.statuses.confirmed,
date: date, createdAt: date, updatedAt: date
date: date, createdAt: date, updatedAt: date,
network_type
}
if(isTribe) {
msg.senderAlias = sender_alias
@ -316,7 +317,7 @@ export async function approveOrRejectMember(req,res) {
export async function receiveMemberApprove(payload) {
console.log('=> receiveMemberApprove')
const { owner, chat, chat_name, sender } = await helpers.parseReceiveParams(payload)
const { owner, chat, chat_name, sender, network_type } = await helpers.parseReceiveParams(payload)
if(!chat) return console.log('no chat')
await chat.update({status: constants.chat_statuses.approved})
@ -328,7 +329,8 @@ export async function receiveMemberApprove(payload) {
sender: (sender && sender.id) || 0,
messageContent:'', remoteMessageContent:'',
status: constants.statuses.confirmed,
date: date, createdAt: date, updatedAt: date
date: date, createdAt: date, updatedAt: date,
network_type
}
const message = await models.Message.create(msg)
socket.sendJson({
@ -362,7 +364,7 @@ export async function receiveMemberApprove(payload) {
export async function receiveMemberReject(payload) {
console.log('=> receiveMemberReject')
const { chat, sender, chat_name } = await helpers.parseReceiveParams(payload)
const { chat, sender, chat_name, network_type } = await helpers.parseReceiveParams(payload)
if(!chat) return console.log('no chat')
await chat.update({status: constants.chat_statuses.rejected})
// dang.. nothing really to do here?
@ -374,7 +376,8 @@ export async function receiveMemberReject(payload) {
sender: (sender && sender.id) || 0,
messageContent:'', remoteMessageContent:'',
status: constants.statuses.confirmed,
date: date, createdAt: date, updatedAt: date
date: date, createdAt: date, updatedAt: date,
network_type
}
const message = await models.Message.create(msg)
socket.sendJson({
@ -391,7 +394,7 @@ export async function receiveMemberReject(payload) {
export async function receiveTribeDelete(payload) {
console.log('=> receiveTribeDelete')
const { chat, sender } = await helpers.parseReceiveParams(payload)
const { chat, sender, network_type } = await helpers.parseReceiveParams(payload)
if(!chat) return console.log('no chat')
// await chat.update({status: constants.chat_statuses.rejected})
// update on tribes server too
@ -403,7 +406,8 @@ export async function receiveTribeDelete(payload) {
sender: (sender && sender.id) || 0,
messageContent:'', remoteMessageContent:'',
status: constants.statuses.confirmed,
date: date, createdAt: date, updatedAt: date
date: date, createdAt: date, updatedAt: date,
network_type
}
const message = await models.Message.create(msg)
socket.sendJson({

13
src/controllers/chats.ts

@ -67,7 +67,7 @@ export async function kickChatMember(req, res){
export async function receiveGroupKick(payload) {
console.log('=> receiveGroupKick')
const { chat, sender, date_string } = await helpers.parseReceiveParams(payload)
const { chat, sender, date_string, network_type } = await helpers.parseReceiveParams(payload)
if (!chat) return
// const owner = await models.Contact.findOne({where:{isOwner:true}})
@ -92,6 +92,7 @@ export async function receiveGroupKick(payload) {
messageContent:'', remoteMessageContent:'',
status: constants.statuses.confirmed,
date: date, createdAt: date, updatedAt: date,
network_type
}
const message = await models.Message.create(msg)
@ -323,7 +324,7 @@ export const deleteChat = async (req, res) => {
export async function receiveGroupJoin(payload) {
console.log('=> receiveGroupJoin')
const { sender_pub_key, sender_alias, chat_uuid, chat_members, chat_type, isTribeOwner, date_string } = await helpers.parseReceiveParams(payload)
const { sender_pub_key, sender_alias, chat_uuid, chat_members, chat_type, isTribeOwner, date_string, network_type } = await helpers.parseReceiveParams(payload)
const chat = await models.Chat.findOne({ where: { uuid: chat_uuid } })
if (!chat) return
@ -393,7 +394,8 @@ export async function receiveGroupJoin(payload) {
sender: (theSender && theSender.id) || 0,
messageContent:'', remoteMessageContent:'',
status: constants.statuses.confirmed,
date: date, createdAt: date, updatedAt: date
date: date, createdAt: date, updatedAt: date,
network_type
}
if(isTribe) {
msg.senderAlias = sender_alias
@ -413,7 +415,7 @@ export async function receiveGroupJoin(payload) {
export async function receiveGroupLeave(payload) {
console.log('=> receiveGroupLeave')
const { sender_pub_key, chat_uuid, chat_type, sender_alias, isTribeOwner, date_string } = await helpers.parseReceiveParams(payload)
const { sender_pub_key, chat_uuid, chat_type, sender_alias, isTribeOwner, date_string, network_type } = await helpers.parseReceiveParams(payload)
const chat = await models.Chat.findOne({ where: { uuid: chat_uuid } })
if (!chat) return
@ -454,7 +456,8 @@ export async function receiveGroupLeave(payload) {
sender: (sender && sender.id) || 0,
messageContent:'', remoteMessageContent:'',
status: constants.statuses.confirmed,
date: date, createdAt: date, updatedAt: date
date: date, createdAt: date, updatedAt: date,
network_type
}
if(isTribe) {
msg.senderAlias = sender_alias

4
src/controllers/invoices.ts

@ -221,6 +221,7 @@ export const receiveInvoice = async (payload) => {
const total_spent = 1
const dat = payload.content || payload
const payment_request = dat.message.invoice
const network_type = dat.network_type||0
var date = new Date();
date.setMilliseconds(0)
@ -246,7 +247,8 @@ export const receiveInvoice = async (payload) => {
date: new Date(invoiceDate),
status: constants.statuses.pending,
createdAt: date,
updatedAt: date
updatedAt: date,
network_type: network_type,
}
const isTribe = chat_type===constants.chat_types.tribe
if(isTribe) {

21
src/controllers/media.ts

@ -206,6 +206,7 @@ export const purchase = async (req, res) => {
chat: {...chat.dataValues, contactIds:[contact_id]},
sender: owner,
type: constants.message_types.purchase,
realSatsContactId: contact_id, // ALWAYS will be keysend, so doesnt matter if tribe owner or not
message: msg,
amount: amount,
success: async (data) => {
@ -224,7 +225,7 @@ export const receivePurchase = async (payload) => {
var date = new Date();
date.setMilliseconds(0)
const {owner, sender, chat, amount, mediaToken, msg_uuid, chat_type, skip_payment_processing, purchaser_id} = await helpers.parseReceiveParams(payload)
const {owner, sender, chat, amount, mediaToken, msg_uuid, chat_type, skip_payment_processing, purchaser_id, network_type} = await helpers.parseReceiveParams(payload)
if(!owner || !sender || !chat) {
return console.log('=> group chat not found!')
}
@ -238,7 +239,8 @@ export const receivePurchase = async (payload) => {
mediaToken: mediaToken,
date: date,
createdAt: date,
updatedAt: date
updatedAt: date,
network_type
})
socket.sendJson({
type: 'purchase',
@ -351,7 +353,7 @@ export const receivePurchaseAccept = async (payload) => {
var date = new Date();
date.setMilliseconds(0)
const {owner, sender, chat, mediaToken, mediaKey, mediaType, originalMuid} = await helpers.parseReceiveParams(payload)
const {owner, sender, chat, mediaToken, mediaKey, mediaType, originalMuid, network_type} = await helpers.parseReceiveParams(payload)
if(!owner || !sender || !chat) {
return console.log('=> no group chat!')
}
@ -383,7 +385,8 @@ export const receivePurchaseAccept = async (payload) => {
originalMuid:originalMuid||'',
date: date,
createdAt: date,
updatedAt: date
updatedAt: date,
network_type
})
socket.sendJson({
type: 'purchase_accept',
@ -395,7 +398,7 @@ export const receivePurchaseDeny = async (payload) => {
console.log('=> receivePurchaseDeny')
var date = new Date()
date.setMilliseconds(0)
const {owner, sender, chat, amount, mediaToken} = await helpers.parseReceiveParams(payload)
const {owner, sender, chat, amount, mediaToken, network_type} = await helpers.parseReceiveParams(payload)
if(!owner || !sender || !chat) {
return console.log('=> no group chat!')
}
@ -410,7 +413,8 @@ export const receivePurchaseDeny = async (payload) => {
mediaToken,
date: date,
createdAt: date,
updatedAt: date
updatedAt: date,
network_type
})
socket.sendJson({
type: 'purchase_deny',
@ -424,7 +428,7 @@ export const receiveAttachment = async (payload) => {
var date = new Date();
date.setMilliseconds(0)
const {owner, sender, chat, mediaToken, mediaKey, mediaType, content, msg_id, chat_type, sender_alias, msg_uuid, reply_uuid} = await helpers.parseReceiveParams(payload)
const {owner, sender, chat, mediaToken, mediaKey, mediaType, content, msg_id, chat_type, sender_alias, msg_uuid, reply_uuid, network_type} = await helpers.parseReceiveParams(payload)
if(!owner || !sender || !chat) {
return console.log('=> no group chat!')
}
@ -436,7 +440,8 @@ export const receiveAttachment = async (payload) => {
sender: sender.id,
date: date,
createdAt: date,
updatedAt: date
updatedAt: date,
network_type
}
if(content) msg.messageContent = content
if(mediaToken) msg.mediaToken = mediaToken

49
src/controllers/messages.ts

@ -11,7 +11,6 @@ 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;
@ -200,49 +199,35 @@ export const sendMessage = async (req, res) => {
content: remote_text_map || remote_text || text
}
if(reply_uuid) msgToSend.replyUuid=reply_uuid
network.sendMessage({
const sendMessageParams:{[k:string]:any} = {
chat: chat,
sender: owner,
amount: amount||0,
type: msgtype,
message: msgToSend,
})
}
// IF BOOST AND TRIBE OWNER NEED TO SEND ACTUAL SATS TO OG POSTER
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)
const ogMsg = await models.Message.findOne({where:{
uuid: reply_uuid,
}})
if(ogMsg && ogMsg.sender) {
sendMessageParams.realSatsContactId = 123
}
}
}
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
})
}
// final send
network.sendMessage(sendMessageParams)
}
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, amount} = await helpers.parseReceiveParams(payload)
const {owner, sender, chat, content, remote_content, msg_id, chat_type, sender_alias, msg_uuid, date_string, reply_uuid, amount, network_type} = await helpers.parseReceiveParams(payload)
if(!owner || !sender || !chat) {
return console.log('=> no group chat!')
}
@ -262,7 +247,8 @@ export const receiveMessage = async (payload) => {
messageContent: text,
createdAt: date,
updatedAt: date,
status: constants.statuses.received
status: constants.statuses.received,
network_type: network_type,
}
const isTribe = chat_type===constants.chat_types.tribe
if(isTribe) {
@ -286,7 +272,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, amount} = await helpers.parseReceiveParams(payload)
const {owner, sender, chat, content, remote_content, chat_type, sender_alias, msg_uuid, date_string, reply_uuid, amount, network_type} = await helpers.parseReceiveParams(payload)
if(!owner || !sender || !chat) {
return console.log('=> no group chat!')
}
@ -306,7 +292,8 @@ export const receiveBoost = async (payload) => {
messageContent: text,
createdAt: date,
updatedAt: date,
status: constants.statuses.received
status: constants.statuses.received,
network_type
}
const isTribe = chat_type===constants.chat_types.tribe
if(isTribe) {

23
src/controllers/payment.ts

@ -128,7 +128,7 @@ export const receivePayment = async (payload) => {
var date = new Date();
date.setMilliseconds(0)
const {owner, sender, chat, amount, content, mediaType, mediaToken, chat_type, sender_alias, msg_uuid, reply_uuid} = await helpers.parseReceiveParams(payload)
const {owner, sender, chat, amount, content, mediaType, mediaToken, chat_type, sender_alias, msg_uuid, reply_uuid, network_type} = await helpers.parseReceiveParams(payload)
if(!owner || !sender || !chat) {
return console.log('=> no group chat!')
}
@ -142,7 +142,8 @@ export const receivePayment = async (payload) => {
amountMsat: parseFloat(amount) * 1000,
date: date,
createdAt: date,
updatedAt: date
updatedAt: date,
network_type
}
if(content) msg.messageContent = content
if(mediaType) msg.mediaType = mediaType
@ -168,7 +169,7 @@ export const listPayments = async (req, res) => {
const limit = (req.query.limit && parseInt(req.query.limit)) || 100
const offset = (req.query.offset && parseInt(req.query.offset)) || 0
// const MIN_VAL=constants.min_sat_amount
const MIN_VAL=constants.min_sat_amount
try {
const msgs = await models.Message.findAll({
where:{
@ -180,12 +181,16 @@ export const listPayments = async (req, res) => {
constants.message_types.keysend,
]}
},
// {
// type: constants.message_types.message, // for example /loopout message
// amount: {
// [Op.gt]: MIN_VAL // greater than
// }
// }
{
type: {[Op.or]: [
constants.message_types.message, // paid bot msgs
constants.message_types.boost,
]},
amount: {
[Op.gt]: MIN_VAL // greater than
},
network_type: constants.network_types.lightning
}
],
},
order: [['createdAt', 'desc']],

3
src/helpers.ts

@ -154,6 +154,7 @@ export async function parseReceiveParams(payload) {
const skip_payment_processing = dat.message.skipPaymentProcessing
const reply_uuid = dat.message.replyUuid
const purchaser_id = dat.message.purchaser
const network_type = dat.network_type||0
const isTribeOwner = dat.isTribeOwner?true:false
const isConversation = !chat_type || (chat_type && chat_type == constants.chat_types.conversation)
@ -176,7 +177,7 @@ export async function parseReceiveParams(payload) {
}
chat = await models.Chat.findOne({ where: { uuid: chat_uuid } })
}
return { owner, sender, chat, sender_pub_key, sender_alias, isTribeOwner, chat_uuid, amount, content, mediaToken, mediaKey, mediaType, originalMuid, chat_type, msg_id, chat_members, chat_name, chat_host, chat_key, remote_content, msg_uuid, date_string, reply_uuid, skip_payment_processing, purchaser_id, sender_photo_url }
return { owner, sender, chat, sender_pub_key, sender_alias, isTribeOwner, chat_uuid, amount, content, mediaToken, mediaKey, mediaType, originalMuid, chat_type, msg_id, chat_members, chat_name, chat_host, chat_key, remote_content, msg_uuid, date_string, reply_uuid, skip_payment_processing, purchaser_id, sender_photo_url, network_type }
}
async function asyncForEach(array, callback) {

3
src/models/ts/message.ts

@ -92,4 +92,7 @@ export default class Message extends Model<Message> {
@Column
replyUuid: string
@Column(DataType.INTEGER)
network_type: number
}

2
src/network/modify.ts

@ -67,6 +67,7 @@ export async function purchaseFromOriginalSender(payload, chat, purchaser){
sender: owner,
type: constants.message_types.purchase,
amount: amount,
realSatsContactId: mediaKey.sender,
message: {
mediaToken: mt,
skipPaymentProcessing: true,
@ -87,6 +88,7 @@ export async function purchaseFromOriginalSender(payload, chat, purchaser){
role: constants.chat_roles.reader,
},
type: constants.message_types.purchase,
realSatsContactId: ogmsg.sender,
message: msg,
amount: amount,
success: ()=>{},

29
src/network/receive.ts

@ -122,6 +122,7 @@ async function onReceive(payload){
}
}
// forward boost sats to recipient
let realSatsContactId = null
if(payload.type===msgtypes.boost && payload.message.replyUuid) {
const ogMsg = await models.Message.findOne({where:{
uuid: payload.message.replyUuid,
@ -129,11 +130,11 @@ 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) {
forwardBoostSatsToContact(chat,ogMsg.sender,amtToForward)
realSatsContactId = ogMsg.sender
}
}
}
if(doAction) forwardMessageToTribe(payload, senderContact)
if(doAction) forwardMessageToTribe(payload, senderContact, realSatsContactId)
else console.log('=> insufficient payment for this action')
}
if(isTribeOwner && payload.type===msgtypes.purchase) {
@ -183,21 +184,7 @@ async function doTheAction(data){
}
}
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]},
sender: owner,
type: constants.message_types.keysend,
amount: amount,
message: { content:'!' },
success: ()=>{},
failure: ()=>{}
})
}
async function forwardMessageToTribe(ogpayload, sender){
async function forwardMessageToTribe(ogpayload, sender, realSatsContactId){
// console.log('forwardMessageToTribe')
const chat = await models.Chat.findOne({where:{uuid:ogpayload.chat.uuid}})
@ -224,6 +211,7 @@ async function forwardMessageToTribe(ogpayload, sender){
},
chat: chat,
skipPubKey: payload.sender.pub_key,
realSatsContactId: realSatsContactId,
success: ()=>{},
receive: ()=>{},
isForwarded: true,
@ -245,6 +233,7 @@ export async function initTribesSubscriptions(){
const msg = message.toString()
// check topic is signed by sender?
const payload = await parseAndVerifyPayload(msg)
payload.network_type = constants.network_types.mqtt
onReceive(payload)
} catch(e){}
})
@ -309,7 +298,8 @@ async function saveAnonymousKeysend(response, memo, sender_pubkey) {
messageContent: memo||'',
status: constants.statuses.confirmed,
createdAt: new Date(settleDate),
updatedAt: new Date(settleDate)
updatedAt: new Date(settleDate),
network_type: constants.network_types.lightning
})
socket.sendJson({
type:'keysend',
@ -361,7 +351,8 @@ export async function parseKeysendInvoice(i){
const dat = payload
if(value && dat && dat.message){
dat.message.amount = value // ADD IN TRUE VALUE
}
}
dat.network_type = constants.network_types.lightning
onReceive(dat)
}
}

10
src/network/send.ts

@ -11,7 +11,7 @@ import constants from '../constants'
type NetworkType = undefined | 'mqtt' | 'lightning'
export async function sendMessage(params) {
const { type, chat, message, sender, amount, success, failure, skipPubKey, isForwarded } = params
const { type, chat, message, sender, amount, success, failure, skipPubKey, isForwarded, realSatsContactId } = params
if(!chat || !sender) return
const isTribe = chat.type===constants.chat_types.tribe
@ -83,12 +83,10 @@ export async function sendMessage(params) {
console.log('-> sending to ', contact.id, destkey)
let mqttTopic = networkType==='mqtt' ? `${destkey}/${chatUUID}` : ''
// sending a payment to one subscriber, buying a pic from OG poster
// or keysend such as forwarding boost to og poster
if(isTribeOwner && contactIds.length===1 && amount && amount>constants.min_sat_amount &&
(msg.type===constants.message_types.purchase || msg.type===constants.message_types.keysend)
) {
// or boost to og poster
if(isTribeOwner && amount && realSatsContactId===contactId) {
mqttTopic = '' // FORCE KEYSEND!!!
}

2
src/utils/setup.ts

@ -38,6 +38,8 @@ async function setVersion() {
async function migrate() {
addTableColumn('sphinx_messages', 'network_type', 'INTEGER')
addTableColumn('sphinx_chats', 'meta')
addTableColumn('sphinx_contacts', 'tip_amount', 'BIGINT')

Loading…
Cancel
Save