Esempio n. 1
0
        public async Task LoadMessagesAsync()
        {
            try
            {
                var messages = await ParseAccess.LoadMessages(conversationId);

                foreach (var message in messages)
                {
                    var isMe = false;
                    if (message.Get <string>("author") == ParseAccess.CurrentUser().ObjectId)
                    {
                        isMe = true;
                    }

                    var newMessage = new UserMessage
                    {
                        ObjectId  = message.ObjectId,
                        Body      = message.Get <string>("body"),
                        IsMe      = isMe,
                        CreatedAt = message.CreatedAt.Value + RestService.TimeDiff
                    };

                    if (!Messages.Contains(newMessage))
                    {
                        Messages.Add(newMessage);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
Esempio n. 2
0
        public async Task ExecutePostAnswerAsync(Answer answer)
        {
            if (IsBusy)
            {
                return;
            }

            ProgressDialogManager.LoadProgressDialog("Loading...");

            try
            {
                IsBusy = true;
                await ParseAccess.AddAnswer(answer);

                //UserDialogs.Instance.Toast("Posted.", TimeSpan.FromSeconds(3));

                IsPosted = true;
            }
            catch (Exception e)
            {
                UserDialogs.Instance.Alert(e.Message, "ERROR", "OK");
            }
            finally
            {
                IsBusy = false;

                ProgressDialogManager.DisposeProgressDialog();
            }
        }
Esempio n. 3
0
        public async Task ExecuteSaveProfileCommandAsync()
        {
            if (IsBusy)
            {
                return;
            }

            ProgressDialogManager.LoadProgressDialog("Loading...");

            try
            {
                IsBusy = true;
                await ParseAccess.UpdateProfile(UserDetail);

                UserDialogs.Instance.Toast("Profile updated.", TimeSpan.FromSeconds(3));
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
            finally
            {
                IsBusy = false;
                ProgressDialogManager.DisposeProgressDialog();
            }
        }
Esempio n. 4
0
        public async Task ExecuteGetUserCommandAsync()
        {
            if (IsBusy)
            {
                return;
            }

            ProgressDialogManager.LoadProgressDialog("Loading...");

            try
            {
                IsBusy = true;
                var user = await ParseAccess.GetUser(ParseAccess.CurrentUser().ObjectId);

                UserDetail = new User
                {
                    Username  = user.Get <string>("username"),
                    FirstName = user.Get <string>("firstName"),
                    LastName  = user.Get <string>("lastName")
                };
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
            finally
            {
                IsBusy = false;
                ProgressDialogManager.DisposeProgressDialog();
            }
        }
        public async Task LoadMyConversationsAsync()
        {
            if (IsBusy)
            {
                return;
            }

            ProgressDialogManager.LoadProgressDialog("Loading...");
            try
            {
                IsBusy = true;

                var conversations = await ParseAccess.LoadMyConversations();

                foreach (var conversation in conversations)
                {
                    var members = conversation.Get <IList <ParseObject> >("members");

                    var otherUser = new User
                    {
                        ObjectId  = members[0].ObjectId,
                        Username  = members[0].Get <string>("username"),
                        FirstName = members[0].Get <string>("firstName"),
                        LastName  = members[0].Get <string>("lastName")
                    };

                    var messageObject = await ParseAccess.GetLastMessage(conversation.ObjectId);

                    if (messageObject != null)
                    {
                        var lastMessage = new UserMessage
                        {
                            Body      = messageObject.Get <string>("body"),
                            CreatedAt = messageObject.CreatedAt.Value + RestService.TimeDiff
                        };

                        var conv = new Conversation
                        {
                            OtherUser   = otherUser,
                            LastMessage = lastMessage
                        };

                        Conversations.Add(conv);
                    }
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
            finally
            {
                IsBusy = false;
                ProgressDialogManager.DisposeProgressDialog();
            }
        }
Esempio n. 6
0
 public async Task SendMessageAsync(string body)
 {
     try
     {
         await ParseAccess.SendMessage(conversationId, body);
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex);
     }
 }
Esempio n. 7
0
        //public void EnableLiveQuery()
        //{
        //    _ws = new WebSocket("ws://ec2-52-63-31-67.ap-southeast-2.compute.amazonaws.com:1337/");

        //    _ws.Open();
        //    _ws.Opened += (sender, e) =>
        //    {
        //        _ws.Send(Newtonsoft.Json.JsonConvert.SerializeObject(new { op = "connect", applicationId = "SuperMen", windowsKey = "rickpham" }));

        //    };

        //    _ws.MessageReceived += (sender, e) =>
        //    {
        //        Debug.WriteLine(e.Message);


        //        Debug.WriteLine(_ws.State);
        //    };
        //    _ws.Error += (sender, e) =>
        //    {
        //        Debug.WriteLine(e.Exception);


        //    };

        //    Debug.WriteLine(_ws.State);
        //}

        //public void Subscribe()
        //{
        //    _ws.Send(Newtonsoft.Json.JsonConvert.SerializeObject(new { op = "subscribe", requestId = 1, query = new { className = "Message", where = new { conversationId } } }));
        //}


        public async Task GetConversationIdAsync()
        {
            try
            {
                conversationId = await ParseAccess.GetConversationId(otherUserId);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
Esempio n. 8
0
 public async Task UpdateInfo(User user)
 {
     try
     {
         await ParseAccess.UpdateProfile(user);
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
     }
 }
Esempio n. 9
0
        public async Task SignUp(User user)
        {
            try
            {
                await ParseAccess.SignUp(user);

                IsAsyncFinished = true;
            } catch (Exception e)
            {
                UserDialogs.Instance.Alert(e.Message, "ERROR SIGNING UP", "OK");
            }
        }
        public async Task SendHelperRequest()
        {
            if (IsBusy)
            {
                return;
            }

            try
            {
                await ParseAccess.AddRequestedHelper(questionId);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
        }
Esempio n. 11
0
 public async Task Login(User user)
 {
     try
     {
         IsBusy = true;
         await ParseAccess.Login(user);
     }
     catch (Exception e)
     {
         UserDialogs.Instance.Alert(e.Message, "ERROR SIGNING IN", "OK");
     }
     finally
     {
         IsBusy = false;
     }
 }
        public async Task LoadMyRequestDetailAsync()
        {
            if (IsBusy)
            {
                return;
            }

            ProgressDialogManager.LoadProgressDialog("Loading...");

            try
            {
                IsBusy = true;
                var request = await ParseAccess.GetMyRequest(requestId);

                var state     = "Closed";
                var stateFlag = request.Get <int>("stateFlag");

                if (stateFlag == (int)RequestState.Active)
                {
                    state = "Active";
                }
                else if (stateFlag == (int)RequestState.InProgress)
                {
                    state = "In Progress";
                }


                var topicObjects = request.Get <IList <ParseObject> >("topics");
                var topics       = new List <string>();
                foreach (var topic in topicObjects)
                {
                    topics.Add(topic.Get <string>("topicText"));
                }

                var helpers = request.Get <IList <ParseUser> >("requestedHelpers");
                foreach (var helper in helpers)
                {
                    var user = new User
                    {
                        ObjectId  = helper.ObjectId,
                        FirstName = helper.Get <string>("firstName"),
                        LastName  = helper.Get <string>("lastName"),
                        Username  = helper.Get <string>("username")
                    };

                    Helpers.Add(user);
                }
                Request = new Question()
                {
                    Title     = request.Get <string>("title"),
                    Body      = request.Get <string>("body"),
                    ObjectId  = request.ObjectId,
                    Topics    = topics,
                    CreatedAt = request.CreatedAt.Value + RestService.TimeDiff,
                    State     = state
                };
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
            finally
            {
                IsBusy = false;
                ProgressDialogManager.DisposeProgressDialog();
            }
        }
Esempio n. 13
0
        public async Task ExecuteLoadUsersCommandAsync(string filter)
        {
            if (IsBusy)
            {
                return;
            }

            ProgressDialogManager.LoadProgressDialog("Loading...");
            try
            {
                IsBusy = true;
                Users.Clear();


                followedUsers.Clear();

                try
                {
                    followedUsers.AddRange((await ParseAccess.GetUser(ParseAccess.CurrentUser().ObjectId)).Get <IList <string> >("followedUsers"));
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }

                IEnumerable <Parse.ParseObject> users;
                if (filter == "Followed Users")
                {
                    users = await ParseAccess.LoadFollowedUsers(followedUsers);
                }
                else
                {
                    users = await ParseAccess.LoadUsers();
                }

                foreach (var user in users)
                {
                    var isFollowed = false;

                    var topicObjects = user.Get <IList <ParseObject> >("followedTopics");
                    var topics       = new List <string>();
                    foreach (var topic in topicObjects)
                    {
                        topics.Add(topic.Get <string>("topicText"));
                    }
                    if (followedUsers.Contains(user.ObjectId))
                    {
                        isFollowed = true;
                    }
                    var u = new User
                    {
                        Username       = user.Get <string>("username"),
                        FirstName      = user.Get <string>("firstName"),
                        LastName       = user.Get <string>("lastName"),
                        ObjectId       = user.ObjectId,
                        IsFollowed     = isFollowed,
                        FollowedTopics = topics
                    };
                    Users.Add(u);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
            finally
            {
                IsBusy = false;
                ProgressDialogManager.DisposeProgressDialog();
            }
        }
        public async Task ExecuteLoadQuestionsCommandAsync(string filter)
        {
            if (IsBusy)
            {
                return;
            }

            ProgressDialogManager.LoadProgressDialog("Loading...");

            try
            {
                IsBusy = true;
                Questions.Clear();
                DateTime now = RestService.GetServerTime();

                followedOppors.Clear();

                try
                {
                    followedOppors.AddRange((await ParseAccess.GetUser(ParseAccess.CurrentUser().ObjectId)).Get <IList <string> >("followedOppors"));
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }

                IEnumerable <Parse.ParseObject> questions;
                if (filter == "Followed Tasks")
                {
                    questions = await ParseAccess.LoadFollowedOppors(followedOppors);
                }
                else if (filter == "Followed Topics")
                {
                    questions = await ParseAccess.LoadOpporsBasedOnTopics();
                }
                else if (filter == "My Requests")
                {
                    questions = await ParseAccess.LoadMyRequests();
                }
                else
                {
                    questions = await ParseAccess.LoadQuestions();
                }

                foreach (var question in questions)
                {
                    var isFollowed = false;
                    var state      = "Closed";
                    var stateFlag  = question.Get <int>("stateFlag");

                    var topicObjects = question.Get <IList <ParseObject> >("topics");
                    var topics       = new List <string>();
                    foreach (var topic in topicObjects)
                    {
                        topics.Add(topic.Get <string>("topicText"));
                    }

                    if (stateFlag == (int)RequestState.Active)
                    {
                        state = "Active";
                    }
                    else if (stateFlag == (int)RequestState.InProgress)
                    {
                        state = "In Progress";
                    }

                    if (followedOppors.Contains(question.ObjectId))
                    {
                        isFollowed = true;
                    }
                    var q = new Question
                    {
                        ObjectId   = question.ObjectId,
                        Title      = question.Get <string>("title"),
                        Body       = question.Get <string>("body"),
                        TimeAgo    = HelperFunctions.TimeAgo(question.UpdatedAt.Value, now),
                        IsFollowed = isFollowed,
                        State      = state,
                        Topics     = topics
                    };
                    Questions.Add(q);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
            finally
            {
                IsBusy = false;
                ProgressDialogManager.DisposeProgressDialog();
            }
        }
        public async Task ExecuteUnfollowOppors(string id)
        {
            followedOppors.Remove(id);

            await ParseAccess.UpdateFollowedOppors(followedOppors);
        }
        public async Task ExecuteLoadQuestionDetailCommandAsync()
        {
            if (IsBusy)
            {
                return;
            }

            ProgressDialogManager.LoadProgressDialog("Loading...");

            try
            {
                IsBusy = true;
                var question = await ParseAccess.GetQuestion(questionId);

                var state     = "Closed";
                var stateFlag = question.Get <int>("stateFlag");

                if (stateFlag == (int)RequestState.Active)
                {
                    state = "Active";
                }
                else if (stateFlag == (int)RequestState.InProgress)
                {
                    state = "In Progress";
                }

                var topicObjects = question.Get <IList <ParseObject> >("topics");
                var topics       = new List <string>();
                foreach (var topic in topicObjects)
                {
                    topics.Add(topic.Get <string>("topicText"));
                }

                var ownerObject = question.Get <ParseObject>("createdBy");

                var owner = new User
                {
                    ObjectId  = ownerObject.ObjectId,
                    FirstName = ownerObject.Get <string>("firstName"),
                    LastName  = ownerObject.Get <string>("lastName"),
                    Username  = ownerObject.Get <string>("username")
                };
                Question = new Question()
                {
                    Title     = question.Get <string>("title"),
                    Body      = question.Get <string>("body"),
                    ObjectId  = question.ObjectId,
                    Topics    = topics,
                    CreatedAt = question.CreatedAt.Value + RestService.TimeDiff,
                    Owner     = owner,
                    State     = state
                };

                Answers.Clear();
                var answers = await ParseAccess.LoadAnswers(question);

                foreach (var answer in answers)
                {
                    ParseUser userObject = answer.Get <ParseUser>("createdBy");
                    var       user       = new User
                    {
                        ObjectId  = userObject.ObjectId,
                        FirstName = userObject.Get <string>("firstName"),
                        LastName  = userObject.Get <string>("lastName"),
                        Username  = userObject.Get <string>("username")
                    };

                    DateTime now = RestService.GetServerTime();
                    var      a   = new Answer
                    {
                        Body      = answer.Get <string>("body"),
                        CreatedBy = user,
                        TimeAgo   = HelperFunctions.TimeAgo(answer.UpdatedAt.Value, now)
                    };
                    Answers.Add(a);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
            finally
            {
                IsBusy = false;
                ProgressDialogManager.DisposeProgressDialog();
            }
        }
Esempio n. 17
0
        public async Task ExecuteFollowUsers(string id)
        {
            followedUsers.Add(id);

            await ParseAccess.UpdateFollowedUsers(followedUsers);
        }