public async Task UpdateDialogsFromCache()
        {
            var cached = await DurableCacheManager.GetDialogs();

            if (cached != null)
            {
                AddUpdateDialogsInCollection(cached, false);
            }
        }
        /// <summary>
        /// Returns updated messages ids
        /// </summary>
        public async Task UpdateDialogsFromApiByIds(IReadOnlyCollection <int> dialogIds)
        {
            var newDialogs = await DialogsClient.GetDialogsByIds(dialogIds);

            if (newDialogs.Any())
            {
                AddUpdateDialogsInCollection(newDialogs, false);
                // ReSharper disable once InconsistentlySynchronizedField
                await DurableCacheManager.SaveDialogs(collection);
            }
        }
        public async Task UpdateDialogsFromApi()
        {
            var newDialogs = await DialogsClient.GetDialogs();

            if (newDialogs.Any())
            {
                AddUpdateDialogsInCollection(newDialogs, true);
                // ReSharper disable once InconsistentlySynchronizedField
                await DurableCacheManager.SaveDialogs(collection);
            }
        }
        public async Task UpdateMessagesFromApiByIds(int dialogId, IReadOnlyCollection <int> messagesIds)
        {
            var dialog = FirstOrDefaultWithLock(dialogId);

            if (dialog == null)
            {
                return;
            }

            var collection  = dialog.Messages;
            var newMessages = await MessagesClient.GetMessagesByIds(messagesIds);

            if (newMessages.Any())
            {
                AddUpdateMessagesInCollection(dialogId, newMessages, dialog.UnreadCount, false);
                await DurableCacheManager.SaveMessages(dialog.Id, collection).ConfigureAwait(false);
            }
        }
        public async Task UpdateMessagesFromApi(int dialogId, int?offset = null)
        {
            var dialog = FirstOrDefaultWithLock(dialogId);

            if (dialog == null)
            {
                return;
            }

            var collection  = dialog.Messages;
            var newMessages = await MessagesClient.GetMessages(dialog.Id, offset);

            if (newMessages.Any())
            {
                var isNewestMessagesBatch = offset == null;
                AddUpdateMessagesInCollection(dialogId, newMessages, dialog.UnreadCount, isNewestMessagesBatch);
                await DurableCacheManager.SaveMessages(dialog.Id, collection).ConfigureAwait(false);
            }
        }