in code/Server/Common/Managers/PushNotificationsManager.cs [580:782]
private string ActivityViewToString(ActivityView activity, string userHandle)
{
// check inputs
if (activity == null)
{
this.log.LogException("got null activity");
}
if (string.IsNullOrWhiteSpace(userHandle))
{
this.log.LogException("got null userHandle");
}
string result = string.Empty;
// first add the actor user name(s)
switch ((ActivityType)activity.ActivityType)
{
// aggregate notification
case ActivityType.Like:
case ActivityType.Comment:
case ActivityType.Reply:
if (activity.ActorUsers == null || activity.ActorUsers.Count < 1)
{
this.log.LogException("unexpected ActorUsers");
}
// add usernames
result += this.UserListToString(activity.ActorUsers, userHandle);
// do not send a notification if the result is null
if (string.IsNullOrWhiteSpace(result))
{
// this can happen when the user is deleted before the push notification has been processed
this.log.LogInformation("got an empty user list, perhaps due to a race condition");
return null;
}
// add remaining count of users
if (activity.TotalActions > activity.ActorUsers.Count)
{
result += " & " + (activity.TotalActions - activity.ActorUsers.Count) + " other user";
}
if (activity.TotalActions > (activity.ActorUsers.Count + 1))
{
result += "s";
}
break;
// non-aggregate notifications
case ActivityType.CommentPeer:
case ActivityType.ReplyPeer:
case ActivityType.Following:
case ActivityType.FollowRequest:
case ActivityType.FollowAccept:
if (activity.ActorUsers == null || activity.ActorUsers.Count != 1 || activity.ActorUsers[0] == null)
{
// this can happen when the user is deleted before the push notification has been processed
this.log.LogInformation("got a null user, perhaps due to a race condition");
return null;
}
result += this.GetUserDisplayName(activity.ActorUsers[0]);
// sometimes, the user may be invalid
if (string.IsNullOrWhiteSpace(result))
{
this.log.LogInformation("exiting due to empty actor string");
return null;
}
break;
default:
this.log.LogException("got unusual activity type " + activity.ActivityType);
break;
}
// now add the action
switch ((ActivityType)activity.ActivityType)
{
case ActivityType.Like:
result += " liked";
break;
case ActivityType.Comment:
result += " commented on";
break;
case ActivityType.Reply:
result += " replied to";
break;
case ActivityType.CommentPeer:
case ActivityType.ReplyPeer:
result += " mentioned";
break;
case ActivityType.Following:
result += " is following";
break;
case ActivityType.FollowRequest:
result += " requested to follow";
break;
case ActivityType.FollowAccept:
result += " accepted a follow request from";
break;
default:
this.log.LogException("got unusual activity type " + activity.ActivityType);
break;
}
// now add the acted on owner
switch ((ActivityType)activity.ActivityType)
{
case ActivityType.Like:
case ActivityType.Comment:
case ActivityType.Reply:
if (activity.ActedOnUser == null || activity.ActedOnUser.UserHandle == userHandle)
{
result += " your";
}
else
{
string actedOnUserName = this.GetUserDisplayName(activity.ActedOnUser);
if (string.IsNullOrWhiteSpace(actedOnUserName))
{
// this can happen when the acted on user has been deleted
this.log.LogInformation("got null acted on user name");
return null;
}
result += " " + actedOnUserName + "'s";
}
break;
case ActivityType.CommentPeer:
case ActivityType.ReplyPeer:
result += " you in a";
break;
case ActivityType.Following:
case ActivityType.FollowRequest:
case ActivityType.FollowAccept:
if (activity.ActedOnUser == null || activity.ActedOnUser.UserHandle == userHandle)
{
result += " you";
}
else
{
string actedOnUserName = this.GetUserDisplayName(activity.ActedOnUser);
if (string.IsNullOrWhiteSpace(actedOnUserName))
{
// this can happen when the acted on user has been deleted
this.log.LogInformation("got null acted on user name");
return null;
}
result += " " + actedOnUserName;
}
break;
default:
this.log.LogException("got unusual activity type " + activity.ActivityType);
break;
}
// now add the acted on content type
switch ((ActivityType)activity.ActivityType)
{
case ActivityType.Like:
case ActivityType.Comment:
case ActivityType.Reply:
case ActivityType.CommentPeer:
case ActivityType.ReplyPeer:
// type of content
if ((ContentType)activity.ActedOnContent.ContentType == ContentType.Comment)
{
result += " comment";
}
else if ((ContentType)activity.ActedOnContent.ContentType == ContentType.Reply)
{
result += " reply";
}
else if ((ContentType)activity.ActedOnContent.ContentType == ContentType.Topic)
{
result += " topic";
}
else
{
this.log.LogException("unexpected ActedOnContent Type " + activity.ActedOnContent.ContentType);
}
break;
case ActivityType.Following:
case ActivityType.FollowRequest:
case ActivityType.FollowAccept:
// do nothing
break;
default:
this.log.LogException("got unusual activity type " + activity.ActivityType);
break;
}
return result;
}