import store from './store'
import * as types from './constants'

import { showNotification, initializeApp, updateChannel, updateChannelVolume, removeMessage }
  from './actions'

export default function(eventType, data) {
  switch (eventType) {
    case 'echo':
      console.log('>>> echo >>>')
      console.log(data)
      console.log('<<<<<<<<<<<<')
      break
    case 'initialize':
      store.dispatch(initializeApp(data))
      break
    case 'channelUpdate':
      Object.keys(data).forEach(key => {
        const chan = data[key]
        if (chan) {
          store.dispatch(updateChannel(key, chan))
          if ('ring' == chan.mode) {
            new Notification(`Incoming call from ${chan.number}.`)
          }
        } else {
          //
        }
      })
      break
    case 'channelVolumeChange':
      Object.keys(data).forEach(id => {
        store.dispatch(updateChannelVolume(id, data[id]))
      })
      break
    case 'inboxUpdate':
      Object.keys(data).forEach(id => {
        const message = data[id]
        if (message) {
          //
        } else {
          store.dispatch(removeMessage(id))
        }
      })
      break
    case 'event_error':
    case 'input_error':
      console.log(`error: ${eventType}`)
      break
    default:
      console.error(`Unknown event type: ${eventType}.`)
      break
  }
}

@@ -136,16 +136,45 @@
 lVolume,
+ updateAppStatus, addMessage,
  removeM
@@ -454,16 +454,90 @@
 (data))%0A
+//      store.dispatch(updateAppStatus('APP_STATUS_INITIALIZED')) // temp%0A
       br
@@ -1159,34 +1159,71 @@
 ge) %7B%0A          
-//
+store.dispatch(addMessage(id, message))
 %0A        %7D else 

fix addMessage dispatch