textiot
Version:
A framework for building web and native (IoT) Dapps on the IPFS network
85 lines (84 loc) • 2.96 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const api_1 = require("../core/api");
/**
* Invites is an API module for managing thread invites
*
* @extends API
*/
class Invites extends api_1.API {
/**
* Accept an invite to a thread
*
* @param invite Invite ID
* @param key Key for an external invite
*/
accept(invite, key) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.sendPost(`invites/${invite}/accept`, undefined, { key: key || '' });
return response.json();
});
}
/**
* Adds a peer-to-peer invite to a thread
*
* @param thread Thread ID (can also use ‘default’)
* @param address Account Address (omit to create an external invite)
* @returns Whether the operation was successfull
*/
add(thread, address) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.sendPost(`invites`, undefined, {
thread,
address: address || ''
});
return response.status === 201;
});
}
/**
* Adds a external invite to a thread
*
* @param thread Thread ID (can also use ‘default’)
* @returns An external invite object
*/
addExternal(thread) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.sendPost(`invites`, undefined, {
thread
});
return response.json();
});
}
/**
* Lists all pending thread invites
* @returns An array of invite views
*/
list() {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.sendGet('invites');
return response.json();
});
}
/**
* Ignore a direct invite to a thread
*
* @param id ID of the invite
* @returns Whether the operation was successfull
*/
ignore(id) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.sendPost(`invites/${id}/ignore`);
return response.status === 200;
});
}
}
exports.default = Invites;
;