Open michaelsnook opened 4 days ago
Starting over on the implementation here:
friend_relationship
- a stable reference with an ID of its ownfriend_request_action
- actions table for when someone invites, declines, accepts, ends, etc., keeps track of who made the action and to whom it was directed, and the relationship IDfriend_relationship_current
- a view for the current status of the relationship, whose "go" is it, etc.by
/for
where "by" is always the current user ID and "for" is always the other person. So if person A sends a request to person B, and person B accepts, person A's uid
will be the value for the first action's uid_by
and the second action's uid_for
. uid_less
and uid_more
-- clients will be responsible for knowing the values of both UIDs and sending them along. (if we want the client to be able to be more ignorant, we can use serverless functions!) RLS will reject any insert where uid_less > uid_more
uid_first_from
and uid_first_to
(as well as the aforementioned greater/less-than constraint), and when there is already a relationship present the UI will instead attempt to insert a friend request action, whose RLS will have some subquery stuff that joins to the view of the current friendship:
pending
: uid_by can "cancel"; uid_for can "accept" or "decline"friends
: either party can "remove"unconnected
(or the relationship is not found): either party can "invite"__NB: I get to the end of this and realize actually we can probably do away with the friend_relationship table and keep the original/current structure of just the actions and the summary; contrary to points above and below.__
As for the UI
public_profile
with friend_relationship_current
attached (if present)friend_relationship_current
where status = 'pending'
and uid_by
is me (the user)uid_for
is mestatus = 'friends'
Trying again but back to just the actions and the summary:
We'll have a friendship_summary
- a view with
id, uid_by, uid_for
accept, invite, cancel, remove, decline
friends, pending, unconnected
(or blocked
, for later) User interactions will happen on friend_request_action
- an actions table for when someone invites, accepts etc.
uid_by
and who is it for uid_for
uid_less
and uid_more
fields, whose validity will be enforced by RLS and ensured by the client. This order-enforced pairing becomes the unique identifier for the relationship, preventing mismatches where some records use B,A
and others use A,B
and so the full picture becomes fragmented. uid_by
and the second action's uid_for
, but for both events the uid_less
and uid_more
will be the same for any given pair of users.accept, invite, cancel, remove, decline
From this friendship summary we derive who can take what actions:
pending
: uid_by can "cancel"; uid_for can "accept" or "decline"friends
: either party can "remove"unconnected
(or NULL): either party can "invite"As for the UI
public_profile
with friend_relationship_current
attached (if present)friend_relationship_current
where status = 'pending'
and uid_by
is the useruid_for
is the userstatus = 'friends'
Friends data model: we need to fill out this friend request action table. We're currently just using an actions table and a view; want to add a unique relationship identification table and have that be the feeding ground for the view, and have actions reference that table specifically.
friend_relationship
type table that has unique set for the uid_from and uid_to.friend_relationship_id
and do not need to store the to and from fields.friend_relationship_current
can be a view that takes the most recent record from the friend_request_action table for each of these unique relationship_ids and also calulates another overall status of "no | yes | pending"