示例#1
0
        private static void json_Callback(IAsyncResult result)
        {
            object[]    vars = (object[])result.AsyncState;
            RequestType type = (RequestType)vars[1];

            HttpWebRequest  myHttpWebRequest = (HttpWebRequest)vars[0];
            HttpWebResponse response         = null;
            string          data;
            JObject         obj = null;
            ConvMessage     convMessage;

            try
            {
                response = (HttpWebResponse)myHttpWebRequest.EndGetResponse(result);
                Stream responseStream = response.GetResponseStream();
                if (string.Equals(response.Headers[HttpRequestHeader.ContentEncoding], "gzip", StringComparison.OrdinalIgnoreCase))
                {
                    data = decompressResponse(responseStream);
                }
                else
                {
                    using (var reader = new StreamReader(responseStream))
                    {
                        data = reader.ReadToEnd();
                    }
                }
                obj = JObject.Parse(data);
            }
            catch (IOException ioe)
            {
                obj = null;
            }
            catch (WebException we)
            {
                obj = null;
            }
            catch (JsonException je)
            {
                obj = null;
            }
            catch (Exception e)
            {
                obj = null;
            }
            finally
            {
                if (vars[2] is postResponseFunction)
                {
                    postResponseFunction finalCallbackFunction = vars[2] as postResponseFunction;
                    finalCallbackFunction(obj);
                }
                else if (vars[2] is postUploadPhotoFunction)
                {
                    postUploadPhotoFunction finalCallbackFunctionForUpload = vars[2] as postUploadPhotoFunction;
                    convMessage = vars[3] as ConvMessage;
                    SentChatBubble chatBubble = vars[4] as SentChatBubble;
                    finalCallbackFunctionForUpload(obj, convMessage, chatBubble);
                }
            }
        }
        //call this from UI thread
        private void addSentMessageToMsgMap(SentChatBubble sentChatBubble)
        {
            NewChatThread currentPage = App.newChatThreadPage;

            if (currentPage != null)
            {
                currentPage.OutgoingMsgsMap[sentChatBubble.MessageId] = sentChatBubble;
            }
        }
        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);
            }
        }
示例#4
0
        public static void uploadFile(byte[] dataBytes, postUploadPhotoFunction finalCallbackFunction, ConvMessage convMessage,
                                      SentChatBubble chatbubble)
        {
            HttpWebRequest req = HttpWebRequest.Create(new Uri(HikeConstants.FILE_TRANSFER_BASE_URL)) as HttpWebRequest;

            addToken(req);
            req.Method      = "PUT";
            req.ContentType = convMessage.FileAttachment.ContentType.Contains(HikeConstants.IMAGE) ||
                              convMessage.FileAttachment.ContentType.Contains(HikeConstants.VIDEO) ? "" : convMessage.FileAttachment.ContentType;
            req.Headers["Connection"]           = "Keep-Alive";
            req.Headers["Content-Name"]         = convMessage.FileAttachment.FileName;
            req.Headers["X-Thumbnail-Required"] = "0";

            req.BeginGetRequestStream(setParams_Callback, new object[] { req, RequestType.UPLOAD_FILE, dataBytes, finalCallbackFunction, convMessage,
                                                                         chatbubble });
        }
