@uimkit/uikit-react
Version:
<img style="width:64px" src="https://mgmt.uimkit.chat/media/img/avatar.png"/>
107 lines (104 loc) • 4.16 kB
JavaScript
import { __awaiter, __generator } from 'tslib';
import invariant_1 from '../../node_modules/.pnpm/invariant@2.2.4/node_modules/invariant/invariant.js';
import 'redux';
import { t } from 'i18next';
import '../../types/models.js';
import '../../types/events.js';
import '../rootReducer.js';
import { AccountListActionType, fetchingAccountList } from './actions.js';
import './selectors.js';
import '../conversations/actions.js';
import '../../node_modules/.pnpm/lodash.flatten@4.4.0/node_modules/lodash.flatten/index.js';
import '../../node_modules/.pnpm/lodash.some@4.6.0/node_modules/lodash.some/index.js';
import '../messages/actions.js';
import '../contacts/actions.js';
/**
* 查询指定账号
*
* @param id 账号ID
* @returns
*/
var fetchAccount = function (id) {
return function (dispatch, getState, context) { return __awaiter(void 0, void 0, void 0, function () {
var client, onError, account, e_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
client = getState().common.client;
onError = context.onError;
invariant_1(client, "requires client");
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, client.getAccount({ account_id: id, subscribe: true })];
case 2:
account = _a.sent();
dispatch({
type: AccountListActionType.ACCOUNT_FETCHED,
payload: account
});
return [3 /*break*/, 4];
case 3:
e_1 = _a.sent();
console.error("fetch account error", e_1);
onError && onError(e_1, t("default:chat:accounts:fetchError"));
return [3 /*break*/, 4];
case 4: return [2 /*return*/];
}
});
}); };
};
/**
* 查询全部账号
*
* @param limit 翻页大小
* @returns
*/
var fetchAllAccounts = function (limit) {
if (limit === void 0) { limit = 100; }
return function (dispatch, getState, context) { return __awaiter(void 0, void 0, void 0, function () {
var client, onError, offset, request, response, e_2;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
client = getState().common.client;
onError = context.onError;
invariant_1(client, "requires client");
offset = 0;
_a.label = 1;
case 1:
request = { offset: offset, limit: limit, subscribe: true };
dispatch(fetchingAccountList(request));
_a.label = 2;
case 2:
_a.trys.push([2, 4, , 5]);
return [4 /*yield*/, client.getAccountList(request)];
case 3:
response = _a.sent();
dispatch({
type: AccountListActionType.ACCOUNT_LIST_FETCHED,
payload: { request: request, response: response }
});
if (response.data.length < limit) {
return [3 /*break*/, 6];
}
else {
offset += limit;
}
return [3 /*break*/, 5];
case 4:
e_2 = _a.sent();
dispatch({
type: AccountListActionType.ERROR_FETCHING_ACCOUNT_LIST,
payload: { request: request, error: e_2 },
});
onError && onError(e_2, t("default:chat:accounts:fetchAllError"));
return [3 /*break*/, 6];
case 5: return [3 /*break*/, 1];
case 6: return [2 /*return*/];
}
});
}); };
};
export { fetchAccount, fetchAllAccounts };
//# sourceMappingURL=commands.js.map