/// <summary>
        /// Send message, mark all as read
        /// </summary>
        private async void OnTextCompleted(object?sender = null, EventArgs?args = null)
        {
            var text = popupEntryView.Text;

            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            popupEntryView.Completed   -= OnTextCompleted;
            activityIndicator.IsVisible = true;

            await dialogsManager.SetDialogAndMessagesReadAndPublish(dialogId);

            await NetExceptionCatchHelpers.CatchNetException(
                async() =>
            {
                await messagesManager.SendMessage(dialogId, text, null);
                popupEntryView.Text = string.Empty;
            },
                () =>
            {
                OnTextCompleted();
                return(Task.CompletedTask);
            },
                LocalizedStrings.SendMessageNoInternetError);

            activityIndicator.IsVisible = false;
            popupEntryView.Completed   += OnTextCompleted;
        }
        /// <summary>
        /// Load more messages when scroll reached the end of the page
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void OnLoadMoreMessages(object sender, ItemVisibilityEventArgs e)
        {
            if (dialogsManager.GetIsInitRequired(dialogId))
            {
                return;
            }

            var message       = (Message)e.Item;
            var messagesCount = messagesManager.GetMessagesCount(dialogId);

            if (messagesCount >= Consts.BatchSize && messagesManager.IsMessageOlderThanAll(dialogId, message.Id))
            {
                activityIndicator.IsVisible = true;
                await NetExceptionCatchHelpers.CatchNetException(
                    async() =>
                {
                    await messagesManager.UpdateMessagesFromApi(dialogId, messagesCount);
                    messagesListView.ScrollIfExist(message, ScrollToPosition.Center);
                },
                    () =>
                {
                    OnLoadMoreMessages(sender, e);
                    return(Task.CompletedTask);
                },
                    LocalizedStrings.MessagesNoInternetError);

                activityIndicator.IsVisible = false;
            }
        }
Beispiel #3
0
        private async void OnSendButtonPressed(object sender, EventArgs e)
        {
            if (voiceMessageTempPath == null)
            {
                return;
            }

            activityIndicator.IsVisible = true;

            await NetExceptionCatchHelpers.CatchNetException(
                async() =>
            {
                sendButton.IsEnabled = false;
                await messagesManager.SendMessage(dialogId, null, voiceMessageTempPath);
                DeleteTempFile();
                await Navigation.PopAsync();
            },
                () =>
            {
                OnSendButtonPressed(sender, e);
                return(Task.CompletedTask);
            },
                LocalizedStrings.SendMessageNoInternetError);

            activityIndicator.IsVisible = false;
            sendButton.IsEnabled        = true;
        }
Beispiel #4
0
        /// <summary>
        /// Called when long pooling calls Reset. If update unsuccessful show error popup and retry
        /// </summary>
        private async Task InitFromApi()
        {
            activityIndicator.IsVisible = true;

            await NetExceptionCatchHelpers.CatchNetException(
                dialogsManager.UpdateDialogsFromApi,
                InitFromApi,
                LocalizedStrings.DialogsNoInternetError);

            activityIndicator.IsVisible = false;
            dialogsListView.ScrollIfExist(dialogsManager.First(), ScrollToPosition.Center);
        }
        /// <summary>
        /// Called on start. If update unsuccessful show error popup and retry
        /// </summary>
        private async Task InitFromApi()
        {
            activityIndicator.IsVisible = true;

            await NetExceptionCatchHelpers.CatchNetException(
                async() =>
            {
                await messagesManager.UpdateMessagesFromApi(dialogId);
                dialogsManager.SetIsInitRequiredToFalse(dialogId);
            },
                InitFromApi,
                LocalizedStrings.MessagesNoInternetError);

            activityIndicator.IsVisible = false;
        }
        private async void OnItemLongPressed(object sender, ItemLongPressedEventArgs e)
        {
            if (newMessageInputShown)
            {
                return;
            }

            var message = (Message)e.Item;

            // Possible to delete current user messages that is not older than 1d
            if (dialogId == AuthorizationManager.UserId ||
                message.Profile?.Id != AuthorizationManager.UserId ||
                message.Date < DateTime.Now.AddDays(-1) ||
                message.Deleted)
            {
                longTappedMessageId = null;
                return;
            }

            // Delete by double long press
            if (longTappedMessageId != message.Id)
            {
                longTappedMessageId = message.Id;
                return;
            }

            longTappedMessageId         = null;
            activityIndicator.IsVisible = true;

            await NetExceptionCatchHelpers.CatchNetException(
                () => messagesManager.DeleteMessage(dialogId, message.Id),
                () =>
            {
                OnItemLongPressed(sender, e);
                return(Task.CompletedTask);
            },
                LocalizedStrings.DeleteMessageNoInternetError);

            activityIndicator.IsVisible = false;
        }