@cutls/megalodon
Version:
Mastodon, Pleroma, Misskey API client for node.js and browser
1,157 lines • 105 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
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());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
import FormData from 'form-data';
import MisskeyAPI from './misskey/api_client';
import { DEFAULT_UA } from './default';
import MisskeyOAuth from './misskey_oauth';
import { NotImplementedError, ArgumentError, UnexpectedError } from './megalodon';
var Misskey = (function () {
function Misskey(baseUrl, accessToken, userAgent) {
if (accessToken === void 0) { accessToken = null; }
if (userAgent === void 0) { userAgent = DEFAULT_UA; }
var token = '';
if (accessToken) {
token = accessToken;
}
var agent = DEFAULT_UA;
if (userAgent) {
agent = userAgent;
}
this.client = new MisskeyAPI.Client(baseUrl, token, agent);
this.baseUrl = baseUrl;
}
Misskey.prototype.baseUrlToHost = function (baseUrl) {
return baseUrl.replace('https://', '');
};
Misskey.prototype.cancel = function () {
return this.client.cancel();
};
Misskey.prototype.registerApp = function (client_name_1) {
return __awaiter(this, arguments, void 0, function (client_name, options) {
var _this = this;
if (options === void 0) { options = {
scopes: MisskeyAPI.DEFAULT_SCOPE,
redirect_uris: this.baseUrl
}; }
return __generator(this, function (_a) {
return [2, this.createApp(client_name, options).then(function (appData) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, this.generateAuthUrlAndToken(appData.client_secret).then(function (session) {
appData.url = session.url;
appData.session_token = session.token;
return appData;
})];
});
}); })];
});
});
};
Misskey.prototype.createApp = function (client_name_1) {
return __awaiter(this, arguments, void 0, function (client_name, options) {
var redirect_uris, scopes, params;
if (options === void 0) { options = {
scopes: MisskeyAPI.DEFAULT_SCOPE,
redirect_uris: this.baseUrl
}; }
return __generator(this, function (_a) {
redirect_uris = options.redirect_uris || this.baseUrl;
scopes = options.scopes || MisskeyAPI.DEFAULT_SCOPE;
params = {
name: client_name,
description: '',
permission: scopes,
callbackUrl: redirect_uris
};
return [2, this.client.post('/api/app/create', params).then(function (res) {
var appData = {
id: res.data.id,
name: res.data.name,
website: null,
redirect_uri: res.data.callbackUrl,
client_id: '',
client_secret: res.data.secret
};
return MisskeyOAuth.AppData.from(appData);
})];
});
});
};
Misskey.prototype.generateAuthUrlAndToken = function (clientSecret) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, this.client
.post('/api/auth/session/generate', {
appSecret: clientSecret
})
.then(function (res) { return res.data; })];
});
});
};
Misskey.prototype.verifyAppCredentials = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.fetchAccessToken = function (_client_id, client_secret, session_token, _redirect_uri) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, this.client
.post('/api/auth/session/userkey', {
appSecret: client_secret,
token: session_token
})
.then(function (res) {
var token = new MisskeyOAuth.TokenData(res.data.accessToken, 'misskey', '', 0, null, null);
return token;
})];
});
});
};
Misskey.prototype.refreshToken = function (_client_id, _client_secret, _refresh_token) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.revokeToken = function (_client_id, _client_secret, _token) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.registerAccount = function (_username, _email, _password, _agreement, _locale, _reason) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.verifyAccountCredentials = function () {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
return [2, this.client.post('/api/i').then(function (res) {
return Object.assign(res, {
data: MisskeyAPI.Converter.userDetail(res.data, _this.baseUrlToHost(_this.baseUrl))
});
})];
});
});
};
Misskey.prototype.updateCredentials = function (options) {
return __awaiter(this, void 0, void 0, function () {
var params;
var _this = this;
return __generator(this, function (_a) {
params = {};
if (options) {
if (options.bot !== undefined) {
params = Object.assign(params, {
isBot: options.bot
});
}
if (options.display_name) {
params = Object.assign(params, {
name: options.display_name
});
}
if (options.note) {
params = Object.assign(params, {
description: options.note
});
}
if (options.locked !== undefined) {
params = Object.assign(params, {
isLocked: options.locked
});
}
if (options.source) {
if (options.source.language) {
params = Object.assign(params, {
lang: options.source.language
});
}
if (options.source.sensitive) {
params = Object.assign(params, {
alwaysMarkNsfw: options.source.sensitive
});
}
}
}
return [2, this.client.post('/api/i', params).then(function (res) {
return Object.assign(res, {
data: MisskeyAPI.Converter.userDetail(res.data, _this.baseUrlToHost(_this.baseUrl))
});
})];
});
});
};
Misskey.prototype.getAccount = function (id) {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
return [2, this.client
.post('/api/users/show', {
userId: id
})
.then(function (res) {
return Object.assign(res, {
data: MisskeyAPI.Converter.userDetail(res.data, _this.baseUrlToHost(_this.baseUrl))
});
})];
});
});
};
Misskey.prototype.getAccountStatuses = function (id, options) {
return __awaiter(this, void 0, void 0, function () {
var params;
var _this = this;
return __generator(this, function (_a) {
if (options && options.pinned) {
return [2, this.client
.post('/api/users/show', {
userId: id
})
.then(function (res) {
if (res.data.pinnedNotes) {
return __assign(__assign({}, res), { data: res.data.pinnedNotes.map(function (n) { return MisskeyAPI.Converter.note(n, _this.baseUrlToHost(_this.baseUrl)); }) });
}
return __assign(__assign({}, res), { data: [] });
})];
}
params = {
userId: id
};
if (options) {
if (options.limit) {
params = Object.assign(params, {
limit: options.limit
});
}
if (options.max_id) {
params = Object.assign(params, {
untilId: options.max_id
});
}
if (options.since_id) {
params = Object.assign(params, {
sinceId: options.since_id
});
}
if (options.exclude_replies) {
params = Object.assign(params, {
includeReplies: false
});
}
if (options.exclude_reblogs) {
params = Object.assign(params, {
includeMyRenotes: false
});
}
if (options.only_media) {
params = Object.assign(params, {
withFiles: options.only_media
});
}
}
return [2, this.client.post('/api/users/notes', params).then(function (res) {
var statuses = res.data.map(function (note) { return MisskeyAPI.Converter.note(note, _this.baseUrlToHost(_this.baseUrl)); });
return Object.assign(res, {
data: statuses
});
})];
});
});
};
Misskey.prototype.getAccountFavourites = function (_id, _options) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.subscribeAccount = function (_id) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.unsubscribeAccount = function (_id) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.getAccountFollowers = function (id, options) {
return __awaiter(this, void 0, void 0, function () {
var params;
var _this = this;
return __generator(this, function (_a) {
params = {
userId: id
};
if (options) {
if (options.limit) {
params = Object.assign(params, {
limit: options.limit
});
}
}
return [2, this.client.post('/api/users/followers', params).then(function (res) {
return Object.assign(res, {
data: res.data.map(function (f) { return MisskeyAPI.Converter.follower(f, _this.baseUrlToHost(_this.baseUrl)); })
});
})];
});
});
};
Misskey.prototype.getAccountFollowing = function (id, options) {
return __awaiter(this, void 0, void 0, function () {
var params;
var _this = this;
return __generator(this, function (_a) {
params = {
userId: id
};
if (options) {
if (options.limit) {
params = Object.assign(params, {
limit: options.limit
});
}
}
return [2, this.client.post('/api/users/following', params).then(function (res) {
return Object.assign(res, {
data: res.data.map(function (f) { return MisskeyAPI.Converter.following(f, _this.baseUrlToHost(_this.baseUrl)); })
});
})];
});
});
};
Misskey.prototype.getAccountLists = function (_id) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.getIdentityProof = function (_id) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.followAccount = function (id, _options) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this.client.post('/api/following/create', {
userId: id
})];
case 1:
_a.sent();
return [2, this.client
.post('/api/users/relation', {
userId: id
})
.then(function (res) {
return Object.assign(res, {
data: MisskeyAPI.Converter.relation(res.data)
});
})];
}
});
});
};
Misskey.prototype.unfollowAccount = function (id) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this.client.post('/api/following/delete', {
userId: id
})];
case 1:
_a.sent();
return [2, this.client
.post('/api/users/relation', {
userId: id
})
.then(function (res) {
return Object.assign(res, {
data: MisskeyAPI.Converter.relation(res.data)
});
})];
}
});
});
};
Misskey.prototype.blockAccount = function (id) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this.client.post('/api/blocking/create', {
userId: id
})];
case 1:
_a.sent();
return [2, this.client
.post('/api/users/relation', {
userId: id
})
.then(function (res) {
return Object.assign(res, {
data: MisskeyAPI.Converter.relation(res.data)
});
})];
}
});
});
};
Misskey.prototype.unblockAccount = function (id) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this.client.post('/api/blocking/delete', {
userId: id
})];
case 1:
_a.sent();
return [2, this.client
.post('/api/users/relation', {
userId: id
})
.then(function (res) {
return Object.assign(res, {
data: MisskeyAPI.Converter.relation(res.data)
});
})];
}
});
});
};
Misskey.prototype.muteAccount = function (id, _notifications) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this.client.post('/api/mute/create', {
userId: id
})];
case 1:
_a.sent();
return [2, this.client
.post('/api/users/relation', {
userId: id
})
.then(function (res) {
return Object.assign(res, {
data: MisskeyAPI.Converter.relation(res.data)
});
})];
}
});
});
};
Misskey.prototype.unmuteAccount = function (id) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this.client.post('/api/mute/delete', {
userId: id
})];
case 1:
_a.sent();
return [2, this.client
.post('/api/users/relation', {
userId: id
})
.then(function (res) {
return Object.assign(res, {
data: MisskeyAPI.Converter.relation(res.data)
});
})];
}
});
});
};
Misskey.prototype.pinAccount = function (_id) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.unpinAccount = function (_id) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.getRelationship = function (id) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, this.client
.post('/api/users/relation', {
userId: id
})
.then(function (res) {
return Object.assign(res, {
data: MisskeyAPI.Converter.relation(res.data)
});
})];
});
});
};
Misskey.prototype.getRelationships = function (ids) {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
return [2, Promise.all(ids.map(function (id) { return _this.getRelationship(id); })).then(function (results) { return (__assign(__assign({}, results[0]), { data: results.map(function (r) { return r.data; }) })); })];
});
});
};
Misskey.prototype.searchAccount = function (q, options) {
return __awaiter(this, void 0, void 0, function () {
var params;
var _this = this;
return __generator(this, function (_a) {
params = {
query: q,
detail: true
};
if (options) {
if (options.resolve !== undefined) {
params = Object.assign(params, {
localOnly: options.resolve
});
}
if (options.limit) {
params = Object.assign(params, {
limit: options.limit
});
}
}
return [2, this.client.post('/api/users/search', params).then(function (res) {
return Object.assign(res, {
data: res.data.map(function (u) { return MisskeyAPI.Converter.userDetail(u, _this.baseUrlToHost(_this.baseUrl)); })
});
})];
});
});
};
Misskey.prototype.lookupAccount = function (acct) {
return __awaiter(this, void 0, void 0, function () {
var params;
var _this = this;
return __generator(this, function (_a) {
params = {
query: acct,
detail: true
};
return [2, this.client.post('/api/users/search', params).then(function (res) {
return Object.assign(res, {
data: MisskeyAPI.Converter.user(res.data[0], _this.baseUrlToHost(_this.baseUrl))
});
})];
});
});
};
Misskey.prototype.getBookmarks = function (_options) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.getFavourites = function (options) {
return __awaiter(this, void 0, void 0, function () {
var params;
var _this = this;
return __generator(this, function (_a) {
params = {};
if (options) {
if (options.limit) {
params = Object.assign(params, {
limit: options.limit
});
}
if (options.max_id) {
params = Object.assign(params, {
untilId: options.max_id
});
}
if (options.min_id) {
params = Object.assign(params, {
sinceId: options.min_id
});
}
}
return [2, this.client.post('/api/i/favorites', params).then(function (res) {
return Object.assign(res, {
data: res.data.map(function (fav) { return MisskeyAPI.Converter.note(fav.note, _this.baseUrlToHost(_this.baseUrl)); })
});
})];
});
});
};
Misskey.prototype.getMutes = function (options) {
return __awaiter(this, void 0, void 0, function () {
var params;
var _this = this;
return __generator(this, function (_a) {
params = {};
if (options) {
if (options.limit) {
params = Object.assign(params, {
limit: options.limit
});
}
if (options.max_id) {
params = Object.assign(params, {
untilId: options.max_id
});
}
if (options.min_id) {
params = Object.assign(params, {
sinceId: options.min_id
});
}
}
return [2, this.client.post('/api/mute/list', params).then(function (res) {
return Object.assign(res, {
data: res.data.map(function (mute) { return MisskeyAPI.Converter.userDetail(mute.mutee, _this.baseUrlToHost(_this.baseUrl)); })
});
})];
});
});
};
Misskey.prototype.getBlocks = function (options) {
return __awaiter(this, void 0, void 0, function () {
var params;
var _this = this;
return __generator(this, function (_a) {
params = {};
if (options) {
if (options.limit) {
params = Object.assign(params, {
limit: options.limit
});
}
if (options.max_id) {
params = Object.assign(params, {
untilId: options.max_id
});
}
if (options.min_id) {
params = Object.assign(params, {
sinceId: options.min_id
});
}
}
return [2, this.client.post('/api/blocking/list', params).then(function (res) {
return Object.assign(res, {
data: res.data.map(function (blocking) { return MisskeyAPI.Converter.userDetail(blocking.blockee, _this.baseUrlToHost(_this.baseUrl)); })
});
})];
});
});
};
Misskey.prototype.getDomainBlocks = function (_options) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.blockDomain = function (_domain) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.unblockDomain = function (_domain) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.getFilters = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.getFilter = function (_id) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.createFilter = function (_phrase, _context, _options) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.updateFilter = function (_id, _phrase, _context, _options) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.deleteFilter = function (_id) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.report = function (account_id, options) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, this.client
.post('/api/users/report-abuse', {
userId: account_id,
comment: (options === null || options === void 0 ? void 0 : options.comment) || ''
})
.then(function (res) {
return Object.assign(res, {
data: {
id: '',
action_taken: false,
comment: (options === null || options === void 0 ? void 0 : options.comment) || '',
account_id: account_id,
status_ids: [],
category: null,
forwarded: null,
action_taken_at: null,
rule_ids: null
}
});
})];
});
});
};
Misskey.prototype.getFollowRequests = function (_limit) {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
return [2, this.client.post('/api/following/requests/list').then(function (res) {
return Object.assign(res, {
data: res.data.map(function (r) { return MisskeyAPI.Converter.user(r.follower, _this.baseUrlToHost(_this.baseUrl)); })
});
})];
});
});
};
Misskey.prototype.acceptFollowRequest = function (id) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this.client.post('/api/following/requests/accept', {
userId: id
})];
case 1:
_a.sent();
return [2, this.client
.post('/api/users/relation', {
userId: id
})
.then(function (res) {
return Object.assign(res, {
data: MisskeyAPI.Converter.relation(res.data)
});
})];
}
});
});
};
Misskey.prototype.rejectFollowRequest = function (id) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this.client.post('/api/following/requests/reject', {
userId: id
})];
case 1:
_a.sent();
return [2, this.client
.post('/api/users/relation', {
userId: id
})
.then(function (res) {
return Object.assign(res, {
data: MisskeyAPI.Converter.relation(res.data)
});
})];
}
});
});
};
Misskey.prototype.getEndorsements = function (_options) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.getFeaturedTags = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.createFeaturedTag = function (_name) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.deleteFeaturedTag = function (_id) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.getSuggestedTags = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.getPreferences = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.getSuggestions = function (limit) {
return __awaiter(this, void 0, void 0, function () {
var params;
var _this = this;
return __generator(this, function (_a) {
params = {};
if (limit) {
params = Object.assign(params, {
limit: limit
});
}
return [2, this.client
.post('/api/users/recommendation', params)
.then(function (res) { return (__assign(__assign({}, res), { data: res.data.map(function (u) { return MisskeyAPI.Converter.userDetail(u, _this.baseUrlToHost(_this.baseUrl)); }) })); })];
});
});
};
Misskey.prototype.getTag = function (_id) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.followTag = function (_id) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.unfollowTag = function (_id) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.postStatus = function (status, options) {
return __awaiter(this, void 0, void 0, function () {
var params, pollParam;
var _this = this;
return __generator(this, function (_a) {
params = {
text: status
};
if (options) {
if (options.media_ids) {
params = Object.assign(params, {
fileIds: options.media_ids
});
}
if (options.poll) {
pollParam = {
choices: options.poll.options,
expiresAt: null,
expiredAfter: options.poll.expires_in
};
if (options.poll.multiple !== undefined) {
pollParam = Object.assign(pollParam, {
multiple: options.poll.multiple
});
}
params = Object.assign(params, {
poll: pollParam
});
}
if (options.in_reply_to_id) {
params = Object.assign(params, {
replyId: options.in_reply_to_id
});
}
if (options.sensitive) {
params = Object.assign(params, {
cw: ''
});
}
if (options.spoiler_text) {
params = Object.assign(params, {
cw: options.spoiler_text
});
}
if (options.visibility) {
params = Object.assign(params, {
visibility: MisskeyAPI.Converter.encodeVisibility(options.visibility)
});
}
if (options.quote_id) {
params = Object.assign(params, {
renoteId: options.quote_id
});
}
}
return [2, this.client
.post('/api/notes/create', params)
.then(function (res) { return (__assign(__assign({}, res), { data: MisskeyAPI.Converter.note(res.data.createdNote, _this.baseUrlToHost(_this.baseUrl)) })); })];
});
});
};
Misskey.prototype.getStatus = function (id) {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
return [2, this.client
.post('/api/notes/show', {
noteId: id
})
.then(function (res) { return (__assign(__assign({}, res), { data: MisskeyAPI.Converter.note(res.data, _this.baseUrlToHost(_this.baseUrl)) })); })];
});
});
};
Misskey.prototype.getStatusSource = function (id) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, this.client
.post('/api/notes/show', {
noteId: id
})
.then(function (res) { return (__assign(__assign({}, res), { data: {
id: id,
text: res.data.text || '',
spoiler_text: res.data.cw || ''
} })); })];
});
});
};
Misskey.prototype.editStatus = function (_id, _options) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, new Promise(function (_, reject) {
var err = new NotImplementedError('misskey does not support');
reject(err);
})];
});
});
};
Misskey.prototype.deleteStatus = function (id) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, this.client.post('/api/notes/delete', {
noteId: id
})];
});
});
};
Misskey.prototype.getStatusContext = function (id, options) {
return __awaiter(this, void 0, void 0, function () {
var params;
var _this = this;
return __generator(this, function (_a) {
params = {
noteId: id
};
if (options) {
if (options.limit) {
params = Object.assign(params, {
limit: options.limit
});
}
if (options.max_id) {
params = Object.assign(params, {
untilId: options.max_id
});
}