Ejemplo n.º 1
0
        private void ChatService_OnReceivedMessage(object sender, TheChat.Core.EventHandlers.MessageEventArgs e)
        {
            string nombre;

            if (Preferences.Get("UserType", 0) == 1) //Employee
            {
                nombre = Preferences.Get("Name", string.Empty);
            }
            else
            {
                nombre = Preferences.Get("Company", string.Empty);
            }
            JobMe.Models.Chat.ChatMessage msg = new JobMe.Models.Chat.ChatMessage();

            Device.BeginInvokeOnMainThread(() =>
            {
                //si el mensaje es para mi
                if (nombre == e.Message.Sender)
                {
                    GetContacts();
                }
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Invoked when the attachment icon is clicked.
        /// </summary>
        /// <param name="obj">The object</param>
        private async void AttachmentClicked(object obj)
        {
            int userid = Preferences.Get("UserID", 0);

            if (!await JobMePermissions.GalleryPermission())
            {
                return;
            }
            var options = new PickMediaOptions();

            options.CompressionQuality = 50;

            var photo = await CrossMedia.Current.PickPhotoAsync(options);

            if (photo != null)
            {
                var ext = photo.Path.Split('.').Last();

                var stream = photo.GetStreamWithImageRotatedForExternalStorage();

                var bytes = ImageHelper.ReadFully(stream);

                var base64Photo = Convert.ToBase64String(bytes);

                string myfoto = base64Photo;

                string fname = Path.GetFileName(photo.Path);

                string To = string.Empty;
                //mensaje para enviar
                var message = new PhotoMessage(ProfileName)
                {
                    Base64Photo = base64Photo,
                    FileEnding  = fname,
                    Recipient   = ChatDetail.ContactID.ToString(),
                    Avatar      = userid.ToString(),
                    Color       = ChatDetail.IDPosition.ToString(),
                };
                //mensaje para mostrar
                Models.Chat.ChatMessage msg = new JobMe.Models.Chat.ChatMessage()
                {
                    Time        = DateTime.Now,
                    ContactID   = ChatDetail.ContactID,
                    UserID      = ChatDetail.UserID,
                    IDPosition  = ChatDetail.IDPosition,
                    IsReceived  = false,
                    Base64Photo = photo.Path,
                    ImageUrl    = EndPoint.BLOB_ENDPOINT + fname,
                    IsImage     = true
                };

                //Verifica que este conectado al hub
                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());
                    }
                }

                //Este es el mensaje que se envia al hub
                await App.ChatService1.SendMessageAsync(message);

                //Este mensaje es el que se agrega a la lista
                ChatMessageInfo.Add(msg);

                if (Preferences.Get("UserType", 0) == 1) //Employee
                {
                    Task.Run(() => Services.PushNotifications.PushServices.SendPushAsync(ChatDetail.ContactID, Preferences.Get("Name", string.Empty), "📷 Imagen", "chat"));
                }
                else
                {
                    Task.Run(() => Services.PushNotifications.PushServices.SendPushAsync(ChatDetail.ContactID, Preferences.Get("Company", string.Empty), "📷 Imagen", "chat"));
                }

                //Ocultar el teclado en ios
                MessagingCenter.Send <ChatMessageViewModel, string>(this, "FocusKeyboardStatus", "nada");

                //Esto es para agregarlo a la base de datos
                await Services.Chat.ChatService.AddMessageAsync(msg);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Invoked when the camera icon is clicked.
        /// </summary>
        /// <param name="obj">The object</param>
        private async void CameraClicked(object obj)
        {
            try
            {
                int userid = Preferences.Get("UserID", 0);

                if (!await JobMePermissions.CameraPermission())
                {
                    return;
                }
                var mediaOptions = new StoreCameraMediaOptions()
                {
                    SaveToAlbum        = false,
                    Directory          = "Sample",
                    PhotoSize          = Device.RuntimePlatform == Device.Android?PhotoSize.Full: PhotoSize.Medium,
                    DefaultCamera      = Plugin.Media.Abstractions.CameraDevice.Front,
                    RotateImage        = false,
                    CompressionQuality = 80,
                    AllowCropping      = true,
                    SaveMetaData       = false,
                };
                //options.CompressionQuality = 50;

                var photo = await CrossMedia.Current.TakePhotoAsync(mediaOptions);

                if (photo != null)
                {
                    var ext = photo.Path.Split('.').Last();

                    var stream = photo.GetStreamWithImageRotatedForExternalStorage();

                    var bytes = ImageHelper.ReadFully(stream);

                    var base64Photo = Convert.ToBase64String(bytes);

                    string myfoto = base64Photo;

                    string fname = Path.GetFileName(photo.Path);

                    string To = string.Empty;
                    //mensaje para enviar
                    var message = new PhotoMessage(ProfileName)
                    {
                        Base64Photo = base64Photo,
                        FileEnding  = fname,
                        Recipient   = ChatDetail.ContactID.ToString(),
                        Avatar      = userid.ToString(),
                        Color       = ChatDetail.IDPosition.ToString(),
                    };
                    //mensaje para mostrar
                    JobMe.Models.Chat.ChatMessage msg = new JobMe.Models.Chat.ChatMessage()
                    {
                        Time        = DateTime.Now,
                        ContactID   = ChatDetail.ContactID,
                        UserID      = ChatDetail.UserID,
                        IDPosition  = ChatDetail.IDPosition,
                        IsReceived  = false,
                        Base64Photo = photo.Path,
                        ImageUrl    = EndPoint.BLOB_ENDPOINT + fname,
                        IsImage     = true
                    };

                    //Este mensaje es el que se agrega a la lista
                    ChatMessageInfo.Add(msg);

                    //Verifica que este conectado al hub
                    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());
                        }
                    }

                    //Este es el mensaje que se envia al hub
                    await App.ChatService1.SendMessageAsync(message);



                    if (Preferences.Get("UserType", 0) == 1) //Employee
                    {
                        Task.Run(() => Services.PushNotifications.PushServices.SendPushAsync(ChatDetail.ContactID, Preferences.Get("Name", string.Empty), "📷 Imagen", "chat"));
                    }
                    else
                    {
                        Task.Run(() => Services.PushNotifications.PushServices.SendPushAsync(ChatDetail.ContactID, Preferences.Get("Company", string.Empty), "📷 Imagen", "chat"));
                    }

                    //Esto es para agregarlo a la base de datos
                    await Services.Chat.ChatService.AddMessageAsync(msg);

                    //Ocultar el teclado en ios
                    MessagingCenter.Send <ChatMessageViewModel, string>(this, "FocusKeyboardStatus", "nada");
                }

                // UserDialogs.Instance.HideLoading();
            }
            catch (Exception ex)
            {
                await App.Current.MainPage.DisplayAlert("JobMe", ex.Message, "ok");

                //throw;
            }
        }