示例#5
0
        private static void setParams_Callback(IAsyncResult result)
        {
            object[]             vars                  = (object[])result.AsyncState;
            JObject              data                  = new JObject();
            HttpWebRequest       req                   = vars[0] as HttpWebRequest;
            Stream               postStream            = req.EndGetRequestStream(result);
            postResponseFunction finalCallbackFunction = null;
            RequestType          type                  = (RequestType)vars[1];

            switch (type)
            {
                #region REGISTER ACCOUNT
            case RequestType.REGISTER_ACCOUNT:
                string pin          = vars[2] as string;
                string unAuthMSISDN = vars[3] as string;
                finalCallbackFunction = vars[4] as postResponseFunction;
                data.Add("set_cookie", "0");
                data.Add("devicetype", "windows");
                data[HikeConstants.DEVICE_ID] = Utils.getHashedDeviceId();
                //data[HikeConstants.DEVICE_TOKEN] = Utils.getDeviceId();//for push notifications
                data[HikeConstants.DEVICE_VERSION] = Utils.getDeviceModel();
                data[HikeConstants.APP_VERSION]    = Utils.getAppVersion();
                string inviteToken = "";
                if (!string.IsNullOrEmpty(inviteToken))
                {
                    data[HikeConstants.INVITE_TOKEN_KEY] = inviteToken;
                }
                if (pin != null)
                {
                    data.Add("msisdn", unAuthMSISDN);
                    data.Add("pin", pin);
                }
                Compress4(data.ToString(Formatting.None), postStream);
                postStream.Close();
                req.BeginGetResponse(json_Callback, new object[] { req, type, finalCallbackFunction });
                return;

                #endregion
                #region INVITE
            case RequestType.INVITE:
                string phoneNo = vars[2] as string;
                data.Add("to", phoneNo);
                break;

                #endregion
                #region VALIDATE NUMBER
            case RequestType.VALIDATE_NUMBER:
                string numberToValidate = vars[2] as string;
                finalCallbackFunction = vars[3] as postResponseFunction;
                data.Add("phone_no", numberToValidate);
                break;

                #endregion
                #region CALL ME
            case RequestType.CALL_ME:
                string msisdn = vars[2] as string;
                finalCallbackFunction = vars[3] as postResponseFunction;
                data.Add("msisdn", msisdn);
                break;

                #endregion
                #region SET NAME
            case RequestType.SET_NAME:
                string nameToSet = vars[2] as string;
                finalCallbackFunction = vars[3] as postResponseFunction;
                data.Add("name", nameToSet);
                break;

                #endregion
                #region SET PROFILE
            case RequestType.SET_PROFILE:
                JObject jo = vars[2] as JObject;
                data = jo;
                finalCallbackFunction = vars[3] as postResponseFunction;
                break;

                #endregion
                #region POST ADDRESSBOOK
            case RequestType.POST_ADDRESSBOOK:
                Dictionary <string, List <ContactInfo> > contactListMap = vars[2] as Dictionary <string, List <ContactInfo> >;
                finalCallbackFunction = vars[3] as postResponseFunction;
                data = getJsonContactList(contactListMap);
                string x = data.ToString(Newtonsoft.Json.Formatting.None);
                Compress4(x, postStream);
                postStream.Close();
                req.BeginGetResponse(json_Callback, new object[] { req, type, finalCallbackFunction });
                ContactUtils.ContactState = ContactUtils.ContactScanState.ADDBOOK_POSTED;
                return;

                #endregion
                #region SOCIAL POST
            case RequestType.SOCIAL_POST:
                data = vars[2] as JObject;
                finalCallbackFunction = vars[3] as postResponseFunction;
                break;

                #endregion
                #region SOCIAL DELETE
            case RequestType.SOCIAL_DELETE:
                finalCallbackFunction = vars[2] as postResponseFunction;
                break;

                #endregion
                #region UPDATE ADDRESSBOOK
            case RequestType.UPDATE_ADDRESSBOOK:
                Dictionary <string, List <ContactInfo> > contacts_to_update = vars[2] as Dictionary <string, List <ContactInfo> >;
                JArray ids_json = vars[3] as JArray;
                finalCallbackFunction = vars[4] as postResponseFunction;
                if (ids_json != null)
                {
                    data.Add("remove", ids_json);
                }
                JObject ids_to_update = getJsonContactList(contacts_to_update);
                if (ids_to_update != null)
                {
                    data.Add("update", ids_to_update);
                }
                break;

                #endregion
                #region DELETE ACCOUNT
            case RequestType.DELETE_ACCOUNT:
                finalCallbackFunction = vars[2] as postResponseFunction;
                break;

                #endregion
                #region POST PROFILE ICON
            case RequestType.POST_PROFILE_ICON:
                byte[] imageBytes = (byte[])vars[2];
                finalCallbackFunction = vars[3] as postResponseFunction;
                postStream.Write(imageBytes, 0, imageBytes.Length);
                postStream.Close();
                req.BeginGetResponse(json_Callback, new object[] { req, type, finalCallbackFunction });
                return;

                #endregion
                #region POST PUSH NOTIFICATION DATA
            case RequestType.POST_PUSHNOTIFICATION_DATA:
                string uri = (string)vars[2];
                finalCallbackFunction = vars[3] as postResponseFunction;
                data.Add("dev_token", uri);
                data.Add("dev_type", "windows");
                break;

                #endregion
            case RequestType.POST_INFO_ON_APP_UPDATE:
                finalCallbackFunction = vars[2] as postResponseFunction;
                if (Utils.IsWP8)
                {
                    data["_os"] = "win8";
                }
                else
                {
                    data["_os"] = "win7";
                }
                data["_os_version"]   = Utils.getOSVersion();
                data["deviceversion"] = Utils.getDeviceModel();
                data["app_version"]   = Utils.getAppVersion();
                data["dev_type"]      = "windows";
                break;

                #region UPLOAD FILE
            case RequestType.UPLOAD_FILE:
                byte[] dataBytes = (byte[])vars[2];
                postUploadPhotoFunction finalCallbackForUploadFile = vars[3] as postUploadPhotoFunction;
                ConvMessage             convMessage = vars[4] as ConvMessage;
                SentChatBubble          chatBubble  = vars[5] as SentChatBubble;
                int    bufferSize       = 2048;
                int    startIndex       = 0;
                int    noOfBytesToWrite = 0;
                double progressValue    = 0;
                while (startIndex < dataBytes.Length)
                {
                    Thread.Sleep(5);
                    noOfBytesToWrite = dataBytes.Length - startIndex;
                    noOfBytesToWrite = noOfBytesToWrite < bufferSize ? noOfBytesToWrite : bufferSize;
                    postStream.Write(dataBytes, startIndex, noOfBytesToWrite);
                    progressValue = ((double)(startIndex + noOfBytesToWrite) / dataBytes.Length) * 100;
                    bool updated = chatBubble.updateProgress(progressValue);
                    if (!updated)
                    {
                        chatBubble.setAttachmentState(Attachment.AttachmentState.CANCELED);
                        break;
                    }
                    startIndex += noOfBytesToWrite;
                }

                postStream.Close();
                req.BeginGetResponse(json_Callback, new object[] { req, type, finalCallbackForUploadFile, convMessage, chatBubble });
                return;

                #endregion
                #region DEFAULT
            default:
                break;
                #endregion
            }

            using (StreamWriter sw = new StreamWriter(postStream))
            {
                string json = data.ToString(Newtonsoft.Json.Formatting.None);
                sw.Write(json);
            }
            postStream.Close();
            req.BeginGetResponse(json_Callback, new object[] { req, type, finalCallbackFunction });
        }
