Exemplo n.º 1
0
        public ActivityPost PublishStream(FacebookObjectId targetId, string message)
        {
            var streamMap = new METHOD_MAP
            {
                { "method", "stream.publish" },
                { "message", message },
                { "target_id", targetId.ToString() },
            };

            Utility.FailableFunction(() => _SendRequest(streamMap));

            // Return a proxy that looks close to what we expect the updated status to look like.
            // We'll replace it with the real one the next time we sync.
            return(new ActivityPost(_Service)
            {
                ActorUserId = _UserId,
                TargetUserId = targetId,
                Attachment = null,
                CanComment = false,
                CanLike = false,
                CanRemoveComments = false,
                CommentCount = 0,
                Created = DateTime.Now,
                HasLiked = false,
                LikedCount = 0,
                LikeUri = null,
                Message = message,
                PostId = new FacebookObjectId("-1"),
                RawComments = new FBMergeableCollection <ActivityComment>(),
                Updated = DateTime.Now,
            });
        }
Exemplo n.º 2
0
        public void RemoveLike(FacebookObjectId postId)
        {
            var likeMap = new METHOD_MAP
            {
                { "method", "stream.removeLike" },
                { "post_id", postId.ToString() },
            };

            Utility.FailableFunction(() => _SendRequest(likeMap));
        }
Exemplo n.º 3
0
        public List <FacebookPhotoTag> GetPhotoTags(FacebookObjectId photoId)
        {
            var tagMap = new METHOD_MAP
            {
                { "method", "photos.getTags" },
                { "pids", photoId.ToString() },
            };

            string response = Utility.FailableFunction(() => _SendRequest(tagMap));

            return(_jsonSerializer.DeserializePhotoTagsList(response));
        }
Exemplo n.º 4
0
        public bool GetPhotoCanComment(FacebookObjectId photoId)
        {
            var commentMap = new METHOD_MAP
            {
                { "method", "photos.canComment" },
                { "pid", photoId.ToString() },
            };

            string response = Utility.FailableFunction(() => _SendRequest(commentMap));

            return(_jsonSerializer.DeserializePhotoCanCommentResponse(response));
        }
Exemplo n.º 5
0
        public FacebookObjectId AddPhotoComment(FacebookObjectId photoId, string comment)
        {
            var addMap = new METHOD_MAP
            {
                { "method", "photos.addComment" },
                { "pid", photoId.ToString() },
                { "body", comment },
            };

            string response = Utility.FailableFunction(() => _SendRequest(addMap));

            return(_jsonSerializer.DeserializePhotoAddCommentResponse(response));
        }
Exemplo n.º 6
0
 internal UnfriendNotification(FacebookService service, FacebookObjectId userId)
     : base(service)
 {
     Created                 = default(DateTime);
     Updated                 = default(DateTime);
     IsHidden                = false;
     IsUnread                = true;
     NotificationId          = new FacebookObjectId("Unfriended_" + userId.ToString());
     RecipientId             = service.UserId;
     SenderId                = userId;
     Sender.PropertyChanged += _OnSenderPropertyChanged;
     Title     = string.Format(_friendRemovalFormat, Sender.ProfileUri.ToString(), Sender.Name);
     TitleText = string.Format(_friendRemovalTextFormat, Sender.Name);
     Link      = Sender.ProfileUri;
 }
Exemplo n.º 7
0
        public void RemoveComment(FacebookObjectId commentId)
        {
            if (!FacebookObjectId.IsValid(commentId))
            {
                // If we're removing a comment that we haven't yet posted we can't remove it.
                return;
            }
            var commentMap = new METHOD_MAP
            {
                { "method", "stream.removeComment" },
                { "comment_id", commentId.ToString() },
            };

            Utility.FailableFunction(() => _SendRequest(commentMap));
        }
Exemplo n.º 8
0
        public ActivityPost UpdateStatus(string newStatus)
        {
            var statusMap = new METHOD_MAP
            {
                { "method", "status.set" },
                { "status", newStatus },
                { "uid", _UserId.ToString() },
            };

            string result  = Utility.FailableFunction(() => _SendRequest(statusMap));
            bool   success = _jsonSerializer.DeserializeStatusSetResponse(result);

            Assert.IsTrue(success);

            // Return a proxy that looks close to what we expect the updated status to look like.
            // We'll replace it with the real one the next time we sync, unless a feed is being shown
            // from which this should be excluded.
            return(new ActivityPost(_Service)
            {
                ActorUserId = _UserId,
                Attachment = null,
                CanComment = false,
                CanLike = false,
                CanRemoveComments = false,
                CommentCount = 0,
                Created = DateTime.Now,
                HasLiked = false,
                LikedCount = 0,
                LikeUri = null,
                Message = newStatus,
                PostId = new FacebookObjectId("FakeStatusId"),
                RawComments = new FBMergeableCollection <ActivityComment>(),
                TargetUserId = default(FacebookObjectId),
                Updated = DateTime.Now,
            });
        }
Exemplo n.º 9
0
        public List <FacebookPhotoTag> AddPhotoTag(FacebookObjectId photoId, FacebookObjectId userId, float x, float y)
        {
            Verify.IsTrue(FacebookObjectId.IsValid(userId), "Invalid userId");
            Verify.IsTrue(FacebookObjectId.IsValid(photoId), "Invalid photoId");

            x *= 100;
            y *= 100;
            var tagMap = new METHOD_MAP
            {
                { "method", "photos.addTag" },
                { "pid", photoId.ToString() },
                { "tag_uid", userId.ToString() },
                { "x", string.Format("{0:0.##}", x) },
                { "y", string.Format("{0:0.##}", y) },
            };

            string response = Utility.FailableFunction(() => _SendRequest(tagMap));

            return(GetPhotoTags(photoId));
        }
