Browse Source

include and check for tribe priceToJoin

feature/dockerfile-arm
Evan Feenstra 5 years ago
parent
commit
9909442389
  1. 23
      api/controllers/chats.ts
  2. 2
      api/network/receive.ts
  3. 19
      dist/api/controllers/chats.js
  4. 2
      dist/api/controllers/chats.js.map
  5. 3
      dist/api/network/receive.js
  6. 2
      dist/api/network/receive.js.map

23
api/controllers/chats.ts

@ -201,7 +201,7 @@ const deleteChat = async (req, res) => {
async function joinTribe(req, res){
console.log('=> joinTribe')
const { uuid, group_key, name, host } = req.body
const { uuid, group_key, name, host, amount } = req.body
const existing = await models.Chat.findOne({where:{uuid}})
if(existing) {
@ -232,7 +232,8 @@ async function joinTribe(req, res){
}
let date = new Date()
date.setMilliseconds(0)
const chat = await models.Chat.create({
const chatParams = {
uuid: uuid,
contactIds: JSON.stringify(contactIds),
createdAt: date,
@ -241,23 +242,18 @@ async function joinTribe(req, res){
type: constants.chat_types.tribe,
host: host || tribes.getHost(),
groupKey: group_key,
})
models.ChatMember.create({
contactId: theTribeOwner.id,
chatId: chat.id,
role: constants.chat_roles.owner,
lastActive: date,
})
}
network.sendMessage({ // send my data to tribe owner
chat: {
...chat.dataValues, members: {
...chatParams, members: {
[owner.publicKey]: {
key: owner.contactKey,
alias: owner.alias||''
}
}
},
amount:amount||0,
sender: owner,
message: {},
type: constants.message_types.group_join,
@ -265,6 +261,13 @@ async function joinTribe(req, res){
failure(res, e)
},
success: async function () {
const chat = await models.Chat.create(chatParams)
models.ChatMember.create({
contactId: theTribeOwner.id,
chatId: chat.id,
role: constants.chat_roles.owner,
lastActive: date,
})
success(res, jsonUtils.chatToJson(chat))
}
})

2
api/network/receive.ts

@ -18,6 +18,7 @@ const typesToModify=[
msgtypes.attachment
]
async function onReceive(payload){
console.log("=>>> onReceive",payload)
// if tribe, owner must forward to MQTT
let doAction = true
const toAddIn:{[k:string]:any} = {}
@ -36,6 +37,7 @@ async function onReceive(payload){
if(payload.message.amount<chat.pricePerMessage) doAction=false
}
if(doAction) forwardMessageToTribe(payload)
else console.log('insufficient payment for this action')
}
}
if(doAction) {

19
dist/api/controllers/chats.js

@ -222,7 +222,7 @@ function joinTribe(req, res) {
}
let date = new Date();
date.setMilliseconds(0);
const chat = yield models_1.models.Chat.create({
const chatParams = {
uuid: uuid,
contactIds: JSON.stringify(contactIds),
createdAt: date,
@ -231,15 +231,9 @@ function joinTribe(req, res) {
type: constants.chat_types.tribe,
host: host || tribes.getHost(),
groupKey: group_key,
});
models_1.models.ChatMember.create({
contactId: theTribeOwner.id,
chatId: chat.id,
role: constants.chat_roles.owner,
lastActive: date,
});
};
network.sendMessage({
chat: Object.assign(Object.assign({}, chat.dataValues), { members: {
chat: Object.assign(Object.assign({}, chatParams), { members: {
[owner.publicKey]: {
key: owner.contactKey,
alias: owner.alias || ''
@ -253,6 +247,13 @@ function joinTribe(req, res) {
},
success: function () {
return __awaiter(this, void 0, void 0, function* () {
const chat = yield models_1.models.Chat.create(chatParams);
models_1.models.ChatMember.create({
contactId: theTribeOwner.id,
chatId: chat.id,
role: constants.chat_roles.owner,
lastActive: date,
});
res_1.success(res, jsonUtils.chatToJson(chat));
});
}

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

File diff suppressed because one or more lines are too long

3
dist/api/network/receive.js

@ -28,6 +28,7 @@ const typesToModify = [
];
function onReceive(payload) {
return __awaiter(this, void 0, void 0, function* () {
console.log("=>>> onReceive", payload);
// if tribe, owner must forward to MQTT
let doAction = true;
const toAddIn = {};
@ -49,6 +50,8 @@ function onReceive(payload) {
}
if (doAction)
forwardMessageToTribe(payload);
else
console.log('insufficient payment for this action');
}
}
if (doAction) {

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

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