textiot
Version:
A framework for building web and native (IoT) Dapps on the IPFS network
90 lines (89 loc) • 2.97 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 });
exports.accountThread = exports.setAvatar = exports.avatar = exports.setName = exports.name = exports.get = void 0;
const react_native_1 = require("react-native");
const buffer_1 = require("buffer");
const model_1 = require("./model");
const { ProfileBridge } = react_native_1.NativeModules;
/**
* Get the profile.
* ```typescript
* Textile.profile.get();
* ```
*/
function get() {
return __awaiter(this, void 0, void 0, function* () {
const result = yield ProfileBridge.get();
return model_1.Peer.decode(buffer_1.Buffer.from(result, 'base64'));
});
}
exports.get = get;
/**
* Get the name.
* ```typescript
* Textile.profile.name();
* ```
*/
function name() {
return __awaiter(this, void 0, void 0, function* () {
const result = yield ProfileBridge.name();
return result.length > 0 ? result : undefined;
});
}
exports.name = name;
/**
* Update the name.
* ```typescript
* Textile.profile.setName(name);
* ```
*/
function setName(name) {
return __awaiter(this, void 0, void 0, function* () {
yield ProfileBridge.setName(name);
});
}
exports.setName = setName;
/**
* Get the BlockId of the current user Avatar.
* ```typescript
* Textile.profile.avatar();
* ```
*/
function avatar() {
return __awaiter(this, void 0, void 0, function* () {
const result = yield ProfileBridge.avatar();
return result.length > 0 ? result : undefined;
});
}
exports.avatar = avatar;
/**
* Set the user's avatar image
* @param item The path to an image or existing hash to set as the avatar
* @returns A Promise that will resolve with the Block result
*/
function setAvatar(item) {
return __awaiter(this, void 0, void 0, function* () {
const result = yield ProfileBridge.setAvatar(item);
return model_1.Block.decode(buffer_1.Buffer.from(result, 'base64'));
});
}
exports.setAvatar = setAvatar;
/**
* Get the account thread.
*/
function accountThread() {
return __awaiter(this, void 0, void 0, function* () {
const result = yield ProfileBridge.accountThread();
return model_1.Thread.decode(buffer_1.Buffer.from(result, 'base64'));
});
}
exports.accountThread = accountThread;
;