Browse Source

tribe delete route, send tribe_delete message to all members, also set deleted=true on tribe server

push-params
Evan Feenstra 4 years ago
parent
commit
dfb35ef2e6
  1. 32
      api/controllers/chats.ts
  2. 15
      api/utils/tribes.ts
  3. 33
      dist/api/controllers/chats.js
  4. 2
      dist/api/controllers/chats.js.map
  5. 17
      dist/api/utils/tribes.js
  6. 2
      dist/api/utils/tribes.js.map

32
api/controllers/chats.ts

@ -275,18 +275,34 @@ export const deleteChat = async (req, res) => {
const tribeOwnerPubKey = chat.ownerPubkey
if(owner.publicKey===tribeOwnerPubKey) {
return failure(res, "cannot leave your own tribe")
}
const isPending = chat.status===constants.chat_statuses.pending
const isRejected = chat.status===constants.chat_statuses.rejected
if(!isPending && !isRejected) { // dont send if pending
network.sendMessage({
// delete a group or tribe
let notOK = false
await network.sendMessage({
chat,
sender: owner,
message: {},
type: constants.message_types.group_leave,
type: constants.message_types.tribe_delete,
success: function () {
tribes.delete_tribe(chat.uuid)
},
failure: function(){
failure(res, 'failed to send tribe_delete message')
notOK = true
}
})
if(notOK) return console.log('failed to send tribe_delete message')
} else {
// leave a group or tribe
const isPending = chat.status===constants.chat_statuses.pending
const isRejected = chat.status===constants.chat_statuses.rejected
if(!isPending && !isRejected) { // dont send if pending
network.sendMessage({
chat,
sender: owner,
message: {},
type: constants.message_types.group_leave,
})
}
}
await chat.update({

15
api/utils/tribes.ts

@ -148,6 +148,21 @@ export async function edit({ uuid, host, name, description, tags, img, price_per
}
}
export async function delete_tribe({ uuid }) {
const host = getHost()
try {
const token = await genSignedTimestamp()
await fetch(`https://${host}/tribe/${uuid}?token=` + token, {
method: 'DELETE',
})
// const j = await r.json()
} catch(e) {
console.log('[tribes] unauthorized to delete')
throw e
}
}
export async function putActivity( uuid:string, host:string ) {
try {
const token = await genSignedTimestamp()

33
dist/api/controllers/chats.js

@ -269,17 +269,36 @@ exports.deleteChat = (req, res) => __awaiter(void 0, void 0, void 0, function* (
}
const tribeOwnerPubKey = chat.ownerPubkey;
if (owner.publicKey === tribeOwnerPubKey) {
return res_1.failure(res, "cannot leave your own tribe");
}
const isPending = chat.status === constants.chat_statuses.pending;
const isRejected = chat.status === constants.chat_statuses.rejected;
if (!isPending && !isRejected) { // dont send if pending
network.sendMessage({
// delete a group or tribe
let notOK = false;
yield network.sendMessage({
chat,
sender: owner,
message: {},
type: constants.message_types.group_leave,
type: constants.message_types.tribe_delete,
success: function () {
tribes.delete_tribe(chat.uuid);
},
failure: function () {
res_1.failure(res, 'failed to send tribe_delete message');
notOK = true;
}
});
if (notOK)
return console.log('failed to send tribe_delete message');
}
else {
// leave a group or tribe
const isPending = chat.status === constants.chat_statuses.pending;
const isRejected = chat.status === constants.chat_statuses.rejected;
if (!isPending && !isRejected) { // dont send if pending
network.sendMessage({
chat,
sender: owner,
message: {},
type: constants.message_types.group_leave,
});
}
}
yield chat.update({
deleted: true,

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

File diff suppressed because one or more lines are too long

17
dist/api/utils/tribes.js

@ -176,6 +176,23 @@ function edit({ uuid, host, name, description, tags, img, price_per_message, pri
});
}
exports.edit = edit;
function delete_tribe({ uuid }) {
return __awaiter(this, void 0, void 0, function* () {
const host = getHost();
try {
const token = yield genSignedTimestamp();
yield node_fetch_1.default(`https://${host}/tribe/${uuid}?token=` + token, {
method: 'DELETE',
});
// const j = await r.json()
}
catch (e) {
console.log('[tribes] unauthorized to delete');
throw e;
}
});
}
exports.delete_tribe = delete_tribe;
function putActivity(uuid, host) {
return __awaiter(this, void 0, void 0, function* () {
try {

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

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