示例#6
0
        private void Initialize()
        {
            gtalkHelper.RosterUpdated -= Initialize;

            Dispatcher.BeginInvoke(() => {
                string displayName = email;
                string status      = string.Empty;
                if (App.Current.Roster.Contains(to))
                {
                    Contact t   = App.Current.Roster[to];
                    displayName = t.NameOrEmail;
                    status      = t.Status;
                }

                PageTitle.Text = displayName.ToUpper();
                if (status != string.Empty)
                {
                    PageTitle.Text += ", " + char.ToUpper(status[0]) + status.Substring(1);
                }

                TypingStatus.Text = String.Format(AppResources.Chat_NoticeTyping, displayName);

                if (gtalkHelper.IsContactPinned(email))
                {
                    pinButton.IsEnabled = false;
                }

                chatLog = gtalkHelper.ChatLog(to);

                MessageList.Visibility = System.Windows.Visibility.Collapsed;

                MessageList.Children.Clear();

                lock (chatLog) {
                    var otr = false;

                    foreach (var message in chatLog)
                    {
                        UserControl bubble;

                        if (message.OTR != otr)
                        {
                            if (message.OTR)
                            {
                                ShowStartOtr();
                            }
                            else
                            {
                                ShowEndOtr();
                            }

                            otr = message.OTR;
                        }

                        if (message.Body == null)
                        {
                            continue;
                        }

                        if (message.Outbound)
                        {
                            bubble = new SentChatBubble();

                            (bubble as SentChatBubble).Text      = message.Body;
                            (bubble as SentChatBubble).TimeStamp = message.Time;
                        }
                        else
                        {
                            bubble = new ReceivedChatBubble();

                            (bubble as ReceivedChatBubble).Text      = message.Body;
                            (bubble as ReceivedChatBubble).TimeStamp = message.Time;
                        }

                        MessageList.Children.Add(bubble);
                    }
                }

                MessageList.Visibility = System.Windows.Visibility.Visible;
                MessageList.UpdateLayout();
                Scroller.UpdateLayout();
                Scroller.ScrollToVerticalOffset(Scroller.ExtentHeight);

                var unread = settings["unread"] as Dictionary <string, int>;
                lock (unread) {
                    unread[email] = 0;
                }
                if (App.Current.Roster.Contains(email))
                {
                    App.Current.Roster[email].UnreadCount = 0;
                }
                foreach (var con in App.Current.RecentContacts)
                {
                    if (con.Email == email)
                    {
                        con.UnreadCount = 0;
                        break;
                    }
                }

                Uri url            = gtalkHelper.GetPinUri(email);
                ShellTile existing = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri == url);

                if (existing != null)
                {
                    existing.Update(
                        new StandardTileData {
                        Count = 0
                    }
                        );
                }

                var contact = App.Current.Roster[email];

                if (contact != null)
                {
                    contact.UnreadCount = 0;
                }

                // Sets to broadcast the first message in a conversation
                to = email;
            });
        }
