fewensa / telegram-client

Rust Telegram Client
MIT License
93 stars 13 forks source link

Retrieving deleted message fails #17

Closed Karrq closed 4 years ago

Karrq commented 4 years ago

Hi, I was messing around and I tried to retrieve from the api a message that was just deleted.

Basically I registered the handler for on_update_delete_messages to emit a log and call api.get_messages with the chat_id and the message_ids that were in the update.

I also register a handler for on_messages to read the messages received there but it is not called when I'm trying to get a deleted message.

Here's the log (which is why I'm opening the issue)

18:04:53 [INFO] [/.../telegram-client-0.6.1/src/api.rs:104] <=== {"@type":"updateDeleteMessages","chat_id":-REDACTED,"message_ids":[25165824],"is_permanent":true,"from_cache":false}
18:04:53 [INFO] [src/listeners.rs:238] message(s) deleted, chat_id=-REDACTED, message_ids=[25165824]
18:04:53 [INFO] [/.../telegram-client-0.6.1/src/api.rs:94] ===> {"@type":"getMessages","chat_id":-REDACTED,"message_ids":[25165824]}
18:04:53 [INFO] [/.../telegram-client-0.6.1/src/api.rs:104] <=== {"@type":"messages","total_count":1,"messages":[null]}
18:04:53 [ERROR] [/.../telegram-client-0.6.1/src/handler.rs:200] TELEGRAM DATA FAIL. IF YOU SEE THIS MESSAGE, PLEASE POST AN ISSUE TO https://github.com/fewensa/telegram-client/issues 
 INCLUDE THIS JSON => {"@type":"messages","total_count":1,"messages":[null]}
fewensa commented 4 years ago

I think It's tdlib data questions. You see that json data.

{"@type":"messages","total_count":1,"messages":[null]}

"messages":[null]

the messages is Vec<null>

and the rtdlib it's Optional<Vec<Message>>

https://github.com/fewensa/rtdlib/blob/a7e68f8dbde1850b57b4e357d1ab0294cf23a37b/src/types/messages.rs#L10-L19

pub struct Messages {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  /// Approximate total count of messages found
  total_count: i64,
  /// List of messages; messages may be null
  messages: Option<Vec<Message>>,

}

According to the annotation type provided by tdlibjson (List of messages; messages may be null), it should be Option<Vec<Message>>, not Vec<Option<Message>>

But now the returned data is [null], then rtdlib will be updated in the near future to fix this issue.

fewensa commented 4 years ago

Hi @Karrq the reference commit fix this bug, If you have any question, please ping me. you need change dependence to last version.