Exemplo n.º 10
0
        public FacebookPhotoAlbum GetAlbum(FacebookObjectId albumId)
        {
            Verify.IsTrue(FacebookObjectId.IsValid(albumId), "Invalid albumId");

            var albumMap = new METHOD_MAP
            {
                { "method", "photos.getAlbums" },
                { "aids", albumId.ToString() },
            };

            string response = Utility.FailableFunction(() => _SendRequest(albumMap));
            List <FacebookPhotoAlbum> albumsResponse = _jsonSerializer.DeserializeGetAlbumsResponse(response);

            Assert.IsFalse(albumsResponse.Count > 1);

            if (albumsResponse.Count == 0)
            {
                return(null);
            }
            return(albumsResponse[0]);
        }
Exemplo n.º 11
0
        public FacebookContact TryGetUser(FacebookObjectId userId, bool getFullData)
        {
            _Verify();

            var userMap = new METHOD_MAP
            {
                { "method", "users.GetInfo" },
                { "uids", userId.ToString() },
                //{ "fields", _UserColumns },
            };

            if (getFullData)
            {
                userMap["fields"] = _UserColumns;
            }
            else
            {
                userMap["fields"] = _UserColumnsLite;
            }

            // Facebook bogusly errors this call fairly frequently.
            List <FacebookContact> contactList = null;
            int reaskCount = 0;

            do
            {
                string result = Utility.FailableFunction(5, () => _SendRequest(userMap));
                contactList = _jsonSerializer.DeserializeUsersList(result);
            } while (contactList.Count == 0 && ++reaskCount < 3);

            if (contactList.Count == 0)
            {
                // I'd like to do something better here.  This fails too frequently.
                // Maybe once we move to the graph API there will be a more privacy friendly way to get this data.
                return(null);
                //throw new FacebookException("Unable to obtain information about the user.", null);
            }

            return(contactList[0]);
        }
Exemplo n.º 12
0
        public FacebookPhoto AddPhotoToAlbum(FacebookObjectId albumId, string caption, string imageFile)
        {
            _Verify();

            var updateMap = new METHOD_MAP
            {
                { "method", "photos.upload" },
            };

            if (FacebookObjectId.IsValid(albumId))
            {
                updateMap.Add("aid", albumId.ToString());
            }

            if (!string.IsNullOrEmpty(caption))
            {
                updateMap.Add("caption", caption);
            }

            string response = Utility.FailableFunction(() => _SendFileRequest(updateMap, imageFile));

            return(_jsonSerializer.DeserializePhotoUploadResponse(response));
        }
Exemplo n.º 13
0
        private void _GetUserInfo()
        {
            _ClearUserInfo();

            try
            {
                string userPath = Path.Combine(_settingsRootPath, UserId.ToString());
                Utility.EnsureDirectory(userPath);

                string userSettingPath = Path.Combine(userPath, _UserSettingsFileName);
                if (!File.Exists(userSettingPath))
                {
                    return;
                }

                XDocument xdoc = XDocument.Load(userSettingPath);

                // Currently not providing a migration path from v1 settings.
                // Consider doing this in the future, or a path from 2 if we add a v3.
                // It's also worth noting that if an older version gets run, the way these are implemented will tend to stomp over each other.
                if (2 != (int)xdoc.Root.Attribute("v"))
                {
                    return;
                }

                XElement contactsElement = xdoc.Root.Element("friends");
                if (contactsElement != null)
                {
                    double il = 0;
                    foreach (var contact in
                             from contactNode in contactsElement.Elements("contact")
                             let isDouble = double.TryParse((string)contactNode.Attribute("interestLevel"), out il)
                                            select new _LiteContact
                    {
                        UserId = new FacebookObjectId((string)contactNode.Attribute("uid")),
                        Name = (string)contactNode.Attribute("name"),
                        InterestLevel = (isDouble ? (double?)il : null)
                    })
                    {
                        _friendLookup.Add(contact.UserId, contact);
                    }
                }

                XElement knownFriendRequestsElement = xdoc.Root.Element("knownFriendRequests");
                if (knownFriendRequestsElement != null)
                {
                    _ignoredFriendRequests.AddRange(from contactNode in knownFriendRequestsElement.Elements("contact") select new FacebookObjectId((string)contactNode.Attribute("uid")));
                }

                XElement unknownFriendRemovalsElement = xdoc.Root.Element("unreadUnfriendings");
                if (unknownFriendRemovalsElement != null)
                {
                    _unknownFriendRemovals.AddRange(from contactNode in knownFriendRequestsElement.Elements("contact") select new FacebookObjectId((string)contactNode.Attribute("uid")));
                }

                XElement readMessagesElement = xdoc.Root.Element("readMessages");
                if (readMessagesElement != null)
                {
                    _readMessages.AddRange(from messageNode in readMessagesElement.Elements("message") select new FacebookObjectId((string)messageNode.Attribute("id")));
                }

                _hasUserInfo = true;
            }
            catch
            {
                _ClearUserInfo();
                throw;
            }
        }