示例#7
0
        private void SendButton_Click(object sender, EventArgs e)
        {
            if (MessageText.Text.Length == 0)
            {
                return;
            }

            ShowProgressBar(AppResources.Chat_ProgressSendingMessage);

            sendButton.IsEnabled = false;

            try {
                gtalk.SendMessage(to, MessageText.Text, data => Dispatcher.BeginInvoke(() => {
                    HideProgressBar();

                    var bubble       = new SentChatBubble();
                    bubble.Text      = MessageText.Text;
                    bubble.TimeStamp = DateTime.Now;

                    App.Current.GtalkHelper.AddRecentContact(currentContact);

                    MessageList.Children.Add(bubble);

                    sendButton.IsEnabled = true;

                    MessageList.UpdateLayout();
                    Scroller.UpdateLayout();
                    Scroller.ScrollToVerticalOffset(Scroller.ExtentHeight);

                    lock (chatLog) {
                        while (chatLog.Count >= GoogleTalkHelper.MaximumChatLogSize)
                        {
                            chatLog.RemoveAt(0);
                        }
                        chatLog.Add(new Message {
                            Body     = MessageText.Text,
                            Outbound = true,
                            Time     = DateTime.Now,
                            OTR      = otr
                        });
                    }

                    MessageText.Text = "";
                    // Refocus text box to reset text suggestions.
                    // Only refocus is it's currently focused.
                    if (System.Windows.Input.FocusManager.GetFocusedElement() == MessageText)
                    {
                        this.Focus();
                        MessageText.Focus();
                    }

                    FlurryWP7SDK.Api.LogEvent("Chat - Chat sent");
                }), error => {
                    HideProgressBar();
                    if (error.StartsWith("403"))
                    {
                        settings.Remove("token");
                        settings.Remove("rootUrl");
                        gtalkHelper.LoginIfNeeded();
                    }
                    else
                    {
                        Dispatcher.BeginInvoke(
                            () => {
                            sendButton.IsEnabled = true;
                            gtalkHelper.ShowToast(AppResources.Chat_ErrorMessageNotSent);
                        }
                            );
                    }
                });
            } catch (InvalidOperationException) {
                Dispatcher.BeginInvoke(
                    () => {
                    HideProgressBar();
                    MessageBox.Show(
                        AppResources.Chat_ErrorAuthExpiredBody,
                        AppResources.Chat_ErrorAuthExpiredTitle,
                        MessageBoxButton.OK
                        );
                    App.Current.RootFrame.Navigate(new Uri("/Pages/Login.xaml", UriKind.Relative));
                }
                    );
            }
        }
        public void onEventReceived(string type, object obj)
        {
            #region MESSAGE_SENT
            if (HikePubSub.MESSAGE_SENT == type)
            {
                object[]    vals        = (object[])obj;
                ConvMessage convMessage = (ConvMessage)vals[0];

                bool                   isNewGroup = (bool)vals[1];
                SentChatBubble         chatBubble = (SentChatBubble)vals[2];
                ConversationListObject convObj    = MessagesTableUtils.addChatMessage(convMessage, isNewGroup);
                if (convObj == null)
                {
                    return;
                }
                if (chatBubble != null)
                {
                    chatBubble.MessageId = convMessage.MessageId;
                }

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    if (chatBubble != null)
                    {
                        addSentMessageToMsgMap(chatBubble);
                    }

                    if (convObj.ConvBoxObj == null)
                    {
                        convObj.ConvBoxObj = new ConversationBox(convObj);
                        if (App.ViewModel.ConversationListPage != null)
                        {
                            ContextMenuService.SetContextMenu(convObj.ConvBoxObj, App.ViewModel.ConversationListPage.createConversationContextMenu(convObj));
                        }
                    }
                    else if (App.ViewModel.MessageListPageCollection.Contains(convObj.ConvBoxObj))//cannot use convMap here because object has pushed to map but not to ui
                    {
                        App.ViewModel.MessageListPageCollection.Remove(convObj.ConvBoxObj);
                    }

                    App.ViewModel.MessageListPageCollection.Insert(0, convObj.ConvBoxObj);

                    if (!isNewGroup)
                    {
                        mPubSub.publish(HikePubSub.MQTT_PUBLISH, convMessage.serialize(convMessage.IsSms ? false : true));
                    }
                });
                //if (!isNewGroup)
                //    mPubSub.publish(HikePubSub.MQTT_PUBLISH, convMessage.serialize(convMessage.IsSms ? false : true));
            }
            #endregion
            #region FORWARD_ATTACHMENT
            else if (HikePubSub.FORWARD_ATTACHMENT == type)
            {
                object[]       vals           = (object[])obj;
                ConvMessage    convMessage    = (ConvMessage)vals[0];
                string         sourceFilePath = (string)vals[1];
                SentChatBubble chatBubble     = (SentChatBubble)vals[2];

                ConversationListObject convObj = MessagesTableUtils.addChatMessage(convMessage, false);
                chatBubble.MessageId = convMessage.MessageId;

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    addSentMessageToMsgMap(chatBubble);

                    if (convObj.ConvBoxObj == null)
                    {
                        convObj.ConvBoxObj = new ConversationBox(convObj);
                        if (App.ViewModel.ConversationListPage != null)
                        {
                            ContextMenuService.SetContextMenu(convObj.ConvBoxObj, App.ViewModel.ConversationListPage.createConversationContextMenu(convObj));
                        }
                    }
                    else if (App.ViewModel.MessageListPageCollection.Contains(convObj.ConvBoxObj))//cannot use convMap here because object has pushed to map but not to ui
                    {
                        App.ViewModel.MessageListPageCollection.Remove(convObj.ConvBoxObj);
                    }

                    App.ViewModel.MessageListPageCollection.Insert(0, convObj.ConvBoxObj);
                    //forward attachment message
                    string destinationFilePath = HikeConstants.FILES_BYTE_LOCATION + "/" + convMessage.Msisdn + "/" + convMessage.MessageId;
                    //while writing in iso, we write it as failed and then revert to started
                    MiscDBUtil.saveAttachmentObject(convMessage.FileAttachment, convMessage.Msisdn, convMessage.MessageId);

                    //since, Location & Contact has required info in metadata string, no need to use raw files
                    if (!convMessage.FileAttachment.ContentType.Contains(HikeConstants.CT_CONTACT) &&
                        !convMessage.FileAttachment.ContentType.Contains(HikeConstants.LOCATION))
                    {
                        MiscDBUtil.copyFileInIsolatedStorage(sourceFilePath, destinationFilePath);
                    }
                    mPubSub.publish(HikePubSub.MQTT_PUBLISH, convMessage.serialize(true));
                });
            }
            #endregion
            #region ATTACHMENT_SEND
            else if (HikePubSub.ATTACHMENT_SENT == type)
            {
                object[]       vals        = (object[])obj;
                ConvMessage    convMessage = (ConvMessage)vals[0];
                byte[]         fileBytes   = (byte[])vals[1];
                SentChatBubble chatBubble  = (SentChatBubble)vals[2];

                //In case of sending attachments, here message state should be unknown instead of sent_unconfirmed
                //convMessage.MessageStatus = ConvMessage.State.SENT_UNCONFIRMED;
                ConversationListObject convObj = MessagesTableUtils.addChatMessage(convMessage, false);

                // in case of db failure convObj returned will be null
                if (convObj == null)
                {
                    return;
                }
                chatBubble.MessageId = convMessage.MessageId;

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    addSentMessageToMsgMap(chatBubble);
                    if (convObj.ConvBoxObj == null)
                    {
                        convObj.ConvBoxObj = new ConversationBox(convObj);
                        if (App.ViewModel.ConversationListPage != null)
                        {
                            ContextMenuService.SetContextMenu(convObj.ConvBoxObj, App.ViewModel.ConversationListPage.createConversationContextMenu(convObj));
                        }
                    }
                    else if (App.ViewModel.MessageListPageCollection.Contains(convObj.ConvBoxObj))
                    {
                        App.ViewModel.MessageListPageCollection.Remove(convObj.ConvBoxObj);
                    }
                    App.ViewModel.MessageListPageCollection.Insert(0, convObj.ConvBoxObj);
                    //send attachment message (new attachment - upload case)
                    MessagesTableUtils.addUploadingOrDownloadingMessage(convMessage.MessageId, chatBubble);
                    convMessage.FileAttachment.FileState = Attachment.AttachmentState.FAILED_OR_NOT_STARTED;
                    MiscDBUtil.saveAttachmentObject(convMessage.FileAttachment, convMessage.Msisdn, convMessage.MessageId);
                    convMessage.FileAttachment.FileState = Attachment.AttachmentState.STARTED;

                    AccountUtils.postUploadPhotoFunction finalCallbackForUploadFile = new AccountUtils.postUploadPhotoFunction(uploadFileCallback);
                    if (!convMessage.FileAttachment.ContentType.Contains(HikeConstants.CT_CONTACT))
                    {
                        MiscDBUtil.storeFileInIsolatedStorage(HikeConstants.FILES_BYTE_LOCATION + "/" + convMessage.Msisdn + "/" +
                                                              Convert.ToString(convMessage.MessageId), fileBytes);
                    }
                    AccountUtils.uploadFile(fileBytes, finalCallbackForUploadFile, convMessage, chatBubble);
                });
            }
            #endregion
            #region ATTACHMENT_RESEND_OR_FORWARD
            else if (HikePubSub.ATTACHMENT_RESEND == type)
            {
                object[]       vals        = (object[])obj;
                ConvMessage    convMessage = (ConvMessage)vals[0];
                SentChatBubble chatBubble  = (SentChatBubble)vals[1];
                byte[]         fileBytes;
                if (convMessage.FileAttachment.ContentType.Contains(HikeConstants.CT_CONTACT))
                {
                    fileBytes = Encoding.UTF8.GetBytes(convMessage.MetaDataString);
                }
                else
                {
                    MiscDBUtil.readFileFromIsolatedStorage(HikeConstants.FILES_BYTE_LOCATION + "/" + convMessage.Msisdn + "/" +
                                                           Convert.ToString(convMessage.MessageId), out fileBytes);
                }
                AccountUtils.postUploadPhotoFunction finalCallbackForUploadFile = new AccountUtils.postUploadPhotoFunction(uploadFileCallback);
                AccountUtils.uploadFile(fileBytes, finalCallbackForUploadFile, convMessage, chatBubble);
            }
            #endregion
            #region MESSAGE_RECEIVED_READ
            else if (HikePubSub.MESSAGE_RECEIVED_READ == type)  // represents event when a msg is read by this user
            {
                long[] ids = (long[])obj;
                updateDbBatch(ids, (int)ConvMessage.State.RECEIVED_READ);
            }
            #endregion
            #region MESSAGE_DELETED
            else if (HikePubSub.MESSAGE_DELETED == type)
            {
                object[] o = (object[])obj;

                long msgId = (long)o[0];
                MessagesTableUtils.deleteMessage(msgId); // delete msg with given msgId from messages table

                ConversationListObject c = (ConversationListObject)o[1];
                bool delConv             = (bool)o[2];
                if (delConv)
                {
                    // delete the conversation from DB.
                    ConversationTableUtils.deleteConversation(c.Msisdn);
                    //ConversationTableUtils.saveConvObjectList();
                }
                else
                {
                    //update conversation
                    ConversationTableUtils.updateConversation(c);
                }
                // TODO :: persistence.removeMessage(msgId);
            }
            #endregion
            #region BLOCK_USER
            else if (HikePubSub.BLOCK_USER == type)
            {
                string msisdn = (string)obj;
                UsersTableUtils.block(msisdn);
                JObject blockObj = blockUnblockSerialize("b", msisdn);
                mPubSub.publish(HikePubSub.MQTT_PUBLISH, blockObj);
            }
            #endregion
            #region UNBLOCK_USER
            else if (HikePubSub.UNBLOCK_USER == type)
            {
                string msisdn = (string)obj;
                UsersTableUtils.unblock(msisdn);
                JObject unblockObj = blockUnblockSerialize("ub", msisdn);
                mPubSub.publish(HikePubSub.MQTT_PUBLISH, unblockObj);
            }
            #endregion
            #region ADD_OR_UPDATE_PROFILE
            else if (HikePubSub.ADD_OR_UPDATE_PROFILE == type)
            {
                object[] vals           = (object[])obj;
                string   msisdn         = (string)vals[0];
                byte[]   fullViewBytes  = (byte[])vals[1];
                byte[]   thumbnailBytes = (byte[])vals[2];
                if (Utils.isGroupConversation(msisdn))
                {
                    string grpId = msisdn.Replace(":", "_");
                    MiscDBUtil.saveAvatarImage(grpId + HikeConstants.FULL_VIEW_IMAGE_PREFIX, fullViewBytes, false);
                    MiscDBUtil.saveAvatarImage(grpId, thumbnailBytes, false);
                }
                else
                {
                    MiscDBUtil.saveAvatarImage(HikeConstants.MY_PROFILE_PIC, thumbnailBytes, false);
                }
            }
            #endregion
            #region GROUP LEFT
            else if (HikePubSub.GROUP_LEFT == type)
            {
                /*
                 * 1. Delete conversation with this groupId
                 * 2. Delete ConvMessages
                 * 3. Delete GroupInfo
                 * 4. Delete GroupMembers
                 */
                string groupId = (string)obj;
                ConversationTableUtils.deleteConversation(groupId);
                //ConversationTableUtils.saveConvObjectList();
                MessagesTableUtils.deleteAllMessagesForMsisdn(groupId);
                GroupTableUtils.deleteGroupWithId(groupId);
                GroupManager.Instance.GroupCache.Remove(groupId);
                GroupManager.Instance.DeleteGroup(groupId);
            }
            #endregion
            #region BLOCK GROUP OWNER
            else if (HikePubSub.BLOCK_GROUPOWNER == type)
            {
                string groupOwner = (string)obj;
                UsersTableUtils.block(groupOwner);
                JObject blockObj = blockUnblockSerialize("b", groupOwner);
                mPubSub.publish(HikePubSub.MQTT_PUBLISH, blockObj);
            }
            #endregion
            #region UNBLOCK GROUP OWNER
            else if (HikePubSub.UNBLOCK_GROUPOWNER == type)
            {
                string groupOwner = (string)obj;
                UsersTableUtils.unblock(groupOwner);
                JObject unblockObj = blockUnblockSerialize("ub", groupOwner);
                mPubSub.publish(HikePubSub.MQTT_PUBLISH, unblockObj);
            }
            #endregion
            #region DELETE CONVERSATION
            else if (HikePubSub.DELETE_CONVERSATION == type)
            {
                string convMsisdn = (string)obj;
                if (Utils.isGroupConversation(convMsisdn))                 // if Group Conversation delete groups too
                {
                    GroupTableUtils.deleteGroupWithId(convMsisdn);         // remove entry from Group Table
                    GroupManager.Instance.GroupCache.Remove(convMsisdn);
                    GroupManager.Instance.DeleteGroup(convMsisdn);         // delete the group file
                }
                MessagesTableUtils.deleteAllMessagesForMsisdn(convMsisdn); //removed all chat messages for this msisdn
                ConversationTableUtils.deleteConversation(convMsisdn);     // removed entry from conversation table
                //ConversationTableUtils.saveConvObjectList();
                MiscDBUtil.deleteMsisdnData(convMsisdn);
            }
            #endregion
        }