예제 #1
0
        public async Task <IActionResult> PutChatDetail([FromRoute] int id, [FromBody] ChatDetail chatDetail)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != chatDetail.ChatId)
            {
                return(BadRequest());
            }

            _context.Entry(chatDetail).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ChatDetailExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #2
0
        //SfListView listView;
        /// <summary>
        /// Initializes a collection and add it to the message items.
        /// </summary>
        private async void GenerateMessageInfo(ChatDetail chat)
        {
            IsVisible = false;

            if (Preferences.Get("UserType", 0) == 1)
            {
                chat.TipoMensaje = 1;
            }
            else
            {
                chat.TipoMensaje = 2;
            }

            this.ChatMessageInfo = await Services.Chat.ChatService.GetMessagesNewAsync(chat);

            foreach (var item in ChatMessageInfo)
            {
                item.Sender = ProfileName;
            }

            Count = this.ChatMessageInfo.Count;

            ((LinearLayout)this.listView.LayoutManager).ScrollToRowIndex(
                Count - 1, Syncfusion.ListView.XForms.ScrollToPosition.End, true);

            IsVisible = true;
        }
        public async Task <ApiResponse> Handle(EditMessageCommand request, CancellationToken cancellationToken)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                ChatDetail chatDetail = await _dbContext
                                        .ChatDetail
                                        .FirstOrDefaultAsync(x => x.IsDeleted == false &&
                                                             x.ChatId == request.ChatId);

                if (chatDetail == null)
                {
                    throw new Exception(StaticResource.ChatNotFound);
                }

                chatDetail.ModifiedDate           = request.ModifiedDate;
                chatDetail.ModifiedById           = request.ModifiedById;
                chatDetail.ChatSourceEntityId     = request.ChatSourceEntityId;
                chatDetail.EntityId               = request.EntityId;
                chatDetail.Message                = request.Message;
                chatDetail.EntitySourceDocumentId = request.EntitySourceDocumentId;
                await _dbContext.SaveChangesAsync();

                response.StatusCode = StaticResource.successStatusCode;
                response.Message    = "Success";
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = StaticResource.SomethingWrong + ex.Message;
            }

            return(response);
        }
예제 #4
0
        public static async void UpdateContador(ChatDetail ch)
        {
            var client = new HttpClient();

            var uri = EndPoint.BACKEND_ENDPOINT + "api/Chat/UpdateContador";

            // Request body

            byte[] byteData = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(ch));

            string msj = string.Empty;

            using (var content = new ByteArrayContent(byteData))
            {
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                var response = await client.PostAsync(uri, content);

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    var result = await response.Content.ReadAsStringAsync();
                }
                else
                {
                    msj = "Ocurrio un error al agregar la vacante";
                }
            }
        }
예제 #5
0
        public HttpResponseMessage Post(string command, ChatDetail chatdetail)
        {
            try
            {
                if (command == "ChatMessage")
                {
                    Boolean ds = chatmessage.ChatMessages(chatdetail);
                }
                else if (command == "ChatGroupMessageForTeacher")
                {
                    Boolean ds = chatmessage.ChatGroupMessageForTeacher(chatdetail);
                }
                else if (command == "ChatGroupMessageForStudent")
                {
                    Boolean ds = chatmessage.ChatGroupMessageForStudent(chatdetail);
                }
                else if (command == "ChatGroupMessageFromStudentToTeacher")
                {
                    Boolean ds = chatmessage.ChatGroupMessageFromStudentToTeacher(chatdetail);
                }

                var message = Request.CreateResponse(HttpStatusCode.Created);
                return(message);
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ex));
            }
        }
