Exemplo n.º 1
0
        private void PostLikesCallBack2(IAsyncResult asynchronousResult)
        {
            try
            {
                HttpWebRequest  hwr      = (HttpWebRequest)asynchronousResult.AsyncState;
                HttpWebResponse response = hwr.EndGetResponse(asynchronousResult) as HttpWebResponse;
                HttpStatusCode  code     = response.StatusCode;
                Stream          stream   = response.GetResponseStream();
                StreamReader    sr       = new StreamReader(stream);
                String          result   = sr.ReadToEnd();

                if (likesArticle != null)
                {
                    LikeContent lc = new LikeContent();
                    lc.article_title = postTitle;
                    lc.article_id    = postId;
                    likesArticle.Add(lc);
                }
                if (this.currentArticle != null && !cacheArticle.Contains(this.currentArticle) && this.currentArticle.title == postTitle)
                {
                    cacheArticle.Add(this.currentArticle);
                }
                PostLikesHandler(true);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
                errorMessage = e.Message;
                PostLikesHandler(false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Like indicator
        /// </summary>
        /// <param name="msg"></param>
        public async static void LikeInd(QHMessage msg)
        {
            long   NumberId  = 0;
            string FullName  = "";
            string avatar    = "";
            long   ContentID = 0;
            long   CommentID = 0;
            long   ReplyID   = 0;
            long   OwnerID   = 0;

            if (msg.TryGetAt((byte)MsgLikeIndArg.FullName, ref FullName))
            {
            }
            if (msg.TryGetAt((byte)MsgLikeIndArg.OwnerID, ref OwnerID))
            {
            }
            if (msg.TryGetAt((byte)MsgLikeIndArg.NumberID, ref NumberId))
            {
            }
            if (msg.TryGetAt((byte)MsgLikeIndArg.ContentID, ref ContentID))
            {
                if (msg.TryGetAt((byte)MsgLikeIndArg.CommentID, ref CommentID))
                {
                    if (msg.TryGetAt((byte)MsgLikeIndArg.ReplyID, ref ReplyID))
                    {
                    }
                }
            }
            if (msg.TryGetAt((byte)MsgLikeIndArg.CommentID, ref CommentID))
            {
            }
            if (msg.TryGetAt((byte)MsgLikeIndArg.ReplyID, ref ReplyID))
            {
            }
            //LikeReply
            if (ReplyID > 0)
            {
                if (Helper.Instance().ListReplyComment.ContainsKey(ReplyID))
                {
                    var item = Helper.Instance().ListReplyComment[ReplyID];
                    item.Owner = Helper.Instance().MyAccount.Number_Id;
                    if (item.Likes.IndexOf(NumberId) < 0)
                    {
                        item.Likes.Add(NumberId);
                        item.Reset();
                    }
                    if (Helper.IdNews == CommentID && Helper.IndexPage == Helpers.IsDetailNews.Reply)
                    {
                    }
                    else
                    {
                        if (OwnerID == Helper.Instance().MyAccount.Number_Id)
                        {
                            Device.BeginInvokeOnMainThread(() =>
                            {
                                DependencyService.Get <ILocalNotificationService>().LocalNotification("AppBongBan", FullName + " đã thích trả lời bình luận của bạn", (int)Helpers.Notifi.LikeReply, 0);
                            });
                        }
                        else
                        {
                            var acc = await Helper.Instance().CheckExistAccount(OwnerID);

                            if (acc.Number_Id > 0)
                            {
                                Device.BeginInvokeOnMainThread(() =>
                                {
                                    DependencyService.Get <ILocalNotificationService>().LocalNotification("AppBongBan", FullName + " đã thích trả lời bình luận của " + acc.fullname, (int)Helpers.Notifi.LikeReply, 0);
                                });
                            }
                        }
                    }
                }
                else
                {
                    if (OwnerID == Helper.Instance().MyAccount.Number_Id)
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            DependencyService.Get <ILocalNotificationService>().LocalNotification("AppBongBan", FullName + " đã thích trả lời bình luận của bạn", (int)Helpers.Notifi.LikeReply, 0);
                        });
                    }
                    else
                    {
                        var acc = await Helper.Instance().CheckExistAccount(OwnerID);

                        if (acc.Number_Id > 0)
                        {
                            Device.BeginInvokeOnMainThread(() =>
                            {
                                DependencyService.Get <ILocalNotificationService>().LocalNotification("AppBongBan", FullName + " đã thích trả lời bình luận của " + acc.fullname, (int)Helpers.Notifi.LikeReply, 0);
                            });
                        }
                    }
                }

                return;
            }
            //LikeComment
            if (CommentID > 0)
            {
                if (Helper.Instance().ListComment.ContainsKey(CommentID))
                {
                    var item = Helper.Instance().ListComment[CommentID];
                    if (item.likes.IndexOf(NumberId) < 0)
                    {
                        item.likes.Add(NumberId);
                        item.Reset();
                    }
                    if (Helper.IdNews == ContentID && Helper.IndexPage == Helpers.IsDetailNews.Comment)
                    {
                    }
                    //nếú chưa có trong danh sách comment
                    else
                    {
                        if (OwnerID == Helper.Instance().MyAccount.Number_Id)
                        {
                            Device.BeginInvokeOnMainThread(() =>
                            {
                                DependencyService.Get <ILocalNotificationService>().LocalNotification("AppBongBan", FullName + " đã thích bình luận của bạn", (int)Helpers.Notifi.LikeComment, 0);
                            });
                        }
                        else
                        {
                            var accounOwner = await Helper.Instance().CheckExistAccount(OwnerID);

                            if (accounOwner != null && accounOwner.Number_Id > 0)
                            {
                                Device.BeginInvokeOnMainThread(() =>
                                {
                                    DependencyService.Get <ILocalNotificationService>().LocalNotification("AppBongBan", FullName + " đã thích bài viết của" + accounOwner.fullname, (int)Helpers.Notifi.LikeComment, 0);
                                });
                            }
                        }
                    }
                }
                else
                {
                    if (OwnerID == Helper.Instance().MyAccount.Number_Id)
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            DependencyService.Get <ILocalNotificationService>().LocalNotification("AppBongBan", FullName + " đã thích bình luận của bạn", (int)Helpers.Notifi.LikeComment, 0);
                        });
                    }
                    else
                    {
                        var accounOwner = await Helper.Instance().CheckExistAccount(OwnerID);

                        if (accounOwner != null && accounOwner.Number_Id > 0)
                        {
                            Device.BeginInvokeOnMainThread(() =>
                            {
                                DependencyService.Get <ILocalNotificationService>().LocalNotification("AppBongBan", FullName + " đã thích bài viết của" + accounOwner.fullname, (int)Helpers.Notifi.LikeComment, 0);
                            });
                        }
                    }
                }
                return;
            }
            //LikeContent
            if (ContentID > 0)
            {
                if (Helper.Instance().ListContent.ContainsKey(ContentID))
                {
                    var item = Helper.Instance().ListContent[ContentID];
                    var Like = new LikeContent {
                        Content_Id = ContentID, Owner = NumberId
                    };
                    if (!item.LikeContent.LikeContent.ContainsKey("" + NumberId))
                    {
                        item.LikeContent.LikeContent.Add("" + NumberId, Like);
                        item.LikeContent.Reset();
                    }

                    if (Helper.IdNews == ContentID && Helper.IndexPage == Helpers.IsDetailNews.Content)
                    {
                    }
                    //Nếu người dùng chưa vào giao diện chi tiết content
                    else
                    {
                        var id = Helper.Instance().MyAccount.Number_Id;
                        if (id == OwnerID)
                        {
                            Device.BeginInvokeOnMainThread(() =>
                            {
                                DependencyService.Get <ILocalNotificationService>().LocalNotification("AppBongBan", FullName + " đã thích bài viết của bạn", (int)Notifi.LikeContent, 0);
                            });
                        }

                        else
                        {
                            var accounOwner = await Helper.Instance().CheckExistAccount(OwnerID);

                            if (accounOwner != null && accounOwner.Number_Id > 0)
                            {
                                Device.BeginInvokeOnMainThread(() =>
                                {
                                    DependencyService.Get <ILocalNotificationService>().LocalNotification("AppBongBan", FullName + " đã thích bài viết của " + accounOwner.fullname, (int)Notifi.LikeContent, 0);
                                });
                            }
                        }
                    }
                }
                else
                {
                    var id = Helper.Instance().MyAccount.Number_Id;
                    if (id == OwnerID)
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            DependencyService.Get <ILocalNotificationService>().LocalNotification("AppBongBan", FullName + " đã thích bài viết của bạn", (int)Notifi.LikeContent, 0);
                        });
                    }

                    else
                    {
                        var accounOwner = await Helper.Instance().CheckExistAccount(OwnerID);

                        if (accounOwner != null && accounOwner.Number_Id > 0)
                        {
                            Device.BeginInvokeOnMainThread(() =>
                            {
                                DependencyService.Get <ILocalNotificationService>().LocalNotification("AppBongBan", FullName + " đã thích bài viết của " + accounOwner.fullname, (int)Notifi.LikeContent, 0);
                            });
                        }
                    }
                }
                return;
            }
        }