Ejemplo n.º 4
0
        private async void VideoClicked(object obj)
        {
            int userid = Preferences.Get("UserID", 0);

            try
            {
                if (!await JobMePermissions.CameraPermission())
                {
                    return;
                }

                await CrossMedia.Current.Initialize();

                //var photo = await CrossMedia.Current.PickVideoAsync();
                var photo = await CrossMedia.Current.TakeVideoAsync(new StoreVideoOptions
                {
                    SaveToAlbum        = false,
                    Quality            = Device.RuntimePlatform == Device.Android?VideoQuality.High:VideoQuality.Medium,
                    CompressionQuality = 90,
                    DefaultCamera      = CameraDevice.Front,
                    Directory          = "Media",
                    Name = "video.mp4",
                });

                // var photo = await CrossMedia.Current.TakeVideoAsync(mediaOptions);
                string fname      = string.Empty;
                string myfilename = string.Empty;

                if (photo != null)
                {
                    //var stream = photo.GetStream();
                    FileInfo fi;
                    UserDialogs.Instance.ShowLoading("Uploading video");

                    switch (Device.RuntimePlatform)
                    {
                    case Device.iOS:
                        fi = new FileInfo(photo.Path);
                        string extn    = fi.Extension;
                        var    newname = photo.Path.Replace(extn, ".mp4");

                        fname = DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() +
                                DateTime.Now.Year.ToString() +
                                DateTime.Now.Millisecond.ToString() + "video.mp4";

                        await UserService.UploadVideo(photo, Preferences.Get("UserID", 0).ToString() + "_" + fname);

                        //fname = Path.GetFileName(photo.Path);
                        myfilename = Preferences.Get("UserID", 0).ToString() + "_" + fname.Split('.').First();
                        break;

                    case Device.Android:

                        //Stream stream = null;
                        fname = DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() +
                                DateTime.Now.Year.ToString() +
                                DateTime.Now.Millisecond.ToString() + "video.mp4";

                        try
                        {
                            UserDialogs.Instance.ShowLoading("Compressing video");

                            string compressedfile = await DependencyService.Get <IVideoCompress>().CompressVideo(photo.Path);


                            Stream stream = File.Open(compressedfile, FileMode.Open, System.IO.FileAccess.ReadWrite);

                            await UserService.UploadVideo(stream, Preferences.Get("UserID", 0).ToString() + "_" + fname);
                        }
                        catch (Exception)
                        {
                            await UserService.UploadVideo(photo, Preferences.Get("UserID", 0).ToString() + "_" + fname);

                            //throw;
                        }


                        break;

                    default:
                        break;
                    }

                    myfilename = Preferences.Get("UserID", 0).ToString() + "_" + fname.Split('.').First();

                    MemoryStream imagen = DependencyService.Get <IVideoBitMap>().GenerateThumbImage(photo.Path, 2);

                    //var bytes = ImageHelper.ReadFully(imagen);

                    var base64Photo = Convert.ToBase64String(imagen.ToArray());

                    string To = string.Empty;
                    //mensaje para enviar
                    var message = new VideoMessage(ProfileName)
                    {
                        Base64Photo = base64Photo,
                        FileEnding  = myfilename + ".jpg",
                        Recipient   = ChatDetail.ContactID.ToString(),
                        //VideoUrl = EndPoint.BACKEND_ENDPOINT + "/uploads/" +fname,
                        VideoUrl   = EndPoint.BACKEND_ENDPOINT + "/uploads/" + myfilename + ".mp4",
                        VideoImage = EndPoint.BLOB_ENDPOINT + myfilename + ".jpg",
                        IsVideo    = true,
                        Avatar     = userid.ToString(),
                        Color      = ChatDetail.IDPosition.ToString(),
                    };

                    //Verificar que esta conectado al HUb

                    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());
                        }
                    }

                    //Este es el mensaje que se envia al hub
                    await App.ChatService1.SendMessageAsync(message);

                    UserDialogs.Instance.HideLoading();
                    //mensaje para mostrar
                    JobMe.Models.Chat.ChatMessage msg = new JobMe.Models.Chat.ChatMessage()
                    {
                        Time        = DateTime.Now,
                        ContactID   = ChatDetail.ContactID,
                        UserID      = ChatDetail.UserID,
                        IDPosition  = ChatDetail.IDPosition,
                        IsReceived  = false,
                        Base64Photo = base64Photo,
                        ImageUrl    = EndPoint.BLOB_ENDPOINT + myfilename + ".jpg",
                        VideoUrl    = EndPoint.BACKEND_ENDPOINT + "/uploads/" + myfilename + ".mp4",
                        IsVideo     = true
                    };


                    if (Preferences.Get("UserType", 0) == 1) //Employee
                    {
                        Task.Run(() => Services.PushNotifications.PushServices.SendPushAsync(ChatDetail.ContactID, Preferences.Get("Name", string.Empty), "📹 Video", "chat"));
                    }
                    else
                    {
                        Task.Run(() => Services.PushNotifications.PushServices.SendPushAsync(ChatDetail.ContactID, Preferences.Get("Company", string.Empty), "📹 Video", "chat"));
                    }

                    //Esto es para agregarlo a la base de datos
                    await Services.Chat.ChatService.AddMessageAsync(msg);

                    //Este mensaje es el que se agrega a la lista
                    ChatMessageInfo.Add(msg);

                    //Ocultar el teclado en ios
                    //MessagingCenter.Send<ChatMessageViewModel, string>(this, "FocusKeyboardStatus", "nada");
                }

                // UserDialogs.Instance.HideLoading();
            }
            catch (Exception ex)
            {
                string errmsg;

                if (ex.HResult == -2146233029)
                {
                    errmsg = "La operación tardo demasiado, verifica tu conexión a internet";
                }
                else
                {
                    errmsg = "No se pudo enviar el video, intenta nuevamente";
                }

                await App.Current.MainPage.DisplayAlert("JobMe", errmsg, "ok");

                UserDialogs.Instance.HideLoading();
                //throw;
            }
        }