예제 #6
0
    public void AddMessage(short _sessionId, string _strMess, List <UserDataInGame> _listOtherPlayerData)
    {
        if (listData == null)
        {
            listData = new List <ChatDetail>();
        }
        if (listPanelChatDetail == null)
        {
            listPanelChatDetail = new List <PanelChatDetailController>();
        }

        ChatDetail _tmpChatDetail = null;

        if (_sessionId == DataManager.instance.userData.sessionId)
        {
            _tmpChatDetail      = new ChatDetail(DataManager.instance.userData.CastToUserDataInGame(), _strMess);
            _tmpChatDetail.isMe = true;
        }
        else
        {
            for (int i = 0; i < _listOtherPlayerData.Count; i++)
            {
                if (_listOtherPlayerData[i].IsEqual(_sessionId))
                {
                    _tmpChatDetail = new ChatDetail(_listOtherPlayerData[i].ShallowCopy(), _strMess);
                    break;
                }
            }
        }

        if (_tmpChatDetail == null)
        {
            return;
        }

        listData.Insert(0, _tmpChatDetail);

        if (listData.Count > maxChatContent && listData.Count > 0)
        {
            listData.RemoveAt(listData.Count - 1);
        }

        if (currentState == State.Show)
        {
            if (listPanelChatDetail.Count > maxChatContent && listPanelChatDetail.Count > 0)
            {
                listPanelChatDetail[listPanelChatDetail.Count - 1].SelfDestruction();
            }
            AddPanelDetail(_tmpChatDetail);
        }
        else
        {
            if (onHasNewMessage != null)
            {
                onHasNewMessage();
            }
        }
    }
