From b743511d1d44a56bd2edd9f234040bb339a3de6d Mon Sep 17 00:00:00 2001 From: Jeffrey Linwood Date: Mon, 6 Mar 2017 09:12:08 -0600 Subject: [PATCH] Updated Chat SDK version and the way channels are created if not found --- static/chat/index.html | 2 +- static/chat/index.js | 30 ++++++++++++++---------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/static/chat/index.html b/static/chat/index.html index c5d76a0..6ae4569 100755 --- a/static/chat/index.html +++ b/static/chat/index.html @@ -19,7 +19,7 @@ - + diff --git a/static/chat/index.js b/static/chat/index.js index 6cea9bd..5eb7d69 100755 --- a/static/chat/index.js +++ b/static/chat/index.js @@ -63,23 +63,21 @@ $(function() { var promise = chatClient.getChannelByUniqueName('general'); promise.then(function(channel) { generalChannel = channel; - if (!generalChannel) { - // If it doesn't exist, let's create it - console.log('Creating general channel'); - chatClient.createChannel({ - uniqueName: 'general', - friendlyName: 'General Chat Channel' - }).then(function(channel) { - console.log('Created general channel:'); - console.log(channel); - generalChannel = channel; - setupChannel(); - }); - } else { - console.log('Found general channel:'); - console.log(generalChannel); + console.log('Found general channel:'); + console.log(generalChannel); + setupChannel(); + }).catch(function() { + // If it doesn't exist, let's create it + console.log('Creating general channel'); + chatClient.createChannel({ + uniqueName: 'general', + friendlyName: 'General Chat Channel' + }).then(function(channel) { + console.log('Created general channel:'); + console.log(channel); + generalChannel = channel; setupChannel(); - } + }); }); }