Beispiel #1
0
 /// <summary>
 ///     Initialize All MessagesSent
 /// </summary>
 public void Clear()
 {
     LastSentMessages.Clear();
     DelayedMessages.Clear();
     _waitingMessagesCount = 0;
     Result.Clear();
     LostMessages.Clear();
     WaitingMessages.Clear();
     Result.Clear();
 }
        public TranslationChatViewModel()
        {
            Messages.Insert(0, new Message()
            {
                Text = "Hi there", Sender = MessageSender.System, DateCreated = DateTime.Now, Language = "English", Status = MessageStatus.Delivered
            });
            Messages.Insert(0, new Message()
            {
                Text = "I de o", Sender = MessageSender.User, DateCreated = DateTime.Now, Language = "English", Status = MessageStatus.Sent
            });
            Messages.Insert(0, new Message()
            {
                Text = "Soft Soft", Sender = MessageSender.System, DateCreated = DateTime.Now, Language = "Spain", Status = MessageStatus.Read
            });
            Messages.Insert(0, new Message()
            {
                Text = "Translate this guy for me shap shap. E get why I talk am.", Sender = MessageSender.User, DateCreated = DateTime.Now, Language = "English", Status = MessageStatus.Pending
            });
            MessageAppearingCommand    = new Command <Message>(OnMessageAppearing);
            MessageDisappearingCommand = new Command <Message>(OnMessageDisappearing);

            OnSendCommand = new Command(() =>
            {
                if (!string.IsNullOrEmpty(TextToSend))
                {
                    Messages.Add(new Message()
                    {
                        Text = TextToSend, DateCreated = DateTime.Now, Language = "English", Status = MessageStatus.Delivered
                    });
                    TextToSend = string.Empty;
                }
            });

            //Code to simulate reveing a new message procces
            Device.StartTimer(TimeSpan.FromSeconds(5), () =>
            {
                if (LastMessageVisible)
                {
                    Messages.Insert(0, new Message()
                    {
                        Text = "New message test", Sender = MessageSender.System, DateCreated = DateTime.Now, Status = MessageStatus.Delivered
                    });
                }
                else
                {
                    DelayedMessages.Enqueue(new Message()
                    {
                        Text = "New message test", Sender = MessageSender.User, DateCreated = DateTime.Now, Status = MessageStatus.Read
                    });
                    PendingMessageCount++;
                }
                return(true);
            });
        }
Beispiel #3
0
        private void OnMessageAppearing(Models.Message message)
        {
            int idx = Messages.IndexOf(message);

            if (idx <= 6)
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    while (DelayedMessages.Count > 0)
                    {
                        Messages.Insert(0, DelayedMessages.Dequeue());
                    }
                    ShowScrollTap       = false;
                    LastMessageVisible  = true;
                    PendingMessageCount = 0;
                });
            }
        }
        void OnMessageAppearing(Message message)
        {
            var idx = Messages.IndexOf(message);

            Debug.WriteLine($"{idx}/{Messages.Count} appearing : {message.Text}");

            if (idx <= 5)
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    while (DelayedMessages.Count > 0)
                    {
                        Messages.Insert(0, DelayedMessages.Dequeue());
                    }
                    ShowScrollTap       = false;
                    LastMessageVisible  = true;
                    PendingMessageCount = 0;
                });
            }
        }