예제 #7
0
        public Boolean ChatGroupMessageForTeacher(ChatDetail chatdetail)
        {
            try
            {
                SqlConnection conn = new SqlConnection();
                conn = new SqlConnection(constr);
                string SqlString = "";
                SqlString = "select vchFCMToken from Student_Master where vchFCMToken IS NOT NULL and vchFCMToken!='' and intstanderd_id='" + chatdetail.intstandard_id.ToString() + "' and intDivision_id='" + chatdetail.intDivision_id.ToString() + "' and intschool_id='" + chatdetail.intSchool_id.ToString() + "' and intAcademic_id='" + chatdetail.intAcademic_id.ToString() + "'";
                SqlDataAdapter sda = new SqlDataAdapter(SqlString, conn);
                DataTable      dt  = new DataTable();
                sda.Fill(dt);


                string s = chatdetail.Message.Trim();

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string     regId         = dt.Rows[i]["vchFCMToken"].ToString();
                    var        applicationID = "AIzaSyCHfQSjFsEybdNRibLORHTMVVp6CKoI5TQ"; // PbojmyrmspdqkZ0pINni7DyqvhY2
                    string     message       = chatdetail.Message.Trim();
                    string     title         = "Group";
                    string     Sendername    = chatdetail.SenderName;
                    string     GroupName     = chatdetail.GRoupName;
                    var        SENDER_ID     = "574926706382";
                    var        value         = chatdetail.Message.Trim();
                    WebRequest tRequest;
                    tRequest             = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
                    tRequest.Method      = "post";
                    tRequest.ContentType = " application/x-www-form-urlencoded;charset=UTF-8";
                    tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID));
                    tRequest.Headers.Add(string.Format("Sender: id={0}", SENDER_ID));
                    string postData = "collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.message="
                                      + value + "&data.time=" + System.DateTime.Now.ToString() + "&registration_id=" + regId + "&data.title=" + title + "&data.Sendername=" + Sendername + "&data.GroupName=" + GroupName + "&data.Standard_id=" + chatdetail.intstandard_id.ToString() + "&data.Division_id=" + chatdetail.intDivision_id.ToString() + "";
                    Console.WriteLine(postData);
                    Byte[] byteArray = Encoding.UTF8.GetBytes(postData);
                    tRequest.ContentLength = byteArray.Length;
                    Stream dataStream = tRequest.GetRequestStream();
                    dataStream.Write(byteArray, 0, byteArray.Length);
                    dataStream.Close();
                    WebResponse tResponse = tRequest.GetResponse();
                    dataStream = tResponse.GetResponseStream();
                    StreamReader tReader             = new StreamReader(dataStream);
                    String       sResponseFromServer = tReader.ReadToEnd();
                    //txtResponse.Text = sResponseFromServer; //printing response from GCM server.
                    //txtStream.Text = postData.ToString().Trim();
                    tReader.Close();
                    dataStream.Close();
                    tResponse.Close();
                }
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
예제 #8
0
        public Boolean ChatMessages(ChatDetail chatdetail)
        {
            try
            {
                string     regId            = chatdetail.FCMToken.ToString().Trim();
                var        applicationID    = "AIzaSyCHfQSjFsEybdNRibLORHTMVVp6CKoI5TQ"; // PbojmyrmspdqkZ0pINni7DyqvhY2
                var        value            = chatdetail.Message.Trim();
                string     userid           = chatdetail.User_id.ToString();
                string     title            = "IndividualChat";
                var        SENDER_ID        = "574926706382";
                string     ReceivrName      = chatdetail.ReceiverName.Trim();
                string     RecieverFCMTOken = chatdetail.FCMToken.Trim();
                string     Sendername       = chatdetail.SenderName.Trim();
                string     senderFCMToken   = chatdetail.SenderFCMToken.Trim();
                string     UserTypeid       = chatdetail.intUserType_id.ToString();
                WebRequest tRequest;
                tRequest             = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
                tRequest.Method      = "post";
                tRequest.ContentType = " application/x-www-form-urlencoded;charset=UTF-8";
                tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID));

                tRequest.Headers.Add(string.Format("Sender: id={0}", SENDER_ID));

                string postData = "collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.message="
                                  + value + "&data.time=" + System.DateTime.Now.ToString() + "&registration_id=" + regId + "&data.title=" + title + "&data.userid=" + userid + "&data.ReceivrName=" + ReceivrName + "&data.RecieverFCMTOken=" + RecieverFCMTOken + "&data.Sendername=" + Sendername + "&data.senderFCMToken=" + senderFCMToken + "&data.UserTypeid=" + UserTypeid + "";

                Console.WriteLine(postData);
                Byte[] byteArray = Encoding.UTF8.GetBytes(postData);
                tRequest.ContentLength = byteArray.Length;

                Stream dataStream = tRequest.GetRequestStream();
                dataStream.Write(byteArray, 0, byteArray.Length);
                dataStream.Close();

                WebResponse tResponse = tRequest.GetResponse();

                dataStream = tResponse.GetResponseStream();

                StreamReader tReader = new StreamReader(dataStream);

                String sResponseFromServer = tReader.ReadToEnd();

                //txtResponse.Text = sResponseFromServer; //printing response from GCM server.
                //txtStream.Text = postData.ToString().Trim();
                tReader.Close();
                dataStream.Close();
                tResponse.Close();
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
예제 #9
0
        public DataSet Get(string command, string intSchool_id, string intUserid, string intStandard_id, string intDivision_id, string intAcademic_id)
        {
            ChatDetail chatdetail = new ChatDetail();

            chatdetail.intSchool_id   = Convert.ToInt32(intSchool_id);
            chatdetail.User_id        = Convert.ToInt32(intUserid);
            chatdetail.intstandard_id = Convert.ToInt32(intStandard_id);
            chatdetail.intDivision_id = Convert.ToInt32(intDivision_id);
            chatdetail.intAcademic_id = Convert.ToInt32(intAcademic_id);
            DataSet ds = record.ChatDetails(command, chatdetail);

            return(ds);
        }
예제 #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChatMessagePage" /> class.
 /// </summary>
 public ChatMessagePage(ChatDetail data)
 {
     InitializeComponent();
     BindingContext = new ViewModels.Chat.ChatMessageViewModel(data);
     ListView.DataSource.GroupDescriptors.Add(new GroupDescriptor
     {
         PropertyName = "Time",
         KeySelector  = obj =>
         {
             var item = obj as ChatMessage;
             return(item.Time.Date);
         }
     });
 }
        async void OnDismissButtonClicked(object sender, EventArgs args)
        {
            Console.WriteLine(" name " + nameField.Text + " message " + messageField.Text + " count " + countField.Text);
            var cd = new ChatDetail {
                Name = nameField.Text, Message = messageField.Text, MessageCount = countField.Text, ReceivedStamp = "yesterday"
            };

            //Monkeys.Add(cd);
            if (PlusButtonEventHandler != null)
            {
                PlusButtonEventHandler(this, cd);
            }

            await Navigation.PopModalAsync();
        }
