Browse Source

fix final format of bot_res forward

push-params
Evan Feenstra 4 years ago
parent
commit
d03e6e0d03
  1. 13
      api/controllers/actions.ts
  2. 13
      api/controllers/bots.ts
  3. 2
      api/network/index.ts
  4. 11
      dist/api/controllers/actions.js
  5. 2
      dist/api/controllers/actions.js.map
  6. 11
      dist/api/controllers/bots.js
  7. 2
      dist/api/controllers/bots.js.map
  8. 2
      dist/api/network/index.js.map

13
api/controllers/actions.ts

@ -86,10 +86,15 @@ export async function finalAction(a:Action, bot_id:string){
const dest = botMember.memberPubkey
if(!dest) return console.log('no dest to send to')
const topic = `${dest}/${myBot.uuid}`
const data = {
message:a,
bot_id,
sender:{pub_key: owner.publicKey}, // for verify sig
const data = <network.Msg>{
action, bot_id, bot_name,
type:constants.message_types.bot_res,
message:{ content:a.content, amount:amount||0 },
chat:{ uuid: chat_uuid},
sender:{
pub_key: String(owner.publicKey),
alias: bot_name, role:0
}, // for verify sig
}
try {
await network.signAndSend({dest,data}, topic)

13
api/controllers/bots.ts

@ -6,7 +6,7 @@ import * as jsonUtils from '../utils/json'
import { success, failure } from '../utils/res'
import * as network from '../network'
import * as intercept from '../network/intercept'
import {finalAction} from './actions'
import {finalAction,Action} from './actions'
import * as socket from '../utils/socket'
const constants = require(path.join(__dirname, '../../config/constants.json'))
@ -220,10 +220,12 @@ export async function receiveBotRes(payload) {
}
const chat_uuid = dat.chat && dat.chat.uuid
const sender_pub_key =dat.sender.pub_key
const amount = dat.message.amount
const amount = dat.message.amount||0
const msg_uuid = dat.message.uuid||''
const content = dat.message.content
const botName = dat.message.bot_name
const botName = dat.bot_name
const action = dat.action
const bot_name = dat.bot_name
if(!chat_uuid) return console.log('=> receiveBotRes Error no chat_uuid')
const chat = await models.Chat.findOne({where:{uuid:chat_uuid}})
@ -234,10 +236,13 @@ export async function receiveBotRes(payload) {
const isTribeOwner = owner.publicKey===tribeOwnerPubKey
if(isTribeOwner){
console.log("=> is tribeOwner, do finalAction!")
// IF IS TRIBE ADMIN forward to the tribe
// received the entire action?
const bot_id = payload.bot_id
finalAction(payload.message, bot_id)
finalAction(<Action>{
action, bot_name, chat_uuid, content, amount,
}, bot_id)
} else {
const theChat = await models.Chat.findOne({where:{

2
api/network/index.ts

@ -3,6 +3,7 @@ import {
initGrpcSubscriptions,initTribesSubscriptions,parseKeysendInvoice,
typesToReplay,typesToForward,
} from './receive'
import {Msg} from './interfaces'
/*
Abstracts between lightning network and MQTT depending on Chat type and sender
@ -14,5 +15,6 @@ export {
initTribesSubscriptions,
parseKeysendInvoice,
typesToReplay,typesToForward,
Msg,
}

11
dist/api/controllers/actions.js

@ -89,9 +89,14 @@ function finalAction(a, bot_id) {
return console.log('no dest to send to');
const topic = `${dest}/${myBot.uuid}`;
const data = {
message: a,
bot_id,
sender: { pub_key: owner.publicKey },
action, bot_id, bot_name,
type: constants.message_types.bot_res,
message: { content: a.content, amount: amount || 0 },
chat: { uuid: chat_uuid },
sender: {
pub_key: String(owner.publicKey),
alias: bot_name, role: 0
},
};
try {
yield network.signAndSend({ dest, data }, topic);

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

File diff suppressed because one or more lines are too long

11
dist/api/controllers/bots.js

@ -228,10 +228,12 @@ function receiveBotRes(payload) {
}
const chat_uuid = dat.chat && dat.chat.uuid;
const sender_pub_key = dat.sender.pub_key;
const amount = dat.message.amount;
const amount = dat.message.amount || 0;
const msg_uuid = dat.message.uuid || '';
const content = dat.message.content;
const botName = dat.message.bot_name;
const botName = dat.bot_name;
const action = dat.action;
const bot_name = dat.bot_name;
if (!chat_uuid)
return console.log('=> receiveBotRes Error no chat_uuid');
const chat = yield models_1.models.Chat.findOne({ where: { uuid: chat_uuid } });
@ -241,10 +243,13 @@ function receiveBotRes(payload) {
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
const isTribeOwner = owner.publicKey === tribeOwnerPubKey;
if (isTribeOwner) {
console.log("=> is tribeOwner, do finalAction!");
// IF IS TRIBE ADMIN forward to the tribe
// received the entire action?
const bot_id = payload.bot_id;
actions_1.finalAction(payload.message, bot_id);
actions_1.finalAction({
action, bot_name, chat_uuid, content, amount,
}, bot_id);
}
else {
const theChat = yield models_1.models.Chat.findOne({ where: {

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

File diff suppressed because one or more lines are too long

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

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../api/network/index.ts"],"names":[],"mappings":";;AAAA,iCAAqD;AAWjD,sBAXI,kBAAW,CAWJ;AAAC,sBAXI,kBAAW,CAWJ;AAAC,iBAXI,aAAM,CAWJ;AAVlC,uCAGkB;AAQd,gCAVA,+BAAqB,CAUA;AACrB,kCAXsB,iCAAuB,CAWtB;AACvB,8BAZ8C,6BAAmB,CAY9C;AACnB,wBAZA,uBAAa,CAYA;AAAC,yBAZA,wBAAc,CAYA"}
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../api/network/index.ts"],"names":[],"mappings":";;AAAA,iCAAqD;AAYjD,sBAZI,kBAAW,CAYJ;AAAC,sBAZI,kBAAW,CAYJ;AAAC,iBAZI,aAAM,CAYJ;AAXlC,uCAGkB;AASd,gCAXA,+BAAqB,CAWA;AACrB,kCAZsB,iCAAuB,CAYtB;AACvB,8BAb8C,6BAAmB,CAa9C;AACnB,wBAbA,uBAAa,CAaA;AAAC,yBAbA,wBAAc,CAaA"}
Loading…
Cancel
Save