Пример #1
0
        public void CommentItem(FacebookItem item, string text)
        {
            dynamic parameters = new ExpandoObject();

            parameters.message = text;

            dynamic result = facebookClient.Post("/" + item.fullId + "/comments", parameters);

            item.isCommented = true;
            UpdateNewsFeed();
        }
        private static void OnItemChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            FacebookItem item = args.NewValue as FacebookItem;

            if (item == null)
            {
                return;
            }

            TextBlockFacebookText textblock = (TextBlockFacebookText)obj;
            //  textblock = item.Textblock;
        }
Пример #3
0
        public void UnlikeItem(FacebookItem item)
        {
            dynamic parameters = new ExpandoObject();

            facebookClient.Delete("/" + item.fullId + "/likes", parameters);
        }
Пример #4
0
        void backgroundWorkerNewsFeed_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                if (e != null)
                {
                    if (e.Cancel)
                    {
                        return;
                    }
                }
                dynamic parameters = new ExpandoObject();

                if (!IsInitialFetch && LastUpdate != null)
                {
                    // danach kamen keine Updates mehr durch :(
                    //  parameters.since = GetUnixTimestamp(LastUpdate).ToString();
                }

                string[] feeds = { "home", "feed" };

                foreach (string feedName in feeds)
                {
                    dynamic result = facebookClient.Get("/me/" + feedName, parameters); // Home

                    if (result != null)
                    {
                        foreach (dynamic post in result.data)
                        {
                            if (e != null)
                            {
                                if (e.Cancel)
                                {
                                    return;
                                }
                            }
                            FacebookItem item = FacebookItem.ConvertResponseToItem(post, this);
                            if (item == null)
                            {
                                AppController.Current.Logger.writeToLogfile("Null item in facebook retrieval");
                                continue;
                            }

                            FacebookItem ExistingItem = null;
                            try
                            {
                                switch (item.MessageType)
                                {
                                case FacebookItem.MessageTypes.Link:
                                    if (Links.Where(oldItem => oldItem.fullId == item.fullId).Count() > 0)
                                    {
                                        ExistingItem = Links.Where(oldItem => oldItem.fullId == item.fullId).First();
                                    }

                                    break;

                                case FacebookItem.MessageTypes.Video:
                                    if (Videos.Where(oldItem => oldItem.fullId == item.fullId).Count() > 0)
                                    {
                                        ExistingItem = Videos.Where(oldItem => oldItem.fullId == item.fullId).First();
                                    }

                                    break;

                                case FacebookItem.MessageTypes.Photo:
                                    if (Photos.Where(oldItem => oldItem.fullId == item.fullId).Count() > 0)
                                    {
                                        ExistingItem = Photos.Where(oldItem => oldItem.fullId == item.fullId).First();
                                    }

                                    break;

                                case FacebookItem.MessageTypes.Note:
                                    if (Notes.Where(oldItem => oldItem.fullId == item.fullId).Count() > 0)
                                    {
                                        ExistingItem = Notes.Where(oldItem => oldItem.fullId == item.fullId).First();
                                    }

                                    break;

                                case FacebookItem.MessageTypes.Event:
                                    if (Events.Where(oldItem => oldItem.fullId == item.fullId).Count() > 0)
                                    {
                                        ExistingItem = Events.Where(oldItem => oldItem.fullId == item.fullId).First();
                                    }

                                    break;

                                case FacebookItem.MessageTypes.CheckIn:
                                    if (CheckIns.Where(oldItem => oldItem.fullId == item.fullId).Count() > 0)
                                    {
                                        ExistingItem = CheckIns.Where(oldItem => oldItem.fullId == item.fullId).First();
                                    }

                                    break;

                                default:
                                    if (StatusMessages.Where(oldItem => oldItem.fullId == item.fullId).Count() > 0)
                                    {
                                        ExistingItem = StatusMessages.Where(oldItem => oldItem.fullId == item.fullId).First();
                                    }

                                    break;
                                }
                            }
                            catch
                            {
                                ExistingItem = null;
                            }
                            if (ExistingItem == null)
                            {
                                try
                                {
                                    dynamic comments = facebookClient.Get("/" + item.fullId + "/comments", parameters);
                                    item.Comments.Clear();
                                    if (comments != null)
                                    {
                                        if (comments.data != null)
                                        {
                                            AppController.Current.Logger.writeToLogfile("Facebook item has comments/data");
                                            foreach (dynamic fbcomment in comments.data)
                                            {
                                                AppController.Current.Logger.writeToLogfile("Reading comment");
                                                FacebookComment comment = new FacebookComment(fbcomment);
                                                comment.Account = item.Account;
                                                if (comment.User.Id == this.Id.ToString())
                                                {
                                                    item.isCommented = true;
                                                }
                                                item.Comments.Add(comment);
                                            }
                                        }
                                    }
                                }
                                catch { }
                                item.ReceivingAccount = this;
                                backgroundWorkerNewsFeed.ReportProgress(100, item);
                                continue;
                            }
                            else
                            {
                                if (item.LikesCount != ExistingItem.LikesCount)
                                {
                                    item.HasUpdatedLikes = true;
                                }

                                List <FacebookComment> updatedComments = new List <FacebookComment>();
                                foreach (FacebookComment comment in item.Comments)
                                {
                                    if (e != null)
                                    {
                                        if (e.Cancel)
                                        {
                                            return;
                                        }
                                    }
                                    if (ExistingItem.Comments.Where(c => c.Text == comment.Text && c.User.Id == comment.User.Id).Count() == 0)
                                    {
                                        updatedComments.Add(comment);
                                    }
                                }

                                if (updatedComments.Count > 0)
                                {
                                    item.HasUpdatedComments = true;
                                    item.Comments.Clear();
                                    foreach (FacebookComment comment in updatedComments)
                                    {
                                        item.Comments.Add(comment);
                                    }
                                }
                                if (item.HasUpdatedComments || item.HasUpdatedLikes)
                                {
                                    item.ReceivingAccount = this;
                                    backgroundWorkerNewsFeed.ReportProgress(100, item);
                                }
                                else
                                {
                                    item = null;
                                }
                            }
                        }
                    }
                }
            }
            catch (FacebookOAuthException oauthExp)
            {
                AppController.Current.Logger.writeToLogfile(oauthExp);
            }
            catch (Exception exp)
            {
                AppController.Current.Logger.writeToLogfile(exp);;
            }
        }
