The match social features have been successfully integrated into the tournament bracket system. When a match is completed, players can now:
- Send friend requests to their opponents
- Chat with teammates (for team tournaments)
- Build connections within the gaming community
File: src/components/tournaments/TournamentBracket.tsx
New Features:
-
Real-time Match Completion Detection
- Subscribes to
tournament_matchestable updates - Automatically detects when a match has a winner or is a draw
- Triggers social panel display for involved players
- Subscribes to
-
User Involvement Detection
- Solo tournaments: Direct player ID matching
- Team tournaments: Checks team membership via tournament registrations
-
Opponent Identification
- Solo tournaments: Returns the opposing player's user ID
- Team tournaments: Returns the captain or first member of the opposing team
-
Post-Match Social Panel Integration
- Displays
PostMatchSocialPanelcomponent when match completes - Passes match context, tournament info, opponent ID, and team ID
- Only shows to users who participated in the match
- Displays
checkUserInvolvedInSoloMatch()- Verifies if current user is player1 or player2getOpponentForSoloMatch()- Returns the opponent's user ID
checkUserInvolvedInTeamMatch()- Checks if user's team is involved in matchgetOpponentForTeamMatch()- Gets representative player from opposing teamgetUserTeamId()- Retrieves user's team ID for the tournament
getTournamentName()- Fetches tournament title for displayhandleMatchCompleted()- Orchestrates the entire flow when a match ends
The component subscribes to database changes on the tournament_matches table:
supabase
.channel(`tournament-matches-${tournamentId}`)
.on('postgres_changes', {
event: 'UPDATE',
schema: 'public',
table: 'tournament_matches',
filter: `tournament_id=eq.${tournamentId}`
}, async (payload) => {
// Handle match completion
})
.subscribe();All required tables are already created via migration 20251120084920_add_match_social_features.sql:
- match_friend_requests - Stores friend requests between players
- match_team_chat_messages - Stores team chat messages
- match_team_chat_read_status - Tracks message read status
The migration 20251119085638_add_match_team_chat_enhancements.sql provides:
- Enhanced
channelstable with match and tournament context create_match_team_channel()function for team chat creation- RLS policies for secure access control
The following services are already implemented and integrated:
-
matchFriendshipService.ts
checkFriendshipStatus()- Check relationship between usersgetOpponentUserProfile()- Fetch opponent profile datagenerateMatchContextMessage()- Create context messages
-
matchTeamChatService.ts
getTeamMembersForMatch()- Get team member listcreateMatchTeamChannel()- Create team chat channelcreateAndInitializeTeamChat()- Complete team chat setup
Match Completed (winner_id set)
↓
Real-time Update Detected
↓
Check User Involvement
↓ ↓
Solo Mode Team Mode
↓ ↓
Get Opponent User ID
↓
Display PostMatchSocialPanel
↓ ↓
Add Friend Team Chat
- Player completes a match
- Social panel appears automatically
- Player can send friend request to opponent
- Panel includes opponent's profile, avatar, and country
- Team completes a match
- Social panel appears for all team members
- Players can:
- Send friend request to opposing team representative
- Open team chat to coordinate with teammates
- Team chat persists throughout the tournament
All features are protected by Row Level Security (RLS):
- Friend requests: Users can only view/modify their own requests
- Team chat: Only team members can view/send messages
- Read status: Users can only manage their own read status
-
Solo Tournament
- Complete a match and verify social panel appears
- Send friend request to opponent
- Verify opponent receives notification
-
Team Tournament
- Complete a match as team member
- Verify all team members see the social panel
- Open team chat and send messages
- Verify opponent identification works correctly
-
Edge Cases
- User not involved in match (should not see panel)
- Match with no opponent data
- Team tournament with solo player data
- Multiple matches completing simultaneously
- Social panel appears automatically upon match completion
- Panel can be dismissed and won't show again for the same match
- Friend requests are prevented if already sent
- Team chat is created on-demand and persists
- All operations are real-time and secure