コード例 #1
0
        private async void GetChatList()
        {
            try
            {
                chatlistdetail = await FirebaseChatHelper.GetChatForGroup("GroupChat", user_id, JobData.job_id);
            }
            catch (Exception ex)
            {
                chatlistdetail = new List <ChatDetailListModel>();
                //await MaterialDialog.Instance.SnackbarAsync(AppResource.error_ServerError, 3000);
            }

            if (AllChatDetailList != null && AllChatDetailList.Count == chatlistdetail.Count)
            {
            }
            else
            {
                AllChatDetailList = new ObservableCollection <ChatDetailListModel>(chatlistdetail);
                ChatDetailList    = AllChatDetailList;
                COUNT             = ChatDetailList.Count;
                MessagingCenter.Send("", "ScrollToEnd");
                MessagingCenter.Unsubscribe <string, int>(this, "ChatDetailTitle");


                var msgItem = new GroupChatDBModel()
                {
                    GroupJobId       = JobData.job_id,
                    UserMessagesList = ChatDetailList
                };
                if (groupChatMessagesDbService.IsGroupChatPresentInDB())
                {
                    var newmsgItem = groupChatMessagesDbService.ReadAllItems().Where(x => x.GroupJobId == JobData.job_id).ToList();
                    if (newmsgItem != null && newmsgItem.Count > 0)
                    {
                        var       msgID  = newmsgItem.FirstOrDefault().ID;
                        BsonValue bsonid = msgID;
                        groupChatMessagesDbService.UpdateGroupChatDataInDb(bsonid, msgItem);
                    }
                    else
                    {
                        groupChatMessagesDbService.CreateGroupChatDataInDB(msgItem);
                    }
                }
                else
                {
                    groupChatMessagesDbService.CreateGroupChatDataInDB(msgItem);
                }
            }
            if (ChatDetailList != null && ChatDetailList.Count > 0)
            {
                ToolbarIcon = "resource://Khadamat_CustomerApp.SvgImages.toolbar.svg";
            }
            else
            {
                ToolbarIcon = string.Empty;
            }

            chatTimer = new Timer(_ => UpdateChatFromFirebase(), null, 0, 1000);
        }
コード例 #2
0
        private async void UpdateChatFromFirebase()
        {
            try
            {
                try
                {
                    chatlistdetail = await FirebaseChatHelper.GetChatForGroup("GroupChat", user_id, JobData.job_id);
                }
                catch (Exception ex)
                {
                    chatlistdetail = new List <ChatDetailListModel>();
                }
                if (chatlistdetail.Count > ChatDetailList.Count)
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        MakeGroupChatRead();
                    });
                    updatechatlistdetail = chatlistdetail.Skip(ChatDetailList.Count).ToList();
                    try
                    {
                        foreach (var item in updatechatlistdetail)
                        {
                            AllChatDetailList.Add(item);
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                    ChatDetailList = AllChatDetailList;
                    COUNT          = ChatDetailList.Count;
                    MessagingCenter.Send("", "ScrollToEnd");


                    var msgItem = new GroupChatDBModel()
                    {
                        GroupJobId       = JobData.job_id,
                        UserMessagesList = ChatDetailList
                    };
                    if (groupChatMessagesDbService.IsGroupChatPresentInDB())
                    {
                        var newmsgItem = groupChatMessagesDbService.ReadAllItems().Where(x => x.GroupJobId == JobData.job_id).ToList();
                        if (newmsgItem != newmsgItem)
                        {
                            var       msgID  = newmsgItem.FirstOrDefault().ID;
                            BsonValue bsonid = msgID;
                            groupChatMessagesDbService.UpdateGroupChatDataInDb(bsonid, msgItem);
                        }
                        else
                        {
                            groupChatMessagesDbService.CreateGroupChatDataInDB(msgItem);
                        }
                    }
                    else
                    {
                        groupChatMessagesDbService.CreateGroupChatDataInDB(msgItem);
                    }
                }

                if (ChatDetailList != null && ChatDetailList.Count > 0)
                {
                    ToolbarIcon = "resource://Khadamat_CustomerApp.SvgImages.toolbar.svg";
                }
                else
                {
                    ToolbarIcon = string.Empty;
                }
            }
            catch (Exception ex)
            {
            }
        }