コード例 #1
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;
					}
				}
			}
		}
コード例 #2
0
		//Users
		public static List<User> ParseForUsers (JToken token, FeedTypeEnum.FeedType key, int offset)
		{

			//List<User> ListToReturn = new List<User> ();
			//foreach (JToken jt in (JArray)token ["users"]) {
			//	ListToReturn.Add (JsonConvert.DeserializeObject<User> (jt.ToString ()));
			//}
	
				
			//return ListToReturn;

			JArray resultArray = (JArray)token["users"];

			if (resultArray.Count == 0)
			{
				throw new RESTError(Strings.no_active_posts);
			}

			if (!Globe.SharedInstance.UserFeeds.ContainsKey(key.ToString()))
			{
				Globe.SharedInstance.UserFeeds.Add(key.ToString(), new List<User>());
			}

			//if (offset == 0){}
			foreach (JToken userToken in resultArray)
			{
				FeedUtils.PassUserToAllFeedsIfExists(JsonConvert.DeserializeObject<User>(userToken.ToString()), key);
			}
			return Globe.SharedInstance.UserFeeds[key.ToString()];
		}
コード例 #3
0
		//Posts
		public static List<Post> ParseForPosts (JToken token, FeedTypeEnum.FeedType key, int offset)
		{

			JArray resultArray = (JArray)token ["posts"];

			if (offset == 0)
			{
				if (Globe.SharedInstance.PostFeeds.ContainsKey(key.ToString()))
				{
					Globe.SharedInstance.PostFeeds[key.ToString()].Clear();
				}
			}

			if (resultArray.Count == 0) {
				throw new RESTError (Strings.no_active_posts);
			}

			if (!Globe.SharedInstance.PostFeeds.ContainsKey (key.ToString ())) {
				Globe.SharedInstance.PostFeeds.Add (key.ToString (), new List<Post> ());
			}

			if (offset == 0) {
				Globe.SharedInstance.PostFeeds[key.ToString()].Clear();
			}
			foreach (JToken postToken in resultArray) {
				FeedUtils.PassPostToAllFeedsIfExistsWithInclude (JsonConvert.DeserializeObject<Post> (postToken.ToString ()), key);
			}
			return Globe.SharedInstance.PostFeeds [key.ToString ()];
		}
コード例 #4
0
		//notifications
		public static List<Notification> ParseForNotifications (JToken token, FeedTypeEnum.FeedType key)
		{
			JArray resultArray = (JArray)token ["notifications"];

			if (resultArray.Count == 0) {
				throw new RESTError (Strings.no_notifications);
			}

			if (!Globe.SharedInstance.NotificationFeeds.ContainsKey (key.ToString ())) {
				Globe.SharedInstance.NotificationFeeds.Add (key.ToString (), new List<Notification> ());
			}

			foreach (JToken notificationToken in resultArray) {
				Notification notification = JsonConvert.DeserializeObject<Notification> (notificationToken.ToString ());

				if (notification.type == Strings.notification_type_repost)
				{
					notification.message = notification.user.username + " reposted your post";
				}

				if (key == FeedTypeEnum.FeedType.StatusFeed && notification.type == Strings.notification_type_comment) {
					notification.message = "\"" + notification.message + "\"";
				}
				FeedUtils.PassPostToAllNotificationsFeedsIfExists (notification, key);
			}
			return Globe.SharedInstance.NotificationFeeds [key.ToString ()];

		}
コード例 #5
0
ファイル: FeedUtils.cs プロジェクト: natevarghese/XamarinTen
		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));

			}
		}
コード例 #6
0
ファイル: FeedUtils.cs プロジェクト: natevarghese/XamarinTen
		public static void PassPostToAllNotificationsFeedsIfExists (Notification notification, FeedTypeEnum.FeedType key)
		{
			if (notification == null)
			{
				return;
			}

			if (notification.post != null && notification.post.IsExpired () && key == FeedTypeEnum.FeedType.StatusFeed){
				return;
			}

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

					if (key == FeedTypeEnum.FeedType.StatusFeed && currentDict.Value [i].post != null && notification.post != null && currentDict.Value [i].post.idPost == notification.post.idPost) {
						currentDict.Value [i] = notification;
						foundIt = true;
					}
				}

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

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

			}
		}