Browse Source

Merge pull request #51 from stakwork/fix-confs

Fix confs
hosting-provider v0.9.17
Evan Feenstra 5 years ago
committed by GitHub
parent
commit
342fd56fd5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      api/controllers/confirmations.ts
  2. 25
      api/network/send.ts
  3. 7
      api/utils/tribes.ts
  4. 23
      dist/api/controllers/confirmations.js
  5. 2
      dist/api/controllers/confirmations.js.map
  6. 26
      dist/api/network/send.js
  7. 2
      dist/api/network/send.js.map
  8. 9
      dist/api/utils/tribes.js
  9. 2
      dist/api/utils/tribes.js.map

21
api/controllers/confirmations.ts

@ -77,3 +77,24 @@ export async function receiveConfirmation(payload) {
})
}
}
export async function tribeOwnerAutoConfirmation(msg_id,chat_uuid){
const message = await models.Message.findOne({ where:{id:msg_id} })
const chat = await models.Chat.findOne({where:{uuid:chat_uuid}})
if(message){
let statusMap = {}
try{
statusMap = JSON.parse(message.statusMap||'{}')
} catch(e){}
statusMap['chat'] = constants.statuses.received
await message.update({
status: constants.statuses.received,
statusMap: JSON.stringify(statusMap)
})
socket.sendJson({
type: 'confirmation',
response: jsonUtils.messageToJson(message, chat, null)
})
}
}

25
api/network/send.ts

