Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
￴￴ committed Aug 29, 2024
1 parent 43673f6 commit 6779d5c
Show file tree
Hide file tree
Showing 13 changed files with 372 additions and 932 deletions.
2 changes: 1 addition & 1 deletion package/telegram_client/bin/generate_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void main(List<String> args) async {
"created_at": "2022-12-26T05:26:40.500935+00:00",
// "group": [],
// "private": [],
"client_user_id": 0,
"client_tg_user_id": 0,
"client_title": "",
"client_token": "",
"owner_user_id": 0,
Expand Down
54 changes: 6 additions & 48 deletions package/telegram_client/bin/tdlib_docs_to_json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,18 @@ import 'package:general_lib/general_lib.dart';

void main(List<String> args) async {
String params = """
int64 id_
Session identifier.
bool is_current_
True, if this session is the current session.
bool is_password_pending_
True, if a 2-step verification password is needed to complete authorization of the session.
bool is_unconfirmed_
True, if the session wasn't confirmed from another session.
bool can_accept_secret_chats_
True, if incoming secret chats can be accepted by the session.
bool can_accept_calls_
True, if incoming calls can be accepted by the session.
object_ptr< SessionType > type_
Session type based on the system and application version, which can be used to display a corresponding icon.
int32 api_id_
Telegram API identifier, as provided by the application.
string application_name_
Name of the application, as provided by the application.
string application_version_
The version of the application, as provided by the application.
bool is_official_application_
True, if the application is an official application or uses the api_id of an official application.
string system_language_code_
IETF language tag of the user's operating system language; must be non-empty.
string device_model_
Model of the device the application has been run or is running on, as provided by the application.
string platform_
Operating system the application has been run or is running on, as provided by the application.
Model of the device the application is being run on; must be non-empty.
string system_version_
Version of the operating system the application has been run or is running on, as provided by the application.
Version of the operating system the application is being run on. If empty, the version is automatically detected by TDLib.
int32 log_in_date_
Point in time (Unix timestamp) when the user has logged in.
int32 last_active_date_
Point in time (Unix timestamp) when the session was last used.
string ip_address_
IP address from which the session was created, in human-readable format.
string location_
A human-readable description of the location from which the session was created, based on the IP address.
string application_version_
Application version; must be non-empty.
"""
.trim();

Expand Down
31 changes: 10 additions & 21 deletions package/telegram_client/lib/mtproto/mtproto_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ class Mtproto {
'system_language_code': 'en',
'new_verbosity_level': 0,
'application_version': 'v1',
'device_model': 'VGVsZWdyYW0gQ2xpZW50IEFaS0FERVYgR0xPQkFMIENPUlBPUkFUSU9O'
.general_lib_utils_decryptFromBase64(),
'device_model': 'VGVsZWdyYW0gQ2xpZW50IEFaS0FERVYgR0xPQkFMIENPUlBPUkFUSU9O'.general_lib_utils_decryptFromBase64(),
'system_version': Platform.operatingSystemVersion,
"database_key": "",
"start": true,
Expand All @@ -96,10 +95,8 @@ class Mtproto {
Duration invoke_time_out = Duration(minutes: 10);
late double timeOutUpdate;
FutureOr<void> Function(dynamic update, Mtproto Mtproto)? on_receive_update;
FutureOr<String> Function(int client_id, Mtproto Mtproto)?
on_generate_extra_invoke;
FutureOr<Map> Function(String extra, int client_id, Mtproto Mtproto)?
on_get_invoke_data;
FutureOr<String> Function(int client_id, Mtproto Mtproto)? on_generate_extra_invoke;
FutureOr<Map> Function(String extra, int client_id, Mtproto Mtproto)? on_get_invoke_data;
Mtproto({
String? pathTdl,
Map? clientOption,
Expand Down Expand Up @@ -149,8 +146,7 @@ class Mtproto {
} else if (update is MtprotoIsolateReceiveDataError) {
MtprotoIsolateReceiveDataError tdlibIsolateReceiveDataError = update;
try {
MtprotoClient? tdlibClient =
clients.getClientById(tdlibIsolateReceiveDataError.clientId);
MtprotoClient? tdlibClient = clients.getClientById(tdlibIsolateReceiveDataError.clientId);
if (tdlibClient != null) {
tdlibClient.close();
}
Expand Down Expand Up @@ -237,7 +233,7 @@ class Mtproto {
MtprotoClient? getClientByUserId(int clientUserId) {
for (var i = 0; i < clients.length; i++) {
MtprotoClient tdlibClient = clients[i];
if (tdlibClient.client_user_id == clientUserId) {
if (tdlibClient.client_tg_user_id == clientUserId) {
return tdlibClient;
}
}
Expand Down Expand Up @@ -302,14 +298,11 @@ class Mtproto {
}

/// receive all update data
EventEmitterListener on(
String type_update, FutureOr<dynamic> Function(UpdateMt update) callback,
{void Function(Object data)? onError}) {
EventEmitterListener on(String type_update, FutureOr<dynamic> Function(UpdateMt update) callback, {void Function(Object data)? onError}) {
return event_emitter.on(type_update, null, (Event ev, context) async {
try {
if (ev.eventData is MtprotoIsolateReceiveData) {
MtprotoIsolateReceiveData tdlibIsolateReceiveData =
(ev.eventData as MtprotoIsolateReceiveData);
MtprotoIsolateReceiveData tdlibIsolateReceiveData = (ev.eventData as MtprotoIsolateReceiveData);
await callback(UpdateMt(
update: tdlibIsolateReceiveData.updateData,
client_id: tdlibIsolateReceiveData.clientId,
Expand Down Expand Up @@ -345,10 +338,8 @@ class Mtproto {
Duration? invokeTimeOut,
String? extra,
bool? iSAutoGetChat,
FutureOr<String> Function(int client_id, Mtproto Mtproto)?
onGenerateExtraInvoke,
FutureOr<Map> Function(String extra, int client_id, Mtproto Mtproto)?
onGetInvokeData,
FutureOr<String> Function(int client_id, Mtproto Mtproto)? onGenerateExtraInvoke,
FutureOr<Map> Function(String extra, int client_id, Mtproto Mtproto)? onGetInvokeData,
bool isThrowOnError = true,
}) async {
onGetInvokeData ??= on_get_invoke_data;
Expand Down Expand Up @@ -389,9 +380,7 @@ class Mtproto {
parameters["@extra"] = generateUuid(15);
}

if (iSAutoGetChat &&
RegExp(r"^(sendMessage|getChatMember)$", caseSensitive: false)
.hashData(method)) {
if (iSAutoGetChat && RegExp(r"^(sendMessage|getChatMember)$", caseSensitive: false).hashData(method)) {
if (parameters["chat_id"] is int) {
client_send(
clientId,
Expand Down
8 changes: 4 additions & 4 deletions package/telegram_client/lib/scheme/mtproto_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ import 'package:telegram_client/isolate/isolate.dart';
class MtprotoClient {
int client_id;
Isolate isolate;
int client_user_id;
int client_tg_user_id;
DateTime join_date = DateTime.now();

MtprotoClient({
required this.client_id,
required this.isolate,
this.client_user_id = 0,
this.client_tg_user_id = 0,
});

/// close
Expand All @@ -57,7 +57,7 @@ class MtprotoClient {
Map toJson() {
return {
"client_id": client_id,
"client_user_id": client_user_id,
"client_tg_user_id": client_tg_user_id,
"join_date": join_date.toString(),
};
}
Expand All @@ -73,7 +73,7 @@ extension MtprotoClients on List<MtprotoClient> {
MtprotoClient? getClientByUserId(int clientUserId) {
for (var i = 0; i < length; i++) {
MtprotoClient tdlibClient = this[i];
if (tdlibClient.client_user_id == clientUserId) {
if (tdlibClient.client_tg_user_id == clientUserId) {
return tdlibClient;
}
}
Expand Down
6 changes: 3 additions & 3 deletions package/telegram_client/lib/scheme/tdlib_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import 'dart:convert';
/// add state data
class TdlibClient {
int client_id;
int client_user_id;
int client_tg_user_id;
bool is_bot;
Map client_option;
Map client_dynamic = {};
Expand All @@ -49,14 +49,14 @@ class TdlibClient {
required this.client_id,
required this.client_option,
this.is_bot = false,
this.client_user_id = 0,
this.client_tg_user_id = 0,
});

/// add state data
Map toJson() {
return {
"client_id": client_id,
"client_user_id": client_user_id,
"client_tg_user_id": client_tg_user_id,
"join_date": join_date.millisecondsSinceEpoch,
};
}
Expand Down
Loading

0 comments on commit 6779d5c

Please sign in to comment.