Beispiel #5
0
        private void refreshModel()
        {
            int    inquiryId  = (int)Application.Current.Properties["InquiryID"];
            string _token     = Application.Current.Properties["currentToken"].ToString();
            int    customerId = (int)Application.Current.Properties["CustomerId"];
            List <InquiryChatModel> inquiryChatModels = null;
            CustomerController      controller        = new CustomerController();

            inquiryChatModels = controller.getChatModels(inquiryId, _token);

            if (inquiryChatModels != null)
            {
                foreach (InquiryChatModel icm in inquiryChatModels)
                {
                    int lastmId = 0;
                    if (Messages.Count > 0)
                    {
                        lastmId = Messages[0].messageId;
                    }
                    if (icm.MessageId > lastmId)
                    {
                        Message message = new Message();
                        message.messageId = icm.MessageId;
                        message.Text      = icm.Message;
                        message.User      = icm.SenderId == customerId ? Constants.customerDetails.FirstName : "Jax";
                        message.sentTime  = icm.SendDate.ToString("MM/dd/yyyy h:mm tt");


                        if (LastMessageVisible)
                        {
                            Messages.Insert(0, message);
                        }
                        else
                        {
                            DelayedMessages.Enqueue(message);
                            PendingMessageCount++;
                        }
                    }
                }
            }
        }
        public ChatPageViewModel()
        {
            Messages.Insert(0, new Message()
            {
                Text = "Hi, How can I help you?"
            });

            MessageAppearingCommand    = new Command <Message>(OnMessageAppearing);
            MessageDisappearingCommand = new Command <Message>(OnMessageDisappearing);

            OnSendCommand = new Command(() =>
            {
                if (!string.IsNullOrEmpty(TextToSend))
                {
                    Messages.Insert(0, new Message()
                    {
                        Text = TextToSend, User = App.User
                    });

                    if (LastMessageVisible)
                    {
                        Messages.Insert(0, new Message()
                        {
                            Text = "Reply to " + TextToSend, User = "******"
                        });
                    }
                    else
                    {
                        DelayedMessages.Enqueue(new Message()
                        {
                            Text = "Reply to " + TextToSend, User = "******"
                        });
                        PendingMessageCount++;
                    }

                    TextToSend = string.Empty;
                }
            });
        }
Beispiel #7
0
        public ChatPageViewModel()
        {
            Messages.Insert(0, new Message()
            {
                Text = "Добрый день, как я могу вам помочь?"
            });

            MessageAppearingCommand    = new Command <Message>(OnMessageAppearing);
            MessageDisappearingCommand = new Command <Message>(OnMessageDisappearing);

            OnSendCommand = new Command(() =>
            {
                if (!string.IsNullOrEmpty(TextToSend))
                {
                    Messages.Insert(0, new Message()
                    {
                        Text = TextToSend, User = App.User
                    });

                    if (LastMessageVisible)
                    {
                        Messages.Insert(0, new Message()
                        {
                            Text = "Ответ на " + TextToSend, User = "******"
                        });
                    }
                    else
                    {
                        DelayedMessages.Enqueue(new Message()
                        {
                            Text = "Ответ на " + TextToSend, User = "******"
                        });
                        PendingMessageCount++;
                    }

                    TextToSend = string.Empty;
                }
            });
        }
Beispiel #8
0
        public void Init()
        {
            var seconds = TimeSpan.FromSeconds(1);

            Device.StartTimer(seconds, () => {
                if (LastMessageVisible)
                {
                    ch.OnMessageReceived = (BaseChannel baseChannel, BaseMessage baseMessage) => {
                        Messages.Insert(0, (UserMessage)baseMessage);
                        //Messages.Add((UserMessage)baseMessage);
                    };
                }
                else
                {
                    ch.OnMessageReceived = (BaseChannel baseChannel, BaseMessage baseMessage) => {
                        DelayedMessages.Enqueue((UserMessage)baseMessage);
                        PendingMessageCount++;
                    };
                }
                return(true);
            });
            AddChannelHandler("MyKey", ch);
        }
