textiot
Version:
A framework for building web and native (IoT) Dapps on the IPFS network
81 lines (80 loc) • 2.84 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");
/**
* Messages is an API module for managing thread/block messages
*
* Messages are added as blocks in a thread
*
* @extends API
*/
class Messages extends api_1.API {
/**
* Adds a message to a thread
*
* @param thread Thread ID
* @param body Message body
* @returns The generated message block
*/
add(thread, body) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.sendPost(`threads/${thread}/messages`, [body]);
return response.json();
});
}
/**
* Retrieves a message by block ID
*
* @param id ID of the target message
* @returns The target message block
*/
get(id) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.sendGet(`messages/${id}`);
return response.json();
});
}
/**
* Retrieves thread messages
*
* @param thread Thread ID (can also use ‘default’)
* @param offset Offset ID to start listing from (omit for latest)
* @param limit List page size (default: 5)
* @returns An array of message blocks
*/
list(thread, offset, limit) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.sendGet('messages', undefined, {
thread: thread || '',
offset: offset || '',
limit: limit || 5
});
return response.json();
});
}
/**
* Ignores a thread message by its ID
*
* This adds an 'ignore' thread block targeted at the comment.
* Ignored blocks are by default not returned when listing.
*
* @param id ID of the message
* @returns The added ignore block
*/
ignore(id) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.sendDelete(`blocks/${id}`);
return response.json();
});
}
}
exports.default = Messages;
;