public static async Task <bool> AddChatMessage(ChatDetailListModel chatModel) { try { await firebase .Child("Chat").Child(chatModel.SenderUserId.ToString()).Child(chatModel.RecieverUserId.ToString()).PostAsync(chatModel); var chatModel1 = new ChatDetailListModel() { IsSender = !chatModel.IsSender, RecieverUserId = chatModel.SenderUserId, SenderUserId = chatModel.RecieverUserId, UserMessage = chatModel.UserMessage, UserMessageTime = chatModel.UserMessageTime, TimeStamp = chatModel.TimeStamp }; await firebase .Child("Chat").Child(chatModel1.SenderUserId.ToString()).Child(chatModel1.RecieverUserId.ToString()).PostAsync(chatModel1); return(true); } catch (Exception ex) { Console.WriteLine("AddingChatToFirebase_Exception:- " + ex.Message); return(false); } }
public async void AddMessageFirebase(ChatDetailListModel item) { try { if (Common.CheckConnection()) { Chatdetailresponse response; try { response = await _webApiRestClient.GetAsync <Chatdetailresponse>(string.Format(ApiUrl.AddGroupChatRequest, JobData.job_id, Convert.ToInt32(Enums.UserTypeEnum.Customer))); } catch (Exception ex) { Console.WriteLine("SendMsgApi_Exception:- " + ex.Message); response = null; IsBackPress = true; await MaterialDialog.Instance.SnackbarAsync(message : AppResource.error_ServerError, msDuration : 3000); return; } if (response != null) { if (response.status) { MessagingCenter.Send("", "ScrollToEnd"); MessageEntry = string.Empty; var data = await FirebaseChatHelper.AddChatMessageForGroup(item, "GroupChat"); } else if (response.message == null) { MessagingCenter.Send("", "ScrollToEnd"); MessageEntry = string.Empty; var data = await FirebaseChatHelper.AddChatMessageForGroup(item, "GroupChat"); } else { await MaterialDialog.Instance.SnackbarAsync(message : response.message, msDuration : 3000); } 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; msgItem.ID = msgID; BsonValue bsonid = msgID; groupChatMessagesDbService.UpdateGroupChatDataInDb(bsonid, msgItem); } else { groupChatMessagesDbService.CreateGroupChatDataInDB(msgItem); } } else { groupChatMessagesDbService.CreateGroupChatDataInDB(msgItem); } } IsBackPress = true; } else { await MaterialDialog.Instance.SnackbarAsync(message : AppResource.error_InternetError, msDuration : 3000); } } catch (Exception ex) { //await MaterialDialog.Instance.SnackbarAsync(message: ex.Message, // msDuration: 3000); IsBackPress = true; Console.WriteLine("SendMsgCommand_Exception:- " + ex.Message); } }
public async void AddMessagetoFirebase() { try { if (Common.CheckConnection()) { var item = new ChatDetailListModel() { sender_user_id = user_id, job_id = JobData.job_id, coordinator_id = JobData.coordinator_id, worker_id = JobData.worker_id, customer_id = null, sender_user_Name = user_name, coordinator_Name = !string.IsNullOrEmpty(JobData.coordinator_Name) ? AppResource.coordinator_Name : JobData.coordinator_Name, job_Name = ChatDetailTitle, receiver_user_Name = null, worker_Name = JobData.worker_Name, customer_Name = null, image_url = null, file_url = null, is_file = false, is_image = false, is_loading = false, IsViewBtnVisible = false, is_message = true, msg_datetime = DateTime.Now, user_message = MessageEntry, user_message_time = DateTime.Now.ToString("dd/MM/yyyy, hh:mm:ss tt"), is_sender = true, time_stamp = DependencyService.Get <IGetTimeStamp>().TimeStamp() }; //var request = new ChatDetailModelApi() //{ // from_user_id = user_id, // to_user_id = JobData.job_id //}; Chatdetailresponse response; try { MessageEntry = string.Empty; response = await _webApiRestClient.GetAsync <Chatdetailresponse>(string.Format(ApiUrl.AddGroupChatRequest, JobData.job_id, Convert.ToInt32(Enums.UserTypeEnum.Customer))); } catch (Exception ex) { Console.WriteLine("SendMsgApi_Exception:- " + ex.Message); response = null; await MaterialDialog.Instance.SnackbarAsync(message : AppResource.error_ServerError, msDuration : 3000); return; } if (response != null) { if (response.status) { try { AllChatDetailList.Add(item); } catch (Exception ex) { } ChatDetailList = AllChatDetailList; MessagingCenter.Send("", "ScrollToEnd"); MessageEntry = string.Empty; var data = await FirebaseChatHelper.AddChatMessageForGroup(item, "GroupChat"); } else if (response.message == null) { try { AllChatDetailList.Add(item); } catch (Exception ex) { } ChatDetailList = AllChatDetailList; MessagingCenter.Send("", "ScrollToEnd"); MessageEntry = string.Empty; var data = await FirebaseChatHelper.AddChatMessageForGroup(item, "GroupChat"); } else { await MaterialDialog.Instance.SnackbarAsync(message : response.message, msDuration : 3000); } 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; msgItem.ID = msgID; BsonValue bsonid = msgID; groupChatMessagesDbService.UpdateGroupChatDataInDb(bsonid, msgItem); } else { groupChatMessagesDbService.CreateGroupChatDataInDB(msgItem); } } else { groupChatMessagesDbService.CreateGroupChatDataInDB(msgItem); } } } else { await MaterialDialog.Instance.SnackbarAsync(message : AppResource.error_InternetError, msDuration : 3000); } } catch (Exception ex) { //await MaterialDialog.Instance.SnackbarAsync(message: ex.Message, // msDuration: 3000); Console.WriteLine("SendMsgCommand_Exception:- " + ex.Message); } }
public static async Task<bool> AddChatMessageForGroup(ChatDetailListModel chatModel, string firebasechatname) { try { //For Customer await firebase .Child(firebasechatname).Child(chatModel.job_id.ToString()).Child(chatModel.sender_user_id.ToString()).PostAsync(chatModel); //For Coordinator var chatModel_Coordinator = new ChatDetailListModel() { is_sender = !chatModel.is_sender, job_id = chatModel.job_id, sender_user_id = chatModel.coordinator_id, coordinator_id = null, customer_id = chatModel.sender_user_id, worker_id = chatModel.worker_id, job_Name = chatModel.job_Name, sender_user_Name = chatModel.coordinator_Name, coordinator_Name = null, file_url = chatModel.file_url, image_url = chatModel.image_url, is_loading = false, is_message = chatModel.is_message, msg_datetime = chatModel.msg_datetime, receiver_user_Name = chatModel.sender_user_Name, customer_Name = chatModel.sender_user_Name, worker_Name = chatModel.worker_Name, user_message = chatModel.user_message, user_message_time = chatModel.user_message_time, file_name = chatModel.file_name, is_image = chatModel.is_image, is_file = chatModel.is_file, time_stamp = chatModel.time_stamp }; await firebase .Child(firebasechatname).Child(chatModel_Coordinator.job_id.ToString()).Child(chatModel_Coordinator.sender_user_id.ToString()).PostAsync(chatModel_Coordinator); // For worker if (chatModel.worker_id.HasValue && chatModel.worker_id.Value > 0) { var chatModel_Worker = new ChatDetailListModel() { is_sender = !chatModel.is_sender, job_id = chatModel.job_id, sender_user_id = chatModel.worker_id, coordinator_id = chatModel.coordinator_id, customer_id = chatModel.sender_user_id, worker_id = null, sender_user_Name = chatModel.worker_Name, coordinator_Name = chatModel.coordinator_Name, customer_Name = chatModel.sender_user_Name, job_Name = chatModel.job_Name, worker_Name = null, file_url = chatModel.file_url, image_url = chatModel.image_url, is_loading = false, is_message = chatModel.is_message, msg_datetime = chatModel.msg_datetime, receiver_user_Name = chatModel.sender_user_Name, user_message = chatModel.user_message, user_message_time = chatModel.user_message_time, file_name = chatModel.file_name, is_image = chatModel.is_image, is_file = chatModel.is_file, time_stamp = chatModel.time_stamp }; await firebase .Child(firebasechatname).Child(chatModel_Worker.job_id.ToString()).Child(chatModel_Worker.sender_user_id.ToString()).PostAsync(chatModel_Worker); } // Common(admin/finance officer viewing) var chatModel_Common = new ChatDetailListModel() { is_sender = !chatModel.is_sender, job_id = chatModel.job_id, sender_user_id = 0, coordinator_id = chatModel.coordinator_id, customer_id = chatModel.sender_user_id, worker_id = chatModel.worker_id, job_Name = chatModel.job_Name, sender_user_Name = chatModel.sender_user_Name, coordinator_Name = chatModel.coordinator_Name, file_url = chatModel.file_url, image_url = chatModel.image_url, is_loading = false, is_message = chatModel.is_message, msg_datetime = chatModel.msg_datetime, receiver_user_Name = null, customer_Name = chatModel.sender_user_Name, worker_Name = chatModel.worker_Name, user_message = chatModel.user_message, user_message_time = chatModel.user_message_time, file_name = chatModel.file_name, is_image = chatModel.is_image, is_file = chatModel.is_file, time_stamp = chatModel.time_stamp }; await firebase .Child(firebasechatname).Child(chatModel_Common.job_id.ToString()).Child(chatModel_Common.sender_user_id.ToString()).PostAsync(chatModel_Common); return true; } catch (Exception ex) { Console.WriteLine("AddingChatToFirebase_Exception:- " + ex.Message); return false; } }