Exemplo n.º 1
0
        public async void DialogsAddAsync()
        {
            const ulong AddCount = 20;
            Task <GetConversationsResult> outerTask = D.api.Messages.GetConversationsAsync(new GetConversationsParams
            {
                Count  = AddCount,
                Offset = D.TotalDialogsCount,
                Fields = new List <string> {
                    "All"
                }
            });
            GetConversationsResult results = new GetConversationsResult();
            List <MyDialog>        TMP     = new List <MyDialog>();
            await outerTask.ContinueWith(task =>
            {
                results = task.Result;
            });

            foreach (var i in results.Items)
            {
                TMP.Add(new MyDialog(i.Conversation, i.LastMessage));

                D.TotalDialogsCount++;
                //DialogPictureList.Images.Add(DialogsList.Last().Id, LoadImageFromUrl(DialogsList.Last().PicUrl));
            }
            D.DialogsList.AddRange(TMP);
            ObjDialogList.AddObjects(TMP);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            AuthorizeVK();
            AuthorizeTelegram();

            LastCheck = _api.Messages.GetConversations(new GetConversationsParams
            {
                Count  = 1,
                Filter = VkNet.Enums.SafetyEnums.GetConversationFilter.Unread
            });
            var    a       = LastCheck.Items.Count;
            Thread thread1 = new Thread(partVK.Start);
            Thread thread2 = new Thread(partTG.Start);

            thread1.Start();
            thread2.Start();
        }
Exemplo n.º 3
0
        public async void DialogsUpdAsync()
        {
            Task <GetConversationsResult> outerTask = D.api.Messages.GetConversationsAsync(new GetConversationsParams
            {
                Count  = D.TotalDialogsCount,
                Offset = 0,
                Fields = new List <string> {
                    "All"
                }
            });
            GetConversationsResult results = new GetConversationsResult();
            await outerTask.ContinueWith(task =>
            {
                results = task.Result;

                for (var i = 0; i < D.DialogsList.Count; i++)
                {
                    D.DialogsList[i].UpdateInfo(results.Items[i].LastMessage, results.Items[i].Conversation);
                }
            });

            ObjDialogList.UpdateObjects(D.DialogsList);
        }
Exemplo n.º 4
0
        private (DateTime, List <long>) GetUpdatedPeerIds(DateTime lastDate)
        {
            GetConversationsResult conversations = null;
            var   result    = new List <long>();
            ulong?offset    = 0;
            ulong?blockSize = 50;
            var   maxDate   = lastDate;

            do
            {
                conversations = _api.Messages.GetConversations(new GetConversationsParams
                {
                    Count    = blockSize,
                    Extended = false,
                    Offset   = offset
                });

                result.AddRange(
                    conversations.Items
                    .Where(item => item.LastMessage.Date > lastDate)
                    .Select(item => item.Conversation.Peer.Id).ToList()
                    );

                var minDate = conversations.Items.Min(i => i.LastMessage.Date).Value;
                var tmp     = conversations.Items.Max(i => i.LastMessage.Date).Value;
                maxDate = maxDate > tmp ? maxDate : tmp;

                if (minDate < lastDate)
                {
                    break;
                }
                offset += blockSize;
                Thread.Sleep(250);
            } while ((ulong)conversations.Items.Count == blockSize.Value);

            return(maxDate, result);
        }