예제 #12
0
        public async Task SendMessage(chatDetail message)
        {
            var           senderId  = Context.ConnectionId;
            List <string> readConId = new List <string>();
            //IReadOnlyList<string> lstConnectionId = users.Where(s => s.UserId == Convert.ToInt16(UserId) || s.UserId == Convert.ToInt16(ReceiverUserId)).ToList().Select(s => String.Join(',', s.connectionIds)).ToList();
            var u = users.Where(s => s.UserId == Convert.ToInt16(message.fromUserId) || s.UserId == Convert.ToInt16(message.toUserId)).Select(s => s.connectionIds).ToList();

            foreach (var c in u)
            {
                readConId.AddRange(c);
            }
            ChatDetail objChat = new ChatDetail();

            objChat.FromUserId = message.fromUserId; // Convert.ToInt16(UserId);
            objChat.ToUserId   = message.toUserId;   // Convert.ToInt16(ReceiverUserId);
            objChat.UserId     = message.fromUserId; // Convert.ToInt16(objChat.FromUserId);
            objChat.Message    = message.message;
            objChat.CreatedOn  = System.DateTime.Now;
            message.createdOn  = System.DateTime.Now;
            if (users.Where(s => s.UserId == objChat.ToUserId).ToList().Count > 0)
            {
                objChat.IsRead = true;
            }
            else
            {
                objChat.IsRead = false;
            }
            IReadOnlyList <string> lstConnectionId = (IReadOnlyList <string>)readConId;

            try
            {
                //HttpResponseMessage response = await client.PostAsync<ChatDetail>("api/ChatDetailAPI",objChat);
                //response.EnsureSuccessStatusCode();

                var json = JsonConvert.SerializeObject(objChat);

                var stringContent = new StringContent(json, System.Text.UnicodeEncoding.UTF8, "application/json");

                //var client = new HttpClient();
                var response = await client.PostAsync("https://localhost:44314/api/ChatDetailAPI", stringContent);
            }
            catch
            { }
            //await Clients.Clients(lstConnectionId).SendAsync("ReceiveMessage", chat UserId, message, objChat.CreatedOn.ToString("dd/MM HH:mm"), null);

            await Clients.Clients(lstConnectionId).SendAsync("ReceiveMessage", message);
        }
예제 #13
0
    public void AddMessage(UserDataInGame _userData, string _strMess)
    {
        if (listData == null)
        {
            listData = new List <ChatDetail>();
        }
        if (listPanelChatDetail == null)
        {
            listPanelChatDetail = new List <PanelChatDetailController>();
        }

        ChatDetail _tmpChatDetail = new ChatDetail(_userData, _strMess);

        if (_userData.IsEqual(DataManager.instance.userData.userId, DataManager.instance.userData.databaseId))
        {
            _tmpChatDetail.isMe = true;
        }
        else if (_userData.sessionId == DataManager.instance.userData.sessionId)
        {
            _tmpChatDetail.isMe = true;
        }

        listData.Insert(0, _tmpChatDetail);

        if (listData.Count > maxChatContent && listData.Count > 0)
        {
            listData.RemoveAt(listData.Count - 1);
        }

        if (currentState == State.Show)
        {
            if (listPanelChatDetail.Count > maxChatContent && listPanelChatDetail.Count > 0)
            {
                listPanelChatDetail[listPanelChatDetail.Count - 1].SelfDestruction();
            }
            AddPanelDetail(_tmpChatDetail);
        }
        else
        {
            if (onHasNewMessage != null)
            {
                onHasNewMessage();
            }
        }
    }
