Browse Source

Merge pull request #122 from stakwork/personal

Personal
dependabot/npm_and_yarn/ini-1.3.7
Evan Feenstra 4 years ago
committed by GitHub
parent
commit
7096e229ee
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 36
      dist/src/controllers/chatTribes.js
  2. 2
      dist/src/controllers/chatTribes.js.map
  3. 23
      dist/src/controllers/chats.js
  4. 2
      dist/src/controllers/chats.js.map
  5. 12
      dist/src/controllers/contacts.js
  6. 2
      dist/src/controllers/contacts.js.map
  7. 4
      dist/src/controllers/messages.js
  8. 2
      dist/src/controllers/messages.js.map
  9. 3
      dist/src/helpers.js
  10. 2
      dist/src/helpers.js.map
  11. 8
      dist/src/models/ts/chat.js
  12. 2
      dist/src/models/ts/chat.js.map
  13. 4
      dist/src/models/ts/chatMember.js
  14. 2
      dist/src/models/ts/chatMember.js.map
  15. 59
      dist/src/network/receive.js
  16. 2
      dist/src/network/receive.js.map
  17. 21
      dist/src/network/send.js
  18. 2
      dist/src/network/send.js.map
  19. 3
      dist/src/utils/setup.js
  20. 2
      dist/src/utils/setup.js.map
  21. 7
      dist/src/utils/tribeBots.js
  22. 2
      dist/src/utils/tribeBots.js.map
  23. 101
      package-lock.json
  24. 2
      package.json
  25. 39
      src/controllers/chatTribes.ts
  26. 21
      src/controllers/chats.ts
  27. 13
      src/controllers/contacts.ts
  28. 4
      src/controllers/messages.ts
  29. 3
      src/helpers.ts
  30. 6
      src/models/ts/chat.ts
  31. 3
      src/models/ts/chatMember.ts
  32. 57
      src/network/receive.ts
  33. 23
      src/network/send.ts
  34. 5
      src/utils/setup.ts
  35. 7
      src/utils/tribeBots.ts

36
dist/src/controllers/chatTribes.js

