UNPKG

megalodon

Version:

Fediverse API client for node.js and browser

1,121 lines (1,120 loc) 111 kB
"use strict"; 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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; 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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var form_data_1 = __importDefault(require("form-data")); var api_client_js_1 = __importDefault(require("./firefish/api_client.js")); var default_js_1 = require("./default.js"); var FirefishOAuth = __importStar(require("./firefish/oauth.js")); var megalodon_js_1 = require("./megalodon.js"); var notification_js_1 = require("./notification.js"); var Firefish = (function () { function Firefish(baseUrl, accessToken, userAgent) { if (accessToken === void 0) { accessToken = null; } if (userAgent === void 0) { userAgent = default_js_1.DEFAULT_UA; } var token = ''; if (accessToken) { token = accessToken; } var agent = default_js_1.DEFAULT_UA; if (userAgent) { agent = userAgent; } this.client = new api_client_js_1.default.Client(baseUrl, token, agent); this.baseUrl = baseUrl; } Firefish.prototype.cancel = function () { return this.client.cancel(); }; Firefish.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: api_client_js_1.default.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; })]; }); }); })]; }); }); }; Firefish.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: api_client_js_1.default.DEFAULT_SCOPE, redirect_uris: this.baseUrl }; } return __generator(this, function (_a) { redirect_uris = options.redirect_uris || this.baseUrl; scopes = options.scopes || api_client_js_1.default.DEFAULT_SCOPE; params = { name: client_name, description: '', permission: scopes, callbackUrl: redirect_uris }; return [2, this.client.post('/api/app/create', params).then(function (res) { return FirefishOAuth.toAppData(res.data); })]; }); }); }; Firefish.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; })]; }); }); }; Firefish.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 megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.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) { return FirefishOAuth.toTokenData(res.data); })]; }); }); }; Firefish.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 megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.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 megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.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 megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.prototype.verifyAccountCredentials = function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2, this.client.post('/api/i').then(function (res) { return Object.assign(res, { data: api_client_js_1.default.Converter.userDetail(res.data) }); })]; }); }); }; Firefish.prototype.updateCredentials = function (options) { return __awaiter(this, void 0, void 0, function () { var params; 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: api_client_js_1.default.Converter.userDetail(res.data) }); })]; }); }); }; Firefish.prototype.getAccount = function (id) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2, this.client .post('/api/users/show', { userId: id }) .then(function (res) { return Object.assign(res, { data: api_client_js_1.default.Converter.userDetail(res.data) }); })]; }); }); }; Firefish.prototype.getAccountStatuses = function (id, options) { return __awaiter(this, void 0, void 0, function () { var params; 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 api_client_js_1.default.Converter.note(n); }) }); } 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 api_client_js_1.default.Converter.note(note); }); return Object.assign(res, { data: statuses }); })]; }); }); }; Firefish.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 megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.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 megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.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 megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.prototype.getAccountFollowers = function (id, options) { return __awaiter(this, void 0, void 0, function () { var params; 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 api_client_js_1.default.Converter.follower(f); }) }); })]; }); }); }; Firefish.prototype.getAccountFollowing = function (id, options) { return __awaiter(this, void 0, void 0, function () { var params; 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 api_client_js_1.default.Converter.following(f); }) }); })]; }); }); }; Firefish.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 megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.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 megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.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: api_client_js_1.default.Converter.relation(res.data) }); })]; } }); }); }; Firefish.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: api_client_js_1.default.Converter.relation(res.data) }); })]; } }); }); }; Firefish.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: api_client_js_1.default.Converter.relation(res.data) }); })]; } }); }); }; Firefish.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: api_client_js_1.default.Converter.relation(res.data) }); })]; } }); }); }; Firefish.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: api_client_js_1.default.Converter.relation(res.data) }); })]; } }); }); }; Firefish.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: api_client_js_1.default.Converter.relation(res.data) }); })]; } }); }); }; Firefish.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 megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.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 megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.prototype.setAccountNote = function (_id) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2, new Promise(function (_, reject) { var err = new megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.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: api_client_js_1.default.Converter.relation(res.data) }); })]; }); }); }; Firefish.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; }) })); })]; }); }); }; Firefish.prototype.searchAccount = function (q, options) { return __awaiter(this, void 0, void 0, function () { var params; 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 api_client_js_1.default.Converter.userDetail(u); }) }); })]; }); }); }; Firefish.prototype.lookupAccount = function (_acct) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2, new Promise(function (_, reject) { var err = new megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.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 megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.prototype.getFavourites = function (options) { return __awaiter(this, void 0, void 0, function () { var params; 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 api_client_js_1.default.Converter.note(fav.note); }) }); })]; }); }); }; Firefish.prototype.getMutes = function (options) { return __awaiter(this, void 0, void 0, function () { var params; 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 api_client_js_1.default.Converter.userDetail(mute.mutee); }) }); })]; }); }); }; Firefish.prototype.getBlocks = function (options) { return __awaiter(this, void 0, void 0, function () { var params; 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 api_client_js_1.default.Converter.userDetail(blocking.blockee); }) }); })]; }); }); }; Firefish.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 megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.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 megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.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 megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.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 megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.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 megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.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 megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.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 megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.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 megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.prototype.report = function (account_id, options) { return __awaiter(this, void 0, void 0, function () { var category; return __generator(this, function (_a) { category = 'other'; return [2, this.client .post('/api/users/report-abuse', { userId: account_id, comment: options.comment }) .then(function (res) { return Object.assign(res, { data: { id: '', action_taken: false, action_taken_at: null, comment: options.comment, category: category, forwarded: false, status_ids: null, rule_ids: null } }); })]; }); }); }; Firefish.prototype.getFollowRequests = function (_limit) { return __awaiter(this, void 0, void 0, function () { 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 api_client_js_1.default.Converter.user(r.follower); }) }); })]; }); }); }; Firefish.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: api_client_js_1.default.Converter.relation(res.data) }); })]; } }); }); }; Firefish.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: api_client_js_1.default.Converter.relation(res.data) }); })]; } }); }); }; Firefish.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 megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.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 megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.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 megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.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 megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.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 megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.prototype.getPreferences = 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 __awaiter(_this, void 0, void 0, function () { var _a, _b, _c, _d, _e, _f; var _g; return __generator(this, function (_h) { switch (_h.label) { case 0: _b = (_a = Object).assign; _c = [res]; _g = {}; _e = (_d = api_client_js_1.default.Converter).userPreferences; _f = [res.data]; return [4, this.getDefaultPostPrivacy()]; case 1: return [2, _b.apply(_a, _c.concat([(_g.data = _e.apply(_d, _f.concat([_h.sent()])), _g)]))]; } }); }); })]; }); }); }; Firefish.prototype.getDefaultPostPrivacy = function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2, this.client .post('/api/i/registry/get-unsecure', { key: 'defaultNoteVisibility', scope: ['client', 'base'] }) .then(function (res) { if (!res.data || (res.data != 'public' && res.data != 'home' && res.data != 'followers' && res.data != 'specified')) return 'public'; return api_client_js_1.default.Converter.visibility(res.data); }) .catch(function (_) { return 'public'; })]; }); }); }; Firefish.prototype.getFollowedTags = function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2, new Promise(function (_, reject) { var err = new megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.prototype.getSuggestions = function (limit) { return __awaiter(this, void 0, void 0, function () { var params; 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 api_client_js_1.default.Converter.userDetail(u); }) })); })]; }); }); }; Firefish.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 megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.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 megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.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 megalodon_js_1.NotImplementedError('Firefish does not support this method'); reject(err); })]; }); }); }; Firefish.prototype.postStatus = function (status, options) { return __awaiter(this, void 0, void 0, function () { var params, pollParam; 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.spoiler_text) { params = Object.assign(params, { cw: options.spoiler_text }); } if (options.visibility) { params = Object.assign(params, { visibility: api_client_js_1.default.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: api_client_js_1.default.Converter.note(res.data.createdNote) })); })]; }); }); };