Browse Source

modify attachment payload

feature/dockerfile-arm
Evan Feenstra 5 years ago
parent
commit
9cfb8662e4
  1. 118
      api/controllers/chats.ts
  2. 4
      api/helpers.ts
  3. 6
      api/models/ts/chat.ts
  4. 18
      api/network/modify.ts
  5. 68
      api/network/receive.ts
  6. 2
      api/utils/setup.ts
  7. 120
      dist/api/controllers/chats.js
  8. 2
      dist/api/controllers/chats.js.map
  9. 4
      dist/api/helpers.js
  10. 2
      dist/api/helpers.js.map
  11. 8
      dist/api/models/ts/chat.js
  12. 2
      dist/api/models/ts/chat.js.map
  13. 19
      dist/api/network/modify.js
  14. 1
      dist/api/network/modify.js.map
  15. 74
      dist/api/network/receive.js
  16. 2
      dist/api/network/receive.js.map
  17. 2
      dist/api/utils/setup.js
  18. 2
      dist/api/utils/setup.js.map
  19. 15
      frontend/components/Media/index.jsx

118
api/controllers/chats.ts

@ -68,7 +68,7 @@ async function createGroupChat(req, res) {
let chatParams:any = null
if(is_tribe){
chatParams = await createTribeChatParams(owner, contact_ids, name, img)
chatParams = await createTribeChatParams(owner, contact_ids, name, img, price_per_message, price_to_join)
if(is_listed){
// publish to tribe server
tribes.declare({
@ -243,20 +243,27 @@ async function joinTribe(req, res){
async function receiveGroupLeave(payload) {
console.log('=> receiveGroupLeave')
const { sender_pub_key, chat_uuid, chat_type } = await helpers.parseReceiveParams(payload)
const { sender_pub_key, chat_uuid, chat_type, sender_alias, isTribeOwner } = await helpers.parseReceiveParams(payload)
const chat = await models.Chat.findOne({ where: { uuid: chat_uuid } })
if (!chat) return
const sender = await models.Contact.findOne({ where: { publicKey: sender_pub_key } })
if (!sender) return
const isTribe = chat_type===constants.chat_types.tribe
let sender
if(!isTribe || isTribeOwner) {
sender = await models.Contact.findOne({ where: { publicKey: sender_pub_key } })
if (!sender) return
const oldContactIds = JSON.parse(chat.contactIds || '[]')
const contactIds = oldContactIds.filter(cid => cid !== sender.id)
await chat.update({ contactIds: JSON.stringify(contactIds) })
const oldContactIds = JSON.parse(chat.contactIds || '[]')
const contactIds = oldContactIds.filter(cid => cid !== sender.id)
await chat.update({ contactIds: JSON.stringify(contactIds) })
if(chat_type===constants.chat_types.tribe){
await models.ChatMember.destroy({where:{chatId: chat.id, contactId: sender.id}})
if(isTribeOwner) {
if(chat_type===constants.chat_types.tribe){
await models.ChatMember.destroy({where:{chatId: chat.id, contactId: sender.id}})
}
}
}
var date = new Date();
@ -264,9 +271,9 @@ async function receiveGroupLeave(payload) {
const msg = {
chatId: chat.id,
type: constants.message_types.group_leave,
sender: sender.id,
sender: (sender && sender.id) || 0,
date: date,
messageContent: '',
messageContent: `${sender_alias} has left the group`,
remoteMessageContent: '',
status: constants.statuses.confirmed,
createdAt: date,
@ -284,69 +291,60 @@ async function receiveGroupLeave(payload) {
})
}
// only owner needs to add!
// here: can only join if enough $$$!
// forward to all over mqtt
// add to ChatMember table
async function receiveGroupJoin(payload) {
console.log('=> receiveGroupJoin')
const { sender_pub_key, chat_uuid, chat_members, chat_type } = await helpers.parseReceiveParams(payload)
const { sender_pub_key, chat_uuid, chat_members, chat_type, isTribeOwner } = await helpers.parseReceiveParams(payload)
const chat = await models.Chat.findOne({ where: { uuid: chat_uuid } })
if (!chat) return
// THIS CHECK CAN BE DONE IN NETWORK.RECEIVE? --> forward to mqtt if needed to
const isTribe = chat_type===constants.chat_types.tribe
if(isTribe) {
const owner = await models.Contact.findOne({ where: { isOwner: true } })
const verifiedOwnerPubkey = await tribes.verifySignedTimestamp(chat_uuid)
if(verifiedOwnerPubkey!==owner.publicKey){
return // SKIP if not owner (not each member needs to be added)
// but maybe we need to add alias in there somehow? so other people can see "Evan joined"
}
}
var date = new Date()
date.setMilliseconds(0)
let theSender: any = null
const sender = await models.Contact.findOne({ where: { publicKey: sender_pub_key } })
const contactIds = JSON.parse(chat.contactIds || '[]')
if (sender) {
theSender = sender // might already include??
if(!contactIds.includes(sender.id)) contactIds.push(sender.id)
} else {
const member = chat_members[sender_pub_key]
if(member && member.key) {
const createdContact = await models.Contact.create({
publicKey: sender_pub_key,
contactKey: member.key,
alias: member.alias||'Unknown',
status: 1
})
theSender = createdContact
contactIds.push(createdContact.id)
const member = chat_members[sender_pub_key]
const senderAlias = (member && member.alias) || 'Unknown'
if(!isTribe || isTribeOwner) { // dont need to create contacts for these
const sender = await models.Contact.findOne({ where: { publicKey: sender_pub_key } })
const contactIds = JSON.parse(chat.contactIds || '[]')
if (sender) {
theSender = sender // might already include??
if(!contactIds.includes(sender.id)) contactIds.push(sender.id)
} else {
if(member && member.key) {
const createdContact = await models.Contact.create({
publicKey: sender_pub_key,
contactKey: member.key,
alias: senderAlias,
status: 1
})
theSender = createdContact
contactIds.push(createdContact.id)
}
}
}
if(!theSender) return // fail (no contact key?)
if(!theSender) return // fail (no contact key?)
await chat.update({ contactIds: JSON.stringify(contactIds) })
var date = new Date()
date.setMilliseconds(0)
await chat.update({ contactIds: JSON.stringify(contactIds) })
if(isTribe){ // IF TRIBE, ADD TO XREF
models.ChatMember.create({
contactId: theSender.id,
chatId: chat.id,
role: constants.chat_roles.reader,
lastActive: date,
})
if(isTribeOwner){ // IF TRIBE, ADD TO XREF
models.ChatMember.create({
contactId: theSender.id,
chatId: chat.id,
role: constants.chat_roles.reader,
lastActive: date,
})
}
}
const msg = {
chatId: chat.id,
type: constants.message_types.group_join,
sender: theSender.id,
sender: (theSender && theSender.id) || 0,
date: date,
messageContent: '',
messageContent: `${senderAlias} has joined the group`,
remoteMessageContent: '',
status: constants.statuses.confirmed,
createdAt: date,
@ -357,7 +355,7 @@ async function receiveGroupJoin(payload) {
socket.sendJson({
type: 'group_join',
response: {
contact: jsonUtils.contactToJson(theSender),
contact: jsonUtils.contactToJson(theSender||{}),
chat: jsonUtils.chatToJson(chat),
message: jsonUtils.messageToJson(message, null)
}
@ -487,7 +485,7 @@ function createGroupChatParams(owner, contactIds, members, name) {
}
}
async function createTribeChatParams(owner, contactIds, name, img) {
async function createTribeChatParams(owner, contactIds, name, img, price_per_message, price_to_join) {
let date = new Date()
date.setMilliseconds(0)
if (!(owner && contactIds && Array.isArray(contactIds))) {
@ -508,7 +506,9 @@ async function createTribeChatParams(owner, contactIds, name, img) {
type: constants.chat_types.tribe,
groupKey: keys.public,
groupPrivateKey: keys.private,
host: tribes.getHost()
host: tribes.getHost(),
pricePerMessage: price_per_message||0,
priceToJoin: price_to_join||0,
}
}

4
api/helpers.ts

@ -133,6 +133,7 @@ async function sleep(ms) {
async function parseReceiveParams(payload) {
const dat = payload.content || payload
const sender_pub_key = dat.sender.pub_key
const sender_alias = dat.sender.alias
const chat_uuid = dat.chat.uuid
const chat_type = dat.chat.type
const chat_members: { [k: string]: any } = dat.chat.members || {}
@ -145,6 +146,7 @@ async function parseReceiveParams(payload) {
const msg_id = dat.message.id||0
const mediaKey = dat.message.mediaKey
const mediaType = dat.message.mediaType
const isTribeOwner = dat.isTribeOwner?true:false
const isConversation = !chat_type || (chat_type && chat_type == constants.chat_types.conversation)
let sender
@ -159,7 +161,7 @@ async function parseReceiveParams(payload) {
sender = await models.Contact.findOne({ where: { publicKey: sender_pub_key } })
chat = await models.Chat.findOne({ where: { uuid: chat_uuid } })
}
return { owner, sender, chat, sender_pub_key, chat_uuid, amount, content, mediaToken, mediaKey, mediaType, chat_type, msg_id, chat_members, chat_name, chat_host, chat_key }
return { owner, sender, chat, sender_pub_key, sender_alias, isTribeOwner, chat_uuid, amount, content, mediaToken, mediaKey, mediaType, chat_type, msg_id, chat_members, chat_name, chat_host, chat_key }
}
export {

6
api/models/ts/chat.ts

@ -54,4 +54,10 @@ export default class Chat extends Model<Chat> {
@Column
host: string
@Column
priceToJoin: number
@Column
pricePerMessage: number
}

18
api/network/modify.ts

@ -0,0 +1,18 @@
import * as path from 'path'
const constants = require(path.join(__dirname,'../../config/constants.json'))
const msgtypes = constants.message_types
export function modifyPayload(payload) {
if(payload.type===msgtypes.attachment) {
console.log("MODIFY, ", payload)
// download image from mediaToken
// decrypt key
// decrypt image
// new key, re-encrypt, re-upload
// new payload
// how to link w og msg? ogMediaToken?
}
return payload
}

68
api/network/receive.ts

@ -6,32 +6,54 @@ import * as tribes from '../utils/tribes'
import {SPHINX_CUSTOM_RECORD_KEY, verifyAscii} from '../utils/lightning'
import { models } from '../models'
import {sendMessage} from './send'
import {modifyPayload} from './modify'
const constants = require(path.join(__dirname,'../../config/constants.json'))
const types = constants.message_types
const msgtypes = constants.message_types
const typesToForward=[
types.message, types.attachment, types.group_join, types.group_leave
msgtypes.message, msgtypes.group_join, msgtypes.group_leave, msgtypes.attachment
]
const typesToModify=[
msgtypes.attachment
]
async function onReceive(payload){
// if tribe, owner must forward to MQTT
// console.log("RECEIVED PAYLOAD",payload)
let doAction = true
const toAddIn:{[k:string]:any} = {}
const isTribe = payload.chat && payload.chat.type===constants.chat_types.tribe
if(isTribe && typesToForward.includes(payload.type)){
const tribeOwnerPubKey = await tribes.verifySignedTimestamp(payload.chat.uuid)
const owner = await models.Contact.findOne({where: {isOwner:true}})
if(owner.publicKey===tribeOwnerPubKey){
forwardMessageToTribe(payload)
// CHECK PRICES
toAddIn.isTribeOwner = true
const chat = await models.Chat.findOne({where:{uuid:payload.chat.uuid}})
if(payload.type===msgtypes.group_join) {
if(payload.message.amount<chat.priceToJoin) doAction=false
}
if(payload.type===msgtypes.message) {
if(payload.message.amount<chat.pricePerMessage) doAction=false
}
if(doAction) forwardMessageToTribe(payload)
}
}
if(ACTIONS[payload.type]) {
ACTIONS[payload.type](payload)
} else {
console.log('Incorrect payload type:', payload.type)
if(doAction) {
if(ACTIONS[payload.type]) {
ACTIONS[payload.type]({...payload, ...toAddIn})
} else {
console.log('Incorrect payload type:', payload.type)
}
}
}
async function forwardMessageToTribe(payload){
async function forwardMessageToTribe(ogpayload){
let payload
if(typesToModify.includes(ogpayload.type)){
payload = await modifyPayload(ogpayload)
} else {
payload = ogpayload
}
console.log("FORWARD TO TRIBE",payload)
const chat = await models.Chat.findOne({where:{uuid:payload.chat.uuid}})
//const sender = await models.Contact.findOne({where:{publicKey:payload.sender.pub_key}})
@ -52,20 +74,20 @@ async function forwardMessageToTribe(payload){
}
const ACTIONS = {
[types.contact_key]: controllers.contacts.receiveContactKey,
[types.contact_key_confirmation]: controllers.contacts.receiveConfirmContactKey,
[types.message]: controllers.messages.receiveMessage,
[types.invoice]: controllers.invoices.receiveInvoice,
[types.direct_payment]: controllers.payments.receivePayment,
[types.confirmation]: controllers.confirmations.receiveConfirmation,
[types.attachment]: controllers.media.receiveAttachment,
[types.purchase]: controllers.media.receivePurchase,
[types.purchase_accept]: controllers.media.receivePurchaseAccept,
[types.purchase_deny]: controllers.media.receivePurchaseDeny,
[types.group_create]: controllers.chats.receiveGroupCreateOrInvite,
[types.group_invite]: controllers.chats.receiveGroupCreateOrInvite,
[types.group_join]: controllers.chats.receiveGroupJoin,
[types.group_leave]: controllers.chats.receiveGroupLeave,
[msgtypes.contact_key]: controllers.contacts.receiveContactKey,
[msgtypes.contact_key_confirmation]: controllers.contacts.receiveConfirmContactKey,
[msgtypes.message]: controllers.messages.receiveMessage,
[msgtypes.invoice]: controllers.invoices.receiveInvoice,
[msgtypes.direct_payment]: controllers.payments.receivePayment,
[msgtypes.confirmation]: controllers.confirmations.receiveConfirmation,
[msgtypes.attachment]: controllers.media.receiveAttachment,
[msgtypes.purchase]: controllers.media.receivePurchase,
[msgtypes.purchase_accept]: controllers.media.receivePurchaseAccept,
[msgtypes.purchase_deny]: controllers.media.receivePurchaseDeny,
[msgtypes.group_create]: controllers.chats.receiveGroupCreateOrInvite,
[msgtypes.group_invite]: controllers.chats.receiveGroupCreateOrInvite,
[msgtypes.group_join]: controllers.chats.receiveGroupJoin,
[msgtypes.group_leave]: controllers.chats.receiveGroupLeave,
}
export async function initGrpcSubscriptions() {

2
api/utils/setup.ts

@ -34,6 +34,8 @@ async function migrate(){
addTableColumn('sphinx_chats', 'group_key')
addTableColumn('sphinx_chats', 'group_private_key')
addTableColumn('sphinx_chats', 'host')
addTableColumn('sphinx_chats', 'price_to_join', 'BIGINT')
addTableColumn('sphinx_chats', 'price_per_message', 'BIGINT')
try{
await sequelize.query(`
CREATE TABLE sphinx_chat_members (

120
dist/api/controllers/chats.js

@ -65,7 +65,7 @@ function createGroupChat(req, res) {
}));
let chatParams = null;
if (is_tribe) {
chatParams = yield createTribeChatParams(owner, contact_ids, name, img);
chatParams = yield createTribeChatParams(owner, contact_ids, name, img, price_per_message, price_to_join);
if (is_listed) {
// publish to tribe server
tribes.declare(Object.assign(Object.assign({}, chatParams), { pricePerMessage: price_per_message, priceToJoin: price_to_join, description, tags, img }));
@ -232,27 +232,33 @@ exports.joinTribe = joinTribe;
function receiveGroupLeave(payload) {
return __awaiter(this, void 0, void 0, function* () {
console.log('=> receiveGroupLeave');
const { sender_pub_key, chat_uuid, chat_type } = yield helpers.parseReceiveParams(payload);
const { sender_pub_key, chat_uuid, chat_type, sender_alias, isTribeOwner } = yield helpers.parseReceiveParams(payload);
const chat = yield models_1.models.Chat.findOne({ where: { uuid: chat_uuid } });
if (!chat)
return;
const sender = yield models_1.models.Contact.findOne({ where: { publicKey: sender_pub_key } });
if (!sender)
return;
const oldContactIds = JSON.parse(chat.contactIds || '[]');
const contactIds = oldContactIds.filter(cid => cid !== sender.id);
yield chat.update({ contactIds: JSON.stringify(contactIds) });
if (chat_type === constants.chat_types.tribe) {
yield models_1.models.ChatMember.destroy({ where: { chatId: chat.id, contactId: sender.id } });
const isTribe = chat_type === constants.chat_types.tribe;
let sender;
if (!isTribe || isTribeOwner) {
sender = yield models_1.models.Contact.findOne({ where: { publicKey: sender_pub_key } });
if (!sender)
return;
const oldContactIds = JSON.parse(chat.contactIds || '[]');
const contactIds = oldContactIds.filter(cid => cid !== sender.id);
yield chat.update({ contactIds: JSON.stringify(contactIds) });
if (isTribeOwner) {
if (chat_type === constants.chat_types.tribe) {
yield models_1.models.ChatMember.destroy({ where: { chatId: chat.id, contactId: sender.id } });
}
}
}
var date = new Date();
date.setMilliseconds(0);
const msg = {
chatId: chat.id,
type: constants.message_types.group_leave,
sender: sender.id,
sender: (sender && sender.id) || 0,
date: date,
messageContent: '',
messageContent: `${sender_alias} has left the group`,
remoteMessageContent: '',
status: constants.statuses.confirmed,
createdAt: date,
@ -270,67 +276,57 @@ function receiveGroupLeave(payload) {
});
}
exports.receiveGroupLeave = receiveGroupLeave;
// only owner needs to add!
// here: can only join if enough $$$!
// forward to all over mqtt
// add to ChatMember table
function receiveGroupJoin(payload) {
return __awaiter(this, void 0, void 0, function* () {
console.log('=> receiveGroupJoin');
const { sender_pub_key, chat_uuid, chat_members, chat_type } = yield helpers.parseReceiveParams(payload);
const { sender_pub_key, chat_uuid, chat_members, chat_type, isTribeOwner } = yield helpers.parseReceiveParams(payload);
const chat = yield models_1.models.Chat.findOne({ where: { uuid: chat_uuid } });
if (!chat)
return;
// THIS CHECK CAN BE DONE IN NETWORK.RECEIVE? --> forward to mqtt if needed to
const isTribe = chat_type === constants.chat_types.tribe;
if (isTribe) {
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
const verifiedOwnerPubkey = yield tribes.verifySignedTimestamp(chat_uuid);
if (verifiedOwnerPubkey !== owner.publicKey) {
return; // SKIP if not owner (not each member needs to be added)
// but maybe we need to add alias in there somehow? so other people can see "Evan joined"
}
}
var date = new Date();
date.setMilliseconds(0);
let theSender = null;
const sender = yield models_1.models.Contact.findOne({ where: { publicKey: sender_pub_key } });
const contactIds = JSON.parse(chat.contactIds || '[]');
if (sender) {
theSender = sender; // might already include??
if (!contactIds.includes(sender.id))
contactIds.push(sender.id);
}
else {
const member = chat_members[sender_pub_key];
if (member && member.key) {
const createdContact = yield models_1.models.Contact.create({
publicKey: sender_pub_key,
contactKey: member.key,
alias: member.alias || 'Unknown',
status: 1
const member = chat_members[sender_pub_key];
const senderAlias = (member && member.alias) || 'Unknown';
if (!isTribe || isTribeOwner) { // dont need to create contacts for these
const sender = yield models_1.models.Contact.findOne({ where: { publicKey: sender_pub_key } });
const contactIds = JSON.parse(chat.contactIds || '[]');
if (sender) {
theSender = sender; // might already include??
if (!contactIds.includes(sender.id))
contactIds.push(sender.id);
}
else {
if (member && member.key) {
const createdContact = yield models_1.models.Contact.create({
publicKey: sender_pub_key,
contactKey: member.key,
alias: senderAlias,
status: 1
});
theSender = createdContact;
contactIds.push(createdContact.id);
}
}
if (!theSender)
return; // fail (no contact key?)
yield chat.update({ contactIds: JSON.stringify(contactIds) });
if (isTribeOwner) { // IF TRIBE, ADD TO XREF
models_1.models.ChatMember.create({
contactId: theSender.id,
chatId: chat.id,
role: constants.chat_roles.reader,
lastActive: date,
});
theSender = createdContact;
contactIds.push(createdContact.id);
}
}
if (!theSender)
return; // fail (no contact key?)
yield chat.update({ contactIds: JSON.stringify(contactIds) });
var date = new Date();
date.setMilliseconds(0);
if (isTribe) { // IF TRIBE, ADD TO XREF
models_1.models.ChatMember.create({
contactId: theSender.id,
chatId: chat.id,
role: constants.chat_roles.reader,
lastActive: date,
});
}
const msg = {
chatId: chat.id,
type: constants.message_types.group_join,
sender: theSender.id,
sender: (theSender && theSender.id) || 0,
date: date,
messageContent: '',
messageContent: `${senderAlias} has joined the group`,
remoteMessageContent: '',
status: constants.statuses.confirmed,
createdAt: date,
@ -340,7 +336,7 @@ function receiveGroupJoin(payload) {
socket.sendJson({
type: 'group_join',
response: {
contact: jsonUtils.contactToJson(theSender),
contact: jsonUtils.contactToJson(theSender || {}),
chat: jsonUtils.chatToJson(chat),
message: jsonUtils.messageToJson(message, null)
}
@ -460,7 +456,7 @@ function createGroupChatParams(owner, contactIds, members, name) {
type: constants.chat_types.group
};
}
function createTribeChatParams(owner, contactIds, name, img) {
function createTribeChatParams(owner, contactIds, name, img, price_per_message, price_to_join) {
return __awaiter(this, void 0, void 0, function* () {
let date = new Date();
date.setMilliseconds(0);
@ -481,7 +477,9 @@ function createTribeChatParams(owner, contactIds, name, img) {
type: constants.chat_types.tribe,
groupKey: keys.public,
groupPrivateKey: keys.private,
host: tribes.getHost()
host: tribes.getHost(),
pricePerMessage: price_per_message || 0,
priceToJoin: price_to_join || 0,
};
});
}

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

File diff suppressed because one or more lines are too long

4
dist/api/helpers.js

@ -149,6 +149,7 @@ function parseReceiveParams(payload) {
return __awaiter(this, void 0, void 0, function* () {
const dat = payload.content || payload;
const sender_pub_key = dat.sender.pub_key;
const sender_alias = dat.sender.alias;
const chat_uuid = dat.chat.uuid;
const chat_type = dat.chat.type;
const chat_members = dat.chat.members || {};
@ -161,6 +162,7 @@ function parseReceiveParams(payload) {
const msg_id = dat.message.id || 0;
const mediaKey = dat.message.mediaKey;
const mediaType = dat.message.mediaType;
const isTribeOwner = dat.isTribeOwner ? true : false;
const isConversation = !chat_type || (chat_type && chat_type == constants.chat_types.conversation);
let sender;
let chat;
@ -173,7 +175,7 @@ function parseReceiveParams(payload) {
sender = yield models_1.models.Contact.findOne({ where: { publicKey: sender_pub_key } });
chat = yield models_1.models.Chat.findOne({ where: { uuid: chat_uuid } });
}
return { owner, sender, chat, sender_pub_key, chat_uuid, amount, content, mediaToken, mediaKey, mediaType, chat_type, msg_id, chat_members, chat_name, chat_host, chat_key };
return { owner, sender, chat, sender_pub_key, sender_alias, isTribeOwner, chat_uuid, amount, content, mediaToken, mediaKey, mediaType, chat_type, msg_id, chat_members, chat_name, chat_host, chat_key };
});
}
exports.parseReceiveParams = parseReceiveParams;

2
dist/api/helpers.js.map

File diff suppressed because one or more lines are too long

8
dist/api/models/ts/chat.js

@ -77,6 +77,14 @@ __decorate([
sequelize_typescript_1.Column,
__metadata("design:type", String)
], Chat.prototype, "host", void 0);
__decorate([
sequelize_typescript_1.Column,
__metadata("design:type", Number)
], Chat.prototype, "priceToJoin", void 0);
__decorate([
sequelize_typescript_1.Column,
__metadata("design:type", Number)
], Chat.prototype, "pricePerMessage", void 0);
Chat = __decorate([
sequelize_typescript_1.Table({ tableName: 'sphinx_chats', underscored: true })
], Chat);

2
dist/api/models/ts/chat.js.map

@ -1 +1 @@
{"version":3,"file":"chat.js","sourceRoot":"","sources":["../../../../api/models/ts/chat.ts"],"names":[],"mappings":";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Q;AAGV;IADC,6BAAM;;kCACK;AAGZ;IADC,6BAAM;;kCACK;AAGZ;IADC,6BAAM;;sCACS;AAGhB;IADC,6BAAM,CAAC,+BAAQ,CAAC,MAAM,CAAC;;kCACZ;AAGZ;IADC,6BAAM,CAAC,+BAAQ,CAAC,MAAM,CAAC;;oCACV;AAGd;IADC,6BAAM;;wCACW;AAGlB;IADC,6BAAM;;qCACS;AAGhB;IADC,6BAAM;8BACI,IAAI;uCAAA;AAGf;IADC,6BAAM;8BACI,IAAI;uCAAA;AAOf;IALC,6BAAM,CAAC;QACN,IAAI,EAAE,+BAAQ,CAAC,OAAO;QACtB,YAAY,EAAE,KAAK;QACnB,SAAS,EAAE,KAAK;KACjB,CAAC;;qCACc;AAGhB;IADC,6BAAM;;sCACS;AAGhB;IADC,6BAAM;;6CACgB;AAGvB;IADC,6BAAM;;kCACK;AAGZ;IADC,6BAAM;;yCACY;AAGnB;IADC,6BAAM;;6CACgB;AAzDJ,IAAI;IADxB,4BAAK,CAAC,EAAC,SAAS,EAAE,cAAc,EAAE,WAAW,EAAE,IAAI,EAAC,CAAC;GACjC,IAAI,CA2DxB;kBA3DoB,IAAI"}

19
dist/api/network/modify.js

@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const constants = require(path.join(__dirname, '../../config/constants.json'));
const msgtypes = constants.message_types;
function modifyPayload(payload) {
if (payload.type === msgtypes.attachment) {
console.log("MODIFY, ", payload);
// download image from mediaToken
// decrypt key
// decrypt image
// new key, re-encrypt, re-upload
// new payload
// how to link w og msg? ogMediaToken?
}
return payload;
}
exports.modifyPayload = modifyPayload;
//# sourceMappingURL=modify.js.map

1
dist/api/network/modify.js.map

@ -0,0 +1 @@
{"version":3,"file":"modify.js","sourceRoot":"","sources":["../../../api/network/modify.ts"],"names":[],"mappings":";;AAAA,6BAA4B;AAE5B,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAC,6BAA6B,CAAC,CAAC,CAAA;AAC7E,MAAM,QAAQ,GAAG,SAAS,CAAC,aAAa,CAAA;AAExC,SAAgB,aAAa,CAAC,OAAO;IACnC,IAAG,OAAO,CAAC,IAAI,KAAG,QAAQ,CAAC,UAAU,EAAE;QACrC,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;QAChC,iCAAiC;QACjC,cAAc;QACd,gBAAgB;QAChB,iCAAiC;QACjC,cAAc;QAEd,sCAAsC;KACvC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC;AAZD,sCAYC"}

74
dist/api/network/receive.js

@ -17,33 +17,59 @@ const tribes = require("../utils/tribes");
const lightning_2 = require("../utils/lightning");
const models_1 = require("../models");
const send_1 = require("./send");
const modify_1 = require("./modify");
const constants = require(path.join(__dirname, '../../config/constants.json'));
const types = constants.message_types;
const msgtypes = constants.message_types;
const typesToForward = [
types.message, types.attachment, types.group_join, types.group_leave
msgtypes.message, msgtypes.group_join, msgtypes.group_leave, msgtypes.attachment
];
const typesToModify = [
msgtypes.attachment
];
function onReceive(payload) {
return __awaiter(this, void 0, void 0, function* () {
// if tribe, owner must forward to MQTT
// console.log("RECEIVED PAYLOAD",payload)
let doAction = true;
const toAddIn = {};
const isTribe = payload.chat && payload.chat.type === constants.chat_types.tribe;
if (isTribe && typesToForward.includes(payload.type)) {
const tribeOwnerPubKey = yield tribes.verifySignedTimestamp(payload.chat.uuid);
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
if (owner.publicKey === tribeOwnerPubKey) {
forwardMessageToTribe(payload);
// CHECK PRICES
toAddIn.isTribeOwner = true;
const chat = yield models_1.models.Chat.findOne({ where: { uuid: payload.chat.uuid } });
if (payload.type === msgtypes.group_join) {
if (payload.message.amount < chat.priceToJoin)
doAction = false;
}
if (payload.type === msgtypes.message) {
if (payload.message.amount < chat.pricePerMessage)
doAction = false;
}
if (doAction)
forwardMessageToTribe(payload);
}
}
if (ACTIONS[payload.type]) {
ACTIONS[payload.type](payload);
}
else {
console.log('Incorrect payload type:', payload.type);
if (doAction) {
if (ACTIONS[payload.type]) {
ACTIONS[payload.type](Object.assign(Object.assign({}, payload), toAddIn));
}
else {
console.log('Incorrect payload type:', payload.type);
}
}
});
}
function forwardMessageToTribe(payload) {
function forwardMessageToTribe(ogpayload) {
return __awaiter(this, void 0, void 0, function* () {
let payload;
if (typesToModify.includes(ogpayload.type)) {
payload = yield modify_1.modifyPayload(ogpayload);
}
else {
payload = ogpayload;
}
console.log("FORWARD TO TRIBE", payload);
const chat = yield models_1.models.Chat.findOne({ where: { uuid: payload.chat.uuid } });
//const sender = await models.Contact.findOne({where:{publicKey:payload.sender.pub_key}})
@ -61,20 +87,20 @@ function forwardMessageToTribe(payload) {
});
}
const ACTIONS = {
[types.contact_key]: controllers_1.controllers.contacts.receiveContactKey,
[types.contact_key_confirmation]: controllers_1.controllers.contacts.receiveConfirmContactKey,
[types.message]: controllers_1.controllers.messages.receiveMessage,
[types.invoice]: controllers_1.controllers.invoices.receiveInvoice,
[types.direct_payment]: controllers_1.controllers.payments.receivePayment,
[types.confirmation]: controllers_1.controllers.confirmations.receiveConfirmation,
[types.attachment]: controllers_1.controllers.media.receiveAttachment,
[types.purchase]: controllers_1.controllers.media.receivePurchase,
[types.purchase_accept]: controllers_1.controllers.media.receivePurchaseAccept,
[types.purchase_deny]: controllers_1.controllers.media.receivePurchaseDeny,
[types.group_create]: controllers_1.controllers.chats.receiveGroupCreateOrInvite,
[types.group_invite]: controllers_1.controllers.chats.receiveGroupCreateOrInvite,
[types.group_join]: controllers_1.controllers.chats.receiveGroupJoin,
[types.group_leave]: controllers_1.controllers.chats.receiveGroupLeave,
[msgtypes.contact_key]: controllers_1.controllers.contacts.receiveContactKey,
[msgtypes.contact_key_confirmation]: controllers_1.controllers.contacts.receiveConfirmContactKey,
[msgtypes.message]: controllers_1.controllers.messages.receiveMessage,
[msgtypes.invoice]: controllers_1.controllers.invoices.receiveInvoice,
[msgtypes.direct_payment]: controllers_1.controllers.payments.receivePayment,
[msgtypes.confirmation]: controllers_1.controllers.confirmations.receiveConfirmation,
[msgtypes.attachment]: controllers_1.controllers.media.receiveAttachment,
[msgtypes.purchase]: controllers_1.controllers.media.receivePurchase,
[msgtypes.purchase_accept]: controllers_1.controllers.media.receivePurchaseAccept,
[msgtypes.purchase_deny]: controllers_1.controllers.media.receivePurchaseDeny,
[msgtypes.group_create]: controllers_1.controllers.chats.receiveGroupCreateOrInvite,
[msgtypes.group_invite]: controllers_1.controllers.chats.receiveGroupCreateOrInvite,
[msgtypes.group_join]: controllers_1.controllers.chats.receiveGroupJoin,
[msgtypes.group_leave]: controllers_1.controllers.chats.receiveGroupLeave,
};
function initGrpcSubscriptions() {
return __awaiter(this, void 0, void 0, function* () {

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

File diff suppressed because one or more lines are too long

2
dist/api/utils/setup.js

@ -47,6 +47,8 @@ function migrate() {
addTableColumn('sphinx_chats', 'group_key');
addTableColumn('sphinx_chats', 'group_private_key');
addTableColumn('sphinx_chats', 'host');
addTableColumn('sphinx_chats', 'price_to_join', 'BIGINT');
addTableColumn('sphinx_chats', 'price_per_message', 'BIGINT');
try {
yield models_1.sequelize.query(`
CREATE TABLE sphinx_chat_members (

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

@ -1 +1 @@
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../../api/utils/setup.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,2CAA2C;AAC3C,sCAA2C;AAC3C,iDAAoC;AACpC,iCAAgC;AAChC,sCAAqC;AACrC,gDAAwC;AACxC,8CAA0D;AAE1D,MAAM,YAAY,GAAG,CAAC,CAAA;AAEtB,MAAM,aAAa,GAAG,GAAS,EAAE;IAC/B,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAA;IACxC,MAAM,UAAU,EAAE,CAAA;IAClB,IAAI;QACF,MAAM,kBAAS,CAAC,IAAI,EAAE,CAAA;QACtB,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC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,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAA;QAC9B,IAAI,SAAS,CAAA;QACb,IAAG,CAAC,EAAE,EAAE;YACN,IAAI;gBACF,SAAS,GAAG,MAAM,QAAQ,CAAC,EAAE,EAAE,CAAA;aAChC;YAAC,OAAM,CAAC,EAAC,GAAE;SACb;aAAM;YACL,SAAS,GAAG,EAAE,CAAA;SACf;QACD,IAAG,CAAC,SAAS,EAAE;YACb,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAA;YACvC,OAAM;SACP;QACD,IAAI,KAAK,GAAG,SAAS,CAAA;QACrB,qDAAqD;QAErD,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,KAAK,KAAK,kBAAQ,IAAE,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;QAC3E,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAA;QAC1C,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAChB,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAC,EAAC,IAAI,EAAC,UAAU,EAAC,EAAE,UAAU,GAAG,EAAE,GAAG;YACvD,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAClB,CAAC,CAAC,CAAA;IACJ,CAAC;CAAA"}

15
frontend/components/Media/index.jsx

@ -43,8 +43,7 @@ export default function Media(props) {
const ttl = 60*60*24*7 // one week
const file = files[0] || {}
var start = new Date();
const r = await api.media.UPLOAD('upload/attachment',file,{
chat_uuid: '1234567890',
const r = await api.media.UPLOAD('file',file,{
name: file.name||'filename',
description: description||'description',
ttl: ttl,
@ -52,12 +51,12 @@ export default function Media(props) {
var end = new Date();
var time = end.getTime() - start.getTime();
console.log('Upload Timer: finished in', time, 'ms');
// await api.relay.POST('attachment', {
// muid: r.muid,
// file_name: r.filename,
// chat_id: 13,
// ttl: ttl,
// })
await api.relay.POST('attachment', {
muid: r.muid,
file_name: r.filename,
chat_id: 13,
ttl: ttl,
})
}, [description]) // subscribe to "description"
async function search(){

Loading…
Cancel
Save