예제 #14
0
        public async Task <IActionResult> PostChatDetail([FromBody] ChatDetail chatDetail)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                _context.ChatDetail.Add(chatDetail);
                await _context.SaveChangesAsync();

                return(CreatedAtAction("GetChatDetail", new { id = chatDetail.ChatId }, chatDetail));
            }
            catch (Exception)
            {
                return(null);
            }
        }
        public async Task <ApiResponse> Handle(AddMessageCommand request, CancellationToken cancellationToken)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                if (string.IsNullOrEmpty(request.Message) && string.IsNullOrWhiteSpace(request.Message))
                {
                    throw new Exception(StaticResource.ChatMessageEmpty);
                }

                ChatDetail chatDetail = new ChatDetail
                {
                    CreatedDate            = DateTime.UtcNow,
                    CreatedById            = request.CreatedById,
                    IsDeleted              = false,
                    ChatSourceEntityId     = request.ChatSourceEntityId,
                    EntityId               = request.EntityId,
                    Message                = request.Message,
                    EntitySourceDocumentId = request.EntitySourceDocumentId
                };

                await _dbContext.ChatDetail.AddAsync(chatDetail);

                await _dbContext.SaveChangesAsync();

                UserDetails user = await _dbContext.UserDetails.FirstOrDefaultAsync(x => x.IsDeleted == false && x.AspNetUserId == request.CreatedById);

                request.ChatId   = chatDetail.ChatId;
                request.UserName = user.Username;

                response.ResponseData = request;
                response.StatusCode   = StaticResource.successStatusCode;
                response.Message      = "Success";
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = ex.Message;
            }

            return(response);
        }
예제 #16
0
    void AddPanelDetail(ChatDetail _chatDetail)
    {
        GameObject _prefab = null;

        if (_chatDetail.isMe)
        {
            _prefab = panelChatDetailPrefab_me;
        }
        else
        {
            _prefab = panelChatDetailPrefab_others;
        }
        PanelChatDetailController _tmpPanelChatDetail = ((GameObject)LeanPool.Spawn(_prefab, Vector3.zero, Quaternion.identity, panelChatContent)).GetComponent <PanelChatDetailController>();

        _tmpPanelChatDetail.InitData(_chatDetail.userData, _chatDetail.strMess, (_p) => {
            listPanelChatDetail.Remove((PanelChatDetailController)_p);
        });
        _tmpPanelChatDetail.Show();
        listPanelChatDetail.Insert(0, _tmpPanelChatDetail);
        _tmpPanelChatDetail.transform.SetAsLastSibling();
    }
예제 #17
0
        public ChatMessagePage(ChatDetail selecteditem)
        {
            ChatMessageViewModel vm = new ChatMessageViewModel(selecteditem)
            {
                Navigation = Navigation,
                listView   = listView
            };

            viewmodel      = vm;
            BindingContext = vm;
            vm.Navigation  = Navigation;
            selectedchat   = selecteditem;

            InitializeComponent();
            listView.IsVisible = false;
            //listView.Loaded += ListView_Loaded;

            vm.listView = this.listView;

            //visualContainer = ListView.GetVisualContainer();
            // var x = App.ScreenHeight;

            listView.HeightRequest = App.ScreenHeight - 120;

            listView.DataSource.GroupDescriptors.Add(new GroupDescriptor
            {
                PropertyName = "Time",
                KeySelector  = obj =>
                {
                    var item = obj as ChatMessage;
                    return(item.Time.Date);
                }
            });

            listView.IsVisible = true;
        }
예제 #18
0
        public static async Task <bool> DeleteChatAsync(ChatDetail ch)
        {
            var client = new HttpClient();

            var uri = EndPoint.BACKEND_ENDPOINT + "api/Chat/DeleteChat";

            byte[] byteData = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(ch));

            string msj = string.Empty;

            using (var content = new ByteArrayContent(byteData))
            {
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                var response = await client.PostAsync(uri, content);

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    var result = await response.Content.ReadAsStringAsync();

                    try
                    {
                        return(JsonConvert.DeserializeObject <bool>(result));
                    }
                    catch (Exception ex)
                    {
                        return(false);

                        throw;
                    }
                }
                else
                {
                    return(false);
                }
            }
        }