Ejemplo n.º 5
0
        public void ChatService_OnReceivedMessage(object sender, TheChat.Core.EventHandlers.MessageEventArgs e)
        {
            string nombre;

            if (Preferences.Get("UserType", 0) == 1) //Employee
            {
                nombre = Preferences.Get("Name", string.Empty);
            }
            else
            {
                nombre = Preferences.Get("Company", string.Empty);
            }
            JobMe.Models.Chat.ChatMessage msg = new JobMe.Models.Chat.ChatMessage();

            //Device.BeginInvokeOnMainThread(() =>
            //{
            //si el mensaje es para mi
            if (nombre == e.Message.Sender && e.Message.Id != idmessage && e.Message.Color == ChatDetail.IDPosition.ToString() && e.Message.Avatar == ChatDetail.ContactID.ToString())
            {
                idmessage = e.Message.Id;
                //Hay actualizar la lista de contactos

                if (e.Message.TypeInfo.Name == nameof(SimpleTextMessage))     // Memsaje de textpo
                {
                    var z = (SimpleTextMessage)e.Message;
                    msg = new JobMe.Models.Chat.ChatMessage()
                    {
                        Message    = z.Text,
                        Time       = z.Timestamp,
                        IsReceived = true,
                    };

                    ChatMessageInfo.Add(msg);
                }
                else if (e.Message.TypeInfo.Name == nameof(PhotoMessage))     //Mensaje de imagen
                {
                    var z = (PhotoMessage)e.Message;
                    msg = new JobMe.Models.Chat.ChatMessage()
                    {
                        Base64Photo = z.Base64Photo,
                        Time        = z.Timestamp,
                        //ContactID = ChatDetail.ContactID,
                        //UserID = ChatDetail.UserID,
                        //IDPosition = ChatDetail.IDPosition,
                        IsReceived = true,
                    };

                    ChatMessageInfo.Add(msg);
                }
                else if (e.Message.TypeInfo.Name == nameof(PhotoUrlMessage))     //Mensaje de imagen
                {
                    var y = (PhotoUrlMessage)e.Message;

                    msg = new JobMe.Models.Chat.ChatMessage()
                    {
                        Time       = y.Timestamp,
                        ImageUrl   = y.Url,
                        IsReceived = true,
                        IsFile     = y.IsFile,
                        Message    = y.IsFile ? HttpUtility.UrlDecode(Path.GetFileName(y.Url)) : y.Url,
                    };

                    // var result = Path.GetFileName(y.Url);

                    ChatMessageInfo.Add(msg);
                }
                else if (e.Message.TypeInfo.Name == nameof(VideoMessage))     //Mensaje de video
                {
                    var y = (VideoMessage)e.Message;

                    msg = new JobMe.Models.Chat.ChatMessage()
                    {
                        Time        = y.Timestamp,
                        ImageUrl    = y.VideoImage,
                        IsReceived  = true,
                        IsVideo     = true,
                        ImagePath   = y.VideoUrl,
                        Base64Photo = y.Base64Photo

                                      // Message = y.IsFile ? HttpUtility.UrlDecode(Path.GetFileName(y.Url)) : y.Url,
                    };

                    // var result = Path.GetFileName(y.Url);

                    ChatMessageInfo.Add(msg);
                }
            }
            //});
        }
