ReadHistory helper

This commit is contained in:
Wizou 2022-10-25 10:34:53 +02:00
parent 7e9d010392
commit 517fab89bb
6 changed files with 49 additions and 4 deletions

View file

@ -298,7 +298,9 @@ for (int offset_id = 0; ;)
offset_id = messages.Messages[^1].ID; offset_id = messages.Messages[^1].ID;
} }
``` ```
*Note: If you want to stop at a specific msg ID, use Messages_GetHistory `min_id` argument. For example, `min_id: dialog.read_inbox_max_id`* Notes:
- To stop at a specific msg ID, use Messages_GetHistory `min_id` argument. For example, `min_id: dialog.read_inbox_max_id`
- To mark the message history as read, use: `await client.ReadHistory(peer);`
<a name="updates"></a> <a name="updates"></a>
### Monitor all Telegram events happening for the user ### Monitor all Telegram events happening for the user

33
FAQ.md
View file

@ -163,6 +163,7 @@ However, note that those Channel-compatible methods will require an `InputChanne
That object must be created with both fields `channel_id` and `access_hash` correctly filled. You can read more about this in [FAQ #4](#access-hash). That object must be created with both fields `channel_id` and `access_hash` correctly filled. You can read more about this in [FAQ #4](#access-hash).
<a name="chats-chats"></a> <a name="chats-chats"></a>
<a name="chat-not-found"></a>
#### 10. `chats.chats[id]` fails. My chats list is empty or does not contain the chat id. #### 10. `chats.chats[id]` fails. My chats list is empty or does not contain the chat id.
There can be several reasons why `chats.chats` doesn't contain the chat you expect: There can be several reasons why `chats.chats` doesn't contain the chat you expect:
@ -259,6 +260,38 @@ If those missing messages are never obtained during the session, incoming messag
- As recommended, new encryption keys are negotiated every 100 sent/received messages or after one week. - As recommended, new encryption keys are negotiated every 100 sent/received messages or after one week.
If remote client doesn't complete this negotiation before reaching 200 messages, the Secret Chat is aborted. If remote client doesn't complete this negotiation before reaching 200 messages, the Secret Chat is aborted.
<a name="compile"></a>
#### 15. The example codes don't compile on my machine
The snippets of example codes found in the [ReadMe](README.md) or [Examples](EXAMPLES.md) pages were written for .NET 5 / C# 9 minimum.
If you're having compiler problem on code constructs such as `using`, `foreach`, `[^1]` or about "Deconstruct",
that typically means you're still using an obsolete version of .NET (Framework 4.x or Core)
Here are the recommended actions to fix your problem:
- Create a new project for .NET 6+ (in Visual Studio 2019 or more recent):
- Select File > New > Project
- Search for "C# Console"
- Select the **Console App**, but NOT Console App (.NET Framework) !
- On the framework selection page, choose .NET 6.0 or more recent
- Now you can start developing for WTelegramClient 🙂
- If you don't want to target a recent version of .NET, you can upgrade your existing project to use the latest version of the C# language:
- Close Visual Studio
- Edit your *.csproj file **with Notepad**
- Within the first `<PropertyGroup>`, add the following line:
`<LangVersion>latest</LangVersion>`
- Save, close Notepad and reopen your project in Visual Studio
- If you still have issues on some `foreach` constructs, add this class somewhere in your project:
```csharp
static class Extensions
{
public static void Deconstruct<T1, T2>(this KeyValuePair<T1, T2> tuple, out T1 key, out T2 value)
{
key = tuple.Key;
value = tuple.Value;
}
}
```
<a name="troubleshoot"></a> <a name="troubleshoot"></a>
## Troubleshooting guide ## Troubleshooting guide

View file

@ -152,6 +152,7 @@ await client.SendMessageAsync(target, "Hello, World");
➡️ You can find lots of useful code snippets in [EXAMPLES.md](https://github.com/wiz0u/WTelegramClient/blob/master/EXAMPLES.md) ➡️ You can find lots of useful code snippets in [EXAMPLES.md](https://github.com/wiz0u/WTelegramClient/blob/master/EXAMPLES.md)
and in the [Examples subdirectory](https://github.com/wiz0u/WTelegramClient/tree/master/Examples). and in the [Examples subdirectory](https://github.com/wiz0u/WTelegramClient/tree/master/Examples).
➡️ Check [the FAQ](https://github.com/wiz0u/WTelegramClient/blob/master/FAQ.md#compile) if example codes doesn't compile correctly on your machine, or other troubleshooting.
<a name="terminology"></a> <a name="terminology"></a>
# Terminology in Telegram Client API # Terminology in Telegram Client API

View file

@ -657,6 +657,15 @@ namespace WTelegram
public Task<Messages_AffectedMessages> DeleteMessages(InputPeer peer, params int[] id) public Task<Messages_AffectedMessages> DeleteMessages(InputPeer peer, params int[] id)
=> peer is InputPeerChannel channel ? this.Channels_DeleteMessages(channel, id) : this.Messages_DeleteMessages(id); => peer is InputPeerChannel channel ? this.Channels_DeleteMessages(channel, id) : this.Messages_DeleteMessages(id);
/// <summary>Marks message history as read. <para>See <a href="https://corefork.telegram.org/method/messages.readHistory"/><br/> and <a href="https://corefork.telegram.org/method/channels.readHistory"/></para> <para>Possible <see cref="RpcException"/> codes: 400 (<a href="https://corefork.telegram.org/method/messages.readHistory#possible-errors">details</a>)</para></summary>
/// <param name="peer">Target user, channel or group</param>
/// <param name="max_id">If a positive value is passed, only messages with identifiers less or equal than the given one will be marked read</param>
public async Task<bool> ReadHistory(InputPeer peer, int max_id = default) => peer switch
{
InputPeerChannel channel => await this.Channels_ReadHistory(channel, max_id),
_ => (await this.Messages_ReadHistory(peer, max_id)) != null
};
#endregion #endregion
} }
} }

View file

@ -6560,7 +6560,7 @@ namespace TL
/// <summary>Message entity representing a spoiler <para>See <a href="https://corefork.telegram.org/constructor/messageEntitySpoiler"/></para></summary> /// <summary>Message entity representing a spoiler <para>See <a href="https://corefork.telegram.org/constructor/messageEntitySpoiler"/></para></summary>
[TLDef(0x32CA960F)] [TLDef(0x32CA960F)]
public class MessageEntitySpoiler : MessageEntity { } public class MessageEntitySpoiler : MessageEntity { }
/// <summary>Represents a custom emoji <para>See <a href="https://corefork.telegram.org/constructor/messageEntityCustomEmoji"/></para></summary> /// <summary>Represents a custom emoji.<br/>Note that this entity must wrap exactly one regular emoji (the one contained in <see cref="DocumentAttributeCustomEmoji"/>.<c>alt</c>) in the related text, otherwise the server will ignore it. <para>See <a href="https://corefork.telegram.org/constructor/messageEntityCustomEmoji"/></para></summary>
[TLDef(0xC8CF05F8, inheritBefore = true)] [TLDef(0xC8CF05F8, inheritBefore = true)]
public class MessageEntityCustomEmoji : MessageEntity public class MessageEntityCustomEmoji : MessageEntity
{ {

View file

@ -3056,7 +3056,7 @@ namespace TL
/// <summary>React to message <para>See <a href="https://corefork.telegram.org/method/messages.sendReaction"/></para> <para>Possible <see cref="RpcException"/> codes: 400,403 (<a href="https://corefork.telegram.org/method/messages.sendReaction#possible-errors">details</a>)</para></summary> /// <summary>React to message <para>See <a href="https://corefork.telegram.org/method/messages.sendReaction"/></para> <para>Possible <see cref="RpcException"/> codes: 400,403 (<a href="https://corefork.telegram.org/method/messages.sendReaction#possible-errors">details</a>)</para></summary>
/// <param name="big">Whether a bigger and longer reaction should be shown</param> /// <param name="big">Whether a bigger and longer reaction should be shown</param>
/// <param name="add_to_recent">Add this reaction to the recent reactions list</param> /// <param name="add_to_recent">Add this reaction to the <a href="https://corefork.telegram.org/api/reactions#recent-reactions">recent reactions list »</a>.</param>
/// <param name="peer">Peer</param> /// <param name="peer">Peer</param>
/// <param name="msg_id">Message ID to react to</param> /// <param name="msg_id">Message ID to react to</param>
/// <param name="reaction">Reaction (a UTF8 emoji)</param> /// <param name="reaction">Reaction (a UTF8 emoji)</param>