Ejemplo n.º 1
0
        public void updateProfile_Callback(JObject obj)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                if (obj != null && HikeConstants.OK == (string)obj[HikeConstants.STAT])
                {
                    App.ViewModel.ConvMap[groupId].Avatar = fullViewImageBytes;
                    groupImage.Source = grpImage;
                    groupImage.Height = 83;
                    groupImage.Width  = 83;

                    string msg                  = string.Format(AppResources.GroupImgChangedByGrpMember_Txt, AppResources.You_Txt);
                    ConvMessage cm              = new ConvMessage(msg, groupId, TimeUtils.getCurrentTimeStamp(), ConvMessage.State.RECEIVED_READ, -1, -1);
                    cm.GrpParticipantState      = ConvMessage.ParticipantInfoState.GROUP_PIC_CHANGED;
                    cm.GroupParticipant         = App.MSISDN;
                    JObject jo                  = new JObject();
                    jo[HikeConstants.TYPE]      = HikeConstants.MqttMessageTypes.GROUP_DISPLAY_PIC;
                    cm.MetaDataString           = jo.ToString(Newtonsoft.Json.Formatting.None);
                    ConversationListObject cobj = MessagesTableUtils.addChatMessage(cm, false);
                    if (cobj == null)
                    {
                        return;
                    }

                    // handle msgs
                    object[] vs = new object[2];
                    vs[0]       = cm;
                    vs[1]       = cobj;
                    mPubSub.publish(HikePubSub.MESSAGE_RECEIVED, vs);

                    // handle saving image
                    object[] vals = new object[3];
                    vals[0]       = groupId;
                    vals[1]       = fullViewImageBytes;
                    vals[2]       = thumbnailBytes;
                    mPubSub.publish(HikePubSub.ADD_OR_UPDATE_PROFILE, vals);
                }
                else
                {
                    MessageBox.Show(AppResources.CannotChangeGrpImg_Txt, AppResources.Something_Wrong_Txt, MessageBoxButton.OK);
                }
                //progressBar.IsEnabled = false;
                shellProgress.IsVisible = false;
                isProfilePicTapped      = false;
            });
        }
        void imageOpenedHandler(object sender, RoutedEventArgs e)
        {
            BitmapImage     image           = (BitmapImage)sender;
            WriteableBitmap writeableBitmap = new WriteableBitmap(image);
            MemoryStream    msLargeImage    = new MemoryStream();

            writeableBitmap.SaveJpeg(msLargeImage, 90, 90, 0, 90);
            MemoryStream msSmallImage = new MemoryStream();

            writeableBitmap.SaveJpeg(msSmallImage, 35, 35, 0, 95);

            //send image to server here and insert in db after getting response
            AccountUtils.updateProfileIcon(msSmallImage, new AccountUtils.postResponseFunction(updateProfile_Callback));

            object[] vals = new object[3];
            vals[0] = msisdn;
            vals[1] = msSmallImage;
            vals[2] = msLargeImage;
            mPubSub.publish(HikePubSub.ADD_OR_UPDATE_PROFILE, vals);
        }
        public void uploadFileCallback(JObject obj, ConvMessage convMessage, SentChatBubble chatBubble)
        {
            if (obj != null && chatBubble.FileAttachment.FileState != Attachment.AttachmentState.CANCELED &&
                chatBubble.FileAttachment.FileState != Attachment.AttachmentState.FAILED_OR_NOT_STARTED)
            {
                JObject data        = obj[HikeConstants.FILE_RESPONSE_DATA].ToObject <JObject>();
                string  fileKey     = data[HikeConstants.FILE_KEY].ToString();
                string  fileName    = data[HikeConstants.FILE_NAME].ToString();
                string  contentType = data[HikeConstants.FILE_CONTENT_TYPE].ToString();

                chatBubble.updateProgress(110);
                //DO NOT Update message text in db. We sent the below line, but we save content type as message.
                //here message status should be updated in db, as on event listener message state should be unknown

                if (contentType.Contains(HikeConstants.IMAGE))
                {
                    convMessage.Message = String.Format(AppResources.FILES_MESSAGE_PREFIX, AppResources.Photo_Txt) + HikeConstants.FILE_TRANSFER_BASE_URL +
                                          "/" + fileKey;
                }
                else if (contentType.Contains(HikeConstants.AUDIO))
                {
                    convMessage.Message = String.Format(AppResources.FILES_MESSAGE_PREFIX, AppResources.Voice_msg_Txt) + HikeConstants.FILE_TRANSFER_BASE_URL +
                                          "/" + fileKey;
                }
                else if (contentType.Contains(HikeConstants.LOCATION))
                {
                    convMessage.Message = String.Format(AppResources.FILES_MESSAGE_PREFIX, AppResources.Location_Txt) + HikeConstants.FILE_TRANSFER_BASE_URL +
                                          "/" + fileKey;
                }
                else if (contentType.Contains(HikeConstants.VIDEO))
                {
                    convMessage.Message = String.Format(AppResources.FILES_MESSAGE_PREFIX, AppResources.Video_Txt) + HikeConstants.FILE_TRANSFER_BASE_URL +
                                          "/" + fileKey;
                }
                else if (contentType.Contains(HikeConstants.CT_CONTACT))
                {
                    convMessage.Message = String.Format(AppResources.FILES_MESSAGE_PREFIX, AppResources.ContactTransfer_Text) + HikeConstants.FILE_TRANSFER_BASE_URL +
                                          "/" + fileKey;
                }
                convMessage.MessageStatus = ConvMessage.State.SENT_UNCONFIRMED;
                chatBubble.scheduleTryingImage();
                convMessage.FileAttachment.FileKey     = fileKey;
                convMessage.FileAttachment.ContentType = contentType;
                mPubSub.publish(HikePubSub.MQTT_PUBLISH, convMessage.serialize(true));
                chatBubble.setAttachmentState(Attachment.AttachmentState.COMPLETED);
                MiscDBUtil.saveAttachmentObject(convMessage.FileAttachment, convMessage.Msisdn, convMessage.MessageId);
            }
            else
            {
                chatBubble.SetSentMessageStatus(ConvMessage.State.SENT_FAILED);
                chatBubble.setAttachmentState(Attachment.AttachmentState.FAILED_OR_NOT_STARTED);
            }
        }