I am building a small social network where user can connect with other users and like in all other social networks I need activities stream.
I saw some similar questions but I am not sure about others solutions.
So I came up with something like this:
Activity { UserId, ToUserId, ActivityTypeId, ActivityDate, IsRead, ItemId }
UserId - user that generated activity,
ToUserId - user that should see this activity,
ActivityTypeId - new connection, photo, comment etc.,
ActivityDate,
IsRead
ItemId - based on type I know from which table I need to get data (users, comment, photo etc.)
ActivityType { ActivityTypeId, Text}
Text - e.g. Has new connection, Added new comment to, Edited his profile data etc.
When my connection for example get a new connection I should get:
Your connection [fetch name based on UserId]
Has a new connection [fetch data (by ItemId) from table user]
or
Your connection [fetch name based on UserId]
Added new comment to [fetch data (by ItemId) from table (for example) Photo]
My questions:
Is this bad design and why?
Is there better way?
UPDATE:
When user made a new activity I fetch all his connections ID's and for each of them I add that activity in Activity
table.
Or this answer is the better option?
How to implement the activity stream in a social network