Beispiel #1
0
        public async Task GetUpdatesAsync()
        {
            await ConnectAsync();

            if (_lastInitialState == null)
            {
                _lastInitialState = await _client.GetUpdatesState();

                return;
            }

            UpdatesDifference differenceUpdateResponse = await GetUpdatesDifferenceAsync(_lastInitialState);

            if (differenceUpdateResponse is UpdatesDifferenceConstructor differenceUpdate)
            {
                _lastInitialState = differenceUpdate.state;
                UpdatesStateConstructor updatesStateConstructor = _lastInitialState as UpdatesStateConstructor;
                _logger.Debug(string.Format("{0} Update.GetDifference result=[Seq={1} Date={2} Qts={3} Pts{4}]",
                                            DateTime.Now.ToString("HH:mm:ss.fff", CultureInfo.InvariantCulture), updatesStateConstructor.seq,
                                            updatesStateConstructor.date, updatesStateConstructor.qts, updatesStateConstructor.pts));

                if (differenceUpdate.newMessages.Count > 0)
                {
                    IEnumerable <Models.Contact> users          = differenceUpdate.users.Select(u => ((Models.Contact)u)).Where(u => u != null);
                    IEnumerable <Models.Message> messages       = differenceUpdate.newMessages.Select(m => (Models.Message)m).Where(m => m != null);
                    IDictionary <int, int>       lastMessageIds = new Dictionary <int, int>();

                    foreach (Models.Message message in messages)
                    {
                        OnUpdateMessage(this, message);
                        lastMessageIds[message.FromId] = message.Id;
                    }
                    foreach (Models.Contact user in users)
                    {
                        if (lastMessageIds.ContainsKey(user.Id))
                        {
                            await MarkedMessagesAsReadAsync(user, 0, lastMessageIds[user.Id]);
                        }
                    }
                }
            }
            else if (differenceUpdateResponse is UpdatesDifferenceEmptyConstructor)
            {
            }
            else if (differenceUpdateResponse is UpdatesDifferenceSliceConstructor differenceSliceUpdate)
            {
            }
        }
Beispiel #2
0
 public override void OnResponse(BinaryReader reader)
 {
     updatesDifference = TLObject.Read <UpdatesDifference>(reader);
 }