@ -24,7 +24,7 @@ const constants_1 = require("../constants");
function joinTribe(req, res) {
return __awaiter(this, void 0, void 0, function* () {
console.log('=> joinTribe');
const { uuid, group_key, name, host, amount, img, owner_pubkey, owner_alias } = req.body;
const { uuid, group_key, name, host, amount, img, owner_pubkey, owner_alias, my_alias, my_photo_url } = req.body;
const is_private = req.body.private;
const existing = yield models_1.models.Chat.findOne({ where: { uuid } });
if (existing) {
@ -77,6 +77,10 @@ function joinTribe(req, res) {
status: chatStatus,
priceToJoin: amount || 0,
};
if (my_alias)
chatParams.myAlias = my_alias;
if (my_photo_url)
chatParams.myPhotoUrl = my_photo_url;
const typeToSend = is_private ?
constants_1.default.message_types.member_request :
constants_1.default.message_types.group_join;
@ -85,15 +89,19 @@ function joinTribe(req, res) {
chatParams.contactIds;
console.log('=> joinTribe: typeToSend', typeToSend);
console.log('=> joinTribe: contactIdsToSend', contactIdsToSend);
// set my alias to be the custom one
const theOwner = owner.dataValues || owner;
if (my_alias)
theOwner.alias = my_alias;
network.sendMessage({
chat: Object.assign(Object.assign({}, chatParams), { contactIds: contactIdsToSend, members: {
[owner.publicKey]: {
key: owner.contactKey,
alias: owner.alias || ''
alias: my_alias || owner.alias || ''
}
} }),
amount: amount || 0,
sender: owner,
sender: theOwner,
message: {},
type: typeToSend,
failure: function (e) {
@ -130,7 +138,7 @@ function receiveMemberRequest(payload) {
date.setMilliseconds(0);
let theSender = null;
const member = chat_members[sender_pub_key];
const senderAlias = sender_alias || (member && member.alias) || 'Unknown';
const senderAlias = (member && member.alias) || sender_alias || 'Unknown';
const sender = yield models_1.models.Contact.findOne({ where: { publicKey: sender_pub_key } });
if (sender) {
theSender = sender; // might already include??
@ -140,7 +148,7 @@ function receiveMemberRequest(payload) {
const createdContact = yield models_1.models.Contact.create({
publicKey: sender_pub_key,
contactKey: member.key,
alias: senderAlias,
alias: sender_alias || senderAlias,
status: 1,
fromGroup: true,
photoUrl: sender_photo_url
@ -156,6 +164,7 @@ function receiveMemberRequest(payload) {
role: constants_1.default.chat_roles.reader,
status: constants_1.default.chat_statuses.pending,
lastActive: date,
lastAlias: senderAlias,
});
// maybe check here manually????
try {
@ -165,6 +174,7 @@ function receiveMemberRequest(payload) {
role: constants_1.default.chat_roles.reader,
status: constants_1.default.chat_statuses.pending,
lastActive: date,
lastAlias: senderAlias,
});
}
catch (e) { }
@ -178,7 +188,7 @@ function receiveMemberRequest(payload) {
network_type
};
if (isTribe) {
msg.senderAlias = sender_alias;
msg.senderAlias = senderAlias;
msg.senderPic = sender_photo_url;
}
const message = yield models_1.models.Message.create(msg);
@ -316,7 +326,7 @@ function approveOrRejectMember(req, res) {
exports.approveOrRejectMember = approveOrRejectMember;
function receiveMemberApprove(payload) {
return __awaiter(this, void 0, void 0, function* () {
console.log('=> receiveMemberApprove');
console.log('=> receiveMemberApprove'); // received by the joiner only
const { owner, chat, chat_name, sender, network_type } = yield helpers.parseReceiveParams(payload);
if (!chat)
return console.log('no chat');
@ -342,16 +352,20 @@ function receiveMemberApprove(payload) {
});
const amount = chat.priceToJoin || 0;
const theChat = chat.dataValues || chat;
const theOwner = owner.dataValues || owner;
const theAlias = chat.myAlias || owner.alias;
if (theAlias)
theOwner.alias = theAlias;
// send JOIN and my info to all
network.sendMessage({
chat: Object.assign(Object.assign({}, theChat), { members: {
[owner.publicKey]: {
key: owner.contactKey,
alias: owner.alias || ''
alias: theAlias || ''
}
} }),
amount,
sender: owner,
sender: theOwner,
message: {},
type: constants_1.default.message_types.group_join,
});
@ -462,7 +476,9 @@ function replayChatHistory(chat, contact) {
}
}
}
let msg = network.newmsg(m.type, chat, sender, Object.assign(Object.assign(Object.assign(Object.assign({ content }, mediaKeyMap && { mediaKey: mediaKeyMap }), newMediaTerms && { mediaToken: newMediaTerms }), m.mediaType && { mediaType: m.mediaType }), dateString && { date: dateString }));
const isForwarded = m.sender !== 1;
const includeStatus = true;
let msg = network.newmsg(m.type, chat, sender, Object.assign(Object.assign(Object.assign(Object.assign({ content, uuid: m.uuid, replyUuid: m.replyUuid, status: m.status, amount: m.amount }, mediaKeyMap && { mediaKey: mediaKeyMap }), newMediaTerms && { mediaToken: newMediaTerms }), m.mediaType && { mediaType: m.mediaType }), dateString && { date: dateString }), isForwarded, includeStatus);
msg = yield msg_1.decryptMessage(msg, chat);
const data = yield msg_1.personalizeMessage(msg, contact, true);
const mqttTopic = `${contact.publicKey}/${chat.uuid}`;

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

File diff suppressed because one or more lines are too long

23
dist/src/controllers/chats.js

@ -32,7 +32,7 @@ function updateChat(req, res) {
if (!chat) {
return res_1.failure(res, 'chat not found');
}
const { name, photo_url, meta } = req.body;
const { name, photo_url, meta, my_alias, my_photo_url } = req.body;
const obj = {};
if (name)
obj.name = name;
@ -40,6 +40,10 @@ function updateChat(req, res) {
obj.photoUrl = photo_url;
if (meta && typeof meta === 'string')
obj.meta = meta;
if (my_alias)
obj.myAlias = my_alias;
if (my_photo_url || my_photo_url === "")
obj.myPhotoUrl = my_photo_url;
if (Object.keys(obj).length > 0) {
yield chat.update(obj);
}
@ -330,7 +334,7 @@ function receiveGroupJoin(payload) {
date = new Date(date_string);
let theSender = null;
const member = chat_members[sender_pub_key];
const senderAlias = sender_alias || (member && member.alias) || 'Unknown';
const senderAlias = (member && member.alias) || sender_alias || 'Unknown';
if (!isTribe || isTribeOwner) {
const sender = yield models_1.models.Contact.findOne({ where: { publicKey: sender_pub_key } });
const contactIds = JSON.parse(chat.contactIds || '[]');
@ -363,16 +367,27 @@ function receiveGroupJoin(payload) {
return console.log('no sender'); // fail (no contact key?)
yield chat.update({ contactIds: JSON.stringify(contactIds) });
if (isTribeOwner) { // IF TRIBE, ADD new member TO XREF
console.log("UPSERT CHAT MEMBER", {
contactId: theSender.id,
chatId: chat.id,
role: constants_1.default.chat_roles.reader,
status: constants_1.default.chat_statuses.pending,
lastActive: date,
lastAlias: senderAlias,
});
try {
models_1.models.ChatMember.upsert({
contactId: theSender.id,
chatId: chat.id,
role: constants_1.default.chat_roles.reader,
lastActive: date,
status: constants_1.default.chat_statuses.approved
status: constants_1.default.chat_statuses.approved,
lastAlias: senderAlias,
});
}
catch (e) { }
catch (e) {
console.log('=> groupJoin could not upsert ChatMember');
}
chatTribes_1.replayChatHistory(chat, theSender);
tribes.putstats({
chatId: chat.id,

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

File diff suppressed because one or more lines are too long

12
dist/src/controllers/contacts.js

@ -80,6 +80,9 @@ exports.updateContact = (req, res) => __awaiter(void 0, void 0, void 0, function
if (!contact) {
return res_1.failure(res, 'no contact found');
}
const contactKeyChanged = attrs['contact_key'] && contact.contactKey !== attrs['contact_key'];
const aliasChanged = attrs['alias'] && contact.alias !== attrs['alias'];
const photoChanged = attrs['photo_url'] && contact.photoUrl !== attrs['photo_url'];
// update contact
const owner = yield contact.update(jsonUtils.jsonToContact(attrs));
res_1.success(res, jsonUtils.contactToJson(owner));
@ -88,9 +91,6 @@ exports.updateContact = (req, res) => __awaiter(void 0, void 0, void 0, function
if (!(attrs['contact_key'] || attrs['alias'] || attrs['photo_url'])) {
return; // skip if not at least one of these
}
const contactKeyChanged = contact.contactKey !== attrs['contact_key'];
const aliasChanged = contact.alias !== attrs['alias'];
const photoChanged = contact.photoUrl !== attrs['photo_url'];
if (!(contactKeyChanged || aliasChanged || photoChanged)) {
return;
}
@ -202,7 +202,11 @@ exports.receiveContactKey = (payload) => __awaiter(void 0, void 0, void 0, funct
}
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
const sender = yield models_1.models.Contact.findOne({ where: { publicKey: sender_pub_key, status: constants_1.default.contact_statuses.confirmed } });
let contactKeyChanged = false;
if (sender_contact_key && sender) {
if (sender_contact_key !== sender.contactKey) {
contactKeyChanged = true;
}
const objToUpdate = { contactKey: sender_contact_key };
if (sender_alias)
objToUpdate.alias = sender_alias;
@ -217,11 +221,13 @@ exports.receiveContactKey = (payload) => __awaiter(void 0, void 0, void 0, funct
else {
console.log("DID NOT FIND SENDER");
}
if (contactKeyChanged) {
helpers.sendContactKeys({
contactPubKey: sender_pub_key,
sender: owner,
type: constants_1.default.message_types.contact_key_confirmation,
});
}
});
exports.receiveConfirmContactKey = (payload) => __awaiter(void 0, void 0, void 0, function* () {
console.log(`=> confirm contact key for ${payload.sender && payload.sender.pub_key}`, JSON.stringify(payload));

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

File diff suppressed because one or more lines are too long

4
dist/src/controllers/messages.js

@ -217,7 +217,7 @@ exports.sendMessage = (req, res) => __awaiter(void 0, void 0, void 0, function*
});
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, network_type, sender_photo_url } = 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, sender_photo_url, message_status } = yield helpers.parseReceiveParams(payload);
if (!owner || !sender || !chat) {
return console.log('=> no group chat!');
}
@ -236,7 +236,7 @@ exports.receiveMessage = (payload) => __awaiter(void 0, void 0, void 0, function
messageContent: text,
createdAt: date,
updatedAt: date,
status: constants_1.default.statuses.received,
status: message_status || constants_1.default.statuses.received,
network_type: network_type,
};
const isTribe = chat_type === constants_1.default.chat_types.tribe;

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

File diff suppressed because one or more lines are too long

3
dist/src/helpers.js

@ -158,6 +158,7 @@ function parseReceiveParams(payload) {
const amount = dat.message.amount;
const content = dat.message.content;
const remote_content = dat.message.remoteContent;
const message_status = dat.message.status;
const mediaToken = dat.message.mediaToken;
const originalMuid = dat.message.originalMuid;
const msg_id = dat.message.id || 0;
@ -189,7 +190,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, network_type };
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, message_status };
});
}
exports.parseReceiveParams = parseReceiveParams;

2
dist/src/helpers.js.map

File diff suppressed because one or more lines are too long

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

@ -128,6 +128,14 @@ __decorate([
sequelize_typescript_1.Column,
__metadata("design:type", String)
], Chat.prototype, "meta", void 0);
__decorate([
sequelize_typescript_1.Column,
__metadata("design:type", String)
], Chat.prototype, "myPhotoUrl", void 0);
__decorate([
sequelize_typescript_1.Column,
__metadata("design:type", String)
], Chat.prototype, "myAlias", void 0);
Chat = __decorate([
sequelize_typescript_1.Table({ tableName: 'sphinx_chats', underscored: true })
], Chat);

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

@ -1 +1 @@
{"version":3,"file":"chat.js","sourceRoot":"","sources":["../../../../src/models/ts/chat.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+DAAsE;AAGtE,IAAqB,IAAI,GAAzB,MAAqB,IAAK,SAAQ,4BAAW;CA8F5C,CAAA;AAtFC;IANC,6BAAM,CAAC;QACN,IAAI,EAAE,+BAAQ,CAAC,MAAM;QACrB,UAAU,EAAE,IAAI;QAChB,MAAM,EAAE,IAAI;QACZ,aAAa,EAAE,IAAI;KACpB,CAAC;;gCACQ;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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,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;AAGvB;IADC,6BAAM,CAAC,+BAAQ,CAAC,MAAM,CAAC;;0CACJ;AAGpB;IADC,6BAAM,CAAC,+BAAQ,CAAC,MAAM,CAAC;;0CACJ;AAOpB;IALC,6BAAM,CAAC;QACN,IAAI,EAAE,+BAAQ,CAAC,OAAO;QACtB,YAAY,EAAE,KAAK;KAEpB,CAAC;;sCACe;AAGjB;IADC,6BAAM;;qCACS;AAGhB;IADC,6BAAM;;yCACY;AAOnB;IALC,6BAAM,CAAC;QACN,IAAI,EAAE,+BAAQ,CAAC,OAAO;QACtB,YAAY,EAAE,KAAK;QACnB,SAAS,EAAE,KAAK;KACjB,CAAC;;kCACW;AAGb;IADC,6BAAM;;oCACO;AAGd;IADC,6BAAM;;qCACQ;AAGf;IADC,6BAAM;;kCACK;AAGZ;IADC,6BAAM;;wCACW;AAGlB;IADC,6BAAM;;qCACQ;AAlGI,IAAI;IADxB,4BAAK,CAAC,EAAC,SAAS,EAAE,cAAc,EAAE,WAAW,EAAE,IAAI,EAAC,CAAC;GACjC,IAAI,CAoGxB;kBApGoB,IAAI"}

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

@ -40,6 +40,10 @@ __decorate([
sequelize_typescript_1.Column,
__metadata("design:type", Number)
], ChatMember.prototype, "status", void 0);
__decorate([
sequelize_typescript_1.Column,
__metadata("design:type", String)
], ChatMember.prototype, "lastAlias", void 0);
ChatMember = __decorate([
sequelize_typescript_1.Table({ tableName: 'sphinx_chat_members', underscored: true, indexes: [
{ unique: true, fields: ['chat_id', 'contact_id'] }

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

@ -1 +1 @@
{"version":3,"file":"chatMember.js","sourceRoot":"","sources":["../../../../src/models/ts/chatMember.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+DAA4D;AAK5D,IAAqB,UAAU,GAA/B,MAAqB,UAAW,SAAQ,4BAAiB;CAuBxD,CAAA;AApBC;IADC,6BAAM;;0CACO;AAGd;IADC,6BAAM;;6CACU;AAGjB;IADC,6BAAM;;wCACK;AAGZ;IADC,6BAAM;;8CACW;AAGlB;IADC,6BAAM;;iDACc;AAGrB;IADC,6BAAM;8BACK,IAAI;8CAAA;AAGhB;IADC,6BAAM;;0CACO;AArBK,UAAU;IAH9B,4BAAK,CAAC,EAAC,SAAS,EAAE,qBAAqB,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAC;YACnE,EAAC,MAAM,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC,SAAS,EAAC,YAAY,CAAC,EAAC;SAC/C,EAAC,CAAC;GACkB,UAAU,CAuB9B;kBAvBoB,UAAU"}
{"version":3,"file":"chatMember.js","sourceRoot":"","sources":["../../../../src/models/ts/chatMember.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+DAA4D;AAK5D,IAAqB,UAAU,GAA/B,MAAqB,UAAW,SAAQ,4BAAiB;CA0BxD,CAAA;AAvBC;IADC,6BAAM;;0CACO;AAGd;IADC,6BAAM;;6CACU;AAGjB;IADC,6BAAM;;wCACK;AAGZ;IADC,6BAAM;;8CACW;AAGlB;IADC,6BAAM;;iDACc;AAGrB;IADC,6BAAM;8BACK,IAAI;8CAAA;AAGhB;IADC,6BAAM;;0CACO;AAGd;IADC,6BAAM;;6CACU;AAxBE,UAAU;IAH9B,4BAAK,CAAC,EAAC,SAAS,EAAE,qBAAqB,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAC;YACnE,EAAC,MAAM,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC,SAAS,EAAC,YAAY,CAAC,EAAC;SAC/C,EAAC,CAAC;GACkB,UAAU,CA0B9B;kBA1BoB,UAAU"}

59
dist/src/network/receive.js

@ -46,6 +46,7 @@ exports.typesToReplay = [
msgtypes.group_join,
msgtypes.group_leave,
msgtypes.bot_res,
msgtypes.boost,
];
const botTypes = [
constants_1.default.message_types.bot_install,
@ -76,6 +77,7 @@ function onReceive(payload) {
let isTribe = false;
let isTribeOwner = false;
let chat;
let owner;
if (payload.chat && payload.chat.uuid) {
isTribe = payload.chat.type === constants_1.default.chat_types.tribe;
chat = yield models_1.models.Chat.findOne({ where: { uuid: payload.chat.uuid } });
@ -84,7 +86,7 @@ function onReceive(payload) {
}
if (isTribe) {
const tribeOwnerPubKey = chat && chat.ownerPubkey;
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
isTribeOwner = owner.publicKey === tribeOwnerPubKey;
}
if (isTribeOwner)
@ -93,8 +95,11 @@ function onReceive(payload) {
const needsPricePerMessage = typesThatNeedPricePerMessage.includes(payload.type);
// CHECK THEY ARE IN THE GROUP if message
const senderContact = yield models_1.models.Contact.findOne({ where: { publicKey: payload.sender.pub_key } });
if (!senderContact)
return; // need sender contact!
const senderContactId = senderContact.id;
if (needsPricePerMessage) {
const senderMember = senderContact && (yield models_1.models.ChatMember.findOne({ where: { contactId: senderContact.id, chatId: chat.id } }));
const senderMember = yield models_1.models.ChatMember.findOne({ where: { contactId: senderContactId, chatId: chat.id } });
if (!senderMember)
doAction = false;
}
@ -107,7 +112,7 @@ function onReceive(payload) {
timers.addTimer({
amount: chat.escrowAmount,
millis: chat.escrowMillis,
receiver: senderContact.id,
receiver: senderContactId,
msgId: payload.message.id,
chatId: chat.id,
});
@ -118,7 +123,7 @@ function onReceive(payload) {
if (payload.message.amount < chat.priceToJoin)
doAction = false;
if (chat.private) { // check if has been approved
const senderMember = senderContact && (yield models_1.models.ChatMember.findOne({ where: { contactId: senderContact.id, chatId: chat.id } }));
const senderMember = yield models_1.models.ChatMember.findOne({ where: { contactId: senderContactId, chatId: chat.id } });
if (!(senderMember && senderMember.status === constants_1.default.chat_statuses.approved)) {
doAction = false; // dont let if private and not approved
}
@ -130,7 +135,7 @@ function onReceive(payload) {
if (payload.message.uuid) {
const ogMsg = yield models_1.models.Message.findOne({ where: {
uuid: payload.message.uuid,
sender: senderContact.id,
sender: senderContactId,
} });
if (ogMsg)
doAction = true;
@ -154,6 +159,8 @@ function onReceive(payload) {
}
}
}
// make sure alias is unique among chat members
payload = yield uniqueifyAlias(payload, senderContact, chat, owner);
if (doAction)
forwardMessageToTribe(payload, senderContact, realSatsContactId, amtToForward);
else
@ -210,10 +217,41 @@ function doTheAction(data) {
}
});
}
function uniqueifyAlias(payload, sender, chat, owner) {
return __awaiter(this, void 0, void 0, function* () {
if (!chat || !sender || !owner)
return payload;
if (!(payload && payload.sender))
return payload;
const senderContactId = sender.id; // og msg sender
const owner_alias = chat.myAlias || owner.alias;
const sender_alias = payload.sender && payload.sender.alias;
let final_sender_alias = sender_alias;
const chatMembers = yield models_1.models.ChatMember.findAll({ where: { chatId: chat.id } });
if (!(chatMembers && chatMembers.length))
return payload;
asyncForEach(chatMembers, (cm) => {
if (cm.contactId === senderContactId)
return; // dont check against self of course
if (sender_alias === cm.lastAlias || sender_alias === owner_alias) {
// impersonating! switch it up!
final_sender_alias = `${sender_alias}_2`;
}
});
if (sender_alias !== final_sender_alias) {
yield models_1.models.ChatMember.update(// this syntax is necessary when no unique ID on the Model
{ lastAlias: final_sender_alias }, { where: { chatId: chat.id, contactId: senderContactId } });
}
payload.sender.alias = final_sender_alias;
return payload;
});
}
function forwardMessageToTribe(ogpayload, sender, realSatsContactId, amtToForwardToRealSatsContactId) {
return __awaiter(this, void 0, void 0, function* () {
// console.log('forwardMessageToTribe')
const chat = yield models_1.models.Chat.findOne({ where: { uuid: ogpayload.chat.uuid } });
if (!chat)
return;
let payload;
if (sender && typesToModify.includes(ogpayload.type)) {
payload = yield modify_1.modifyPayloadAndSaveMediaKey(ogpayload, chat, sender);
@ -221,13 +259,9 @@ function forwardMessageToTribe(ogpayload, sender, realSatsContactId, amtToForwar
else {
payload = ogpayload;
}
// dont need sender beyond here
//const sender = await models.Contact.findOne({where:{publicKey:payload.sender.pub_key}})
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
const type = payload.type;
const message = payload.message;
// HERE: NEED TO MAKE SURE ALIAS IS UNIQUE
// ASK xref TABLE and put alias there too?
send_1.sendMessage({
type, message,
sender: Object.assign(Object.assign({}, owner.dataValues), { alias: (payload.sender && payload.sender.alias) || '', photoUrl: (payload.sender && payload.sender.photo_url) || '', role: constants_1.default.chat_roles.reader }),
@ -418,4 +452,11 @@ function weave(p) {
return payload;
}
}
function asyncForEach(array, callback) {
return __awaiter(this, void 0, void 0, function* () {
for (let index = 0; index < array.length; index++) {
yield callback(array[index], index, array);
}
});
}
//# sourceMappingURL=receive.js.map

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

File diff suppressed because one or more lines are too long

21
dist/src/network/send.js

@ -29,7 +29,7 @@ function sendMessage(params) {
if (isTribeOwner && !isForwarded) {
theSender = Object.assign(Object.assign({}, (sender.dataValues || sender)), { role: constants_1.default.chat_roles.owner });
}
let msg = newmsg(type, chat, theSender, message);
let msg = newmsg(type, chat, theSender, message, isForwarded);
// console.log("=> MSG TO SEND",msg)
// console.log(type,message)
if (!(sender && sender.publicKey)) {
@ -107,7 +107,7 @@ function sendMessage(params) {
console.log("KEYSEND ERROR", e);
no = e;
}
yield sleep(2);
yield sleep(10);
}));
if (no) {
if (failure)
@ -164,15 +164,26 @@ function checkIfAutoConfirm(data) {
confirmations_1.tribeOwnerAutoConfirmation(data.message.id, data.chat.uuid);
}
}
function newmsg(type, chat, sender, message) {
function newmsg(type, chat, sender, message, isForwarded, includeStatus) {
const includeGroupKey = type === constants_1.default.message_types.group_create || type === constants_1.default.message_types.group_invite;
const includeAlias = sender && sender.alias && chat.type === constants_1.default.chat_types.tribe;
const includePhotoUrl = sender && sender.photoUrl && !sender.privatePhoto && chat && chat.type === constants_1.default.chat_types.tribe;
let aliasToInclude = sender.alias;
if (!isForwarded && includeAlias && chat.myAlias) {
aliasToInclude = chat.myAlias;
}
const includePhotoUrl = sender && !sender.privatePhoto && chat && chat.type === constants_1.default.chat_types.tribe;
let photoUrlToInclude = sender.photoUrl || '';
if (!isForwarded && includePhotoUrl && chat.myPhotoUrl) {
photoUrlToInclude = chat.myPhotoUrl;
}
if (!includeStatus && message.status) {
delete message.status;
}
return {
type: type,
chat: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ uuid: chat.uuid }, chat.name && { name: chat.name }), (chat.type || chat.type === 0) && { type: chat.type }), chat.members && { members: chat.members }), (includeGroupKey && chat.groupKey) && { groupKey: chat.groupKey }), (includeGroupKey && chat.host) && { host: chat.host }),
message: message,
sender: Object.assign({ pub_key: sender.publicKey, alias: includeAlias ? sender.alias : '', role: sender.role || constants_1.default.chat_roles.reader }, includePhotoUrl && { photo_url: sender.photoUrl })
sender: Object.assign({ pub_key: sender.publicKey, alias: includeAlias ? aliasToInclude : '', role: sender.role || constants_1.default.chat_roles.reader }, includePhotoUrl && { photo_url: photoUrlToInclude })
};
}
exports.newmsg = newmsg;

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

File diff suppressed because one or more lines are too long

3
dist/src/utils/setup.js

@ -49,6 +49,9 @@ function setVersion() {
}
function migrate() {
return __awaiter(this, void 0, void 0, function* () {
addTableColumn('sphinx_chat_members', 'last_alias');
addTableColumn('sphinx_chats', 'my_photo_url');
addTableColumn('sphinx_chats', 'my_alias');
addTableColumn('sphinx_messages', 'sender_pic');
addTableColumn('sphinx_messages', 'network_type', 'INTEGER');
addTableColumn('sphinx_chats', 'meta');

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

File diff suppressed because one or more lines are too long

7
dist/src/utils/tribeBots.js

@ -11,11 +11,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", { value: true });
const models_1 = require("../models");
const tribes_1 = require("./tribes");
const node_fetch_1 = require("node-fetch");
function declare_bot({ uuid, name, description, tags, img, price_per_use, owner_pubkey, unlisted, deleted }) {
return __awaiter(this, void 0, void 0, function* () {
const host = tribes_1.getHost();
try {
yield fetch('https://' + host + '/bots', {
const r = yield node_fetch_1.default('https://' + host + '/bots', {
method: 'POST',
body: JSON.stringify({
uuid, owner_pubkey,
@ -26,8 +27,8 @@ function declare_bot({ uuid, name, description, tags, img, price_per_use, owner_
}),
headers: { 'Content-Type': 'application/json' }
});
// const j = await r.json()
// console.log('=> j',j)
const j = yield r.json();
console.log('=> bot created:', j);
}
catch (e) {
console.log('[tribes] unauthorized to declare');

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

@ -1 +1 @@
{"version":3,"file":"tribeBots.js","sourceRoot":"","sources":["../../../src/utils/tribeBots.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sCAAkC;AAClC,qCAAgC;AAEhC,SAAsB,WAAW,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,EAAE,aAAa,EAAE,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAE;;QACpH,MAAM,IAAI,GAAG,gBAAO,EAAE,CAAA;QACtB,IAAI;YACF,MAAM,KAAK,CAAC,UAAU,GAAG,IAAI,GAAG,OAAO,EAAE;gBACvC,MAAM,EAAE,MAAM;gBACd,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;oBACnB,IAAI,EAAE,YAAY;oBAClB,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE;oBACvC,aAAa,EAAE,aAAa,IAAI,CAAC;oBACjC,QAAQ,EAAE,QAAQ,IAAI,KAAK;oBAC3B,OAAO,EAAE,OAAO,IAAI,KAAK;iBAC1B,CAAC;gBACF,OAAO,EAA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GAAG;gBACZ,KAAK,EAAE,CAAC;gBACR,SAAS,EAAE,EAAE;gBACb,SAAS,EAAE,EAAE;gBACb,WAAW,EAAE,CAAC;gBACd,UAAU,EAAE,KAAK;aAClB,CAAC;KACH,CAAA;AACH,CAAC"}

101
package-lock.json

@ -228,9 +228,9 @@
}
},
"@types/cors": {
"version": "2.8.7",
"resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.7.tgz",
"integrity": "sha512-sOdDRU3oRS7LBNTIqwDkPJyq0lpHYcbMTt0TrjzsXbk/e37hcLTH6eZX7CdbDeN0yJJvzw9hFBZkbtCSbk/jAQ==",
"version": "2.8.8",
"resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.8.tgz",
"integrity": "sha512-fO3gf3DxU2Trcbr75O7obVndW/X5k8rJNZkLXlQWStTHhP71PkRqjwPIEI0yMnJdg9R9OasjU+Bsr+Hr1xy/0w==",
"requires": {
"@types/express": "*"
}
@ -267,9 +267,9 @@
"integrity": "sha512-ZxnwyBGO4KX/82AsFHTX82eMw0PsoBcIngEat+zx0y+3yxoNDJucAihg9nAcrc+g4Cwiv/4WcWsX4oiy0ySrRQ=="
},
"@types/express": {
"version": "4.17.8",
"resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.8.tgz",
"integrity": "sha512-wLhcKh3PMlyA2cNAB9sjM1BntnhPMiM0JOBwPBqttjHev2428MLEB4AYVN+d8s2iyCVZac+o41Pflm/ZH5vLXQ==",
"version": "4.17.9",
"resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.9.tgz",
"integrity": "sha512-SDzEIZInC4sivGIFY4Sz1GG6J9UObPwCInYJjko2jzOf/Imx/dlpume6Xxwj1ORL82tBbmN4cPDIDkLbWHk9hw==",
"requires": {
"@types/body-parser": "*",
"@types/express-serve-static-core": "*",
@ -278,9 +278,9 @@
}
},
"@types/express-serve-static-core": {
"version": "4.17.13",
"resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.13.tgz",
"integrity": "sha512-RgDi5a4nuzam073lRGKTUIaL3eF2+H7LJvJ8eUnCI0wA6SNjXc44DCmWNiTLs/AZ7QlsFWZiw/gTG3nSQGL0fA==",
"version": "4.17.14",
"resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.14.tgz",
"integrity": "sha512-uFTLwu94TfUFMToXNgRZikwPuZdOtDgs3syBtAIr/OXorL1kJqUJT9qCLnRZ5KBOWfZQikQ2xKgR2tnDj1OgDA==",
"requires": {
"@types/node": "*",
"@types/qs": "*",
@ -377,12 +377,12 @@
"integrity": "sha512-41qEJgBH/TWgo5NFSvBCJ1qkoi3Q6ONSF2avrHq1LVEZfYpdHmj0y9SuTK+u9ZhG1sYQKBL1AWXKyLWP4RaUoQ=="
},
"@types/serve-static": {
"version": "1.13.5",
"resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.5.tgz",
"integrity": "sha512-6M64P58N+OXjU432WoLLBQxbA0LRGBCRm7aAGQJ+SMC1IMl0dgRVi9EFfoDcS2a7Xogygk/eGN94CfwU9UF7UQ==",
"version": "1.13.8",
"resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.8.tgz",
"integrity": "sha512-MoJhSQreaVoL+/hurAZzIm8wafFR6ajiTM1m4A0kv6AGeVBl4r4pOV8bGFrjjq1sGxDTnCoF8i22o0/aE5XCyA==",
"requires": {
"@types/express-serve-static-core": "*",
"@types/mime": "*"
"@types/mime": "*",
"@types/node": "*"
}
},
"@types/tape": {
@ -430,6 +430,11 @@
"negotiator": "0.6.2"
}
},
"acorn": {
"version": "7.4.1",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz",
"integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A=="
},
"acorn-globals": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/acorn-globals/-/acorn-globals-6.0.0.tgz",
@ -437,13 +442,6 @@
"requires": {
"acorn": "^7.1.1",
"acorn-walk": "^7.1.1"
},
"dependencies": {
"acorn": {
"version": "7.4.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.0.tgz",
"integrity": "sha512-+G7P8jJmCHr+S+cLfQxygbWhXy+8YTVGzAkpEbcLo2mLoL7tij/VG41QSHACSf5QgYRhMZYHuNc6drJaO0Da+w=="
}
}
},
"acorn-walk": {
@ -1707,9 +1705,9 @@
}
},
"decimal.js": {
"version": "10.2.0",
"resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.2.0.tgz",
"integrity": "sha512-vDPw+rDgn3bZe1+F/pyEwb1oMG2XTlRVgAa6B4KccTEpYgF8w6eQllVbQcfIJnZyvzFtFpxnpGtx8dd7DJp/Rw=="
"version": "10.2.1",
"resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.2.1.tgz",
"integrity": "sha512-KaL7+6Fw6i5A2XSnsbhm/6B+NuEA7TZ4vqxnd5tXz9sbKtrN9Srj8ab4vKVdK8YAqZO9P1kg45Y6YLoduPf+kw=="
},
"decode-uri-component": {
"version": "0.2.0",
@ -2006,9 +2004,9 @@
}
},
"dompurify": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.1.0.tgz",
"integrity": "sha512-wKExRhOwUnfm1icoISSXnlmM1P2l07W2tFQqbU+8oySnvy7tHwj2iHJ1kJQi8EfcTlojsHKESOJwCGVJmNUdPQ=="
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.2.3.tgz",
"integrity": "sha512-8Hv7Q0FuwD9rWoB6qI2eZsfKbGXfoUVuGHHrE15vgk4ReOKwOkSgbqb2OMFtc0d5besOEkoLkcyuV10zQ2X5gw=="
},
"dont-sniff-mimetype": {
"version": "1.1.0",
@ -2467,14 +2465,6 @@
"esutils": "^2.0.2",
"optionator": "^0.8.1",
"source-map": "~0.6.1"
},
"dependencies": {
"source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
"optional": true
}
}
},
"esprima": {
@ -2506,6 +2496,11 @@
"es5-ext": "~0.10.14"
}
},
"eventemitter3": {
"version": "4.0.7",
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz",
"integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw=="
},
"evp_bytestokey": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/evp_bytestokey/-/evp_bytestokey-1.0.3.tgz",
@ -3605,11 +3600,6 @@
"xml-name-validator": "^3.0.0"
},
"dependencies": {
"acorn": {
"version": "7.4.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.0.tgz",
"integrity": "sha512-+G7P8jJmCHr+S+cLfQxygbWhXy+8YTVGzAkpEbcLo2mLoL7tij/VG41QSHACSf5QgYRhMZYHuNc6drJaO0Da+w=="
},
"form-data": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz",
@ -3674,9 +3664,9 @@
}
},
"ws": {
"version": "7.3.1",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.3.1.tgz",
"integrity": "sha512-D3RuNkynyHmEJIpD2qrgVkc9DQ23OrN/moAwZX4L8DfvszsJxpjQuUq3LMx6HoYji9fbIOBY18XWBsAux1ZZUA=="
"version": "7.4.1",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.4.1.tgz",
"integrity": "sha512-pTsP8UAfhy3sk1lSk/O/s4tjD0CRwvMnzvwr4OKGX7ZvqZtUyx4KIJB5JWbkykPoc55tixMGgTNoh3k4FkNGFQ=="
}
}
},
@ -5762,6 +5752,12 @@
"sort-keys": "^1.0.0"
}
},
"source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
"optional": true
},
"source-map-support": {
"version": "0.5.16",
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.16.tgz",
@ -5779,9 +5775,9 @@
}
},
"sphinx-bot": {
"version": "0.2.18",
"resolved": "https://registry.npmjs.org/sphinx-bot/-/sphinx-bot-0.2.18.tgz",
"integrity": "sha512-BV1nuzjo1X0ZQtMQ3NeANv6zs+lSE4zwkAVxtDVZebs6nZ9GeafKnd1rZB6IrS9UjvOqGitQTYEmrQ3dD018ow==",
"version": "0.2.19",
"resolved": "https://registry.npmjs.org/sphinx-bot/-/sphinx-bot-0.2.19.tgz",
"integrity": "sha512-RWDpS14BHSlGV1BOIbtcSOkOslYMRF6EKZo+wLBhz6PyE6VByFqXH7luDQYoNex5iHuybt/ZoHScgxuh5WqLmg==",
"requires": {
"@types/cors": "^2.8.7",
"@types/express": "^4.17.8",
@ -5792,13 +5788,6 @@
"express": "^4.17.1",
"isomorphic-dompurify": "^0.6.0",
"node-fetch": "^2.6.1"
},
"dependencies": {
"eventemitter3": {
"version": "4.0.7",
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz",
"integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw=="
}
}
},
"split": {
@ -6555,9 +6544,9 @@
"integrity": "sha512-M4yMwr6mAnQz76TbJm914+gPpB/nCwvZbJU28cUD6dR004SAxDLOOSUaB1JDRqLtaOV/vi0IC5lEAGFgrjGv/g=="
},
"whatwg-url": {
"version": "8.2.2",
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-8.2.2.tgz",
"integrity": "sha512-PcVnO6NiewhkmzV0qn7A+UZ9Xx4maNTI+O+TShmfE4pqjoCMwUMjkvoNhNHPTvgR7QH9Xt3R13iHuWy2sToFxQ==",
"version": "8.4.0",
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-8.4.0.tgz",
"integrity": "sha512-vwTUFf6V4zhcPkWp/4CQPr1TW9Ml6SF4lVyaIMBdJw5i6qUUJ1QWM4Z6YYVkfka0OUIzVo/0aNtGVGk256IKWw==",
"requires": {
"lodash.sortby": "^4.7.0",
"tr46": "^2.0.2",

2
package.json

@ -71,7 +71,7 @@
"short-uuid": "^3.1.1",
"sjcl": "^1.0.8",
"socket.io": "^2.3.0",
"sphinx-bot": "^0.2.18",
"sphinx-bot": "^0.2.19",
"tail": "^2.0.3",
"ts-node": "^8.5.4",
"tsc": "^1.20150623.0",

39
src/controllers/chatTribes.ts

@ -13,7 +13,7 @@ import constants from '../constants'
export async function joinTribe(req, res){
console.log('=> joinTribe')
const { uuid, group_key, name, host, amount, img, owner_pubkey, owner_alias } = req.body
const { uuid, group_key, name, host, amount, img, owner_pubkey, owner_alias, my_alias, my_photo_url } = req.body
const is_private = req.body.private
const existing = await models.Chat.findOne({where:{uuid}})
@ -56,7 +56,7 @@ export async function joinTribe(req, res){
const chatStatus = is_private ?
constants.chat_statuses.pending :
constants.chat_statuses.approved
const chatParams = {
const chatParams:{[k:string]:any} = {
uuid: uuid,
contactIds: JSON.stringify(contactIds),
photoUrl: img||'',
@ -71,6 +71,8 @@ export async function joinTribe(req, res){
status: chatStatus,
priceToJoin: amount||0,
}
if(my_alias) chatParams.myAlias = my_alias
if(my_photo_url) chatParams.myPhotoUrl = my_photo_url
const typeToSend = is_private ?
constants.message_types.member_request :
@ -80,6 +82,9 @@ export async function joinTribe(req, res){
chatParams.contactIds
console.log('=> joinTribe: typeToSend', typeToSend)
console.log('=> joinTribe: contactIdsToSend', contactIdsToSend)
// set my alias to be the custom one
const theOwner = owner.dataValues||owner
if(my_alias) theOwner.alias = my_alias
network.sendMessage({ // send my data to tribe owner
chat: {
...chatParams,
@ -87,12 +92,12 @@ export async function joinTribe(req, res){
members: {
[owner.publicKey]: {
key: owner.contactKey,
alias: owner.alias||''
alias: my_alias||owner.alias||''
}
}
},
amount: amount||0,
sender: owner,
sender: theOwner,
message: {},
type: typeToSend,
failure: function (e) {
@ -127,7 +132,7 @@ export async function receiveMemberRequest(payload) {
let theSender: any = null
const member = chat_members[sender_pub_key]
const senderAlias = sender_alias || (member && member.alias) || 'Unknown'
const senderAlias = (member && member.alias) || sender_alias || 'Unknown'
const sender = await models.Contact.findOne({ where: { publicKey: sender_pub_key } })
if (sender) {
@ -137,7 +142,7 @@ export async function receiveMemberRequest(payload) {
const createdContact = await models.Contact.create({
publicKey: sender_pub_key,
contactKey: member.key,
alias: senderAlias,
alias: sender_alias || senderAlias,
status: 1,
fromGroup: true,
photoUrl: sender_photo_url
@ -153,6 +158,7 @@ export async function receiveMemberRequest(payload) {
role: constants.chat_roles.reader,
status: constants.chat_statuses.pending,
lastActive: date,
lastAlias: senderAlias,
})
// maybe check here manually????
try{
@ -162,6 +168,7 @@ export async function receiveMemberRequest(payload) {
role: constants.chat_roles.reader,
status: constants.chat_statuses.pending,
lastActive: date,
lastAlias: senderAlias,
})
} catch(e){}
@ -175,7 +182,7 @@ export async function receiveMemberRequest(payload) {
network_type
}
if(isTribe) {
msg.senderAlias = sender_alias
msg.senderAlias = senderAlias
msg.senderPic = sender_photo_url
}
const message = await models.Message.create(msg)
@ -318,7 +325,7 @@ export async function approveOrRejectMember(req,res) {
}
export async function receiveMemberApprove(payload) {
console.log('=> receiveMemberApprove')
console.log('=> receiveMemberApprove') // received by the joiner only
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})
@ -345,18 +352,21 @@ export async function receiveMemberApprove(payload) {
const amount = chat.priceToJoin||0
const theChat = chat.dataValues||chat
const theOwner = owner.dataValues||owner
const theAlias = chat.myAlias || owner.alias
if(theAlias) theOwner.alias = theAlias
// send JOIN and my info to all
network.sendMessage({
chat: { ...theChat,
members: {
[owner.publicKey]: {
key: owner.contactKey,
alias: owner.alias||''
alias: theAlias||''
}
}
},
amount,
sender: owner,
sender: theOwner,
message: {},
type: constants.message_types.group_join,
})
@ -464,13 +474,20 @@ export async function replayChatHistory(chat, contact) {
}
}
}
const isForwarded = m.sender!==1
const includeStatus = true
let msg = network.newmsg(m.type, chat, sender, {
content, // replaced with the remoteMessageContent (u are owner) {}
uuid: m.uuid,
replyUuid: m.replyUuid,
status: m.status,
amount: m.amount,
...mediaKeyMap && {mediaKey: mediaKeyMap},
...newMediaTerms && {mediaToken: newMediaTerms},
...m.mediaType && {mediaType: m.mediaType},
...dateString && {date: dateString}
})
}, isForwarded, includeStatus)
msg = await decryptMessage(msg, chat)
const data = await personalizeMessage(msg, contact, true)
const mqttTopic = `${contact.publicKey}/${chat.uuid}`

21
src/controllers/chats.ts

@ -21,12 +21,14 @@ export async function updateChat(req, res){
if(!chat) {
return failure(res,'chat not found')
}
const {name,photo_url,meta} = req.body
const {name,photo_url,meta,my_alias,my_photo_url} = req.body
const obj:{[k:string]:any} = {}
if(name) obj.name=name
if(photo_url) obj.photoUrl=photo_url
if(meta && typeof meta==='string') obj.meta=meta
if(my_alias) obj.myAlias=my_alias
if(my_photo_url || my_photo_url==="") obj.myPhotoUrl=my_photo_url
if(Object.keys(obj).length>0) {
await chat.update(obj)
@ -337,7 +339,7 @@ export async function receiveGroupJoin(payload) {
let theSender: any = null
const member = chat_members[sender_pub_key]
const senderAlias = sender_alias || (member && member.alias) || 'Unknown'
const senderAlias = (member && member.alias) || sender_alias || 'Unknown'
if(!isTribe || isTribeOwner) {
const sender = await models.Contact.findOne({ where: { publicKey: sender_pub_key } })
@ -370,15 +372,26 @@ export async function receiveGroupJoin(payload) {
await chat.update({ contactIds: JSON.stringify(contactIds) })
if(isTribeOwner){ // IF TRIBE, ADD new member TO XREF
console.log("UPSERT CHAT MEMBER",{
contactId: theSender.id,
chatId: chat.id,
role: constants.chat_roles.reader,
status: constants.chat_statuses.pending,
lastActive: date,
lastAlias: senderAlias,
})
try{
models.ChatMember.upsert({
contactId: theSender.id,
chatId: chat.id,
role: constants.chat_roles.reader,
lastActive: date,
status: constants.chat_statuses.approved
status: constants.chat_statuses.approved,
lastAlias: senderAlias,
})
} catch(e) {}
} catch(e) {
console.log('=> groupJoin could not upsert ChatMember')
}
replayChatHistory(chat, theSender)
tribes.putstats({
chatId: chat.id,

13
src/controllers/contacts.ts

@ -83,6 +83,10 @@ export const updateContact = async (req, res) => {
return failure(res, 'no contact found')
}
const contactKeyChanged = attrs['contact_key'] && contact.contactKey!==attrs['contact_key']
const aliasChanged = attrs['alias'] && contact.alias!==attrs['alias']
const photoChanged = attrs['photo_url'] && contact.photoUrl!==attrs['photo_url']
// update contact
const owner = await contact.update(jsonUtils.jsonToContact(attrs))
success(res, jsonUtils.contactToJson(owner))
@ -91,9 +95,6 @@ export const updateContact = async (req, res) => {
if (!(attrs['contact_key'] || attrs['alias'] || attrs['photo_url'])) {
return // skip if not at least one of these
}
const contactKeyChanged = contact.contactKey!==attrs['contact_key']
const aliasChanged = contact.alias!==attrs['alias']
const photoChanged = contact.photoUrl!==attrs['photo_url']
if(!(contactKeyChanged || aliasChanged || photoChanged)) {
return
}
@ -224,7 +225,11 @@ export const receiveContactKey = async (payload) => {
const owner = await models.Contact.findOne({ where: { isOwner: true }})
const sender = await models.Contact.findOne({ where: { publicKey: sender_pub_key, status: constants.contact_statuses.confirmed }})
let contactKeyChanged = false
if (sender_contact_key && sender) {
if(sender_contact_key!==sender.contactKey) {
contactKeyChanged = true
}
const objToUpdate:{[k:string]:any} = {contactKey: sender_contact_key}
if(sender_alias) objToUpdate.alias = sender_alias
if(sender_photo_url) objToUpdate.photoUrl = sender_photo_url
@ -238,12 +243,14 @@ export const receiveContactKey = async (payload) => {
console.log("DID NOT FIND SENDER")
}
if(contactKeyChanged) {
helpers.sendContactKeys({
contactPubKey: sender_pub_key,
sender: owner,
type: constants.message_types.contact_key_confirmation,
})
}
}
export const receiveConfirmContactKey = async (payload) => {
console.log(`=> confirm contact key for ${payload.sender&&payload.sender.pub_key}`, JSON.stringify(payload))

4
src/controllers/messages.ts

@ -244,7 +244,7 @@ export const sendMessage = async (req, res) => {
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, network_type, sender_photo_url} = 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, sender_photo_url, message_status} = await helpers.parseReceiveParams(payload)
if(!owner || !sender || !chat) {
return console.log('=> no group chat!')
}
@ -264,7 +264,7 @@ export const receiveMessage = async (payload) => {
messageContent: text,
createdAt: date,
updatedAt: date,
status: constants.statuses.received,
status: message_status || constants.statuses.received,
network_type: network_type,
}
const isTribe = chat_type===constants.chat_types.tribe

3
src/helpers.ts

@ -144,6 +144,7 @@ export async function parseReceiveParams(payload) {
const amount = dat.message.amount
const content = dat.message.content
const remote_content = dat.message.remoteContent
const message_status = dat.message.status
const mediaToken = dat.message.mediaToken
const originalMuid = dat.message.originalMuid
const msg_id = dat.message.id||0
@ -177,7 +178,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, network_type }
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, message_status }
}
async function asyncForEach(array, callback) {

6
src/models/ts/chat.ts

@ -95,4 +95,10 @@ export default class Chat extends Model<Chat> {
@Column
meta: string
@Column
myPhotoUrl: string
@Column
myAlias: string
}

3
src/models/ts/chatMember.ts

@ -26,4 +26,7 @@ export default class ChatMember extends Model<ChatMember> {
@Column
status: number
@Column
lastAlias: string
}

57
src/network/receive.ts

@ -38,6 +38,7 @@ export const typesToReplay=[ // should match typesToForward
msgtypes.group_join,
msgtypes.group_leave,
msgtypes.bot_res,
msgtypes.boost,
]
const botTypes=[
constants.message_types.bot_install,
@ -67,6 +68,7 @@ async function onReceive(payload){
let isTribe = false
let isTribeOwner = false
let chat
let owner
if(payload.chat&&payload.chat.uuid) {
isTribe = payload.chat.type===constants.chat_types.tribe
@ -75,7 +77,7 @@ async function onReceive(payload){
}
if(isTribe) {
const tribeOwnerPubKey = chat && chat.ownerPubkey
const owner = await models.Contact.findOne({where: {isOwner:true}})
owner = await models.Contact.findOne({where: {isOwner:true}})
isTribeOwner = owner.publicKey===tribeOwnerPubKey
}
if(isTribeOwner) toAddIn.isTribeOwner = true
@ -83,8 +85,10 @@ async function onReceive(payload){
const needsPricePerMessage = typesThatNeedPricePerMessage.includes(payload.type)
// CHECK THEY ARE IN THE GROUP if message
const senderContact = await models.Contact.findOne({where:{publicKey:payload.sender.pub_key}})
if(!senderContact) return // need sender contact!
const senderContactId = senderContact.id
if(needsPricePerMessage) {
const senderMember = senderContact && await models.ChatMember.findOne({where:{contactId:senderContact.id, chatId:chat.id}})
const senderMember = await models.ChatMember.findOne({where:{contactId:senderContactId, chatId:chat.id}})
if(!senderMember) doAction=false
}
// CHECK PRICES
@ -96,7 +100,7 @@ async function onReceive(payload){
timers.addTimer({ // pay them back
amount: chat.escrowAmount,
millis:chat.escrowMillis,
receiver: senderContact.id,
receiver: senderContactId,
msgId: payload.message.id,
chatId: chat.id,
})
@ -106,7 +110,7 @@ async function onReceive(payload){
if(payload.type===msgtypes.group_join) {
if(payload.message.amount<chat.priceToJoin) doAction=false
if(chat.private) { // check if has been approved
const senderMember = senderContact && await models.ChatMember.findOne({where:{contactId:senderContact.id, chatId:chat.id}})
const senderMember = await models.ChatMember.findOne({where:{contactId:senderContactId, chatId:chat.id}})
if(!(senderMember && senderMember.status===constants.chat_statuses.approved)){
doAction=false // dont let if private and not approved
}
@ -118,7 +122,7 @@ async function onReceive(payload){
if(payload.message.uuid) {
const ogMsg = await models.Message.findOne({where:{
uuid: payload.message.uuid,
sender: senderContact.id,
sender: senderContactId,
}})
if(ogMsg) doAction = true
}
@ -141,6 +145,8 @@ async function onReceive(payload){
}
}
}
// make sure alias is unique among chat members
payload = await uniqueifyAlias(payload, senderContact, chat, owner)
if(doAction) forwardMessageToTribe(payload, senderContact, realSatsContactId, amtToForward)
else console.log('=> insufficient payment for this action')
}
@ -191,9 +197,38 @@ async function doTheAction(data){
}
}
async function uniqueifyAlias(payload, sender, chat, owner):Promise<Object> {
if(!chat || !sender || !owner) return payload
if(!(payload && payload.sender)) return payload
const senderContactId = sender.id // og msg sender
const owner_alias = chat.myAlias || owner.alias
const sender_alias = payload.sender&&payload.sender.alias
let final_sender_alias = sender_alias
const chatMembers = await models.ChatMember.findAll({where:{chatId:chat.id}})
if(!(chatMembers && chatMembers.length)) return payload
asyncForEach(chatMembers, (cm)=>{
if(cm.contactId===senderContactId) return // dont check against self of course
if(sender_alias===cm.lastAlias || sender_alias===owner_alias) {
// impersonating! switch it up!
final_sender_alias = `${sender_alias}_2`
}
})
if(sender_alias!==final_sender_alias) {
await models.ChatMember.update( // this syntax is necessary when no unique ID on the Model
{lastAlias:final_sender_alias},
{where:{chatId:chat.id,contactId:senderContactId}}
)
}
payload.sender.alias = final_sender_alias
return payload
}
async function forwardMessageToTribe(ogpayload, sender, realSatsContactId, amtToForwardToRealSatsContactId){
// console.log('forwardMessageToTribe')
const chat = await models.Chat.findOne({where:{uuid:ogpayload.chat.uuid}})
if(!chat) return
let payload
if(sender && typesToModify.includes(ogpayload.type)){
@ -201,14 +236,10 @@ async function forwardMessageToTribe(ogpayload, sender, realSatsContactId, amtTo
} else {
payload = ogpayload
}
// dont need sender beyond here
//const sender = await models.Contact.findOne({where:{publicKey:payload.sender.pub_key}})
const owner = await models.Contact.findOne({where:{isOwner:true}})
const type = payload.type
const message = payload.message
// HERE: NEED TO MAKE SURE ALIAS IS UNIQUE
// ASK xref TABLE and put alias there too?
sendMessage({
type, message,
sender: {
@ -219,7 +250,7 @@ async function forwardMessageToTribe(ogpayload, sender, realSatsContactId, amtTo
},
amount: amtToForwardToRealSatsContactId||0,
chat: chat,
skipPubKey: payload.sender.pub_key,
skipPubKey: payload.sender.pub_key, // dont forward back to self
realSatsContactId,
success: ()=>{},
receive: ()=>{},
@ -386,3 +417,9 @@ function weave(p){
return payload
}
}
async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
}

23
src/network/send.ts

@ -21,7 +21,7 @@ export async function sendMessage(params) {
if(isTribeOwner && !isForwarded) {
theSender = {...(sender.dataValues||sender), role:constants.chat_roles.owner}
}
let msg = newmsg(type, chat, theSender, message)
let msg = newmsg(type, chat, theSender, message, isForwarded)
// console.log("=> MSG TO SEND",msg)
@ -105,7 +105,7 @@ export async function sendMessage(params) {
console.log("KEYSEND ERROR", e)
no = e
}
await sleep(2)
await sleep(10)
})
if(no){
if(failure) failure(no)
@ -156,10 +156,21 @@ function checkIfAutoConfirm(data){
}
}
export function newmsg(type, chat, sender, message){
export function newmsg(type, chat, sender, message, isForwarded:boolean, includeStatus?:boolean){
const includeGroupKey = type===constants.message_types.group_create || type===constants.message_types.group_invite
const includeAlias = sender && sender.alias && chat.type===constants.chat_types.tribe
const includePhotoUrl = sender && sender.photoUrl && !sender.privatePhoto && chat && chat.type===constants.chat_types.tribe
let aliasToInclude = sender.alias
if(!isForwarded && includeAlias && chat.myAlias) {
aliasToInclude = chat.myAlias
}
const includePhotoUrl = sender && !sender.privatePhoto && chat && chat.type===constants.chat_types.tribe
let photoUrlToInclude = sender.photoUrl || ''
if(!isForwarded && includePhotoUrl && chat.myPhotoUrl) {
photoUrlToInclude = chat.myPhotoUrl
}
if(!includeStatus && message.status) {
delete message.status
}
return {
type: type,
chat: {
@ -173,9 +184,9 @@ export function newmsg(type, chat, sender, message){
message: message,
sender: {
pub_key: sender.publicKey,
alias: includeAlias ? sender.alias : '',
alias: includeAlias ? aliasToInclude : '',
role: sender.role || constants.chat_roles.reader,
...includePhotoUrl && {photo_url: sender.photoUrl},
...includePhotoUrl && {photo_url: photoUrlToInclude},
// ...sender.contactKey && {contact_key: sender.contactKey}
}
}

5
src/utils/setup.ts

@ -38,6 +38,11 @@ async function setVersion() {
async function migrate() {
addTableColumn('sphinx_chat_members', 'last_alias')
addTableColumn('sphinx_chats', 'my_photo_url')
addTableColumn('sphinx_chats', 'my_alias')
addTableColumn('sphinx_messages', 'sender_pic')
addTableColumn('sphinx_messages', 'network_type', 'INTEGER')

7
src/utils/tribeBots.ts

@ -1,10 +1,11 @@
import { models } from '../models'
import {getHost} from './tribes'
import fetch from 'node-fetch'
export async function declare_bot({ uuid, name, description, tags, img, price_per_use, owner_pubkey, unlisted, deleted }) {
const host = getHost()
try {
await fetch('https://' + host + '/bots', {
const r = await fetch('https://' + host + '/bots', {
method: 'POST',
body: JSON.stringify({
uuid, owner_pubkey,
@ -15,8 +16,8 @@ export async function declare_bot({ uuid, name, description, tags, img, price_pe
}),
headers: { 'Content-Type': 'application/json' }
})
// const j = await r.json()
// console.log('=> j',j)
const j = await r.json()
console.log('=> bot created:',j)
} catch (e) {
console.log('[tribes] unauthorized to declare')
throw e

Loading…
Cancel
Save