public async Task <ChatConversation> SendMessageToChat(string appId, string chatId, string userId, string message) { var user = await _userRepository.GetAsync(appId, userId); var chat = await _chatRepository.GetAsync(appId, chatId); if (chat != null) { var chatConversation = new ChatConversation() { Id = ObjectId.GenerateNewId().ToString(), UserId = user.Id, Date = DateTime.Now, Text = message, ChatConversationReaders = new List <ChatConversationReader> (), User = new User() { Id = user.Id, FullName = user.FullName } }; await _chatRepository.AddMessageToChatAsync(chatId, chatConversation); return(chatConversation); } return(null); }
public void UpdateChat(ChatConversation chatConversation) { var newchatConversation = this.searchItems.Where(a => a.ChatId == chatConversation.ChatId).FirstOrDefault(); int index = this.searchItems.IndexOf(newchatConversation); this.searchItems[index] = chatConversation; }
private void _objChatSignalRService_OnGetGroupCreateStatusRecieved(object sender, GroupResponseViewModel e) { try { if (e.GroupId != 0) { GroupRepository.SaveGroupCreated(e); ChatModel cm = new ChatModel(); cm.ChatId = e.ChatModel.ChatId; cm.GroupId = e.ChatModel.GroupId; cm.Message = e.ChatModel.Message; cm.LastActiveTime = e.ChatModel.LastActiveTime; ChatConversation chatConversation = ChatConversationRepository.SaveGroupConverstionNewFromServer(cm); if (chatConversation != null) { Activity.RunOnUiThread(() => { MessageReceived(chatConversation, "NewChat"); }); } } } catch (Java.Lang.Exception ex) { Crashes.TrackError(ex); } }
public void UpdateCell(ChatConversation chatConversation) { this.chatConversation = chatConversation; if (chatConversation != null) { CommonHelper.SetCircularImage(contactPic); var BlockListContact = Repositories.ContactRepository.GetContactbyUserId(Convert.ToInt32(chatConversation.ChatId)); if (BlockListContact != null) { txtSenderName.Text = BlockListContact.screenName; if (BlockListContact.contactPicUrl == "") { contactPic.SetImage(new NSUrl(BlockListContact.contactPicUrl), UIImage.FromBundle("default_profile.png")); } else { contactPic.Image = new UIImage("default_profile.png"); } btnUnblock.TouchUpInside += BtnUnblock_TouchUpInside; } } }
private void _adapter_ItemClick(object sender, ChatConversation e) { try { var ChatCon = e; if (ChatCon != null) { var ContactUser = ContactRepository.GetContactbyUserId(Convert.ToInt64(ChatCon.ContactId)); var ContactView = new ContactViewModel { ContactId = (long)ChatCon.ContactId, ChatId = ChatCon.ChatId, ProfileImageUrl = ContactUser.contactPicUrl, IsBlock = e.IsBlock, ChatConvId = e.id }; if (ContactView != null) { var intent = new Intent(Context, typeof(PrivateMessageActivity)); intent.AddFlags(ActivityFlags.SingleTop); intent.PutExtra("ContactObject", JsonConvert.SerializeObject(ContactView)); StartActivity(intent); } } } catch (Exception ex) { Dictionary <string, string> dicVar = new Dictionary <string, string>(); dicVar.Add("Index", e.ToString()); dicVar.Add("Chat Count", Chats.Count.ToString()); Crashes.TrackError(ex, dicVar); } }
public ChatMenuItemControl(ChatConversation ChatConversation) { this.InitializeComponent(); this.ChatConversation = ChatConversation; Load(); }
public async Task AddMessageToChatAsync(string chatId, ChatConversation conversation) { try { await _chats.FindOneAndUpdateAsync(Builders <Chat> .Filter.Eq("Id", chatId), Builders <Chat> .Update.Push("ChatConversations", conversation)); } catch (Exception ex) { _logger.LogError(ex, "AddMessageToChatAsync ChatRepository Exception"); } }
public void SelectConversation(ChatContact contact) { ChatConversation conversation; if (!ConversationsMap.TryGetValue(contact.ID, out conversation)) { conversation = new ChatConversation(contact); ConversationsMap.Add(contact.ID, conversation); } SelectConversation(conversation); }
public void update(ChatConversation Conv) { if (originalChat.Count > 0) { var PreviousMessage = originalChat.Where(a => a.ChatId == Conv.ChatId).FirstOrDefault(); if (PreviousMessage != null) { originalChat.Remove(PreviousMessage); originalChat.Insert(0, Conv); } } }
private void MessageReceived(ChatConversation chatConversation, string ProcessType) { if (ProcessType == "OldChat") { chatsource.UpdateChat(chatConversation); tblChatList.ReloadData(); } else { chatsource.AddChat(chatConversation); tblChatList.ReloadData(); } }
internal static async Task SaveConversationAsync(ChatConversation chatConversation) { var count = await GetCountAsync <ChatConversation>(m => m.Id == chatConversation.Id).ConfigureAwait(false); if (count == 0) { await AddAsync <ChatConversation>(chatConversation).ConfigureAwait(false); } else { await UpdateAsync <ChatConversation>(chatConversation).ConfigureAwait(false); } }
public void SendNewChatImageMessage(ChatConversation conversation, string messageBody, string image) { var msg = new ChatImageMessage(conversation.Other, Me, messageBody, image); //add message to conversation view conversation.Messages.Add(msg); //add message to database DatabaseController.Insert(msg); //send message to networking SendMessage?.Invoke(typeof(ChatImageMessage), msg); SortConversations(); }
public static ChatConversation SaveGroupConverstionNewFromServer(ChatModel chatViewModel) { var db = new SQLiteConnection(CommonConstant.DBPath); ChatConversation mdchatconversation = null; try { var chatConversationResponce = GetConversationbyGroupId((long)chatViewModel.GroupId); if (chatConversationResponce.success) { if (chatConversationResponce.chatConversation == null) { chatConversationResponce.chatConversation = new ChatConversation { GroupId = chatViewModel.GroupId, LastMessage = chatViewModel.Message, LastMessageDate = TimeZone.CurrentTimeZone.ToLocalTime(Convert.ToDateTime(chatViewModel.LastActiveTime)), ChatId = chatViewModel.ChatId, IsGroup = true, UserId = CommonHelper.GetUserId() }; db.Insert(chatConversationResponce.chatConversation); mdchatconversation = chatConversationResponce.chatConversation; } else { chatConversationResponce.chatConversation.LastMessage = chatViewModel.Message; chatConversationResponce.chatConversation.LastMessageDate = TimeZone.CurrentTimeZone.ToLocalTime(Convert.ToDateTime(chatViewModel.LastActiveTime)); chatConversationResponce.chatConversation.IsGroup = true; chatConversationResponce.chatConversation.UserId = CommonHelper.GetUserId(); db.Update(chatConversationResponce.chatConversation); mdchatconversation = chatConversationResponce.chatConversation; } } db.Commit(); } catch (Exception ex) { Crashes.TrackError(ex); Console.WriteLine(ex.Message, ex); } db.Close(); return(mdchatconversation); }
public static ChatConversation GetConversationbyContactId(long contactId) { ChatConversation chatConv = null; var db = new SQLiteConnection(CommonConstant.DBPath); try { chatConv = db.Query <ChatConversation>("select * from 'ChatConversation' where ContactId=" + contactId + " and UserId=" + CommonHelper.GetUserId()) .FirstOrDefault(); } catch (Exception ex) { Console.WriteLine(ex.Message, ex); } db.Close(); return(chatConv); }
public async Task <IHttpActionResult> EnsureConversation(string Destination) { if (string.IsNullOrWhiteSpace(Destination)) { return(BadRequest("You must provide a destination id.")); } var filters = Builders <ChatConversation> .Filter; var user = UserManager.FindByName(User.Identity.Name); var partner = await UserManager.FindByIdAsync(Destination); var collection = IlevusDBContext.Create().GetConversationsCollection(); var first = string.Compare(partner.Id, user.Id) > 0 ? user : partner; var second = string.Compare(partner.Id, user.Id) < 0 ? user : partner; try { var results = await collection.FindAsync( filters.And( filters.Eq("FirstUser", first.Id), filters.Eq("SecondUser", second.Id) ) ); var conversation = await results.FirstOrDefaultAsync(); if (conversation != null) { return(Ok(new ChatConversationViewModel(conversation, partner))); } conversation = new ChatConversation() { FirstUser = first.Id, SecondUser = second.Id }; await collection.InsertOneAsync(conversation); return(Ok(new ChatConversationViewModel(conversation, partner))); } catch (Exception e) { return(InternalServerError(e)); } }
private async Task <BitmapImage> GetPhoto(ContactStore contactStore, ChatConversation item) { try { var contact = await contactStore.GetContactAsync(item.ThreadingInfo.ContactId); var photo = await contact.LargeDisplayPicture.OpenReadAsync(); var img = new BitmapImage(); await img.SetSourceAsync(photo); return(img); } catch { return(null); //var img = new BitmapImage(new Uri("ms-appx:///Assets/StoreLogo.png")); //return img; } }
public static ChatConversation GetConversationbyConversationId(long id) { var chatConv = new ChatConversation(); var db = new SQLiteConnection(CommonConstant.DBPath); try { //chatConv = db.Query<ChatConversation> ("select * from 'ChatConversation' where ChatId=" + Chatid + " Order By ID Desc").FirstOrDefault (); chatConv = db.Query <ChatConversation>("select * from 'ChatConversation' where id=" + id + " and UserId=" + CommonHelper.GetUserId()) .ToList() .FirstOrDefault(); } catch (Exception ex) { Console.WriteLine(ex.Message, ex); } db.Close(); return(chatConv); }
public void AddMessage(ChatMessage msg) { var other = (Me == msg.RecipientID ? msg.SenderID : msg.RecipientID); ChatConversation conversation; if (!ConversationsMap.TryGetValue(other, out conversation)) { ChatContact contact; if (!ContactsMap.TryGetValue(other, out contact)) { contact = new ChatContact(other, "no name"); ContactsMap.Add(other, contact); } conversation = new ChatConversation(contact); ConversationsMap.Add(other, conversation); } conversation.Messages.Add(msg); }
private void MessageReceived(ChatConversation chatConversation, string ProcessType) { try { if (ProcessType == "OldChat") { _adapter.update(chatConversation); _adapter.NotifyDataSetChanged(); } else { _adapter.add(chatConversation); _adapter.NotifyDataSetChanged(); } } catch (Exception ex) { Crashes.TrackError(ex); } }
public static ChatConversation GetConversationIdbyChatId(long chatid) { ChatConversation chatConv = null; var db = new SQLiteConnection(CommonConstant.DBPath); try { var res = db.Query <ChatConversation>("select * from 'ChatConversation' where chatid=" + chatid + " and UserId=" + CommonHelper.GetUserId()).ToList(); var ch = res.FirstOrDefault(); chatConv = ch; //Console.WriteLine("Chat Conversation Id => "+a.ChatId); } catch (Exception ex) { Console.WriteLine(ex.Message, ex); } db.Close(); return(chatConv); }
public static ChatConversation SaveGroupConverstionNewFromServer(ChatModel chatViewModel) { var db = new SQLiteConnection(CommonConstant.DBPath); ChatConversation mdchatconversation = null; try { mdchatconversation = GetConversationbyGroupId((long)chatViewModel.GroupId); if (mdchatconversation == null) { mdchatconversation = new ChatConversation { GroupId = chatViewModel.GroupId, LastMessage = chatViewModel.Message, LastMessageDate = chatViewModel.LastActiveTime, ChatId = chatViewModel.ChatId, IsGroup = true, UserId = CommonHelper.GetUserId() }; db.Insert(mdchatconversation); } else { mdchatconversation.LastMessage = chatViewModel.Message; mdchatconversation.LastMessageDate = chatViewModel.LastActiveTime; mdchatconversation.IsGroup = true; mdchatconversation.UserId = CommonHelper.GetUserId(); db.Update(mdchatconversation); } db.Commit(); } catch (Exception ex) { Console.WriteLine(ex.Message, ex); } db.Close(); return(mdchatconversation); }
private void _adapter_GroupChatItemClick(object sender, ChatConversation e) { try { var ChatCon = e; if (ChatCon != null) { if (_objChatSignalRService.disconnectUser().IsCompleted) { var GroupModel = GroupRepository.GetGroupByID(Convert.ToInt64(ChatCon.GroupId)); // var ContactView = new ContactViewModel { ContactId = (long)ChatCon.ContactId, ChatId = ChatCon.ChatId, ProfileImageUrl = ContactUser.contactPicUrl }; if (GroupModel != null) { var intent = new Intent(Context, typeof(GroupMessageActivity)); intent.PutExtra("GroupObject", JsonConvert.SerializeObject(GroupModel)); StartActivity(intent); } } } } catch (Exception ex) { Crashes.TrackError(ex); } }
protected override async void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); var args = e.Parameter as ChatConversation; if (args != null) { convo = args; } var contact = await ContactUtils.BindPhoneNumberToGlobalContact(convo.Participants.First()); ConvoTitle.Text = contact.DisplayName; ConvoPic.Contact = contact; var reader = convo.GetMessageReader(); var messages = await reader.ReadBatchAsync(); messages.ToList().ForEach(x => observableCollection.Insert(0, new ChatMessageViewControl(x))); Load(); }
public void Init() { instance = new ChatConversation(); }
public ChatConversationEvents(ChatConversation This) { this.This = This; }
public removeContactButtonClickListener(ChatConversation item, Activity context) { this.item = item; this.context = context; }
public void AddChat(ChatConversation chatConversation) { this.searchItems.Add(chatConversation); }
public void add(ChatConversation book) { originalChat.Add(book); }
public void SelectConversation(ChatConversation conversation) { CurrentConversation = conversation; }
public async void ButtonSendChatMessage() { try { if (!string.IsNullOrEmpty(txtChatSendMessage.Text) || lstAttachments.Count > 0) { txtChatSendMessage.Text = txtChatSendMessage.Text.Trim(' ', '\n'); var chatModel = new ChatMessageViewModel { Attachments = lstAttachments ?? new List <AttachmentViewModel>(), ContactId = contactId, Message = txtChatSendMessage.Text, IsRead = false, IsRecieved = false, IsSend = false, MessageTime = DateTime.Now.ToUniversalTime() }; chatConversation = ChatConversationRepository.GetConversationbyContactId(contactId); if (chatConversation != null) { var message = ChatMessageRepository.SaveChatMessage(chatModel, chatConversation.ChatId); chatModel.MobiledatabaseId = message.id; chatModel.ChatId = chatConversation.ChatId; chatModel.IsRead = false; chatModel.IsRecieved = false; chatModel.IsSend = false; mAdapter.add(message); mAdapter.NotifyDataSetChanged(); mRecyclerView.ScrollToPosition(mAdapter.ItemCount - 1); txtChatSendMessage.Text = ""; } lstAttachments = new List <AttachmentViewModel>(); txtChatSendMessage.Text = ""; try { var result = await new ChatService().PostChat(chatModel); if (result.Status == 2 || result.Status == 1) { var ChatResponse = JsonConvert.DeserializeObject <PostChatResponseViewModel>(result.Response.ToString()); if (chatConversation == null) { ChatConversationRepository.SaveConverstionNewFromServer(ChatResponse.Chat); chatConversation = ChatConversationRepository.GetConversationbyContactId(contactId); ChatConversationRepository.UpdateChatLastMessage(chatConversation.id, ChatResponse.ChatMessage.Message, ""); var savedMessages = ChatMessageRepository.SaveChatMessage(ChatResponse.ChatMessage, chatConversation.ChatId); LoadLocalLatestMessages(); txtChatSendMessage.Text = ""; Console.WriteLine("CHAT POSTED : " + result); } else { chatConversation = ChatConversationRepository.GetConversationbyContactId(contactId); ChatConversationRepository.UpdateChatLastMessage(chatConversation.id, ChatResponse.ChatMessage.Message, ""); var savedMessages = ChatMessageRepository.updateChatMessage(ChatResponse.ChatMessage); LoadLocalLatestMessages(); await _objChatSignalRService.Send(chatConversation.ContactId.ToString(), ChatResponse.ChatMessage); } } } catch (Exception ex) { Crashes.TrackError(ex); } } } catch (Exception ex) { Crashes.TrackError(ex); } }
protected override void OnCreate(Bundle savedInstanceState) { try { base.OnCreate(savedInstanceState); AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException; TaskScheduler.UnobservedTaskException += TaskSchedulerOnUnobservedTaskException; SetContentView(Resource.Layout.ChatMessagelayout); var requiredPermissions = new String[] { Manifest.Permission.Internet, Manifest.Permission.WriteExternalStorage, Manifest.Permission.ReadExternalStorage, Manifest.Permission.Camera, Manifest.Permission.ReadContacts }; ActivityCompat.RequestPermissions(this, requiredPermissions, REQUEST_LOCATION); var toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.app_bar); SetSupportActionBar(toolbar); //SupportActionBar.SetDisplayHomeAsUpEnabled(true); //SupportActionBar.SetHomeButtonEnabled(true); //SupportActionBar.SetDisplayUseLogoEnabled(true); ////SupportActionBar.SetIcon(Resource.Drawable.logo512_512); LinearLayout li_toolbarDetails = FindViewById <LinearLayout>(Resource.Id.li_toolbarDetails); CircleImageView IV_Userlogo = FindViewById <CircleImageView>(Resource.Id.iv_customforUserlogo); CircleImageView _IVarrow_back_white = FindViewById <CircleImageView>(Resource.Id.iv_arrow_back_white); TextView toolbar_title = FindViewById <TextView>(Resource.Id.toolbar_title); li_toolbarDetails.Click += Li_toolbarDetails_Click; IV_Userlogo.Click += IV_Userlogo_Click; toolbar_title.Click += Toolbar_title_Click; _IVarrow_back_white.Click += _IVarrow_back_white_Click; // Create your application here ContactObject = JsonConvert.DeserializeObject <ContactViewModel>(Intent.GetStringExtra("ContactObject")); if (ContactObject != null) { ContactName = ContactRepository.GetContactbyUserId(ContactObject.ContactId).name; contactId = ContactObject.ContactId; toolbar_title.Text = ContactName; } if (ContactObject.ProfileImageUrl != null && ContactObject.ProfileImageUrl != "") { Picasso.With(this) .Load(ContactObject.ProfileImageUrl) .Resize(100, 100) .CenterCrop().Placeholder(Resource.Drawable.default_profile) .Into(IV_Userlogo); } else { IV_Userlogo.SetBackgroundResource(Resource.Drawable.default_profile); } txtChatSendMessage = FindViewById <EditText>(Resource.Id.txtSendMessage); btnAttachment = (Button)FindViewById(Resource.Id.btnextra_msg); btnSendButton = FindViewById <Button>(Resource.Id.btnsend_msg); ButtonLayout = FindViewById <LinearLayout>(Resource.Id.linearLayout3); txtChatSendMessage.TextChanged += TxtChatSendMessage_TextChanged; mySwipeRefreshLayout = FindViewById <SwipeRefreshLayout>(Resource.Id.swiperefresh); var refreshListEvent = new SwipeRefreshLayoutPrivateMessage(this); mySwipeRefreshLayout.SetOnRefreshListener(refreshListEvent); refreshListEvent.LoadMoreEvent += RefreshListEvent_LoadMoreEvent; mRecyclerView = FindViewById <RecyclerView>(Resource.Id.recyclerView); if (mRecyclerView != null) { mRecyclerView.HasFixedSize = true; var layoutManager = new LinearLayoutManager(this); mRecyclerView.SetLayoutManager(layoutManager); } imgCamera_msg = FindViewById <ImageView>(Resource.Id.imgCamera_msg); chatConversation = ChatConversationRepository.GetConversationbyContactId(ContactObject.ContactId); btnSendButton.Click += btnSendButton_Click; btnAttachment.Click += BtnAttachment_Click; imgCamera_msg.Click += ImgCamera_msg_Click; } catch (Exception e) { Crashes.TrackError(e); } }