//function that is called when send button is pressed void OnImageTapped(object sender, EventArgs args) { var buttonSend = (Image)sender; //Need to change format for user sent texts //if last message was from the same user dont show name /*int count = MessagesList.Count; * if (count>0 && MessagesList[count-1].UserSent.Equals(currentUser)) * { * //should be false here in final version * MessagesList.Add(new Message { MessageText = Editor_Chat.Text, UserSent = null, Time = DateTime.Now.ToString("h:mm tt"), NotSameUser = true, colorMessage ="Green" }); * } * else * { * MessagesList.Add(new Message { MessageText = Editor_Chat.Text, UserSent = currentUser, Time = DateTime.Now.ToString("h:mm tt"), NotSameUser = true , colorMessage = "White" }); * * }*/ //Send the message MessagesList.Add(new Message { MessageText = Editor_Chat.Text, UserSent = "Roger", Time = DateTime.Now.ToString("h:mm tt"), NotSameUser = false, colorMessage = "Green", alignment = LayoutOptions.EndAndExpand }); //for current testing we are just adding it to the data source //need to reformat the message to: change text to right align, background color to green with opacity MessageListView.ItemsSource = null; MessageListView.ItemsSource = MessagesList; //reset text and hide keyboard string text = Editor_Chat.Text; Editor_Chat.Text = ""; Editor_Chat.Unfocus(); MessageListView.ScrollTo(MessagesList.Last(), ScrollToPosition.End, true); }
//Adds messages to the list public void ParseMessage(List <Message> messages, Dictionary <string, User> users, bool reverse = false) { MessageListView.BatchBegin(); int i = 0; messages.ForEach(message => { var model = new MessageModel { Message = message.Text, Name = viewModel.Users[message.Username].FirstName, Date = message.Timestamp.ToFullDate(), RightSide = (message.Username == LocalUserManager.LocalUser.Username), MessageObject = message }; //Ar į pabaigą ar į pradžią dėti pranešimus if (reverse) { Items.Insert(i, model); i++; } else { Items.Add(model); } }); //Scrolls to the end if at the bottom (kinda, I did my best) if (lastVisible) { MessageListView.ScrollTo(Items.LastOrDefault(), ScrollToPosition.End, false); } MessageListView.BatchCommit(); }
//Handles messages from messaging service after GetMoreHistory() is called public void MessageRecieverLimited(MessagingTask task) { if (task.Conversation.Id != viewModel.Conversation.Id) { return; } Console.WriteLine("Starting adding"); var topMessage = Items.Count >= 2 ? Items[1] : Items.FirstOrDefault(); Console.WriteLine(topMessage == null); var messages = task.Messages; if (messages.Count == 0 || messages[0].Conversation != viewModel.Conversation.Id) { gotAllHistory = true; return; } var users = task.Users; users[LocalUserManager.LocalUser.Username] = LocalUserManager.LocalUser; updatingItems = true; ParseMessage(messages, users, true); updatingItems = false; if (topMessage != null && !lastVisible) { MessageListView.ScrollTo(topMessage, ScrollToPosition.MakeVisible, false); } else { MessageListView.ScrollTo(Items.LastOrDefault(), ScrollToPosition.End, false); } Console.WriteLine("Stopping adding"); }
private void Entry_Completed(object sender, EventArgs e) { Device.BeginInvokeOnMainThread(() => { MessageListView.ScrollTo(vm.Messages.Last(), ScrollToPosition.End, false); }); //EntryText.Focus(); }
public async void notify(string type, params object[] list) { switch (type) { case "new messages": Device.BeginInvokeOnMainThread(() => { if (vm.Messages != null && vm.Messages.Count > 0) { MessageListView.ScrollTo(vm.Messages.Last(), ScrollToPosition.End, false); } }); break; case "error": AlertMessage("Unexpected Error", "Error while getting messages: " + list[0].ToString() + Environment.NewLine + "The chat will try to update automatically."); break; case "session error": AlertMessage("Session Error", "Error while getting session info: " + list[0].ToString() + Environment.NewLine + "The session will try to update automatically."); break; case "EmailError": AlertMessage("Error sending chat copy to the customer", list[0].ToString()); break; case "closing error": AlertMessage("Error closing the session", list[0].ToString()); break; case "session closed": await Navigation.PopAsync(); break; case "message error": AlertMessage("Error sending message!", "Sending the message failed too many times... The message will not be sent." + Environment.NewLine + "Error: " + list[0].ToString()); break; case "closed without copy": AlertMessage("Error sending a copy", "The copy failed to send."); break; case "no internet": AlertMessage("No internet", "There is no internet connection. The background of the chat will stay red until there is no internet connectivity"); break; case "no session error": AlertMessage("Error", "Unable to start chat session. Check your internet connectivity."); break; case "error host": AlertMessage("Error", "Unable to reach host after few attempts. Check your network connectivity. The app will try to reach the host again!"); break; } }
private void EntryText_Focused(object sender, FocusEventArgs e) { if (vm.Messages != null && vm.Messages.Count > 0) { Device.BeginInvokeOnMainThread(() => { MessageListView.ScrollTo(vm.Messages.Last(), ScrollToPosition.End, false); }); } }
private void Button_Clicked(object sender, EventArgs e) { if (vm.Messages != null && vm.Messages.Count > 0) { Device.BeginInvokeOnMainThread(() => { MessageListView.ScrollTo(vm.Messages.Last(), ScrollToPosition.MakeVisible, false); }); } }
public ConversationPage(ConversationViewModel viewModel) { InitializeComponent(); if (!viewModel.Users.ContainsKey(LocalUserManager.LocalUser.Username)) { viewModel.Users[LocalUserManager.LocalUser.Username] = LocalUserManager.LocalUser; } BindingContext = this.viewModel = viewModel; Items = new ObservableCollection <MessageModel> { }; MessageListView.ItemsSource = Items; //Listens messages already loaded MessagingCenter.Subscribe <MessagingTask>(this, MessagingTask.LocalMessagesLimited, (task) => { Device.BeginInvokeOnMainThread(() => { //Adds them to the list MessageRecieverLimited(task); //Stops listening MessagingCenter.Unsubscribe <MessagingTask>(this, MessagingTask.LocalMessagesLimited); MessagingCenter.Subscribe <MessagingTask>(this, MessagingTask.LocalMessagesLimited, MessageRecieverLimited); //Starts listening for new messages MessagingCenter.Subscribe <MessagingTask>(this, MessagingTask.NewMessages, MessageReciever); MessageListView.ScrollTo(Items.LastOrDefault(), ScrollToPosition.End, false); }); }); //Ask for messages already loaded GetMoreHistory(); #pragma warning disable CS0618 // Type or member is obsolete ProfileLayout.GestureRecognizers.Add(new TapGestureRecognizer(async(view) => { ProfileLayout.IsEnabled = false; await ProfileOpener.OpenProfile(viewModel.Users[viewModel.Conversation.Users[0]]); ProfileLayout.IsEnabled = true; })); #pragma warning restore CS0618 // Type or member is obsolete }
public ChatPage() { this.ToolbarItems.Add(new ToolbarItem("Group", "ChatPageGroupButtonImage.png", () => { //What the button does when it is pressed Navigation.PushAsync(new ChatGroupPage()); })); InitializeComponent(); MessagesList = new List <Message> { new Message { MessageText = "Hi Joe how is your camp spot?", UserSent = "Bill", Time = "8:19 PM", NotSameUser = true, colorMessage = "White", alignment = LayoutOptions.Start }, new Message { MessageText = "Pretty good, getting dark you got a campfire started yet?", UserSent = "Joe", Time = "8:22 PM", NotSameUser = true, colorMessage = "White", alignment = LayoutOptions.Start }, new Message { MessageText = "Yeah I started one about an hour ago", UserSent = "George", Time = "8:25 PM", NotSameUser = true, colorMessage = "White", alignment = LayoutOptions.Start }, }; MessageListView.ItemsSource = MessagesList; MessageListView.ScrollTo(MessagesList.Last(), ScrollToPosition.End, true); }
private void Vm_DataAdded(object sender, EventArgs e) { MessageListView.ScrollTo(vm.Messages.Last(), ScrollToPosition.Start, true); }
private void EntryText_Focused(object sender, FocusEventArgs e) { MessageListView.ScrollTo(vm.Messages.Last(), ScrollToPosition.End, false); }
private void Entry_Completed(object sender, EventArgs e) { MessageListView.ScrollTo(vm.Messages.Last(), ScrollToPosition.End, false); //EntryText.Focus(); }
private void Button_Clicked(object sender, EventArgs e) { var x = MessageListView.ItemsSource; MessageListView.ScrollTo(vm.Messages.Last(), ScrollToPosition.MakeVisible, false); }
public async void notify(string type, params object[] list) { switch (type) { case "new messages": //Add the messages to the list from the UI thread. Device.BeginInvokeOnMainThread(() => { if (vm.Messages != null && vm.Messages.Count > 0) { MessageListView.ScrollTo(vm.Messages.Last(), ScrollToPosition.End, false); } }); break; case "error": //Unexpected error AlertMessage("Unexpected Error", "Error while getting messages: " + list[0].ToString() + Environment.NewLine + "The chat will try to update automatically.", false); break; case "no internet": //No internet services AlertMessage("No internet", "The background of the page will become red and will stay red until there is no internet connectivity...", false); break; case "message error": //Too many failed attempts to send a message AlertMessage("Error sending message!", "Sending the message failed too many times... The message will not be sent." + Environment.NewLine + "Error: " + list[0].ToString(), false); break; case "session closed": //Cannot send messages to closed session, ask for chat copy AlertMessage("Session closed", "You cannot send anymore messages in this session because it was closed. If you want to ask another question open a new session. Do you want to get a copy of the chat on your email?", true); break; case "EmailError": //Error while sending email from SendGrid. AlertMessage("Error", "Error occured while sending chat copy:" + Environment.NewLine + list[0].ToString(), false); break; case "send copy": //User has confirmed to send a chat copy vm.SendChatCopy(); break; case "copy error": //Error while getting a chat copy from the server AlertMessage("FAIL", "Error while trying to get a session copy from the server." + Environment.NewLine + list[0].ToString(), false); break; case "email response": Response response = (Response)list[0]; //Check if the enquiry was sent successfully if (response.StatusCode == HttpStatusCode.Accepted) { AlertMessage("Sucess", "Chat copy sent successfuly! If you cannot see the e-mail, please check your SPAM box.", false); } else { //Alert the user if not. AlertMessage("Fail", "Chat copy did not send successfuly. Error code:" + response.StatusCode.ToString(), false); } break; case "session error": AlertMessage("Error", "Unable to start chat session. Check your internet connectivity.", false); break; case "error host": AlertMessage("Error", "Unable to reach host after few attempts. Check your network connectivity. The app will try to reach the host again!", false); break; } }