Browse Source

test create tribe from env

feature/dockerfile-arm
Evan Feenstra 5 years ago
parent
commit
9139b2862a
  1. 35
      api/controllers/chats.ts
  2. 5
      api/controllers/index.ts
  3. 35
      dist/api/controllers/chats.js
  4. 2
      dist/api/controllers/chats.js.map
  5. 4
      dist/api/controllers/index.js
  6. 2
      dist/api/controllers/index.js.map

35
api/controllers/chats.ts

@ -37,6 +37,35 @@ async function mute(req, res) {
success(res, jsonUtils.chatToJson(chat))
}
export async function testCreateTribe(){
console.log("=======> TEST CREATE TRIBE")
const owner = await models.Contact.findOne({ where: { isOwner: true } })
const contact_ids = [1]
const img = 'https://i.pinimg.com/originals/54/7a/9c/547a9cc6b93e10261f1dd8a8af474e03.jpg'
const price_per_message = 0
const price_to_join = 100
const name = `Evan's test tribe`
const chatParams = await createTribeChatParams(owner, contact_ids, name, img, price_per_message, price_to_join)
// publish to tribe server
tribes.declare({
name:chatParams.name,
uuid:chatParams.uuid,
host:chatParams.host,
groupKey:chatParams.groupKey,
pricePerMessage: price_per_message,
priceToJoin: price_to_join,
description:'This is a test group',
tags:['Bitcoin','Lightning'],
img,
})
const chat = await models.Chat.create(chatParams)
await models.ChatMember.create({
contactId: owner.id,
chatId: chat.id,
role: constants.chat_roles.owner,
})
}
// just add self here if tribes
// or can u add contacts as members?
async function createGroupChat(req, res) {
@ -69,7 +98,7 @@ async function createGroupChat(req, res) {
let chatParams:any = null
if(is_tribe){
chatParams = await createTribeChatParams(owner, contact_ids, name, img, price_per_message, price_to_join)
if(is_listed){
if(is_listed && chatParams.uuid){
// publish to tribe server
tribes.declare({
...chatParams,
@ -485,11 +514,11 @@ function createGroupChatParams(owner, contactIds, members, name) {
}
}
async function createTribeChatParams(owner, contactIds, name, img, price_per_message, price_to_join) {
async function createTribeChatParams(owner, contactIds, name, img, price_per_message, price_to_join): Promise<{[k:string]:any}> {
let date = new Date()
date.setMilliseconds(0)
if (!(owner && contactIds && Array.isArray(contactIds))) {
return
return {}
}
// make ts sig here w LNd pubkey - that is UUID

5
api/controllers/index.ts

@ -29,6 +29,11 @@ async function set(app) {
console.log('=> could not auth with media server', e.message)
}
const testTribe = process.env.TEST_TRIBE
if(testTribe && testTribe==='true') {
controllers.chats.testCreateTribe()
}
app.get('/chats', controllers.chats.getChats)
app.post('/group', controllers.chats.createGroupChat)
app.post('/chats/:chat_id/:mute_unmute', controllers.chats.mute)

35
dist/api/controllers/chats.js

@ -45,6 +45,37 @@ function mute(req, res) {
});
}
exports.mute = mute;
function testCreateTribe() {
return __awaiter(this, void 0, void 0, function* () {
console.log("=======> TEST CREATE TRIBE");
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
const contact_ids = [1];
const img = 'https://i.pinimg.com/originals/54/7a/9c/547a9cc6b93e10261f1dd8a8af474e03.jpg';
const price_per_message = 0;
const price_to_join = 100;
const name = `Evan's test tribe`;
const chatParams = yield createTribeChatParams(owner, contact_ids, name, img, price_per_message, price_to_join);
// publish to tribe server
tribes.declare({
name: chatParams.name,
uuid: chatParams.uuid,
host: chatParams.host,
groupKey: chatParams.groupKey,
pricePerMessage: price_per_message,
priceToJoin: price_to_join,
description: 'This is a test group',
tags: ['Bitcoin', 'Lightning'],
img,
});
const chat = yield models_1.models.Chat.create(chatParams);
yield models_1.models.ChatMember.create({
contactId: owner.id,
chatId: chat.id,
role: constants.chat_roles.owner,
});
});
}
exports.testCreateTribe = testCreateTribe;
// just add self here if tribes
// or can u add contacts as members?
function createGroupChat(req, res) {
@ -66,7 +97,7 @@ function createGroupChat(req, res) {
let chatParams = null;
if (is_tribe) {
chatParams = yield createTribeChatParams(owner, contact_ids, name, img, price_per_message, price_to_join);
if (is_listed) {
if (is_listed && chatParams.uuid) {
// publish to tribe server
tribes.declare(Object.assign(Object.assign({}, chatParams), { pricePerMessage: price_per_message, priceToJoin: price_to_join, description, tags, img }));
}
@ -461,7 +492,7 @@ function createTribeChatParams(owner, contactIds, name, img, price_per_message,
let date = new Date();
date.setMilliseconds(0);
if (!(owner && contactIds && Array.isArray(contactIds))) {
return;
return {};
}
// make ts sig here w LNd pubkey - that is UUID
const keys = yield rsa.genKeys();

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

File diff suppressed because one or more lines are too long

4
dist/api/controllers/index.js

@ -38,6 +38,10 @@ function set(app) {
catch (e) {
console.log('=> could not auth with media server', e.message);
}
const testTribe = process.env.TEST_TRIBE;
if (testTribe && testTribe === 'true') {
controllers.chats.testCreateTribe();
}
app.get('/chats', controllers.chats.getChats);
app.post('/group', controllers.chats.createGroupChat);
app.post('/chats/:chat_id/:mute_unmute', controllers.chats.mute);

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

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