public Activity Report(JunaUser reportUser, Comment comment, FeedItem reportFeedItem, JunaUser user, Board board, string time) { var reportActivity = new Activity(); if (reportUser != null) { reportActivity = new ActivityBuilder() .WithActor(user) .WithVerb(BoardInteractionMetadata.INTERACTION_REPORT) .WithObject(reportUser) .WithTarget(board) .WithTime(DateTime.Parse(time)) .Build(); var reportUserActivity = _activityRepository.Save(reportActivity); var boardFeed = _streamClient.Feed(FeedGroup.BoardFeedType, StreamHelper.GetStreamActorId(reportUserActivity)); var streamActivity = new Stream.Activity(reportUserActivity.Actor, reportUserActivity.Verb, reportUserActivity.Object) { Target = reportUserActivity.Target, ForeignId = reportUserActivity.Id.ToString() }; boardFeed.AddActivity(streamActivity); } if (comment != null) { reportActivity = new ActivityBuilder() .WithActor(user) .WithVerb(BoardInteractionMetadata.INTERACTION_REPORT) .WithObject(comment) .WithTarget(board) .WithTime(DateTime.Parse(time)) .Build(); var reportCommentActivity = _activityRepository.Save(reportActivity); var boardFeed = _streamClient.Feed(FeedGroup.BoardFeedType, StreamHelper.GetStreamActorId(reportCommentActivity)); var streamActivity = new Stream.Activity(reportCommentActivity.Actor, reportCommentActivity.Verb, reportCommentActivity.Object) { Target = reportCommentActivity.Target, ForeignId = reportCommentActivity.Id.ToString(), }; boardFeed.AddActivity(streamActivity); } if (reportFeedItem != null) { reportActivity = new ActivityBuilder() .WithActor(user) .WithVerb(BoardInteractionMetadata.INTERACTION_REPORT) .WithObject(reportFeedItem) .WithTarget(board) .WithTime(DateTime.Parse(time)) .Build(); var reportFeedItemActivity = _activityRepository.Save(reportActivity); var boardFeed = _streamClient.Feed(FeedGroup.BoardFeedType, StreamHelper.GetStreamActorId(reportFeedItemActivity)); var streamActivity = new Stream.Activity(reportFeedItemActivity.Actor, reportFeedItemActivity.Verb, reportFeedItemActivity.Object) { Target = reportFeedItemActivity.Target, ForeignId = reportFeedItemActivity.Id.ToString(), }; boardFeed.AddActivity(streamActivity); } return reportActivity; }
public async void CreateFeedItem(Board board, JunaUser user, string contentType, string title, DateTime dateCreated) { var feedItem = new RootCommentFeedItem() { Id = Guid.NewGuid(), ContentType = contentType, Title = title, DateCreated = dateCreated, Actor = user }; _feedItemRepository.Upsert(feedItem); var activity = new ActivityBuilder() .WithActor(user) .WithVerb(BoardInteractionMetadata.INTERACTION_POST) .WithObject(feedItem) .WithTarget(board) .WithTime(dateCreated) .Build(); var createFeedItemActivity = _activityRepository.Save(activity); var boardFeed = _streamClient.Feed(FeedGroup.BoardFeedType, StreamHelper.GetStreamActorId(createFeedItemActivity)); var streamActivity = new Stream.Activity(createFeedItemActivity.Actor, createFeedItemActivity.Verb, createFeedItemActivity.Object) { Target = createFeedItemActivity.Target, ForeignId = createFeedItemActivity.Id.ToString(), }; await boardFeed.AddActivity(streamActivity); if (board.Interactions == null) { board.Interactions = new BoardInteractionMetadata { Likes = 0, Shares = 0, Comments = 0, Followers = 0, Pins = 0, Posts = 0, ActiveUsers = 0 }; } board.Interactions.Posts++; _boardRepository.Upsert(board); await _fcmSenderService.SendFcmBoardNotification( new JunaNotification { Title = title, Actor = user.DisplayName, Action = BoardInteractionMetadata.INTERACTION_POST, ContentType = contentType, ForeignId = board.BoardType.Equals("private")?0 : board.BoardEvent.ForeignId }, board, FCMSenderService.CREATE_OPERATION); }
public Activity BlockUser(JunaUser user, JunaUser blockUser, string time) { var activity = new ActivityBuilder() .WithActor(user) .WithVerb(BoardInteractionMetadata.INTERACTION_BLOCK) .WithObject(blockUser) .WithTime(DateTime.Parse(time)) .Build(); var blockActivity = _activityRepository.Save(activity); var userFeed = _streamClient.Feed(FeedGroup.UserFeedType, StreamHelper.GetStreamActorId(blockActivity)); var streamActivity = new Stream.Activity(blockActivity.Actor, blockActivity.Verb, blockActivity.Object) { Target = blockActivity.Target, ForeignId = blockActivity.Id.ToString() }; userFeed.AddActivity(streamActivity); return blockActivity; }
public Activity MuteUser(JunaUser user, JunaUser muteUser, Board board, string time) { var activity = new ActivityBuilder() .WithActor(user) .WithVerb(BoardInteractionMetadata.INTERACTION_MUTE) .WithObject(muteUser) .WithTarget(board) .WithTime(DateTime.Parse(time)) .Build(); var muteActivity = _activityRepository.Save(activity); var boardFeed = _streamClient.Feed(FeedGroup.BoardFeedType, StreamHelper.GetStreamActorId(muteActivity)); var streamActivity = new Stream.Activity(muteActivity.Actor, muteActivity.Verb, muteActivity.Object) { Target = muteActivity.Target, ForeignId = muteActivity.Id.ToString() }; boardFeed.AddActivity(streamActivity); return muteActivity; }
public Board UserEntersBoard(JunaUser user, string timestamp, Board board) { var activity = new ActivityBuilder() .WithActor(user) .WithVerb(BoardInteractionMetadata.BOARD_INTERACTION_ENTER) .WithObject(board) // .WithForeignId(user) //TODO: this is a bug. Upon entering a Board the Object is set as "JunaUser: userObjectId" // it should be Board-BoardId // when .WithForeignId(user) mwthod is called the previous value is overwritten and we are getting object as "JunaUser: userObjectId" .WithTime(DateTime.Parse(timestamp)) .Build(); var enterBoardActivity = _activityRepository.Save(activity); var boardFeed = _streamClient.Feed(FeedGroup.BoardFeedType, StreamHelper.GetStreamActorId(enterBoardActivity)); var streamActivity = new Stream.Activity(enterBoardActivity.Actor, enterBoardActivity.Verb, enterBoardActivity.Object) { Target = enterBoardActivity.Target, ForeignId = enterBoardActivity.Id.ToString(), }; boardFeed.AddActivity(streamActivity); if (board.Interactions == null) { board.Interactions = new BoardInteractionMetadata { Likes = 0, Shares = 0, Comments = 0, Followers = 0, Pins = 0, Posts = 0, ActiveUsers = 0 }; } // todo: This is not accurate or thread-safe. Also, multiple entries are counted as multiple users board.Interactions.Followers++; board.Interactions.ActiveUsers++; return(_boardRepository.Upsert(board)); }
public void ShareFeedItem(Guid feedItemId, string shareTo, Guid boardId, string userId, string time) { if (feedItemId != null && shareTo != null && boardId != null && userId != null) { var feedItem = _feedItemRepository.GetById(feedItemId); var board = _boardRepository.GetById(boardId); var user = _junaUserRepository.GetByObjectId(userId); var activity = new ActivityBuilder() .WithActor(user) .WithVerb(BoardInteractionMetadata.INTERACTION_SHARE) .WithObject(feedItem) .WithTarget(board) .WithTime(DateTime.Parse(time)) .Build(); var shareActivity = _activityRepository.Save(activity); var boardFeed = _streamClient.Feed(FeedGroup.BoardFeedType, StreamHelper.GetStreamActorId(shareActivity)); var streamActivity = new Stream.Activity(shareActivity.Actor, shareActivity.Verb, shareActivity.Object) { Target = shareActivity.Target, ForeignId = shareActivity.Id.ToString(), }; boardFeed.AddActivity(streamActivity); // Move this to a database trigger or a change feed processor if (feedItem.Interactions == null) { feedItem.Interactions = new InteractionMetadata { Likes = 0, Shares = 0, Pins = 0 } } ; feedItem.Interactions.Shares++; _feedItemRepository.Upsert(feedItem); } }
private async Task ProcessFeedItemsAsync(FeedItem feedItem) { try { logger.TrackTrace($"Processing feed item with Title [{feedItem.Title}] of type: [{feedItem.ContentType}]", SeverityLevel.Information); logger.TrackTrace("\nInserting newsfeed into the database\n", SeverityLevel.Information); logger.TrackTrace($"\n New URL is [{feedItem.Title}]", SeverityLevel.Information); logger.TrackTrace(JsonConvert.SerializeObject(feedItem), SeverityLevel.Verbose); feedItem = await _feedService.StoreItemWithUniqueUrlAsync(feedItem); var activity = _activityService.StoreUniqueActivity(new Activity { Actor = ActivityHelper.GetActor(FOOTBALL_BOT), Verb = InteractionMetadata.INTERACTION_POST, Object = ActivityHelper.GetObject(feedItem), Time = JsonConvert.SerializeObject(feedItem.DatePublished) }); var junaUserFeed = _streamClient.Feed(FeedGroup.JunaFeedType, StreamHelper.GetStreamActorId(activity)); var streamActivity = new Stream.Activity(activity.Actor, activity.Verb, activity.Object) { ForeignId = activity.Id.ToString(), }; await junaUserFeed.AddActivity(streamActivity); logger.TrackTrace($"Successfully processed feed item of type [{feedItem.ContentType}] with url [{feedItem.Url}]"); } catch (DuplicateEntityException) { logger.TrackTrace($"FeedItem with the Url [{feedItem.Url}] already exists. Skipping", SeverityLevel.Warning); } finally { logger.TrackTrace($"Insert attempt completed for record with headline: [{feedItem.Title}]", SeverityLevel.Information); } }
public Comment ReplyToComment(Board board, FeedItem feedItem, JunaUser user, string timeStamp, string replyComment, Comment parentComment) { var activity = new CommentBuilder() .WithActor(user) .WithVerb(BoardInteractionMetadata.INTERACTION_COMMENT) .WithObject(feedItem) .WithTarget(board) .WithTime(DateTime.Parse(timeStamp)) .WithParentCommentId(parentComment) .WithMessage(replyComment) .Build(); var replyCommentActivity = _commentsRepository.Save(activity); var boardFeed = _streamClient.Feed(FeedGroup.BoardFeedType, StreamHelper.GetStreamActorId(replyCommentActivity)); var streamActivity = new Stream.Activity(replyCommentActivity.Actor, replyCommentActivity.Verb, replyCommentActivity.Object) { Target = replyCommentActivity.Target, ForeignId = replyCommentActivity.Id.ToString(), }; streamActivity.SetData("Message", replyCommentActivity.Message); boardFeed.AddActivity(streamActivity); // Move this to a database trigger or a change feed processor if (feedItem.Interactions == null) { feedItem.Interactions = new InteractionMetadata { Likes = 0, Shares = 0, Pins = 0, Comments = 0 } } ; feedItem.Interactions.Comments++; _feedItemRepository.Upsert(feedItem); return(replyCommentActivity); }
public void LikeFeedItem(FeedItem feedItem, JunaUser user, string target, string targetId, string time) { var activity = new Activity(); switch (target) { case "Board": var board = _boardRepository.GetById(Guid.Parse(targetId)); if (board == null) { break; } activity = new ActivityBuilder() .WithActor(user) .WithVerb(BoardInteractionMetadata.INTERACTION_LIKE) .WithObject(feedItem) .WithTarget(board) .WithTime(DateTime.Parse(time)) .Build(); var boardActivity = StoreUniqueActivity(activity); var boardFeed = _streamClient.Feed(FeedGroup.BoardFeedType, StreamHelper.GetStreamActorId(activity)); var streamActivity = new Stream.Activity(boardActivity.Actor, boardActivity.Verb, boardActivity.Object) { Target = boardActivity.Target, ForeignId = boardActivity.Id.ToString(), }; boardFeed.AddActivity(streamActivity); //delete the dislike activity if user has one var dislikeActivity = _activityRepository.GetByActorVerbObjectandTarget( actor: ActivityHelper.GetActor(user), verb: InteractionMetadata.INTERACTION_DISLIKE, objectString: ActivityHelper.GetObject(feedItem), target: ActivityHelper.GetTarget(board)); if (dislikeActivity != null) { UndoDisLike(feedItem, user); } break; case "user": activity = new ActivityBuilder() .WithActor(user) .WithVerb(BoardInteractionMetadata.INTERACTION_LIKE) .WithObject(feedItem) .WithTime(DateTime.Parse(time)) .Build(); var userActivity = StoreUniqueActivity(activity); var userFeed = _streamClient.Feed(FeedGroup.UserFeedType, StreamHelper.GetStreamActorId(activity)); streamActivity = new Stream.Activity(userActivity.Actor, userActivity.Verb, userActivity.Object) { Target = userActivity.Target, ForeignId = userActivity.Id.ToString(), }; userFeed.AddActivity(streamActivity); break; case "Card": //Not implemented yet break; default: break; } // Move this to a database trigger or a change feed processor if (feedItem.Interactions == null) { feedItem.Interactions = new InteractionMetadata { Likes = 0, Shares = 0, Pins = 0 } } ; feedItem.Interactions.Likes++; _feedItemRepository.Upsert(feedItem); }
public void PinFeedItem(FeedItem feedItem, JunaUser user, string target, string targetId, string time) { var activity = new Activity(); switch (target) { case "Board": var board = _boardRepository.GetById(Guid.Parse(targetId)); if (board == null) { break; } activity = new ActivityBuilder() .WithActor(user) .WithVerb(BoardInteractionMetadata.INTERACTION_PIN) .WithObject(feedItem) .WithTarget(board) .WithTime(DateTime.Parse(time)) .Build(); var pinActivity = StoreUniqueActivity(activity); var boardFeed = _streamClient.Feed(FeedGroup.BoardFeedType, StreamHelper.GetStreamActorId(pinActivity)); var streamActivity = new Stream.Activity(pinActivity.Actor, pinActivity.Verb, pinActivity.Object) { Target = pinActivity.Target, ForeignId = pinActivity.Id.ToString() }; boardFeed.AddActivity(streamActivity); break; case "user": var targetUser = _junaUserRepository.GetByObjectId(targetId); if (targetUser == null) { break; } activity = new ActivityBuilder() .WithActor(user) .WithVerb(BoardInteractionMetadata.INTERACTION_PIN) .WithObject(feedItem) .WithTarget(targetUser) .WithTime(DateTime.Parse(time)) .Build(); var userPinActivity = StoreUniqueActivity(activity); var userFeed = _streamClient.Feed(FeedGroup.UserFeedType, StreamHelper.GetStreamActorId(userPinActivity)); var streamPinActivity = new Stream.Activity(userPinActivity.Actor, userPinActivity.Verb, userPinActivity.Object) { Target = userPinActivity.Target, ForeignId = userPinActivity.Id.ToString() }; userFeed.AddActivity(streamPinActivity); break; case "Card": //to be implemented break; default: break; } if (feedItem.Interactions == null) { feedItem.Interactions = new InteractionMetadata { Likes = 0, Shares = 0, Pins = 0 } } ; feedItem.Interactions.Pins++; _feedItemRepository.Upsert(feedItem); }
public static string GetStreamObjectId(Stream.Activity activity) { return(activity.Object.Split(':').Skip(1).FirstOrDefault()); }
private async Task UploadAndSaveFeedItemAsync(FeedItem feedItem, string feedItemType, System.IO.Stream fileStream, JunaUser user, string mimeType, string targetType, Board board, string description) { feedItem.ContentType = feedItemType; feedItem.Actor = user; feedItem.Description = description; feedItem.Url = _blobHelper.GenerateFilePath(guid: feedItem.Id, itemType: feedItemType, username: user.Id.ToString()); var blob = new CloudBlockBlob(new Uri(feedItem.Url), _storageCredentials); await blob.UploadFromStreamAsync(fileStream); var thumbnailUrl = _blobHelper.GenerateThumbnailFilePath(guid: feedItem.Id, itemType: feedItemType, username: user.Id.ToString()); await _thumbnailService.GenerateThumbnail(feedItem.Url, thumbnailUrl, mimeType, feedItem.Title); feedItem.DatePublished = DateTime.UtcNow; feedItem.Thumbnail = new Image { // todo: these two should be read from config ImageHeight = 300, ImageWidth = 300, ImageUrl = thumbnailUrl }; _feedItemRepository.Upsert(feedItem); var activity = new Activity { Id = Guid.NewGuid(), Actor = $"JunaUser:{user.ObjectId}", Time = DateTime.UtcNow.ToString("s", System.Globalization.CultureInfo.InvariantCulture), Object = $"{feedItem.ContentType}:{feedItem.Id}", }; switch (targetType) { case (FeedGroup.BoardFeedType): activity.Target = ActivityHelper.GetTarget(board); activity.Verb = InteractionMetadata.INTERACTION_POST; var postActivity = _activityService.StoreUniqueActivity(activity); var boardFeed = _streamClient.Feed(FeedGroup.BoardFeedType, StreamHelper.GetStreamActorId(postActivity)); var streamActivity = new Stream.Activity(actor: postActivity.Actor, verb: postActivity.Verb, @object: postActivity.Object) { Target = postActivity.Target, ForeignId = postActivity.Id.ToString(), }; await boardFeed.AddActivity(streamActivity); if (board.Interactions == null) { board.Interactions = new BoardInteractionMetadata { Likes = 0, Shares = 0, Comments = 0, Followers = 0, Pins = 0, Posts = 0 }; } board.Interactions.Posts++; _boardsRepository.Upsert(board); // todo: Find a better way to send it than dynamic formatting like this. use a mapper and a transfer object await _fcmSenderService.SendFcmBoardNotification( new JunaNotification { Title = feedItem.Title, Actor = user.DisplayName, Action = activity.Verb, ImageUrl = feedItem.Url, ThumbnailImageUrl = feedItem.Thumbnail.ImageUrl, ThumbnailWidth = feedItem.Thumbnail.ImageWidth, ThumbnailHeight = feedItem.Thumbnail.ImageHeight, ContentType = feedItem.ContentType, ForeignId = board.BoardType.Equals("private") ? 0 : board.BoardEvent.ForeignId }, board, FCMSenderService.CREATE_OPERATION); break; case (FeedGroup.CardFeedType): _activityService.StoreUniqueActivity(new Activity { Actor = ActivityHelper.GetActor(user), Verb = InteractionMetadata.INTERACTION_POST, Object = ActivityHelper.GetObject(feedItem), Target = StreamHelper.GetCardTarget(user), Time = DateTime.UtcNow.ToString("s", System.Globalization.CultureInfo.InvariantCulture) }); feedItem.Interactions.Posts++; break; case (FeedGroup.UserFeedType): activity.Verb = InteractionMetadata.INTERACTION_POST; var userPostActivity = _activityService.StoreUniqueActivity(activity); var userFeed = _streamClient.Feed(FeedGroup.UserFeedType, StreamHelper.GetStreamActorId(userPostActivity)); var userStreamActivity = new Stream.Activity(actor: userPostActivity.Actor, verb: userPostActivity.Verb, @object: userPostActivity.Object) { ForeignId = $"{userPostActivity.Id}", }; await userFeed.AddActivity(userStreamActivity); if (feedItem.Interactions == null) { feedItem.Interactions = new InteractionMetadata { Likes = 0, Shares = 0, Comments = 0, Pins = 0, Posts = 0 }; } feedItem.Interactions.Posts++; _feedItemRepository.Upsert(feedItem); break; } }