fix(webapp): динамический appid Сферума из конфига логина
This commit is contained in:
@@ -12,6 +12,7 @@ import 'chats.dart';
|
||||
import 'contacts.dart';
|
||||
import 'folders.dart';
|
||||
import 'messages.dart';
|
||||
import 'webapp.dart';
|
||||
|
||||
String _normalizeAuthPhone(String phone) {
|
||||
final digits = phone.replaceAll(RegExp(r'\D'), '');
|
||||
@@ -1281,6 +1282,9 @@ class AccountModule {
|
||||
final config = data['config'] as Map?;
|
||||
final serverConfig = config?['server'] as Map?;
|
||||
final userConfig = config?['user'] as Map?;
|
||||
if (serverConfig != null) {
|
||||
await _persistEntryBannerApps(accountId, serverConfig);
|
||||
}
|
||||
final yMap = serverConfig?['y-map'] as Map?;
|
||||
final whiteListLinks = serverConfig?['white-list-links'] as List?;
|
||||
final fileUploadUnsupported = serverConfig?['file-upload-unsupported-types'] as List?;
|
||||
@@ -1305,6 +1309,28 @@ class AccountModule {
|
||||
await AppDatabase.saveLoginInfo(accountId, jsonEncode(info));
|
||||
}
|
||||
|
||||
Future<void> _persistEntryBannerApps(int accountId, Map serverConfig) async {
|
||||
final banners = serverConfig['settings-entry-banners'];
|
||||
if (banners is! List) return;
|
||||
for (final banner in banners) {
|
||||
final items = (banner is Map) ? banner['items'] : null;
|
||||
if (items is! List) continue;
|
||||
for (final item in items) {
|
||||
if (item is! Map) continue;
|
||||
final appId = item['appid'];
|
||||
final icon = item['icon']?.toString().toLowerCase() ?? '';
|
||||
if (appId is int && icon.contains('sferum')) {
|
||||
await AppDatabase.setSyncValue(
|
||||
accountId,
|
||||
EntryBannerApps.sferumKey,
|
||||
appId.toString(),
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, dynamic> _extractChatMarker(List<Map> chats) {
|
||||
int? latestTime;
|
||||
for (final chat in chats) {
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import '../api.dart';
|
||||
import '../../core/protocol/opcode_map.dart';
|
||||
import '../../core/storage/app_database.dart';
|
||||
import '../../core/storage/token_storage.dart';
|
||||
|
||||
abstract class EntryBannerApps {
|
||||
static const String sferumKey = 'entry_banner_app_sferum';
|
||||
}
|
||||
|
||||
class WebAppLaunch {
|
||||
final String url;
|
||||
@@ -8,8 +14,6 @@ class WebAppLaunch {
|
||||
}
|
||||
|
||||
class WebAppModule {
|
||||
static const int sferumBotId = 2340319;
|
||||
|
||||
final Api _api;
|
||||
|
||||
WebAppModule(this._api);
|
||||
@@ -18,7 +22,6 @@ class WebAppModule {
|
||||
if (_api.state != SessionState.online) {
|
||||
throw const WebAppUnavailable('Нет соединения с сервером');
|
||||
}
|
||||
await _resolveBot(botId);
|
||||
final packet = await _api.sendRequest(Opcode.webAppInitData, {
|
||||
'botId': botId,
|
||||
});
|
||||
@@ -33,14 +36,21 @@ class WebAppModule {
|
||||
return WebAppLaunch(url: url);
|
||||
}
|
||||
|
||||
Future<WebAppLaunch> fetchSferum() => fetchLaunch(sferumBotId);
|
||||
Future<WebAppLaunch> fetchSferum() async {
|
||||
final botId = await _resolveEntryApp(EntryBannerApps.sferumKey);
|
||||
if (botId == null) {
|
||||
throw const WebAppUnavailable(
|
||||
'Сферум сейчас недоступен. Переподключитесь и попробуйте снова.',
|
||||
);
|
||||
}
|
||||
return fetchLaunch(botId);
|
||||
}
|
||||
|
||||
Future<void> _resolveBot(int botId) async {
|
||||
try {
|
||||
await _api.sendRequest(Opcode.contactInfo, {
|
||||
'contactIds': [botId],
|
||||
});
|
||||
} catch (_) {}
|
||||
Future<int?> _resolveEntryApp(String key) async {
|
||||
final accountId = await TokenStorage.getActiveAccountId();
|
||||
if (accountId == null) return null;
|
||||
final raw = await AppDatabase.getSyncValue(accountId, key);
|
||||
return int.tryParse(raw ?? '');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user