package ccf.session

import ccf.transport.{Request, Response}

trait Message {
  def send(s: Session): (Session, Option[Response])
  protected def sendRequest(request: Session => Request, session: Session): Option[Response] = session.connection.send(request(session))
}

case class Join(channelId: ChannelId) extends Message {
  def send(s: Session): (Session, Option[Response]) = if (!s.channels(channelId)) {
    (s.next(s.channels + channelId), sendRequest(JoinRequest(channelId), s))
  } else { (s, None) }
}
case class Part(channelId: ChannelId) extends Message {
  def send(s: Session): (Session, Option[Response]) = if (s.channels(channelId)) {
    (s.next(s.channels - channelId), sendRequest(PartRequest(channelId), s))
  } else { (s, None) }
}

package ccf.session

import ccf.transport.{Request, Response}

case object Shutdown

trait Message {
  def send(s: Session): (Session, Option[Response])
  protected def sendRequest(request: Session => Request, session: Session): Option[Response] = session.connection.send(request(session))
}

case class Join(channelId: ChannelId) extends Message {
  def send(s: Session): (Session, Option[Response]) = if (!s.channels(channelId)) {
    (s.next(s.channels + channelId), sendRequest(JoinRequest(channelId), s))
  } else { (s, None) }
}
case class Part(channelId: ChannelId) extends Message {
  def send(s: Session): (Session, Option[Response]) = if (s.channels(channelId)) {
    (s.next(s.channels - channelId), sendRequest(PartRequest(channelId), s))
  } else { (s, None) }
}

Add Shutdown for requesting an actor to shutdown
session: Add Shutdown for requesting an actor to shutdown

Signed-off-by: Karim Osman <94396faf6cc817be76165477038b3cfa832e89a4@reaktor.fi>
Acked-by: Harri Salokorpi <eefb23b8deb8c30dca252cd0ae751b67337dc69f@reaktor.fi>