Beispiel #9
0
        public ChatPageViewModel()
        {
            MessageAppearingCommand    = new Command <Models.Message>(OnMessageAppearing);
            MessageDisappearingCommand = new Command <Models.Message>(OnMessageDisappearing);

            if (!Storage.IsChatBot)
            {
                ResultObj result = MessageLog.GetMessages(Storage.User.Id, Storage.Friend.Id);
                if (result.Messages != null)
                {
                    foreach (Message message in result.Messages)
                    {
                        Messages.Insert(0, new Models.Message()
                        {
                            User = message.Id,
                            Text = message.Text,
                            Time = message.Time.ToLongTimeString(),
                            Date = message.Time.ToLongDateString()
                        });
                    }
                }

                OnSendCommand = new Command(() =>
                {
                    if (!string.IsNullOrEmpty(TextToSend))
                    {
                        MessageLog.Add(Storage.User.Id, Storage.Friend.Id, TextToSend.Trim());
                        TextToSend = string.Empty;
                    }
                });

                Device.StartTimer(TimeSpan.FromSeconds(1), () =>
                {
                    result = MessageLog.GetMessages(Storage.User.Id, Storage.Friend.Id);
                    if (result.Messages != null)
                    {
                        if (result.Messages.Count > Messages.Count)
                        {
                            for (int i = Messages.Count; i < result.Messages.Count; i++)
                            {
                                Models.Message message = new Models.Message()
                                {
                                    User = result.Messages[i].Id,
                                    Text = result.Messages[i].Text,
                                    Time = result.Messages[i].Time.ToLongTimeString(),
                                    Date = result.Messages[i].Time.ToLongDateString()
                                };
                                if (LastMessageVisible)
                                {
                                    Messages.Insert(0, message);
                                }
                                else
                                {
                                    DelayedMessages.Enqueue(message);
                                    PendingMessageCount++;
                                }
                            }
                        }
                    }
                    return(Storage.IsChatNow);
                });
            }
            else
            {
                OnSendCommand = new Command(() =>
                {
                    if (!string.IsNullOrEmpty(TextToSend))
                    {
                        Messages.Insert(0, new Models.Message()
                        {
                            Text = TextToSend,
                            User = Storage.User.Id,
                            Date = DateTime.Now.ToLongDateString(),
                            Time = DateTime.Now.ToLongTimeString()
                        });
                        TextToSend = string.Empty;
                    }
                });

                //Code to simulate reveing a new message procces
                Device.StartTimer(TimeSpan.FromSeconds(3), () =>
                {
                    if (LastMessageVisible)
                    {
                        Messages.Insert(0, new Models.Message()
                        {
                            Text = mes[random.Next(mes.Length)],
                            User = -1,
                            Date = DateTime.Now.ToLongDateString(),
                            Time = DateTime.Now.ToLongTimeString()
                        });
                    }
                    else
                    {
                        DelayedMessages.Enqueue(new Models.Message()
                        {
                            Text = mes[random.Next(mes.Length)],
                            User = -1,
                            Date = DateTime.Now.ToLongDateString(),
                            Time = DateTime.Now.ToLongTimeString()
                        });
                        PendingMessageCount++;
                    }
                    return(true);
                });
            }
        }
        public ChatPageViewModel()
        {
            Messages.Insert(0, new Message()
            {
                Text = "Hi"
            });
            Messages.Insert(0, new Message()
            {
                Text = "How are you?", User = App.User
            });
            Messages.Insert(0, new Message()
            {
                Text = "What's new?"
            });
            Messages.Insert(0, new Message()
            {
                Text = "How is your family", User = App.User
            });
            Messages.Insert(0, new Message()
            {
                Text = "How is your dog?", User = App.User
            });
            Messages.Insert(0, new Message()
            {
                Text = "How is your cat?", User = App.User
            });
            Messages.Insert(0, new Message()
            {
                Text = "How is your sister?"
            });
            Messages.Insert(0, new Message()
            {
                Text = "When we are going to meet?"
            });
            Messages.Insert(0, new Message()
            {
                Text = "I want to buy a laptop"
            });
            Messages.Insert(0, new Message()
            {
                Text = "Where I can find a good one?"
            });
            Messages.Insert(0, new Message()
            {
                Text = "Also I'm testing this chat"
            });
            Messages.Insert(0, new Message()
            {
                Text = "Oh My God!"
            });
            Messages.Insert(0, new Message()
            {
                Text = " No Problem", User = App.User
            });
            Messages.Insert(0, new Message()
            {
                Text = "Hugs and Kisses", User = App.User
            });
            Messages.Insert(0, new Message()
            {
                Text = "When we are going to meet?"
            });
            Messages.Insert(0, new Message()
            {
                Text = "I want to buy a laptop"
            });
            Messages.Insert(0, new Message()
            {
                Text = "Where I can find a good one?"
            });
            Messages.Insert(0, new Message()
            {
                Text = "Also I'm testing this chat"
            });
            Messages.Insert(0, new Message()
            {
                Text = "Oh My God!"
            });
            Messages.Insert(0, new Message()
            {
                Text = " No Problem"
            });
            Messages.Insert(0, new Message()
            {
                Text = "Hugs and Kisses"
            });

            MessageAppearingCommand    = new Command <Message>(OnMessageAppearing);
            MessageDisappearingCommand = new Command <Message>(OnMessageDisappearing);

            OnSendCommand = new Command(() =>
            {
                if (!string.IsNullOrEmpty(TextToSend))
                {
                    Messages.Insert(0, new Message()
                    {
                        Text = TextToSend, User = App.User
                    });
                    TextToSend = string.Empty;
                }
            });

            //Code to simulate reveing a new message procces
            Device.StartTimer(TimeSpan.FromSeconds(5), () =>
            {
                if (LastMessageVisible)
                {
                    Messages.Insert(0, new Message()
                    {
                        Text = "New message test", User = "******"
                    });
                }
                else
                {
                    DelayedMessages.Enqueue(new Message()
                    {
                        Text = "New message test", User = "******"
                    });
                    PendingMessageCount++;
                }
                return(true);
            });
        }
