diff options
author | Andrew Comminos <andrewcomminos@gmail.com> | 2014-01-27 10:07:29 +0400 |
---|---|---|
committer | Andrew Comminos <andrewcomminos@gmail.com> | 2014-01-27 10:07:29 +0400 |
commit | 0833aa5a494216b652d2e7db911246df91e9ab98 (patch) | |
tree | 2c7286fb3be3d52783381751ffeb9616defef825 /src/main | |
parent | a73987c532874a9f235ec5d95216cb78fa426d0f (diff) |
Create a stub root channel if there is none when a UserState message is
sent.
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/morlunk/jumble/protocol/ChannelHandler.java | 12 | ||||
-rw-r--r-- | src/main/java/com/morlunk/jumble/protocol/UserHandler.java | 1 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/main/java/com/morlunk/jumble/protocol/ChannelHandler.java b/src/main/java/com/morlunk/jumble/protocol/ChannelHandler.java index d88ffb5..1f5ae3b 100644 --- a/src/main/java/com/morlunk/jumble/protocol/ChannelHandler.java +++ b/src/main/java/com/morlunk/jumble/protocol/ChannelHandler.java @@ -56,6 +56,18 @@ public class ChannelHandler extends ProtocolHandler { return mChannels.get(id); } + /** + * Creates a stub channel with the given ID. + * Useful for keeping user references when we get a UserState message before a ChannelState. + * @param id The channel ID. + * @return The newly created stub channel. + */ + public Channel createStubChannel(int id) { + Channel channel = new Channel(id, false); + mChannels.put(id, channel); + return channel; + } + public List<Channel> getChannels() { return new ArrayList<Channel>(mChannels.values()); } diff --git a/src/main/java/com/morlunk/jumble/protocol/UserHandler.java b/src/main/java/com/morlunk/jumble/protocol/UserHandler.java index f48d608..3b76b31 100644 --- a/src/main/java/com/morlunk/jumble/protocol/UserHandler.java +++ b/src/main/java/com/morlunk/jumble/protocol/UserHandler.java @@ -91,6 +91,7 @@ public class UserHandler extends ProtocolHandler { newUser = true; // Add user to root channel by default. This works because for some reason, we don't get a channel ID when the user joins into root. Channel root = getService().getChannelHandler().getChannel(0); + if(root == null) root = getService().getChannelHandler().createStubChannel(0); user.setChannelId(0); root.addUser(user.getSession()); root.setSubchannelUserCount(root.getSubchannelUserCount()+1); |