コード例 #1
0
ファイル: FeedUtils.cs プロジェクト: natevarghese/XamarinTen
		public static bool DeletePostFromAllFeedsIfExists (Post post)
		{
			bool AtLeastOneArrayIsGraterThan0 = false;
			foreach (KeyValuePair<string, List<Post>> currentDict in Globe.SharedInstance.PostFeeds) { //loop all post feeds
				for (int i = 0; i < currentDict.Value.Count; i++) {
					if (currentDict.Value [i].idPost == post.idPost) {
						currentDict.Value [i] = post;
						currentDict.Value.Remove (post);
					}
					if (currentDict.Value.Count > 0) {
						AtLeastOneArrayIsGraterThan0 = true;
					}
				}
			}
			return !AtLeastOneArrayIsGraterThan0;
		}
コード例 #2
0
ファイル: FeedUtils.cs プロジェクト: natevarghese/XamarinTen
		public static void PassPostToAllFeedsIfExistsWithInclude (Post post, FeedTypeEnum.FeedType key)
		{
			if (post == null){
				return;
			}

			if (post.IsExpired () && (key != FeedTypeEnum.FeedType.MyProfileFeed || post.userReposter != null)) {
				return;
			}

			foreach (KeyValuePair<string, List<Post>> currentDict in Globe.SharedInstance.PostFeeds) { 
				bool foundIt = false;
				for (int i = 0; i < currentDict.Value.Count; i++) {
					if (currentDict.Value [i].idPost == post.idPost) {
						currentDict.Value [i] = post;
						foundIt = true;
					}
				}

				if (!foundIt && currentDict.Key == key.ToString ()) {
					post.feedType = (int)key;
					currentDict.Value.Add (post);
				}

				currentDict.Value.Sort ((x, y) => y.datestamp.Value.CompareTo (x.datestamp.Value));
			}


			foreach (KeyValuePair<string, List<Notification>> currentDict in Globe.SharedInstance.NotificationFeeds) {
				for (int i = 0; i < currentDict.Value.Count; i++) {
					if (currentDict.Value [i].post != null && currentDict.Value [i].post.idPost == post.idPost) {
						currentDict.Value [i].post = post;
					}
				}
			}
		}
コード例 #3
0
		public static string GetTopTime(Post post)
		{
			if (post == null)
			{
				return "10m";
			}
			DateTime expiration = new DateTime(1970, 1, 1).AddMilliseconds(double.Parse(post.expiration.ToString()));
			DateTime datestamp = new DateTime(1970, 1, 1).AddMilliseconds(double.Parse(post.datestamp.ToString()));
			TimeSpan span = expiration.Subtract(datestamp);

			var sb = new StringBuilder();
			if (span.Days > 365)
				sb.AppendFormat("{0}y", span.Days - 365);
			else if (span.Days > 0)
				sb.AppendFormat("{0}d", span.Days);
			else if (span.Hours > 0)
				sb.AppendFormat("{0}h", span.Hours);
			else if (span.Minutes > 0)
			{
				sb.AppendFormat("{0}m", span.Minutes);
			}
			return sb.ToString();
		}
コード例 #4
0
		public static string GetPostImageURL(Post post)
		{
			return Endpoint.BaseURL + "/post/" + post.idPost + "/image";
		}
コード例 #5
0
		//Comments
		public static async Task<List<Comment>> GetComments (Post post, int offset, int count)
		{
			List<string> appendString = new List<string> () { "post", post.idPost.ToString (), "comment" };

			Dictionary<string, object> requestDictionary = new Dictionary<string, object>();
			requestDictionary.Add("offset", offset);
			requestDictionary.Add("count", count);



			RESTResult data = await RESTHelper.Async ("getcomments", requestDictionary, appendString);
			if (data.ReturnedData != null) {
				List<Comment> returnList = new List<Comment> ();
				JArray resultArray = (JArray)data.ReturnedData ["comments"];
				foreach (JToken token in resultArray) {
					returnList.Add (JsonConvert.DeserializeObject<Comment> (token.ToString ()));
				}
				return returnList;
			}
			throw data.Error;
		}
コード例 #6
0
		//Comment
		public static async Task<Comment> AddComment (Post post, string text)
		{
			Dictionary<string, object> requestDictionary = new Dictionary<string, object> ();
			requestDictionary.Add ("text", text);

			List<string> appendString = new List<string> () { "post", post.idPost.ToString (), "comment" };

			RESTResult data = await RESTHelper.Async ("addcomment", requestDictionary, appendString);
			if (data.ReturnedData != null) {

				///todo get times from server
				/// this is wokring server side
				Comment CommentToTurn = (JsonConvert.DeserializeObject<Comment> (data.ReturnedData["comment"].ToString ()));
				CommentToTurn.user = Globe.SharedInstance.User;
				CommentToTurn.text = text;

				return CommentToTurn;
			}
			throw data.Error;
		}
コード例 #7
0
		public static async Task<bool> DeleteComment (Comment comment, Post post)
		{

			List<string> appendString = new List<string> () {
				"post",
				post.idPost.ToString (),
				"comment",
				comment.idComment.ToString ()
			};

			RESTResult data = await RESTHelper.Async ("deletecomment", null, appendString);
			if (data.ReturnedData != null) {
				return ParseForBool (data.ReturnedData);
			}

			return false;
		}
コード例 #8
0
		public static async Task<bool> RepostPost (Post post)
		{
			List<string> appendString = new List<string> () { "post", post.idPost.ToString (), "repost"  };

			RESTResult data = await RESTHelper.Async ("repost", null, appendString);
			if (data.ReturnedData != null) {
				return ParseForBool (data.ReturnedData);
			}
			return false;
		}
コード例 #9
0
		public static async Task<bool> ReportPost(Post post)
		{
			List<string> appendString = new List<string>() { "services", "flagPost" };

			Dictionary<string, object> requestDictionary = new Dictionary<string, object>();
			requestDictionary.Add("postID", post.idPost.ToString());


			RESTResult data = await RESTHelper.Async("flagpost", requestDictionary, appendString);
			if (data.ReturnedData != null)
			{
				return ParseForBool(data.ReturnedData);
			}
			throw data.Error;
		}
コード例 #10
0
		public static async Task<bool> DeletePost (Post post)
		{

			List<string> appendString = new List<string> () { "post", post.idPost.ToString () };

			RESTResult data = await RESTHelper.Async ("deletepost", null, appendString);
			if (data.ReturnedData != null) {
				return ParseForBool (data.ReturnedData);
			}
			throw data.Error;
		}
コード例 #11
0
		//byte[]
		public static async Task<byte[]> GetPostImage (Post post)
		{
			List<string> appendString = new List<string> () { "post", post.idPost.ToString (), "image" };

			RESTResult data = await RESTHelper.Async ("getpostimage", null, appendString);
			if (data.ByteArray != null) {
				return data.ByteArray ;
			}
			throw data.Error;
		}