Browse Source

edit tribe endpoint

feature/dockerfile-arm
Evan Feenstra 5 years ago
parent
commit
39a0e44c26
  1. 48
      api/controllers/chats.ts
  2. 1
      api/controllers/index.ts
  3. 16
      api/utils/tribes.ts
  4. 31
      dist/api/controllers/chats.js
  5. 2
      dist/api/controllers/chats.js.map
  6. 1
      dist/api/controllers/index.js
  7. 2
      dist/api/controllers/index.js.map
  8. 18
      dist/api/utils/tribes.js
  9. 2
      dist/api/utils/tribes.js.map

48
api/controllers/chats.ts

@ -37,6 +37,50 @@ async function mute(req, res) {
success(res, jsonUtils.chatToJson(chat))
}
async function editTribe(req, res) {
const {
uuid,
name,
is_listed,
price_per_message,
price_to_join,
img,
description,
tags,
} = req.body
if(!uuid) return failure(res, 'group uuid is required')
const owner = await models.Contact.findOne({ where: { isOwner: true } })
const params={
photoUrl: img||'',
name: name,
pricePerMessage: price_per_message||0,
priceToJoin: price_to_join||0
}
if(is_listed) {
tribes.edit({
uuid,
...params,
pricePerMessage: price_per_message||0,
priceToJoin: price_to_join||0,
description, tags, img,
ownerAlias: owner.alias,
})
} else {
// remove from tribes server? or at least just "unlist"
}
const chat = await models.Chat.findOne({where:{uuid}})
if(chat) {
await chat.update(params)
success(res, jsonUtils.chatToJson(chat))
} else {
failure(res, 'cant find chat')
}
}
// just add self here if tribes
// or can u add contacts as members?
async function createGroupChat(req, res) {
@ -536,9 +580,9 @@ async function createTribeChatParams(owner, contactIds, name, img, price_per_mes
uuid: groupUUID,
ownerPubkey: owner.publicKey,
contactIds: JSON.stringify(theContactIds),
photoUrl: img||'',
createdAt: date,
updatedAt: date,
photoUrl: img||'',
name: name,
type: constants.chat_types.tribe,
groupKey: keys.public,
@ -553,7 +597,7 @@ export {
getChats, mute, addGroupMembers,
receiveGroupCreateOrInvite, createGroupChat,
deleteChat, receiveGroupLeave, receiveGroupJoin,
joinTribe,
joinTribe, editTribe,
}

1
api/controllers/index.ts

@ -35,6 +35,7 @@ async function set(app) {
app.delete('/chat/:id', controllers.chats.deleteChat)
app.put('/chat/:id', controllers.chats.addGroupMembers)
app.post('/tribe', controllers.chats.joinTribe)
app.put('/tribe', controllers.chats.editTribe)
app.post('/contacts/tokens', controllers.contacts.generateToken)

16
api/utils/tribes.ts

@ -70,6 +70,22 @@ export async function declare({uuid,name,description,tags,img,groupKey,host,pric
console.log(j)
}
export async function edit({uuid,name,description,tags,img,pricePerMessage,priceToJoin,ownerAlias}) {
const r = await fetch('https://' + getHost() + '/tribes', {
method: 'POST' ,
body: JSON.stringify({
uuid,
name, description, tags, img:img||'',
pricePerMessage:pricePerMessage||0,
priceToJoin:priceToJoin||0,
ownerAlias,
}),
headers: { 'Content-Type': 'application/json' }
})
const j = await r.json()
console.log(j)
}
export async function genSignedTimestamp(){
const now = moment().unix()
const tsBytes = Buffer.from(now.toString(16), 'hex')

31
dist/api/controllers/chats.js

@ -45,6 +45,35 @@ function mute(req, res) {
});
}
exports.mute = mute;
function editTribe(req, res) {
return __awaiter(this, void 0, void 0, function* () {
const { uuid, name, is_listed, price_per_message, price_to_join, img, description, tags, } = req.body;
if (!uuid)
return res_1.failure(res, 'group uuid is required');
const owner = yield models_1.models.Contact.findOne({ where: { isOwner: true } });
const params = {
photoUrl: img || '',
name: name,
pricePerMessage: price_per_message || 0,
priceToJoin: price_to_join || 0
};
if (is_listed) {
tribes.edit(Object.assign(Object.assign({ uuid }, params), { pricePerMessage: price_per_message || 0, priceToJoin: price_to_join || 0, description, tags, img, ownerAlias: owner.alias }));
}
else {
// remove from tribes server? or at least just "unlist"
}
const chat = yield models_1.models.Chat.findOne({ where: { uuid } });
if (chat) {
yield chat.update(params);
res_1.success(res, jsonUtils.chatToJson(chat));
}
else {
res_1.failure(res, 'cant find chat');
}
});
}
exports.editTribe = editTribe;
// just add self here if tribes
// or can u add contacts as members?
function createGroupChat(req, res) {
@ -502,9 +531,9 @@ function createTribeChatParams(owner, contactIds, name, img, price_per_message,
uuid: groupUUID,
ownerPubkey: owner.publicKey,
contactIds: JSON.stringify(theContactIds),
photoUrl: img || '',
createdAt: date,
updatedAt: date,
photoUrl: img || '',
name: name,
type: constants.chat_types.tribe,
groupKey: keys.public,

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

File diff suppressed because one or more lines are too long

1
dist/api/controllers/index.js

@ -44,6 +44,7 @@ function set(app) {
app.delete('/chat/:id', controllers.chats.deleteChat);
app.put('/chat/:id', controllers.chats.addGroupMembers);
app.post('/tribe', controllers.chats.joinTribe);
app.put('/tribe', controllers.chats.editTribe);
app.post('/contacts/tokens', controllers.contacts.generateToken);
app.post('/upload', controllers.uploads.avatarUpload.single('file'), controllers.uploads.uploadFile);
app.post('/invites', controllers.invites.createInvite);

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

File diff suppressed because one or more lines are too long

18
dist/api/utils/tribes.js

@ -84,6 +84,24 @@ function declare({ uuid, name, description, tags, img, groupKey, host, pricePerM
});
}
exports.declare = declare;
function edit({ uuid, name, description, tags, img, pricePerMessage, priceToJoin, ownerAlias }) {
return __awaiter(this, void 0, void 0, function* () {
const r = yield fetch('https://' + getHost() + '/tribes', {
method: 'POST',
body: JSON.stringify({
uuid,
name, description, tags, img: img || '',
pricePerMessage: pricePerMessage || 0,
priceToJoin: priceToJoin || 0,
ownerAlias,
}),
headers: { 'Content-Type': 'application/json' }
});
const j = yield r.json();
console.log(j);
});
}
exports.edit = edit;
function genSignedTimestamp() {
return __awaiter(this, void 0, void 0, function* () {
const now = moment().unix();

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

@ -1 +1 @@
{"version":3,"file":"tribes.js","sourceRoot":"","sources":["../../../api/utils/tribes.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,iCAAgC;AAChC,qCAAoC;AACpC,mCAAkC;AAClC,6BAA4B;AAC5B,6BAA4B;AAC5B,oCAAmC;AAEnC,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,CAAA;AACjD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAC,uBAAuB,CAAC,CAA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