Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class JabberProtocol() extends Actor with ActorLogging {
var privateHandler: ActorRef = null
var rooms = Map[String, RoomDefinition]()

private val rejoinInterval = 5.seconds

override def preStart() {
privateHandler = context.actorOf(
Props(new PrivateMessageHandler(Configuration.defaultLocalization, self)), "privateHandler")
Expand All @@ -52,26 +54,34 @@ class JabberProtocol() extends Actor with ActorLogging {
case Reconnect(otherConnection) =>
log.info(s"Ignored reconnect request from connection $otherConnection")

case JoinRoom(jid, locale, nickname, greeting) =>
case message@JoinRoom(jid, locale, nickname, greeting) =>
log.info(s"Joining room $jid")
val actor = context.actorOf(
Props(new MucMessageHandler(locale, self, jid, nickname)), jid)

val muc = new MultiUserChat(connection, jid)
rooms = rooms.updated(jid, RoomDefinition(muc, actor))

muc.addMessageListener(new MucMessageListener(jid, actor, log))
muc.addParticipantStatusListener(new MucParticipantStatusListener(muc, actor))

val filter = new AndFilter(new PacketTypeFilter(classOf[Message]), new FromContainsFilter(jid))
connection.addPacketListener(
new MessageAutoRepeater(context.system, self, context.system.scheduler, jid, context.dispatcher),
filter)

muc.join(nickname)
greeting match {
case Some(message) => muc.sendMessage(message)
case None =>
try {
// TODO: Move this code to the room actor and use "let it fall" strategy ~ F
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For such todos I always recommend to create an issue with the refactor tag or something. :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have already created it: #358.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks! :)

val muc = new MultiUserChat(connection, jid)
rooms = rooms.updated(jid, RoomDefinition(muc, actor))

muc.addMessageListener(new MucMessageListener(jid, actor, log))
muc.addParticipantStatusListener(new MucParticipantStatusListener(muc, actor))

val filter = new AndFilter(new PacketTypeFilter(classOf[Message]), new FromContainsFilter(jid))
connection.addPacketListener(
new MessageAutoRepeater(context.system, self, context.system.scheduler, jid, context.dispatcher),
filter)

muc.join(nickname)
greeting match {
case Some(text) => muc.sendMessage(text)
case None =>
}
} catch {
case t: Throwable =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, I do not like this approach. But I cannot suggest anything better for now.

I'm ok with this if we at least will log the exception somewhere. At least its message. Like "Cannot join because of t.message()" or something.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a nice suggestion about logging. Thank you, I'll implement that.

log.warning(s"Cannot join room $jid, retrying in $rejoinInterval. Error was $t")
context.stop(actor)
context.system.scheduler.scheduleOnce(rejoinInterval, self, message)
}

case ChatOpened(chat) => {
Expand Down