Skip to content

Commit 5a2daf1

Browse files
committed
Clean up style of if statements and for loops.
1 parent f8edacb commit 5a2daf1

File tree

3 files changed

+55
-33
lines changed

3 files changed

+55
-33
lines changed

main.js

+18-14
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@ slack.init(function(data, ws) {
6767

6868
data = JSON.parse(data);
6969
users = [];
70-
for(var i = 0; i < data.members.length; i++) {
70+
for (var i = 0; i < data.members.length; i++) {
7171
user = data.members[i];
72-
if(!user.deleted && user.id != currentUser.id) users.push(user);
72+
if (!user.deleted && user.id != currentUser.id) {
73+
users.push(user);
74+
}
7375
}
7476

7577
components.userList.setItems(
@@ -94,9 +96,11 @@ slack.getChannels(function(error, response, data){
9496

9597
data = JSON.parse(data);
9698
channels = [];
97-
for(var i = 0; i < data.channels.length; i++) {
99+
for (var i = 0; i < data.channels.length; i++) {
98100
var channel = data.channels[i];
99-
if(!channel.is_archived) channels.push(channel);
101+
if (!channel.is_archived) {
102+
channels.push(channel);
103+
}
100104
}
101105
components.channelList.setItems(
102106
channels.map(function(channel) {
@@ -120,15 +124,16 @@ var updateMessages = function(data, markFn) {
120124
username;
121125

122126
// get the author
123-
if(message.user === currentUser.id)
127+
if (message.user === currentUser.id) {
124128
username = currentUser.name;
125-
else
126-
for(var i=0; i < len; i++) {
129+
} else {
130+
for (var i=0; i < len; i++) {
127131
if (message.user === users[i].id) {
128132
username = users[i].name;
129133
break;
130134
}
131135
}
136+
}
132137

133138
return {text: message.text, username: username};
134139
})
@@ -161,9 +166,9 @@ components.userList.on('select', function(data) {
161166

162167
// get user's id
163168
var userId = '';
164-
for(var i = 0; i < users.length; i++) {
169+
for (var i = 0; i < users.length; i++) {
165170
user = users[i];
166-
if(user.name === userName) {
171+
if (user.name === userName) {
167172
userId = user.id;
168173
break;
169174
}
@@ -207,16 +212,15 @@ function handleSentConfirmation(message) {
207212
var lines = components.chatWindow.getLines(),
208213
keys = Object.keys(lines),
209214
line, i;
210-
for(i=keys.length - 1; i >= 0; i--){
215+
for (i=keys.length - 1; i >= 0; i--) {
211216
line = lines[keys[i]].split('(pending - ');
212217
if (parseInt(line.pop()[0]) === message.reply_to) {
213218

214219
components.chatWindow.deleteLine(parseInt(keys[i]));
215220

216221
if (message.ok) {
217222
components.chatWindow.insertLine(i, line.join(''));
218-
}
219-
else {
223+
} else {
220224
components.chatWindow.insertLine(i, line.join('') + ' (FAILED)');
221225
}
222226
break;
@@ -227,15 +231,15 @@ function handleSentConfirmation(message) {
227231
}
228232

229233
function handleNewMessage(message) {
230-
if(message.channel !== currentChannelId) {
234+
if (message.channel !== currentChannelId) {
231235
return;
232236
}
233237

234238
var len = users.length,
235239
username;
236240

237241
// get the author
238-
for(var i=0; i < len; i++) {
242+
for (var i=0; i < len; i++) {
239243
if (message.user === users[i].id) {
240244
username = users[i].name;
241245
}

slackClient.js

+29-11
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ function slackRequest(endpoint, query, callback) {
3333
process.exit(1);
3434
}
3535

36-
if (callback) callback.apply(this, arguments);
36+
if (callback) {
37+
callback.apply(this, arguments);
38+
}
3739
});
3840
}
3941

@@ -47,56 +49,72 @@ module.exports = {
4749
},
4850
getChannels: function(callback) {
4951
slackRequest('channels.list', {}, function(error, response, data) {
50-
if(callback) callback.apply(this, arguments);
52+
if (callback) {
53+
callback.apply(this, arguments);
54+
}
5155
});
5256
},
5357
joinChannel: function(name, callback) {
5458
slackRequest('channels.join', {
5559
name: name
5660
}, function(error, response, data) {
57-
if(callback) callback.apply(this, arguments);
61+
if (callback) {
62+
callback.apply(this, arguments);
63+
}
5864
});
5965
},
6066
getChannelHistory: function(id, callback) {
6167
slackRequest('channels.history', {
6268
channel: id
6369
}, function(error, response, data) {
64-
if(callback) callback.apply(this, arguments);
70+
if (callback) {
71+
callback.apply(this, arguments);
72+
}
6573
});
6674
},
6775
markChannel: function(id, timestamp, callback) {
6876
slackRequest('channels.mark', {
69-
channel: id,
77+
channel: id,
7078
ts: timestamp
7179
}, function(error, response, data) {
72-
if(callback) callback.apply(this, arguments);
80+
if (callback) {
81+
callback.apply(this, arguments);
82+
}
7383
});
7484
},
7585
getUsers: function(callback) {
7686
slackRequest('users.list', {}, function(error, response, data) {
77-
if(callback) callback.apply(this, arguments);
87+
if (callback) {
88+
callback.apply(this, arguments);
89+
}
7890
});
7991
},
8092
openIm: function(id, callback) {
8193
slackRequest('im.open', {
8294
user: id
8395
}, function(error, response, data) {
84-
if(callback) callback.apply(this, arguments);
96+
if (callback) {
97+
callback.apply(this, arguments);
98+
}
8599
});
86100
},
87101
getImHistory: function(id, callback) {
88102
slackRequest('im.history', {
89103
channel: id
90104
}, function(error, response, data) {
91-
if(callback) callback.apply(this, arguments);
105+
if (callback) {
106+
callback.apply(this, arguments);
107+
}
92108
});
93109
},
94110
markIm: function(id, timestamp, callback) {
95111
slackRequest('im.mark', {
96-
channel: id,
112+
channel: id,
97113
ts: timestamp
98114
}, function(error, response, data) {
99-
if(callback) callback.apply(this, arguments);
115+
if (callback) {
116+
callback.apply(this, arguments);
117+
}
100118
});
101119
},
102120
};

userInterface.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,14 @@ module.exports = {
178178
channelList.on('keypress', keyBindings);
179179
chatWindow.on('keypress', keyBindings);
180180
messageInput.on('keypress', function(ch, key){
181-
if ( key.full === 'escape' ||
182-
key.full === 'C-u' ||
183-
key.full === 'C-c' ||
184-
key.full === 'C-w' ||
185-
key.full === 'C-l' ) {
186-
messageInput.cancel();
187-
keyBindings(ch, key);
188-
}
181+
if (key.full === 'escape' ||
182+
key.full === 'C-u' ||
183+
key.full === 'C-c' ||
184+
key.full === 'C-w' ||
185+
key.full === 'C-l') {
186+
messageInput.cancel();
187+
keyBindings(ch, key);
188+
}
189189
});
190190

191191
// scrolling in chat window

0 commit comments

Comments
 (0)