{ const currentUserId = this.props.user.uid return userId > currentUserId ? `${userId}/${currentUserId}` : `${currentUserId}/${userId}` } //changeChatRoom 방 바뀌었을때 changeChatRoom=(user)=>{ const chatRoomId = this.getChatRoomId(user.uid); const chatRoomData = { id:chatRoomId, name:user.name, } this.props.dispatch(setCurrentChatRoom(chatRoomData)) this.props.dispatch(setPrivateChatRoom(true)); this.activeChatRoom(user.uid); } //활성화된 ChatRoom activeChatRoom=(userId) =>{ this.setState({activeChatRoom:userId}) } //활성화 되었을경우 배경색상 교체하기 renderDirectMessages = () => { const { users } = this.state; return ( users.length > 0 && users.map(user => (
//state에 activeChatRoom 추가
state = {
usersRef: firebase.database().ref("users"),
users: [],
activeChatRoom:""
}
//ChatRoom 얻기
getChatRoomId = (userId) => {
const currentUserId = this.props.user.uid
return userId > currentUserId
? `${userId}/${currentUserId}`
: `${currentUserId}/${userId}`
}
//changeChatRoom 방 바뀌었을때
changeChatRoom=(user)=>{
const chatRoomId = this.getChatRoomId(user.uid);
const chatRoomData = {
id:chatRoomId,
name:user.name,
}
this.props.dispatch(setCurrentChatRoom(chatRoomData))
this.props.dispatch(setPrivateChatRoom(true));
this.activeChatRoom(user.uid);
}
//활성화된 ChatRoom
activeChatRoom=(userId) =>{
this.setState({activeChatRoom:userId})
}
//활성화 되었을경우 배경색상 교체하기
renderDirectMessages = () => {
const { users } = this.state;
return (
users.length > 0 &&
users.map(user => (
<li key={user.uid}
style={{
backgroundColor:user.uid===this.state.activeChatRoom
&&"#ffffff45"
}}
onClick={() => this.changeChatRoom(user)}>
# {user.name}
</li>
))
);
}