Пример #5
0
        void backgroundWorkerNewsFeed_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            FacebookItem item = (FacebookItem)e.UserState;

            if (item == null)
            {
                return;
            }

            string notificationClassName = "Facebook " + FullName + " ";

            if (item.HasUpdatedLikes || item.HasUpdatedComments)
            {
                FacebookItem ExistingItem = null;
                try
                {
                    switch (item.MessageType)
                    {
                    case FacebookItem.MessageTypes.Link:
                        ExistingItem = Links.Where(oldItem => oldItem.fullId == item.fullId).First();

                        break;

                    case FacebookItem.MessageTypes.Video:
                        ExistingItem = Videos.Where(oldItem => oldItem.fullId == item.fullId).First();

                        break;

                    case FacebookItem.MessageTypes.Photo:
                        ExistingItem = Photos.Where(oldItem => oldItem.fullId == item.fullId).First();

                        break;

                    case FacebookItem.MessageTypes.Note:
                        ExistingItem = Notes.Where(oldItem => oldItem.fullId == item.fullId).First();

                        break;

                    case FacebookItem.MessageTypes.Event:
                        ExistingItem = Events.Where(oldItem => oldItem.fullId == item.fullId).First();

                        break;

                    case FacebookItem.MessageTypes.CheckIn:
                        ExistingItem = CheckIns.Where(oldItem => oldItem.fullId == item.fullId).First();

                        break;

                    default:
                        ExistingItem = StatusMessages.Where(oldItem => oldItem.fullId == item.fullId).First();

                        break;
                    }


                    if (item.HasUpdatedLikes)
                    {
                        string notificationText = "";
                        if (!string.IsNullOrWhiteSpace(item.Text))
                        {
                            notificationText += item.Text.Substring(0, Math.Min(20, item.Text.Length - 1)) + "... ";
                        }
                        else
                        {
                            notificationText += "Facebook item... ";
                        }
                        notificationText += "has new likes";
                        if (item.isLiked)
                        {
                            AppController.Current.sendNotification(notificationClassName + "Like", notificationText, "The item has " + (item.LikesCount - ExistingItem.LikesCount).ToString() + " new likes", item.User.Avatar, null);
                        }
                        else
                        {
                            AppController.Current.sendNotification(notificationClassName + "Like (on message you didn't comment or like yourself)", notificationText, "The item has " + (item.LikesCount - ExistingItem.LikesCount).ToString() + " new likes", item.User.Avatar, null);
                        }
                        ExistingItem.UpdatedAt  = item.UpdatedAt;
                        ExistingItem.LikesCount = item.LikesCount;
                    }
                    if (item.HasUpdatedComments)
                    {
                        foreach (FacebookComment newComment in item.Comments)
                        {
                            if (item.isCommented)
                            {
                                AppController.Current.sendNotification(notificationClassName + "Comment", "New comment on entry of " + ExistingItem.User.FullName, newComment.Text + "\r\nby " + newComment.User.FullName, newComment.User.Avatar, null);
                            }
                            else
                            {
                                AppController.Current.sendNotification(notificationClassName + "Comment (on message you didn't comment or like yourself)", "New comment on entry of " + ExistingItem.User.FullName, newComment.Text + "\r\nby " + newComment.User.FullName, newComment.User.Avatar, null);
                            }
                            ExistingItem.Comments.Add(newComment);
                            ExistingItem.UpdatedAt = item.UpdatedAt;
                        }
                    }
                }
                catch (Exception exp)
                {
                    AppController.Current.Logger.writeToLogfile(exp);
                }
            }
            else
            {
                switch (item.MessageType)
                {
                case FacebookItem.MessageTypes.Link:

                    Links.Add(item);
                    if (InitialUpdateDoneForLinks)
                    {
                        notificationClassName += "Link";
                    }

                    break;

                case FacebookItem.MessageTypes.Video:

                    Videos.Add(item);
                    if (InitialUpdateDoneForVideos)
                    {
                        notificationClassName += "Video";
                    }

                    break;

                case FacebookItem.MessageTypes.Photo:

                    Photos.Add(item);
                    if (InitialUpdateDoneForPhotos)
                    {
                        notificationClassName += "Photo";
                    }

                    break;

                case FacebookItem.MessageTypes.Note:

                    Notes.Add(item);
                    if (InitialUpdateDoneForNotes)
                    {
                        notificationClassName += "Note";
                    }

                    break;

                case FacebookItem.MessageTypes.Event:

                    Events.Add(item);
                    if (InitialUpdateDoneForEvents)
                    {
                        notificationClassName += "Event";
                    }

                    break;

                case FacebookItem.MessageTypes.CheckIn:

                    CheckIns.Add(item);
                    if (InitialUpdateDoneForCheckIns)
                    {
                        notificationClassName += "CheckIn";
                    }

                    break;

                default:

                    StatusMessages.Add(item);
                    if (InitialUpdateDoneForStatusMessages)
                    {
                        notificationClassName += "Status message";
                    }

                    break;
                }

                if (notificationClassName != "Facebook " + FullName + " ")
                {
                    AppController.Current.sendNotification(notificationClassName, item.User.FullName, item.Text, item.Avatar, item);
                }
            }
        }
