Esempio n. 1
0
        private void displayConversation(ContactModel contact)
        {
            isLoading();
            CrossCloudFirestore.Current
            .Instance
            .GetCollection("contacts")
            .GetDocument(contact.id)
            .GetCollection("conversations")
            .OrderBy("created_at", false)
            .AddSnapshotListener(async(snapshot, error) =>
            {
                conversationsListView.ItemsSource = conversationList;
                if (snapshot != null)
                {
                    foreach (var documentChange in snapshot.DocumentChanges)
                    {
                        var obj = new ConversationModel
                        {
                            id          = JsonConvert.DeserializeObject <string>(JsonConvert.SerializeObject(documentChange.Document.Data["id"])),
                            message     = JsonConvert.DeserializeObject <string>(JsonConvert.SerializeObject(documentChange.Document.Data["message"])),
                            converseeID = JsonConvert.DeserializeObject <string>(JsonConvert.SerializeObject(documentChange.Document.Data["converseeID"])),
                            created_at  = DateTime.UtcNow
                        };
                        //var json = JsonConvert.SerializeObject(documentChange.Document.Data);
                        //var obj = JsonConvert.DeserializeObject<ConversationModel>(json);
                        switch (documentChange.Type)
                        {
                        case DocumentChangeType.Added:
                            conversationList.Add(obj);
                            break;

                        case DocumentChangeType.Modified:
                            if (conversationList.Where(c => c.id == obj.id).Any())
                            {
                                var item = conversationList.Where(c => c.id == obj.id).FirstOrDefault();
                                item     = obj;
                            }
                            break;

                        case DocumentChangeType.Removed:
                            if (conversationList.Where(c => c.id == obj.id).Any())
                            {
                                var item = conversationList.Where(c => c.id == obj.id).FirstOrDefault();
                                conversationList.Remove(item);
                            }
                            break;
                        }
                        var conv = conversationsListView.ItemsSource.Cast <object>().LastOrDefault();
                        conversationsListView.ScrollTo(conv, ScrollToPosition.End, false);
                    }
                }
                emptyListLabel.IsVisible        = conversationList.Count == 0;
                conversationsListView.IsVisible = !(conversationList.Count == 0);
            });
            stopLoading();
        }
Esempio n. 2
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool retVal = false;

            if (value != null)
            {
                ConversationModel conversation = value as ConversationModel;
                if (conversation.converseeID.Equals(dataClass.LoggedInUser.Uid))
                {
                    retVal = true;
                }
            }
            return(retVal);
        }
Esempio n. 3
0
        async private void sendBtn_Clicked(object sender, EventArgs e)
        {
            var               contact      = BindingContext as ContactModel;
            string            ID           = IDGenerator.generateID();
            ConversationModel conversation = new ConversationModel()
            {
                id          = ID,
                converseeID = dataClass.LoggedInUser.Uid,
                message     = messageEditor.Text,
                created_at  = DateTime.UtcNow
            };
            await CrossCloudFirestore.Current
            .Instance
            .GetCollection("contacts")
            .GetDocument(contact.id)
            .GetCollection("conversations")
            .GetDocument(ID)
            .SetDataAsync(conversation);

            messageEditor.Text = "";
        }