Пример #1
0
 public async Task SendGroup(GroupMessageResponseViewModel message, long groupid)
 {
     try
     {
         _proxy.Invoke("SendGroupMessage", message, groupid);
     }
     catch (Exception ex)
     { }
 }
Пример #2
0
 public async void UpdateGroupChatMessage(string contactid, GroupMessageResponseViewModel model, string privatemsg)
 {
     try
     {
         GroupMessageStatusViewModel _model = new GroupMessageStatusViewModel();
         _model.GroupMessageId = model.MessageId;
         await _objChatSignalRService.SendGroupMessageUpdate(contactid, _model, privatemsg);
     }
     catch (Exception ex)
     {
     }
 }
Пример #3
0
        public static GroupMessage UpdateGroupMessage(GroupMessageResponseViewModel grpMessage)
        {
            var          db     = new SQLiteConnection(CommonConstant.DBPath);
            GroupMessage grpMsg = null;

            try
            {
                if (grpMessage != null)
                {
                    grpMsg = getGroupMessagebyid(grpMessage.MobileDatabaseId);
                    if (grpMsg != null)
                    {
                        grpMsg.GroupId      = grpMessage.GroupId;
                        grpMsg.MessageId    = grpMessage.MessageId;
                        grpMsg.MessageText  = grpMessage.Message;
                        grpMsg.MessageTime  = TimeZone.CurrentTimeZone.ToLocalTime(Convert.ToDateTime(grpMessage.MessageTime));
                        grpMsg.senderName   = grpMessage.SenderProfileName;
                        grpMsg.senderPicUrl = grpMessage.SenderProfilePicUrl;
                        grpMsg.SenderUserId = grpMessage.SenderId;
                        grpMsg.UserId       = CommonHelper.GetUserId();


                        db.Update(grpMsg);
                        if (grpMessage.Attachments.Count > 0)
                        {
                            SaveAttachmentFromServer(grpMessage.Attachments, grpMsg.GroupId,
                                                     grpMsg.MessageId);
                        }

                        if (grpMessage.GroupMessageStatuses.Count > 0)
                        {
                            SaveOrUpdateGroupMessageStatusFromServer(grpMessage.GroupMessageStatuses,
                                                                     grpMsg.MessageId);
                        }
                    }

                    db.Commit();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message, ex);
            }
            db.Close();
            return(grpMsg);
        }
