import MyInfo from "../stores/MyInfoStore" ; import Participant from "../models/Participant" ; import ParticipantsStore from "../stores/ParticipantsStore" ; class ParticipantService { static getLiving ( excludeSelf = false ) { return ParticipantsStore . participants . filter ( ( participant ) => participant . info . isAlive && ( excludeSelf ? participant . info . id !== MyInfo . participant ?. id : true ) ) ; } static reset ( ) { ParticipantsStore . participants = [ ] ; } static replace ( array ) { ParticipantsStore . participants = array ; } static getById ( id ) { return ParticipantsStore . participants . find ( ( participant ) => participant . info . id === id ) ; } static getIndexById ( id ) { return ParticipantsStore . participants ?. findIndex ( ( participant ) => participant . info . id === id ) ; } static removeFromWaitingRoom ( id ) { const waitingRoomIndex = ParticipantsStore . waitingRoom . findIndex ( ( patientParticipant ) => patientParticipant . info . id === id ) ; if ( waitingRoomIndex >= 0 ) { ParticipantsStore . waitingRoom . splice ( waitingRoomIndex , 1 ) ; } } static filterByMentionString ( mentionString ) { mentionString = mentionString . toLowerCase ( ) ; if ( mentionString [ 0 ] === "@" ) { mentionString = mentionString . substring ( 1 ) ; } return ParticipantsStore . participants . filter ( ( participant ) => participant . mentionString . toLowerCase ( ) . startsWith ( mentionString ) ) ; } static getByMentionString ( mentionString ) { mentionString = mentionString . toLowerCase ( ) ; if ( mentionString [ 0 ] === "@" ) { mentionString = mentionString . substring ( 1 ) ; } return ParticipantsStore . participants . filter ( ( participant ) => participant . mentionString . toLowerCase ( ) === mentionString ) ; } } export default ParticipantService ;