Пример #6
0
        public static FacebookItem ConvertResponseToItem(dynamic post, AccountFacebook ReceivingAccount)
        {
            try
            {
                FacebookItem item = new FacebookItem();
                item.Account = ReceivingAccount;
                item.fullId  = post.id as string;
                string[] ids = item.fullId.Split(new Char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
                if (ids.Length < 2)
                {
                    return(null);
                }
                try
                {
                    item.Id = Convert.ToDecimal(ids[1]);
                }
                catch
                {
                    return(null);
                }

                #region Messagetypes

                if (post.type != null)
                {
                    string postType = post.type;
                    switch (postType)
                    {
                    case "photo":
                        item.MessageType = MessageTypes.Photo;
                        break;

                    case "link":
                        item.MessageType = MessageTypes.Link;
                        break;

                    case "event":
                        item.MessageType = MessageTypes.Event;
                        break;

                    case "checkin":
                        item.MessageType = MessageTypes.CheckIn;
                        break;

                    case "status":
                        item.MessageType = MessageTypes.StatusMessage;
                        break;

                    case "video":
                        item.MessageType = MessageTypes.Video;
                        break;

                    case "note":
                        item.MessageType = MessageTypes.Note;
                        break;
                    }
                }

                #endregion

                item.To.FullName = null;

                if (post.to != null)
                {
                    if (post.to.data != null)
                    {
                        foreach (dynamic receiver in post.to.data)
                        {
                            item.To = FacebookUser.CreateFromDynamic(receiver, ReceivingAccount);
                            item.To.ReceivingAccount = ReceivingAccount;
                            // only one receiver for now - should be a collection later on of course
                            break;
                        }
                    }
                }


                DateTime createdDate;
                DateTime.TryParse(post.created_time as string, out createdDate);
                item.CreatedAt = createdDate;

                DateTime updatedDate;
                DateTime.TryParse(post.updated_time as string, out updatedDate);
                item.UpdatedAt = updatedDate;



                //item.User.Id = post.from.id;
                //item.User.FullName = post.from.name;
                item.User = FacebookUser.CreateFromDynamic(post.from, item.Account);
                if (item.User == null)
                {
                    AppController.Current.Logger.writeToLogfile("Null user on item retrieval");
                    return(null);
                }

                if (post.comments != null)
                {
                    AppController.Current.Logger.writeToLogfile("Facebook item has comments");
                    if (post.comments.data != null)
                    {
                        AppController.Current.Logger.writeToLogfile("Facebook item has comments/data");
                        foreach (dynamic fbcomment in post.comments.data)
                        {
                            AppController.Current.Logger.writeToLogfile("Reading comment");
                            FacebookComment comment = new FacebookComment(fbcomment);
                            comment.Account = item.Account;
                            if (comment.Id == ReceivingAccount.Id.ToString())
                            {
                                item.isCommented = true;
                            }
                            item.Comments.Add(comment);
                        }
                    }
                }

                if (post.application != null)
                {
                    item.Application.Name = post.application.name;
                    item.Application.Link = post.application.link;
                    item.Application.Id   = post.application.id;
                }


                if (post.likes != null)
                {
                    if (post.likes.count != null)
                    {
                        item.LikesCount = Convert.ToInt32(post.likes.count);
                    }
                    if (post.likes.data != null)
                    {
                        AppController.Current.Logger.writeToLogfile("Facebook item has likes/data");
                        foreach (dynamic fbLike in post.likes.data)
                        {
                            AppController.Current.Logger.writeToLogfile("Reading like");
                            FacebookUser user = FacebookUser.CreateFromDynamic(fbLike, item.Account);
                            user.ReceivingAccount = item.Account;

                            if (user != null)
                            {
                                item.Likes.Add(user);
                                if (user.FullName == item.Account.FullName)
                                {
                                    item.isLiked = true;
                                }
                            }
                        }
                    }
                }

                if (post.picture != null)
                {
                    FacebookPicture picture = new FacebookPicture();
                    picture.ThumbnailPath = post.picture;
                    picture.Link          = post.link;
                    picture.Caption       = post.caption;
                    item.Picture          = picture.ThumbnailPath;
                    item.PictureLink      = picture.Link;

                    item.Images.Add(picture);
                }

                item.Description = post.description;

                item.Message = post.message;
                item.Name    = post.name;
                item.Caption = post.caption;
                item.Link    = post.link;

                // ganz zum Schluss, das in der Textbox auf diese Aenderung getriggert wird
                item.Text = item.Message;

                return(item);
            }
            catch (Exception exp)
            {
                AppController.Current.Logger.writeToLogfile(exp);
                return(null);
            }
        }