import { MessengerFriend } from './MessengerFriend'; /** * Filter a friend list to a single category. categoryId 0 means * "All" (no filtering) and returns the list unchanged. */ export const filterFriendsByCategory = (friends: MessengerFriend[], categoryId: number): MessengerFriend[] => { if(!friends) return []; if(!categoryId) return friends; return friends.filter(friend => (friend.categoryId === categoryId)); }; /** * Count how many friends belong to each category id. Used to render * member counts on the group chips. */ export const countFriendsByCategory = (friends: MessengerFriend[]): Map => { const counts = new Map(); if(!friends) return counts; for(const friend of friends) { counts.set(friend.categoryId, (counts.get(friend.categoryId) ?? 0) + 1); } return counts; };