예제 #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChatMessageViewModel" /> class.
        /// </summary>
        public ChatMessageViewModel(ChatDetail data)
        {
            System.Diagnostics.Debug.WriteLine(data);
            profileName  = data.SenderName;
            profileImage = data.ImagePath;
            chatId       = data.Id;
            ownerId      = data.OwnerId;
            friendId     = data.FriendId;
            userPhone    = data.SenderPhone;


            this.ChatMessageInfo = new ObservableCollection <ChatMessage> {
            };
            this.MakeVoiceCall   = new Command(this.VoiceCallClicked);
            this.MakeVideoCall   = new Command(this.VideoCallClicked);
            this.MenuCommand     = new Command(this.MenuClicked);
            this.ShowCamera      = new Command(this.CameraClicked);
            this.SendAttachment  = new Command(this.AttachmentClicked);
            this.SendCommand     = new Command(this.SendClicked);
            this.BackCommand     = new Command(this.BackButtonClicked);
            this.ProfileCommand  = new Command(this.ProfileClicked);
            this.fetchMessageList();
            this.startTimer();
        }
예제 #20
0
        public static async Task <ObservableCollection <ChatMessage> > GetMessagesNewAsync(ChatDetail ch)
        {
            var client = new HttpClient();

            var uri = EndPoint.BACKEND_ENDPOINT + "api/Chat/GetMessagesNew";

            //var uri = "https://localhost:44327/api/user";
            // Request body

            //   byte[] byteData = Encoding.UTF8.GetBytes("{}");
            byte[] byteData = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(ch));

            string msj = string.Empty;

            using (var content = new ByteArrayContent(byteData))
            {
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                var response = await client.PostAsync(uri, content);

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    var result = await response.Content.ReadAsStringAsync();

                    try
                    {
                        return(JsonConvert.DeserializeObject <ObservableCollection <ChatMessage> >(result));
                    }
                    catch (Exception ex)
                    {
                        return(null);

                        throw;
                    }
                }
                else
                {
                    return(null);

                    msj = "Ocurrio un error al agregar la vacante";
                }
            }
        }
예제 #21
0
        public ChatMessageViewModel(ChatDetail selecteditem)
        {
            try
            {
                IsVisible = true;
                ChatWidth = App.ScreenWidth - 225;

                //App.ChatService1.OnReceivedMessage += ChatService_OnReceivedMessage;

                if (!App.ChatService1.IsConnected)
                {
                    App.ChatService1 = new TheChat.Core.Services.ChatService();

                    if (Preferences.Get("UserID", 0) > 0)
                    {
                        //await App.ChatService1.InitAsync(Preferences.Get("UserID", 0).ToString());
                        App.ChatService1.OnReceivedMessage -= ChatService_OnReceivedMessage;
                        App.ChatService1.OnReceivedMessage += ChatService_OnReceivedMessage;
                    }
                }
                else
                {
                    App.ChatService1.OnReceivedMessage -= ChatService_OnReceivedMessage;
                    App.ChatService1.OnReceivedMessage += ChatService_OnReceivedMessage;
                }

                this.MakeVoiceCall     = new Command(this.VoiceCallClicked);
                this.MakeVideoCall     = new Command(this.VideoCallClicked);
                this.MenuCommand       = new Command(this.MenuClicked);
                this.ShowCamera        = new Command(this.CameraClicked);
                this.SendAttachment    = new Command(this.AttachmentClicked);
                this.SendCommand       = new Command(this.SendClicked);
                this.BackCommand       = new Command(this.BackButtonClicked);
                this.ProfileCommand    = new Command(this.ProfileClicked);
                this.DeleteChatCommand = new Command(this.DeleteChat);
                this.SendFile          = new Command(this.SendFileClicked);
                this.ShowVideo         = new Command(this.VideoClicked);

                this.LoadMoreItemsCommand = new Command(this.LoadMore);

                this.GenerateMessageInfo(selecteditem);

                this.ImageTappedCommand         = new Command(IncomingImageClicked);
                this.OutgoingImageTappedCommand = new Command(OutgoingImageClicked);

                this.OutgoingVideoTappedCommand = new Command(OutgoingVideoClicked);
                this.IncomingVideoTappedCommand = new Command(IncomingVideoClicked);

                this.FileTappedCommand = new Command(FileClicked);

                ProfileName  = selecteditem.SenderName;
                profileImage = selecteditem.ImagePath;
                Logo         = selecteditem.Logo;
                ChatDetail   = selecteditem;

                if (Preferences.Get("UserType", 0) == 1) //Employee
                {
                    IsLogoVisible  = true;
                    IsImageVisible = false;
                }
                else
                {
                    IsLogoVisible  = false;
                    IsImageVisible = true;
                }

                //App.hubConnection.On<string, string>("ReceiveMessage", (user, message) =>
                //{
                //    ChatMessageInfo.Add(new ChatMessage
                //    {
                //        Message = message,
                //        Time = DateTime.Now,
                //         IsReceived = true
                //    });

                //});
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                App.Current.MainPage.DisplayAlert("Jobme", e.Message, "Ok");
            }
        }
