1import * as React from 'react' 2import {imgMaxWidthRaw} from '../messages/attachment/image/image-render' 3import * as Styles from '../../../styles' 4import * as ChatConstants from '../../../constants/chat2' 5import * as ChatTypes from '../../../constants/types/chat2' 6import * as TeamTypes from '../../../constants/types/teams' 7import * as Container from '../../../util/container' 8import * as TeamsGen from '../../../actions/teams-gen' 9 10export const infoPanelWidthElectron = 320 11export const infoPanelWidthPhone = imgMaxWidthRaw() 12export const infoPanelWidthTablet = 350 13 14export function infoPanelWidth() { 15 if (Styles.isTablet) { 16 return infoPanelWidthTablet 17 } else if (Styles.isMobile) { 18 return infoPanelWidthPhone 19 } else { 20 return infoPanelWidthElectron 21 } 22} 23 24const emptyMap = new Map() 25const isBot = (type: TeamTypes.TeamRoleType) => type === 'bot' || type === 'restrictedbot' 26 27export const useTeamHumans = (teamID: TeamTypes.TeamID) => { 28 const dispatch = Container.useDispatch() 29 React.useEffect(() => { 30 dispatch(TeamsGen.createGetMembers({teamID})) 31 }, [dispatch, teamID]) 32 const teamMembers = Container.useSelector(state => state.teams.teamIDToMembers.get(teamID)) || emptyMap 33 const bots = React.useMemo(() => { 34 const ret = new Set<string>() 35 teamMembers.forEach(({type}, username) => isBot(type) && ret.add(username)) 36 return ret 37 }, [teamMembers]) 38 const teamHumanCount = teamMembers.size - bots.size 39 return {bots, teamHumanCount} 40} 41 42export const useHumans = (conversationIDKey: ChatTypes.ConversationIDKey) => { 43 const conversationMeta = Container.useSelector(state => ChatConstants.getMeta(state, conversationIDKey)) 44 const participantInfo = Container.useSelector(state => 45 ChatConstants.getParticipantInfo(state, conversationIDKey) 46 ) 47 const {bots, teamHumanCount} = useTeamHumans(conversationMeta.teamID) 48 const channelHumans = 49 conversationMeta.teamType === 'adhoc' 50 ? participantInfo.name 51 : participantInfo.all.filter(username => !bots.has(username)) 52 return {channelHumans, teamHumanCount} 53} 54