Пример #4
0
        public static GroupMessage SaveGroupMessage(GroupMessageResponseViewModel grpMessage, string From)
        {
            var          db     = new SQLiteConnection(CommonConstant.DBPath);
            GroupMessage grpMsg = null;

            try
            {
                if (grpMessage != null)
                {
                    grpMsg = new GroupMessage
                    {
                        GroupId      = grpMessage.GroupId,
                        MessageId    = grpMessage.MessageId,
                        MessageText  = grpMessage.Message,
                        MessageTime  = TimeZone.CurrentTimeZone.ToLocalTime(Convert.ToDateTime(grpMessage.MessageTime)),
                        senderName   = grpMessage.SenderProfileName,
                        senderPicUrl = grpMessage.SenderProfilePicUrl,
                        SenderUserId = grpMessage.SenderId,
                        IsRead       = (From == "Private") ? true : false,
                        UserId       = CommonHelper.GetUserId()
                    };
                    db.Insert(grpMsg);
                    if (grpMessage.Attachments.Count > 0)
                    {
                        SaveAttachmentFromServer(grpMessage.Attachments,
                                                 grpMessage.GroupId, grpMessage.MessageId);
                    }

                    db.Commit();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message, ex);
            }
            db.Close();
            return(grpMsg);
        }
 private void _objChatSignalRService_OnGroupMessageReceived(object sender, GroupMessageResponseViewModel e)
 {
     try
     {
         if (e.MessageId != 0)
         {
             var chatmessage = GroupRepository.CheckGroupChatMessage(e.MessageId, e.GroupId);
             if (chatmessage == null)
             {
                 GroupRepository.SaveGroupMessage(e, "Private");
                 InvokeOnMainThread(() =>
                 {
                     LoadLocalLatestMessages();
                 });
                 UpdateGroupChatMessage(e.SenderId.ToString(), e, "Private");
             }
         }
     }
     catch (Exception ex)
     {
         //Toast.MakeText(this, ex.ToString(), ToastLength.Long).Show();
     }
 }
        public async void ButtonSendChatMessage(string sMessageText)
        {
            try
            {
                if (!string.IsNullOrEmpty(sMessageText))
                {
                    var GroupTempSaveMessage = new GroupMessageResponseViewModel
                    {
                        GroupId     = contactViewModel.GroupId,
                        Message     = sMessageText.Trim(' ', '\n'),
                        Attachments = lstAttachments ?? new List <AttachmentViewModel>(),
                        SenderId    = CommonHelper.GetUserId(),
                        MessageTime = DateTime.Now.ToUniversalTime()
                    };

                    var message   = GroupRepository.SaveGroupMessage(GroupTempSaveMessage, "Private");
                    var GroupSend = new GroupMessageRequestViewModel
                    {
                        GroupId          = contactViewModel.GroupId,
                        Message          = sMessageText.Trim(' ', '\n'),
                        Attachments      = lstAttachments ?? new List <AttachmentViewModel>(),
                        MobileDatabaseId = message.id
                    };


                    lstAttachments = new List <AttachmentViewModel>();
                    try
                    {
                        var result = await new GroupChatService().PostGroupMessageService(GroupSend);

                        if (result.Status == 1)
                        {
                            var GroupMessagelist = JsonConvert.DeserializeObject <GroupMessageResponseViewModel>(result.Response.ToString());
                            Console.WriteLine("posted successfully in grp");

                            var chatConversationResponce = ChatConversationRepository.GetConversationbyGroupId(GroupMessagelist.GroupId);
                            if (chatConversationResponce.success)
                            {
                                ChatConversationRepository.UpdateChatLastMessage(chatConversationResponce.chatConversation.id, GroupMessagelist.Message, GroupMessagelist.SenderProfileName);
                            }
                            var savedItem = GroupRepository.UpdateGroupMessage(GroupMessagelist);
                            await _objChatSignalRService.SendGroup(GroupMessagelist, GroupMessagelist.GroupId);

                            LoadLocalLatestMessages();
                        }
                        else
                        {
                            Console.WriteLine("post failed in grp");
                        }
                    }

                    catch (Exception ex)
                    {
                        Crashes.TrackError(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
            }
        }
Пример #7
0
 private async void _objChatSignalRService_OnGroupMessageReceived(object sender, GroupMessageResponseViewModel e)
 {
     try
     {
         if (e.MessageId != 0)
         {
             var chatmessage = GroupRepository.CheckGroupChatMessage(e.MessageId, e.GroupId);
             if (chatmessage == null)
             {
                 GroupRepository.SaveGroupMessage(e, "ChatList");
                 var chatConversation = ChatConversationRepository.GetConversationbyGroupId(e.GroupId);
                 if (e.Attachments.Count > 0)
                 {
                     e.Message = (string.IsNullOrEmpty(e.Message)) ? e.Attachments[e.Attachments.Count - 1].Type : e.Message;
                 }
                 chatConversation = ChatConversationRepository.UpdateChatLastMessage(chatConversation.id, e.Message, e.SenderProfileName);
                 if (chatConversation != null)
                 {
                     Activity.RunOnUiThread(() =>
                     {
                         MessageReceived(chatConversation, "OldChat");
                     });
                 }
                 //else
                 //{
                 //    Activity.RunOnUiThread(() =>
                 //    {
                 //        //chatConversation = new ChatConversation();
                 //        //chatConversation.ChatId = e.ChatId;
                 //        //chatConversation.ContactId = e.ContactId;
                 //        //chatConversation.CreatedDate = e.MessageTime;
                 //        //chatConversation.
                 //        //MessageReceived(chatConversation, "NewChat");
                 //    });
                 //}
                 GroupMessageStatusViewModel _model = new GroupMessageStatusViewModel();
                 _model.GroupMessageId = e.MessageId;
                 await _objChatSignalRService.SendGroupMessageUpdate(e.SenderId.ToString(), _model, "ChatList");
             }
         }
     }
     catch (Java.Lang.Exception ex)
     {
         Crashes.TrackError(ex);
     }
 }
        private async void _objChatSignalRService_OnGroupMessageReceived(object sender, GroupMessageResponseViewModel e)
        {
            try
            {
                if (e.MessageId != 0)
                {
                    var chatmessage = GroupRepository.CheckGroupChatMessage(e.MessageId, e.GroupId);
                    if (chatmessage == null)
                    {
                        GroupRepository.SaveGroupMessage(e, "ChatList");
                        var chatConversationResponse = ChatConversationRepository.GetConversationbyGroupId(e.GroupId);
                        if (chatConversationResponse.success)
                        {
                            if (e.Attachments.Count > 0)
                            {
                                e.Message = (string.IsNullOrEmpty(e.Message)) ? e.Attachments[e.Attachments.Count - 1].Type : e.Message;
                            }
                            chatConversationResponse.chatConversation = ChatConversationRepository.UpdateChatLastMessage(chatConversationResponse.chatConversation.id, e.Message, e.SenderProfileName);
                            if (chatConversationResponse.chatConversation != null)
                            {
                                InvokeOnMainThread(() =>
                                {
                                    MessageReceived(chatConversationResponse.chatConversation, "OldChat");
                                });
                            }
                        }

                        GroupMessageStatusViewModel _model = new GroupMessageStatusViewModel();
                        _model.GroupMessageId = e.MessageId;
                        await _objChatSignalRService.SendGroupMessageUpdate(e.SenderId.ToString(), _model, "ChatList");
                    }
                }
            }
            catch (Exception ex)
            {
                //Crashes.TrackError(ex);
            }
        }