Skip to content

Instantly share code, notes, and snippets.

@ryanpbrewster
Last active May 4, 2016 20:39
Show Gist options
  • Select an option

  • Save ryanpbrewster/8cd1998152ca881c93c82d1769e88621 to your computer and use it in GitHub Desktop.

Select an option

Save ryanpbrewster/8cd1998152ca881c93c82d1769e88621 to your computer and use it in GitHub Desktop.
def generateNotifications(activity: Seq[Event]): Seq[BatchFetchable[String]] = {
activity.map {
case NewPost(userId, groupId, postId) => BatchFetchable[String](
keys = Keys(Set(userId), Set(groupId), Set(postId), Set()),
entities =>
val user = entities.users(userId)
val group = entities.groups(groupId)
val post = entities.posts(postId)
s"${user.fullName} shared ${post.title} with ${group.name}"
)
case DirectMessage(fromId, toId, msgId) => BatchFetchable[String](
keys = Keys(Set(fromId, toId), Set(), Set(), Set(msgId)),
entities =>
val (from, to) = (entities.users(fromId), entities.users(toId))
val msg = entities.msgs(msgId)
s"${from.fullName} said ${msg.text} to ${to.fullName}"
)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment