private Globe() { User = new User (); PostFeeds = new Dictionary<string, List<Post>> (); NotificationFeeds = new Dictionary<string, List<Notification>> (); UserFeeds = new Dictionary<string, List<User>>(); }
public static User FromRandom() { Random random = new Random(); User user = new User(); user.username = StringUtils.FromRandom(random); user.idUser = random.Next(100); user.description = StringUtils.FromRandom(random); user.website = StringUtils.FromRandom(random); user.isprivate = true; user.blocked = false; user.friended = Strings.friended_pending; return user; }
public static string GetProfileImageURL(User user) { return Endpoint.BaseURL + "/profile/" + user.username + "/image"; }
public static async Task<List<User>> TopLikers (int offset, int count, User user) { user.username = StringUtils.RemoveLeadingSymbol (user.username, "@"); Dictionary<string, object> requestDictionary = new Dictionary<string, object>(); requestDictionary.Add("offset", offset); requestDictionary.Add("count", count); List<string> appendString = new List<string> () { "profile", user.username, "like", "top" }; RESTResult data = await RESTHelper.Async ("toplikers", requestDictionary, appendString); if (data.ReturnedData != null) { List<User> returnList = new List<User>(); JArray resultArray = (JArray)data.ReturnedData["users"]; foreach (JToken userToken in resultArray) { returnList.Add(JsonConvert.DeserializeObject<User>(userToken.ToString())); } return returnList; } throw data.Error; }
public static async Task<List<Post>> AllPostsForUser (int offset, int count, User user) { user.username = StringUtils.RemoveLeadingSymbol (user.username, "@"); Dictionary<string, object> requestDictionary = new Dictionary<string, object> (); requestDictionary.Add ("offset", offset); requestDictionary.Add ("count", count); List<string> appendString = new List<string> () { "profile", user.username, "post" }; RESTResult data = await RESTHelper.Async ("allpostsforuser", requestDictionary, appendString); if (data.ReturnedData != null) { return ParseForPosts (data.ReturnedData, FeedTypeEnum.FeedType.MyProfileFeed, offset); } throw data.Error; }
public static async Task<List<Post>> ActivePosts (int offset, int count, User user) { if (user.blocked || (user.friended != Strings.friended_friended && user.isprivate)) { return null; } user.username = StringUtils.RemoveLeadingSymbol (user.username, "@"); Dictionary<string, object> requestDictionary = new Dictionary<string, object> (); requestDictionary.Add ("offset", offset); requestDictionary.Add ("count", count); List<string> appendString = new List<string> () { "profile", user.username, "post", "active" }; RESTResult data = await RESTHelper.Async ("activeposts", requestDictionary, appendString); if (data.ReturnedData != null) { return ParseForPosts (data.ReturnedData, FeedTypeEnum.FeedType.GuestProfileFeed, offset); } throw data.Error; }
//Profile public static async Task<Profile> FullProfile (User user, bool saveToGlobe) { user.username = StringUtils.RemoveLeadingSymbol (user.username, "@"); List<string> appendString = new List<string> () { "profile", user.username }; RESTResult data = await RESTHelper.Async ("fullprofile", null, appendString); if (data.ReturnedData != null) { Profile profile = JsonConvert.DeserializeObject<Profile> (data.ReturnedData ["profile"].ToString ()); if (saveToGlobe) { Globe.SharedInstance.User.isprivate = profile.user.isprivate; Globe.SharedInstance.User.description = profile.user.description; Globe.SharedInstance.User.website = profile.user.website; Globe.SharedInstance.User.username = profile.user.username; } return profile; } throw data.Error; }
public static async Task<bool> SendUnfollowRequest (User user) { List<string> appendString = new List<string> () { "action", user.idUser.ToString (), "unfollow" }; RESTResult data = await RESTHelper.Async ("sendunfollowrequest", null, appendString); if (data.ReturnedData != null) { return ParseForBool (data.ReturnedData); } return false; }
public static async Task<bool> SendFollowRequestResponse (User user, bool approve) { string action = approve ? "approve" : "reject"; List<string> appendString = new List<string> () { "action", user.idUser.ToString (), action }; RESTResult data = await RESTHelper.Async ("sendfollowrequestresponse", null, appendString); if (data.ReturnedData != null) { return ParseForBool (data.ReturnedData); } return false; }
public static async Task<bool> ReportUser(User user) { List<string> appendString = new List<string>() { "services", "blockUser" }; Dictionary<string, object> requestDictionary = new Dictionary<string, object>(); requestDictionary.Add("userID", user.idUser.ToString()); RESTResult data = await RESTHelper.Async("flaguser", requestDictionary, appendString); if (data.ReturnedData != null) { return ParseForBool(data.ReturnedData); } throw data.Error; }
public static async Task<bool> UnblockUser (User user) { List<string> appendString = new List<string> () { "action", user.idUser.ToString(), "unblock" }; RESTResult data = await RESTHelper.Async ("unblockuser", null, appendString); if (data.ReturnedData != null) { return ParseForBool (data.ReturnedData); } throw data.Error; }
public static async Task<byte[]> GetUserImage (User user) { List<string> appendString = new List<string> () { "profile", user.username.ToString (), "image" }; RESTResult data = await RESTHelper.Async ("getuserimage", null, appendString); if (data.ByteArray != null) { return data.ByteArray ; } throw data.Error; }
public static async Task<Post> GetTopTime (User user) { List<string> appendString = new List<string> () { "profile", user.username, "post", "top" }; RESTResult data = await RESTHelper.Async ("toptime", null, appendString); if (data.ReturnedData != null) { return (JsonConvert.DeserializeObject<Post> (data.ReturnedData ["post"].ToString ())); } throw data.Error; }
public static void PassUserToAllFeedsIfExists(User user, FeedTypeEnum.FeedType key) { if (user == null) { return; } foreach (KeyValuePair<string, List<User>> currentDict in Globe.SharedInstance.UserFeeds) { bool foundIt = false; for (int i = 0; i < currentDict.Value.Count; i++) { if (currentDict.Value[i].idUser == user.idUser) { currentDict.Value[i] = user; foundIt = true; } } if (!foundIt && currentDict.Key == key.ToString()) { currentDict.Value.Add(user); } currentDict.Value.Sort((x, y) => y.username.CompareTo(x.username)); } }