@ -3,6 +3,8 @@ import * as LND from '../utils/lightning'
import {personalizeMessage, decryptMessage} from '../utils/msg'
import * as path from 'path'
import * as tribes from '../utils/tribes'
import {tribeOwnerAutoConfirmation} from '../controllers/confirmations'
import {typesToForward} from './receive'
const constants = require(path.join(__dirname,'../../config/constants.json'))
@ -31,14 +33,13 @@ export async function sendMessage(params) {
let isTribeOwner = false
const chatUUID = chat.uuid
if(isTribe) {
// if(type===constants.message_types.confirmation) {
// return // dont send confs for tribe
// }
console.log("is tribe!")
const tribeOwnerPubKey = chat.ownerPubkey
if(sender.publicKey===tribeOwnerPubKey){
console.log('im owner! mqtt!')
isTribeOwner = true
isTribeOwner = sender.publicKey===tribeOwnerPubKey
if(type===constants.message_types.confirmation) {
// if u are owner, go ahead!
if(!isTribeOwner) return // dont send confs for tribe if not owner
}
if(isTribeOwner){
networkType = 'mqtt' // broadcast to all
// decrypt message.content and message.mediaKey w groupKey
msg = await decryptMessage(msg, chat)
@ -106,7 +107,9 @@ export function signAndSend(opts, mqttTopic?:string){
// console.log("ACTUALLY SEND", mqttTopic)
try {
if(mqttTopic) {
await tribes.publish(mqttTopic, data)
await tribes.publish(mqttTopic, data, function(){
if(mqttTopic) checkIfAutoConfirm(opts.data)
})
} else {
await LND.keysendMessage({...opts,data})
}
@ -117,6 +120,12 @@ export function signAndSend(opts, mqttTopic?:string){
})
}
function checkIfAutoConfirm(data){
if(typesToForward.includes(data.type)){
tribeOwnerAutoConfirmation(data.message.id, data.chat.uuid)
}
}
export function newmsg(type, chat, sender, message){
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

7
api/utils/tribes.ts

@ -65,8 +65,11 @@ export function subscribe(topic) {
if (client) client.subscribe(topic)
}
export function publish(topic, msg) {
if (client) client.publish(topic, msg)
export function publish(topic, msg, cb) {
if (client) client.publish(topic, msg, null, function(err){
if(err) console.log(err)
else if(cb) cb()
})
}
export async function declare({ uuid, name, description, tags, img, group_key, host, price_per_message, price_to_join, owner_alias, owner_pubkey, escrow_amount, escrow_millis }) {

23
dist/api/controllers/confirmations.js

@ -88,4 +88,27 @@ function receiveConfirmation(payload) {
});
}
exports.receiveConfirmation = receiveConfirmation;
function tribeOwnerAutoConfirmation(msg_id, chat_uuid) {
return __awaiter(this, void 0, void 0, function* () {
const message = yield models_1.models.Message.findOne({ where: { id: msg_id } });
const chat = yield models_1.models.Chat.findOne({ where: { uuid: chat_uuid } });
if (message) {
let statusMap = {};
try {
statusMap = JSON.parse(message.statusMap || '{}');
}
catch (e) { }
statusMap['chat'] = constants.statuses.received;
yield message.update({
status: constants.statuses.received,
statusMap: JSON.stringify(statusMap)
});
socket.sendJson({
type: 'confirmation',
response: jsonUtils.messageToJson(message, chat, null)
});
}
});
}
exports.tribeOwnerAutoConfirmation = tribeOwnerAutoConfirmation;
//# sourceMappingURL=confirmations.js.map

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

@ -1 +1 @@
{"version":3,"file":"confirmations.js","sourceRoot":"","sources":["../../../api/controllers/confirmations.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,wCAAgC;AAChC,sCAAgC;AAChC,0CAAyC;AACzC,2CAA0C;AAC1C,sCAAqC;AACrC,6BAA4B;AAE5B,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAC,6BAA6B,CAAC,CAAC,CAAA;AAE7E,SAAgB,gBAAgB,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE;IACxD,IAAG,CAAC,MAAM;QAAE,OAAM;IAClB,OAAO,CAAC,WAAW,CAAC;QACnB,IAAI;QACJ,MAAM;QACN,OAAO,EAAE,EAAC,EAAE,EAAC,MAAM,EAAC;QACpB,IAAI,EAAE,SAAS,CAAC,aAAa,CAAC,YAAY;KAC1C,CAAC,CAAA;AACH,CAAC;AARD,4CAQC;AAED,SAAsB,mBAAmB,CAAC,OAAO;;QAChD,OAAO,CAAC,GAAG,CAAC,0BAA0B,EAAE,CAAC,OAAO,CAAC,OAAO,IAAE,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAA;QAE9E,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,IAAI,OAAO,CAAA;QACtC,MAAM,SAAS,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAA;QAC/B,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,EAAE,CAAA;QAC7B,MAAM,cAAc,GAAG,GAAG,CAAC,MAAM,CAAC,OAAO,CAAA;QAEzC,MAAM,KAAK,GAAG,MAAM,eAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAC,CAAC,CAAA;QACvE,MAAM,MAAM,GAAG,MA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msg");
const path = require("path");
const tribes = require("../utils/tribes");
const confirmations_1 = require("../controllers/confirmations");
const receive_1 = require("./receive");
const constants = require(path.join(__dirname, '../../config/constants.json'));
function sendMessage(params) {
return __awaiter(this, void 0, void 0, function* () {
@ -37,14 +39,14 @@ function sendMessage(params) {
let isTribeOwner = false;
const chatUUID = chat.uuid;
if (isTribe) {
// if(type===constants.message_types.confirmation) {
// return // dont send confs for tribe
// }
console.log("is tribe!");
const tribeOwnerPubKey = chat.ownerPubkey;
if (sender.publicKey === tribeOwnerPubKey) {
console.log('im owner! mqtt!');
isTribeOwner = true;
isTribeOwner = sender.publicKey === tribeOwnerPubKey;
if (type === constants.message_types.confirmation) {
// if u are owner, go ahead!
if (!isTribeOwner)
return; // dont send confs for tribe if not owner
}
if (isTribeOwner) {
networkType = 'mqtt'; // broadcast to all
// decrypt message.content and message.mediaKey w groupKey
msg = yield msg_1.decryptMessage(msg, chat);
@ -113,7 +115,10 @@ function signAndSend(opts, mqttTopic) {
// console.log("ACTUALLY SEND", mqttTopic)
try {
if (mqttTopic) {
yield tribes.publish(mqttTopic, data);
yield tribes.publish(mqttTopic, data, function () {
if (mqttTopic)
checkIfAutoConfirm(opts.data);
});
}
else {
yield LND.keysendMessage(Object.assign(Object.assign({}, opts), { data }));
@ -127,6 +132,11 @@ function signAndSend(opts, mqttTopic) {
});
}
exports.signAndSend = signAndSend;
function checkIfAutoConfirm(data) {
if (receive_1.typesToForward.includes(data.type)) {
confirmations_1.tribeOwnerAutoConfirmation(data.message.id, data.chat.uuid);
}
}
function newmsg(type, chat, sender, message) {
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;

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

File diff suppressed because one or more lines are too long

9
dist/api/utils/tribes.js

@ -79,9 +79,14 @@ function subscribe(topic) {
client.subscribe(topic);
}
exports.subscribe = subscribe;
function publish(topic, msg) {
function publish(topic, msg, cb) {
if (client)
client.publish(topic, msg);
client.publish(topic, msg, null, function (err) {
if (err)
console.log(err);
else if (cb)
cb();
});
}
exports.publish = publish;
function declare({ uuid, name, description, tags, img, group_key, host, price_per_message, price_to_join, owner_alias, owner_pubkey, escrow_amount, escrow_millis }) {

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

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save