Beispiel #11
0
        public ChatBotViewModel()
        {
            //DependencyService.Get<IToolbarItemBadgeService>().SetBadge(this, ToolbarItems.First(), "2", Color.Red, Color.White);
            #region messages
            Messages.Insert(0, new Message()
            {
                Text = "Hi im Serapis how can i help you?"
            });
            Messages.Insert(0, new Message()
            {
                Text = "i would like to reorder my prescription?", User = App.User
            });
            Messages.Insert(0, new Message()
            {
                Text = "okay i will check for you"
            });
            Messages.Insert(0, new Message()
            {
                Text = "I See your currently subscribed to Metformin and Thiazolidinediones, for your Diabetes condition)"
            });
            Messages.Insert(0, new Message()
            {
                Text = "I have currently added two items to your basket anything else?"
            });
            Messages.Insert(0, new Message()
            {
                Text = "No.", User = App.User
            });
            Messages.Insert(0, new Message()
            {
                Text = "but we see you ordered iburfan last week for your family, Dont you need another packet?"
            });
            Messages.Insert(0, new Message()
            {
                Text = "No.", User = App.User
            });
            Messages.Insert(0, new Message()
            {
                Text = "okay you may check out now, thank you"
            });
            #endregion
            MessageAppearingCommand    = new Command <Message>(OnMessageAppearing);
            MessageDisappearingCommand = new Command <Message>(OnMessageDisappearing);

            OnSendCommand = new Command(() =>
            {
                if (!string.IsNullOrEmpty(TextToSend))
                {
                    Messages.Insert(0, new Message()
                    {
                        Text = TextToSend, User = App.User
                    });
                    TextToSend = string.Empty;
                }
            });

            //Code to simulate reveing a new message procces
            Device.StartTimer(TimeSpan.FromSeconds(6), () =>
            {
                if (LastMessageVisible)
                {
                    Messages.Insert(0, new Message()
                    {
                        Text = "Hi im Serapis how can i help you?", User = "******"
                    });
                }
                else
                {
                    DelayedMessages.Enqueue(new Message()
                    {
                        Text = "Hi im Serapis how can i help you?", User = "******"
                    });
                    PendingMessageCount++;
                }
                return(true);
            });
        }
