message_toJson method
FutureOr<Map?>
message_toJson({
- required Map update,
- required TelegramClientData telegramClientData,
- required bool is_lite,
- required UpdataOptionTelegramClient updataOptionTelegramClient,
method MessageData
Implementation
FutureOr<Map?> message_toJson({
required Map update,
required TelegramClientData telegramClientData,
required bool is_lite,
required UpdataOptionTelegramClient updataOptionTelegramClient,
}) async {
// http://0.0.0.0:8704/classtd_1_1td__api_1_1message.html
if (update["@type"] == "updateNewMessage") {
final Map message = update["message"];
if ((message["is_outgoing"] == true)) {
if (telegramClientData.is_bot) {
return null;
}
}
bool isSkipUpdate() {
String chat_type = "";
// spambot false
if (message["chat_id"] == 178220800) {
return false;
}
if (message["chat_id"] > 0) {
chat_type = "private";
}
if (message["chat_id"] < 0) {
chat_type = "group";
}
if (message["is_channel_post"] == true) {
chat_type = "channel";
}
if (chat_type.isNotEmpty &&
updataOptionTelegramClient
.updataMessageTelegramClient.skip_old_chat_types
.contains(chat_type)) {
final DateTime dateTime =
DateTime.now().copyWith(microsecond: 0, millisecond: 0);
final DateTime dateTimeMessage =
DateTime.fromMillisecondsSinceEpoch((message["date"] * 1000));
final Duration duration = dateTime.difference(dateTimeMessage);
if (duration >
updataOptionTelegramClient
.updataMessageTelegramClient.duration_old_message_skip) {
return true;
}
}
return false;
}
// check user
if (telegramClientData.is_bot == false) {
if (updataOptionTelegramClient
.updataMessageTelegramClient.user_is_skip_old_message) {
final bool is_skip_update = isSkipUpdate();
if (is_skip_update) {
return null;
}
}
} else {
if (updataOptionTelegramClient
.updataMessageTelegramClient.bot_is_skip_old_message) {
final bool is_skip_update = isSkipUpdate();
if (is_skip_update) {
return null;
}
}
}
final Map msg = await message_Message(
message: message,
telegramClientData: telegramClientData,
is_lite: is_lite,
// isUseCache: updataOptionTelegramClient.updataMessageTelegramClient.is_use_cache,
// durationCacheExpire: updataOptionTelegramClient.updataMessageTelegramClient.duration_expire_cache,
);
if (msg["chat"]["type"] == "channel") {
return {
"@type": "updateChannelPost",
"channel_post": msg,
};
} else {
return {
"@type": "updateMessage",
"message": msg,
};
}
}
return null;
}