예제 #22
0
        /// <summary>
        /// Trae el listado de chats detallados del usuario solicitante
        /// </summary>
        /// <param name="uid"></param>
        /// <returns>Un JSON con el listado de usuarios de forma asíncrona</returns>
        public static async Task <string> getCOU(string uid)
        {
            HttpClient           clienteCWLM = new HttpClient(), clienteUltMensaje = new HttpClient();
            Uri                  uri              = new Uri($"{uriBaseApi}Chats/{uid}");
            List <Chat>          listadoChats     = new List <Chat>();
            List <ChatDetailWLM> listadoDetallado = new List <ChatDetailWLM>();

            try
            {
                var respuesta = await clienteCWLM.GetAsync(uri);

                if (respuesta.IsSuccessStatusCode)
                {
                    var respuestaJson = await clienteCWLM.GetStringAsync(uri);

                    clienteCWLM.Dispose();

                    if (!String.IsNullOrEmpty(respuestaJson))
                    {
                        listadoChats = JsonConvert.DeserializeObject <List <Chat> >(respuestaJson);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            if (listadoChats.Count != new List <Chat>().Count)
            {
                foreach (Chat chatActual in listadoChats)
                {
                    try
                    {
                        Uri uriUltMensaje             = new Uri($"{uriBaseApi}Messages/{chatActual.ID}/lastMessage");
                        HttpResponseMessage respuesta = await clienteUltMensaje.GetAsync(uriUltMensaje);

                        if (respuesta.IsSuccessStatusCode)
                        {
                            String respuestaJson = await clienteUltMensaje.GetStringAsync(uriUltMensaje);

                            Message message = JsonConvert.DeserializeObject <Message>(respuestaJson);

                            listadoDetallado.Add(
                                new ChatDetailWLM(
                                    await ChatDetail.detallar(chatActual, uid), message));
                        }
                    }
                    catch (Exception e)
                    {
                        listadoDetallado.Add(
                            new ChatDetailWLM(
                                await ChatDetail.detallar(chatActual, uid), new Message("", "", DateTime.Now.Ticks / 10000)));
                    }
                }
            }
            else
            {
                listadoDetallado.Add(new ChatDetailWLM(new ChatDetail(0, "", new UserDetail("", "")), new Message("", "", DateTime.Now.Ticks / 10000)));
            }

            listadoDetallado.Sort();
            listadoDetallado.Reverse();
            CWLMQueryPackage query = new CWLMQueryPackage(listadoDetallado);

            return(JsonConvert.SerializeObject(query));
        }