Beispiel #12
0
        public MessagesViewModel(int previous)
        {
            if (previous == 1)
            {
                //Fake previous hardcoded conversation
                Messages.Insert(0, new Message()
                {
                    Text = "Test", User = App.User
                });
                Messages.Insert(0, new Message()
                {
                    Text = "Test!"
                });
                Messages.Insert(0, new Message()
                {
                    Text = "Hey, what's up?", User = App.User
                });
                Messages.Insert(0, new Message()
                {
                    Text = "Nothing much, just working on the messaging feature"
                });
                Messages.Insert(0, new Message()
                {
                    Text = "Hopefully it will be done in time"
                });
                Messages.Insert(0, new Message()
                {
                    Text = "I'm sure you'll get it doen", User = App.User
                });
                Messages.Insert(0, new Message()
                {
                    Text = "*done", User = App.User
                });
                Messages.Insert(0, new Message()
                {
                    Text = "Yeah lol I hope so.."
                });
                Messages.Insert(0, new Message()
                {
                    Text = "You ready for the demo on thursday?", User = App.User
                });
                Messages.Insert(0, new Message()
                {
                    Text = "Yeah"
                });
                Messages.Insert(0, new Message()
                {
                    Text = "I'm a little nervous but hopefully we'll do well"
                });
                Messages.Insert(0, new Message()
                {
                    Text = "Yeah, same. I think we'll do great!", User = App.User
                });
                Messages.Insert(0, new Message()
                {
                    Text = "Yeah, we'll see"
                });
                Messages.Insert(0, new Message()
                {
                    Text = "Alright, see you then. Good luck!", User = App.User
                });
                Messages.Insert(0, new Message()
                {
                    Text = "Thanks, you too!"
                });
            }

            //Perhaps scroll through dialogue to let audience read

            MessageAppearingCommand    = new Command <Message>(OnMessageAppearing);
            MessageDisappearingCommand = new Command <Message>(OnMessageDisappearing);

            //Keeps track of sent messages
            int counter = 0;

            //Begin scripted hardcoded dialogue
            OnSendCommand = new Command(() =>
            {
                if (!string.IsNullOrEmpty(TextToSend))
                {
                    counter++;
                    Messages.Insert(0, new Message()
                    {
                        Text = TextToSend, User = App.User
                    });
                    TextToSend = string.Empty;

                    //First message sent -> "Hey"
                    if (counter == 1)
                    {
                        //First message response -> "Hey"
                        Device.StartTimer(TimeSpan.FromSeconds(5), () =>
                        {
                            if (LastMessageVisible)
                            {
                                Messages.Insert(0, new Message()
                                {
                                    Text = "Hey"
                                });
                            }
                            else
                            {
                                DelayedMessages.Enqueue(new Message()
                                {
                                    Text = "Hey"
                                });
                                PendingMessageCount++;
                            }
                            return(false);
                        });
                    }

                    //Second message sent -> "How are you?"
                    if (counter == 2)
                    {
                        //Second message response-> "Good, you?"
                        Device.StartTimer(TimeSpan.FromSeconds(7), () =>
                        {
                            if (LastMessageVisible)
                            {
                                Messages.Insert(0, new Message()
                                {
                                    Text = "Good, you?"
                                });
                            }
                            else
                            {
                                DelayedMessages.Enqueue(new Message()
                                {
                                    Text = "Good, you?"
                                });
                                PendingMessageCount++;
                            }
                            return(false);
                        });
                    }

                    /* Third message sent -> "Good"                                      *
                    * Perhaps talk to the audience about the use cases of the messaging *
                    * feature and how it will assist mentors and students to openly     *
                    * communicate.                                                      */


                    //Fourth message sent -> "Alright, I gotta finish presenting. See you Later!"
                    if (counter == 4)
                    {
                        //Third message response -> "Alright, later!"
                        Device.StartTimer(TimeSpan.FromSeconds(7), () =>
                        {
                            if (LastMessageVisible)
                            {
                                Messages.Insert(0, new Message()
                                {
                                    Text = "Alright, later!"
                                });
                            }
                            else
                            {
                                DelayedMessages.Enqueue(new Message()
                                {
                                    Text = "Alright, later!"
                                });
                                PendingMessageCount++;
                            }
                            return(false);
                        });
                    }
                }
            });
            //End scripted hardcoded dialogue.

            /* I was too lazy to make a function to be able to easily create and change       *
            * the scripted dialogue, so anything we want to add or change, just manupulate   *
            * the code above. Hopefully its easy to recognize how to add new ones. We should *
            * consider deploying one dialogue varient for the presenter and one for the      *
            * "receiver" to make it more convincing that we are messaging cross platform     *
            * in real time.                                                                  */

            void OnMessageAppearing(Message message)
            {
                var idx = Messages.IndexOf(message);

                if (idx <= 6)
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        while (DelayedMessages.Count > 0)
                        {
                            Messages.Insert(0, DelayedMessages.Dequeue());
                        }
                        ShowScrollTap       = false;
                        LastMessageVisible  = true;
                        PendingMessageCount = 0;
                    });
                }
            }

            void OnMessageDisappearing(Message message)
            {
                var idx = Messages.IndexOf(message);

                if (idx >= 6)
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        ShowScrollTap      = true;
                        LastMessageVisible = false;
                    });
                }
            }
        }