You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 5, 2021. It is now read-only.
How do I get updates for new channel messages without bumping flood limits?
First I tried this:
while (true)
{
Task.Delay(500).Wait();
TLState state = client.SendRequestAsync<TLState>(new TLRequestGetState()).Result;
//if (state.UnreadCount <= 0) continue;
TLRequestGetDifference req = new TLRequestGetDifference { Date = state.Date, Pts = state.Pts, Qts = state.Qts, Sequence = state.Seq + 1 };
TLDifference diff = client.SendRequestAsync<TLAbsDifference>(req).Result as TLDifference;
if (diff != null)
{
foreach (TLUpdateNewChannelMessage upd in diff.OtherUpdates.OfType<TLUpdateNewChannelMessage>())
Console.WriteLine(((TLMessage)upd.Message).Message);
foreach (TLChannel ch in diff.Chats.OfType<TLChannel>().Where(x => !x.Left))
{
TLInputChannel ich = new TLInputChannel { ChannelId = ch.Id, AccessHash = ch.AccessHash ?? 0 };
TLRequestReadHistory readed = new TLRequestReadHistory { Channel = ich, MaxId = -1 };
client.SendRequestAsync<bool>(readed).Wait();
}
}
}
But state.UnreadCount > 0 only for unread messages from PeerUsers. And even if state.UnreadCount > 0, client.SendRequestAsync<TLAbsDifference> always returns TLDifferenceEmpty.
It shows me unread messages, but has two problems.
It causes Flood prevention exception after several iterations if there are no new messages.
It causes InvalidCastException on second iteration if there are new messages.
Here what happens:
I call client.SendRequestAsync<bool>(markHistoryAsReadRequest) to mark messages as read.
It always returns False, despite messages have been marked as read.
On the next iteration I call var dialogs = client.GetUserDialogsAsync().Result as TLDialogs; again.
It causes InvalidCastException because SendRequestAsync<TLAbsDialogs> is called inside GetUserDialogsAsync. But it receives TLBoolTrue as a result. And tries to cast it to TLAbsDialogs which fails.
How do I get updates for new channel messages without bumping flood limits?
First I tried this:
But
state.UnreadCount > 0only for unread messages from PeerUsers. And even ifstate.UnreadCount > 0,client.SendRequestAsync<TLAbsDifference>always returnsTLDifferenceEmpty.Also I tried:
It shows me unread messages, but has two problems.
Here what happens:
client.SendRequestAsync<bool>(markHistoryAsReadRequest)to mark messages as read.False, despite messages have been marked as read.var dialogs = client.GetUserDialogsAsync().Result as TLDialogs;again.SendRequestAsync<TLAbsDialogs>is called insideGetUserDialogsAsync. But it receivesTLBoolTrueas a result. And tries to cast it toTLAbsDialogswhich fails.