const defaultMessageState = {
  messages: [],
  needAnimation: true,
  endedAnimation: false
}

export function messageReducer (state, action) {
  switch (action.type) {
    case 'message':
      const { messages, endedAnimation, needAnimation } = state

      return {
        ...state,
        messages: messages.concat({
          time: action.time,
          text: action.message,
          name: action.name
        }),
        needAnimation: needAnimation && messages.length === 0,
        endedAnimation: endedAnimation || messages.length !== 0
      }

    case 'animationEnd':
      return {
        ...state,
        endedAnimation: true
      }


    case 'ws/select':
      return {
        ...state,
        messages: []
      }

    default:
      return state || defaultMessageState
  }
}


const defaultUserState = { tryAuth: true, isAuthenticated: false }
export function userReducer (state, action) {
  switch (action.type) {
    case 'ws/auth':
      return {
        ...state,
        tryAuth: true
      }

    case 'user':
      return {
        ...state,
        tryAuth: false,
        isAuthenticated: action.isAuth || false,
        isSupa: action.isSupa,
        name: action.name,
        token: action.token
      }

    default:
      return state || defaultUserState
  }
}


const defaultRoomState = []
export function roomsReducer (state, action) {
  switch (action.type) {
    case 'room_all':
      return action.room
    case 'room_add':
      return state.concat(action.room)
    case 'room_rem':
      return state.filter(room => room.key !== action.room.key)
    default:
      return state || defaultRoomState
  }
}


const defaultSelectedRoomState = null
export function selectedRoomReducer (state, action) {
  switch (action.type) {
    case `ws/select`:
      return action.name
    default:
      return state || defaultSelectedRoomState
  }
}

@@ -205,16 +205,21 @@
 messages
+: msg
 , endedA
@@ -256,166 +256,85 @@
 ate%0A
-%0A
       
-return %7B%0A        ...state,%0A        messages: messages.concat(%7B%0A          time: 
+const messages = msg.concat(
 action.
-time,
+m)%0A
 %0A      
-    text: action.message,%0A          name: action.name
+return %7B%0A        ...state,
 %0A   
@@ -342,10 +342,16 @@
     
-%7D)
+messages
 ,%0A  
@@ -408,17 +408,17 @@
 gth === 
-0
+1
 ,%0A      
@@ -477,9 +477,9 @@
 !== 
-0
+1
 %0A   
@@ -580,17 +580,16 @@
      %7D%0A%0A
-%0A
     case
@@ -719,33 +719,32 @@
 ageState%0A  %7D%0A%7D%0A%0A
-%0A
 const defaultUse
@@ -1218,33 +1218,32 @@
 serState%0A  %7D%0A%7D%0A%0A
-%0A
 const defaultRoo
@@ -1576,17 +1576,16 @@
 %0A  %7D%0A%7D%0A%0A
-%0A
 const de

fix reducer