Ejemplo n.º 6
0
        private async void SendFileClicked(object obj)
        {
            string[] fileTypes;

            try
            {
                var status = await Permissions.CheckStatusAsync <Permissions.StorageRead>();

                if (status != PermissionStatus.Granted)
                {
                    status = await Permissions.RequestAsync <Permissions.StorageRead>();
                }

                if (status == PermissionStatus.Granted)
                {
                    var pickedFile = await Plugin.FilePicker.CrossFilePicker.Current.PickFile();

                    if (pickedFile != null)
                    {
                        var stream = pickedFile.GetStream();

                        var bytes = ImageHelper.ReadFully(stream);

                        var base64Photo = Convert.ToBase64String(bytes);

                        string myfoto = base64Photo;

                        string fname = pickedFile.FileName;

                        //mensaje para enviar
                        var message = new PhotoMessage(ProfileName)
                        {
                            Base64Photo = base64Photo,
                            FileEnding  = fname,
                            Recipient   = ChatDetail.ContactID.ToString(),
                            IsFile      = true,
                            Avatar      = ChatDetail.UserID.ToString(),
                            Color       = ChatDetail.IDPosition.ToString(),
                        };
                        //mensaje para mostrar
                        JobMe.Models.Chat.ChatMessage msg = new JobMe.Models.Chat.ChatMessage()
                        {
                            Time       = DateTime.Now,
                            ContactID  = ChatDetail.ContactID,
                            UserID     = ChatDetail.UserID,
                            IDPosition = ChatDetail.IDPosition,
                            IsReceived = false,
                            IsFile     = true,
                            Message    = fname,
                        };

                        //Verifica que este conectado al hub
                        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());
                            }
                        }

                        //Este mensaje es el que se agrega a la lista
                        ChatMessageInfo.Add(msg);

                        //Este es el mensaje que se envia al hub
                        await App.ChatService1.SendMessageAsync(message);



                        if (Preferences.Get("UserType", 0) == 1) //Employee
                        {
                            Task.Run(() => Services.PushNotifications.PushServices.SendPushAsync(ChatDetail.ContactID, Preferences.Get("Name", string.Empty), "📄 Archivo", "chat"));
                        }
                        else
                        {
                            Task.Run(() => Services.PushNotifications.PushServices.SendPushAsync(ChatDetail.ContactID, Preferences.Get("Company", string.Empty), "📄 Archivo", "chat"));
                        }

                        //Ocultar el teclado en ios
                        MessagingCenter.Send <ChatMessageViewModel, string>(this, "FocusKeyboardStatus", "nada");

                        //Esto es para agregarlo a la base de datos
                        await Services.Chat.ChatService.AddMessageAsync(msg);
                    }
                }
            }
            catch (Exception ex)
            {
            }

            // FileData fileData = await Plugin.FilePicker.CrossFilePicker.Current.PickFile(allowedDocumentTypes);//

            // App.Current.MainPage.DisplayAlert("JobMe", "Solo disponible para Premium", "OK");
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Invoked when the send button is clicked.
        /// </summary>
        /// <param name="obj">The object</param>
        private async void SendClicked(object obj)
        {
            try
            {
                if (!string.IsNullOrWhiteSpace(this.NewMessage))
                {
                    int userid = Preferences.Get("UserID", 0);

                    JobMe.Models.Chat.ChatMessage msg = new JobMe.Models.Chat.ChatMessage()
                    {
                        Message    = this.NewMessage,
                        Time       = DateTime.Now,
                        ContactID  = ChatDetail.ContactID,
                        UserID     = ChatDetail.UserID,
                        IDPosition = ChatDetail.IDPosition,
                        IsReceived = false,
                    };

                    var message = new SimpleTextMessage(ProfileName)
                    {
                        Text      = this.NewMessage,
                        Recipient = ChatDetail.ContactID.ToString(),
                        Avatar    = userid.ToString(),
                        Color     = ChatDetail.IDPosition.ToString(),
                        //GroupName = ChatDetail.IDPosition.ToString(),
                    };

                    //Este mensaje es el que se agrega a la lista
                    ChatMessageInfo.Add(msg);

                    //borra el mensaje para que actualice el chat
                    this.NewMessage = null;

                    //Verifica que este conectado al hub
                    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());
                        }
                    }

                    //Este es el mensaje que se envia al hub
                    await App.ChatService1.SendMessageAsync(message);

                    if (Preferences.Get("UserType", 0) == 1) //Employee
                    {
                        Task.Run(() => Services.PushNotifications.PushServices.SendPushAsync(ChatDetail.ContactID, Preferences.Get("Name", string.Empty), msg.Message, "chat"));
                    }
                    else
                    {
                        Task.Run(() => Services.PushNotifications.PushServices.SendPushAsync(ChatDetail.ContactID, Preferences.Get("Company", string.Empty), msg.Message, "chat"));
                    }

                    //Esto es para agregarlo a la base de datos
                    await Services.Chat.ChatService.AddMessageAsync(msg);
                }
            }
            catch (Exception ex)
            {
                // throw;
            }
        }