private void RaiseViewConversation(ConversationModel conversation)
 {
     if (this.ViewConversation != null)
     {
         this.ViewConversation(this, new ConversationStartedArgs(conversation));
     }
 }
 private void RaiseConversationStarted(ConversationModel conversation)
 {
     if (this.ConversationStarted != null)
     {
         this.ConversationStarted(this, new ConversationStartedArgs(conversation));
     }
 }
        private void HandleViewMissedConversation(object parameter)
        {
            if (parameter != null)
            {
                var missedConversation = parameter as MissedConversationModel;
                var conversationData = new ConversationModel()
                                           {
                                               FirstUser = new UserModel() {Username = CurrentUserInfo.Username},
                                               SecondUser = new UserModel() {Username = missedConversation.Username}
                                           };

                var startedConversation = ConversationsPersister.Start(CurrentUserInfo.SessionKey, conversationData);
                RaiseViewConversation(startedConversation);
            }
        }
        public ConversationViewModel(ConversationModel conversation, UserModel currentUser, UserModel partner)
        {
            this.CurrentConversation = conversation;
            this.CurrentUserInfo = currentUser;
            this.Partner = partner;
            this.CurrentConversation.Messages =
                MessagePersister.GetAllMsgsByConversation(CurrentUserInfo.SessionKey,
                                                            CurrentConversation.Id);

            OnPropertyChanged("CurrentConversation");

            pubnub = new PubnubAPI(PUBLISH_KEY, SUBSCRIBE_KEY, SECRET_KEY, true);

            var minId = Math.Min(CurrentUserInfo.Id, Partner.Id);
            var maxId = Math.Max(CurrentUserInfo.Id, Partner.Id);
            channelName = string.Format("channel-{0}-{1}",
                                               minId, maxId);

            Thread t = new Thread(() =>
                                  pubnub.Subscribe(channelName, HandleNewMessageReceived));
            t.IsBackground = true;
            t.Start();
        }
        private void HandleStartConversation(object parameter)
        {
            if (parameter != null)
            {
                var user = parameter as UserModel;
                var conversation = new ConversationModel()
                                       {
                                           FirstUser = CurrentUser,
                                           SecondUser = user
                                       };

                var startedConversation = ConversationsPersister.Start(CurrentUser.SessionKey, conversation);
                RaiseConversationStarted(startedConversation);
            }
        }
 public static ConversationModel Start(string sessionKey, ConversationModel conversationData)
 {
     headers[HttpRequester.sessionKeyHeaderName] = sessionKey;
     return HttpRequester.Post<ConversationModel>(baseUrl + "start", conversationData, headers);
 }
 public ConversationStartedArgs(ConversationModel conversation)
 {
     Conversation = conversation;
 }