jschat 0.2.9 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/jschat/http/jschat.rb +18 -4
- data/lib/jschat/http/public/javascripts/app/controllers/chat_controller.js +1 -1
- data/lib/jschat/http/public/javascripts/app/controllers/signon_controller.js +1 -1
- data/lib/jschat/http/public/javascripts/app/helpers/page_helper.js +1 -1
- data/lib/jschat/http/public/javascripts/app/helpers/text_helper.js +3 -3
- data/lib/jschat/http/public/javascripts/app/models/user.js +15 -0
- data/lib/jschat/http/public/javascripts/app/protocol/display.js +1 -2
- data/lib/jschat/http/public/javascripts/app/ui/commands.js +8 -4
- data/lib/jschat/http/public/javascripts/init.js +4 -2
- metadata +4 -3
data/lib/jschat/http/jschat.rb
CHANGED
|
@@ -189,8 +189,12 @@ helpers do
|
|
|
189
189
|
session[:jschat_id] = @bridge.cookie
|
|
190
190
|
end
|
|
191
191
|
|
|
192
|
+
def cookie_expiration
|
|
193
|
+
Time.now.utc + 94608000
|
|
194
|
+
end
|
|
195
|
+
|
|
192
196
|
def save_last_room(room)
|
|
193
|
-
response.set_cookie 'last-room', room
|
|
197
|
+
response.set_cookie 'last-room', { :value => room, :path => '/', :expires => cookie_expiration }
|
|
194
198
|
end
|
|
195
199
|
|
|
196
200
|
def last_room
|
|
@@ -198,7 +202,7 @@ helpers do
|
|
|
198
202
|
end
|
|
199
203
|
|
|
200
204
|
def save_nickname(name)
|
|
201
|
-
response.set_cookie 'jschat-name', name
|
|
205
|
+
response.set_cookie 'jschat-name', { :value => name, :path => '/', :expires => cookie_expiration }
|
|
202
206
|
end
|
|
203
207
|
|
|
204
208
|
def messages_js(messages)
|
|
@@ -212,7 +216,7 @@ helpers do
|
|
|
212
216
|
end
|
|
213
217
|
|
|
214
218
|
def clear_cookies
|
|
215
|
-
response.set_cookie 'last-room', nil
|
|
219
|
+
response.set_cookie 'last-room', { :value => nil, :path => '/' }
|
|
216
220
|
session[:jschat_id] = nil
|
|
217
221
|
session[:request_token] = nil
|
|
218
222
|
session[:request_token_secret] = nil
|
|
@@ -287,7 +291,12 @@ end
|
|
|
287
291
|
|
|
288
292
|
post '/change-name' do
|
|
289
293
|
load_bridge
|
|
290
|
-
|
|
294
|
+
result = @bridge.change('user', { 'name' => params['name'] })
|
|
295
|
+
if result['notice']
|
|
296
|
+
save_twitter_user({ 'name' => params['name'] }) if twitter_user?
|
|
297
|
+
save_nickname params['name']
|
|
298
|
+
end
|
|
299
|
+
[result].to_json
|
|
291
300
|
end
|
|
292
301
|
|
|
293
302
|
get '/messages' do
|
|
@@ -414,6 +423,11 @@ get '/twitter_auth' do
|
|
|
414
423
|
# TODO: Make this cope if someone has the same name
|
|
415
424
|
room = '#jschat'
|
|
416
425
|
user = load_twitter_user
|
|
426
|
+
|
|
427
|
+
if user['name'] and nickname != user['name']
|
|
428
|
+
@bridge.change('user', { 'name' => user['name'] })
|
|
429
|
+
end
|
|
430
|
+
|
|
417
431
|
save_nickname user['name']
|
|
418
432
|
session[:jschat_id] = user['jschat_id'] if user['jschat_id'] and !user['jschat_id'].empty?
|
|
419
433
|
save_twitter_user('twitter_name' => @twitter.info['screen_name'], 'jschat_id' => session[:jschat_id])
|
|
@@ -113,7 +113,7 @@ JsChat.ChatController = Class.create({
|
|
|
113
113
|
if (message.match(/^\//)) {
|
|
114
114
|
Display.add_message('Error: Command not found. Use /help display commands.', 'error');
|
|
115
115
|
} else {
|
|
116
|
-
Display.message({ 'message': message.escapeHTML(), 'user':
|
|
116
|
+
Display.message({ 'message': message.escapeHTML(), 'user': JsChat.user.name }, new Date());
|
|
117
117
|
new Ajax.Request('/message', {
|
|
118
118
|
method: 'post',
|
|
119
119
|
parameters: { 'message': message, 'to': PageHelper.currentRoom() }
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
JsChat.SignOnController = Class.create({
|
|
2
2
|
initialize: function() {
|
|
3
3
|
this.retries = 0;
|
|
4
|
-
setTimeout(function() { $('name').activate() }, 500);
|
|
4
|
+
setTimeout(function() { $('name').activate(); }, 500);
|
|
5
5
|
$('sign-on').observe('submit', this.submitEvent.bindAsEventListener(this));
|
|
6
6
|
},
|
|
7
7
|
|
|
@@ -72,11 +72,11 @@ var TextHelper = {
|
|
|
72
72
|
if (link.match(/href="/)) {
|
|
73
73
|
result += link;
|
|
74
74
|
} else {
|
|
75
|
-
if (LinkHelper.youtube_url(link)) {
|
|
75
|
+
if (LinkHelper.youtube_url(link) && !JsChat.user.hideImages) {
|
|
76
76
|
result += link.replace(link, LinkHelper.youtube(link));
|
|
77
|
-
} else if (LinkHelper.vimeo_url(link)) {
|
|
77
|
+
} else if (LinkHelper.vimeo_url(link) && !JsChat.user.hideImages) {
|
|
78
78
|
result += link.replace(link, LinkHelper.vimeo(link));
|
|
79
|
-
} else if (LinkHelper.image_url(link)) {
|
|
79
|
+
} else if (LinkHelper.image_url(link) && !JsChat.user.hideImages) {
|
|
80
80
|
result += link.replace(link, LinkHelper.image(link));
|
|
81
81
|
} else if (LinkHelper.url(link)) {
|
|
82
82
|
result += link.replace(link, LinkHelper.link(link));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
User = function() {
|
|
2
|
+
this.name = Cookie.find('jschat-name');
|
|
3
|
+
this.hideImages = Cookie.find('jschat-hideImages') === '1' ? true : false;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
User.prototype.setName = function(name) {
|
|
7
|
+
Cookie.create('jschat-name', name, 28, '/');
|
|
8
|
+
this.name = name;
|
|
9
|
+
$('name').innerHTML = name;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
User.prototype.setHideImages = function(hideImages) {
|
|
13
|
+
this.hideImages = hideImages;
|
|
14
|
+
Cookie.create('jschat-hideImages', (hideImages ? '1' : '0'), 28, '/');
|
|
15
|
+
};
|
|
@@ -14,7 +14,7 @@ var Display = {
|
|
|
14
14
|
},
|
|
15
15
|
|
|
16
16
|
message: function(message, time) {
|
|
17
|
-
var name =
|
|
17
|
+
var name = JsChat.user.name;
|
|
18
18
|
var user_class = name == message['user'] ? 'user active' : 'user';
|
|
19
19
|
var text = '<span class="\#{user_class}">\#{user}</span> <span class="\#{message_class}">\#{message}</span>';
|
|
20
20
|
|
|
@@ -60,7 +60,6 @@ var Display = {
|
|
|
60
60
|
this.scrollMessagesToTop();
|
|
61
61
|
/* This is assumed to be the point at which displaying /lastlog completes */
|
|
62
62
|
$('loading').hide();
|
|
63
|
-
Cookie.create('jschat-name', $('name').innerHTML, 28, '/');
|
|
64
63
|
},
|
|
65
64
|
|
|
66
65
|
scrollMessagesToTop: function() {
|
|
@@ -14,6 +14,7 @@ var UserCommands = {
|
|
|
14
14
|
help.push(['/lastlog', 'Shows recent activity']);
|
|
15
15
|
help.push(['/names', 'Refreshes the names list']);
|
|
16
16
|
help.push(['/name new_name', 'Changes your name']);
|
|
17
|
+
help.push(['/toggle images', 'Toggles showing of images and videos']);
|
|
17
18
|
help.push(['/quit', 'Quit']);
|
|
18
19
|
help.push(['/emotes', 'Shows available emotes']);
|
|
19
20
|
$A(help).each(function(options) {
|
|
@@ -43,10 +44,8 @@ var UserCommands = {
|
|
|
43
44
|
method: 'post',
|
|
44
45
|
parameters: { name: name },
|
|
45
46
|
onSuccess: function(response) {
|
|
46
|
-
this.displayMessages(response.responseText
|
|
47
|
-
|
|
48
|
-
Cookie.create('jschat-name', name, 28, '/');
|
|
49
|
-
});
|
|
47
|
+
this.displayMessages(response.responseText);
|
|
48
|
+
JsChat.user.setName(name);
|
|
50
49
|
}.bind(this),
|
|
51
50
|
onFailure: function() {
|
|
52
51
|
Display.add_message("Server error: couldn't access: #{url}".interpolate({ url: url }), 'server');
|
|
@@ -58,6 +57,11 @@ var UserCommands = {
|
|
|
58
57
|
JsChat.Request.get('/names', function(t) { this.displayMessages(t.responseText); }.bind(this));
|
|
59
58
|
},
|
|
60
59
|
|
|
60
|
+
'/toggle images': function() {
|
|
61
|
+
JsChat.user.setHideImages(!JsChat.user.hideImages);
|
|
62
|
+
Display.add_message("Hide images set to #{hide}".interpolate({ hide: JsChat.user.hideImages }), 'server');
|
|
63
|
+
},
|
|
64
|
+
|
|
61
65
|
'/(join)\\s+(.*)': function() {
|
|
62
66
|
var room = arguments[0][2];
|
|
63
67
|
this.validateAndJoinRoom(room);
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
var JsChat = {};
|
|
2
2
|
|
|
3
3
|
document.observe('dom:loaded', function() {
|
|
4
|
+
JsChat.user = new User();
|
|
5
|
+
|
|
4
6
|
if ($('post_message')) {
|
|
5
7
|
var chatController = new JsChat.ChatController();
|
|
6
8
|
}
|
|
7
9
|
|
|
8
10
|
if ($('sign-on')) {
|
|
9
|
-
if (
|
|
10
|
-
$('name').value =
|
|
11
|
+
if (JsChat.user.name) {
|
|
12
|
+
$('name').value = JsChat.user.name;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
if ($('room') && window.location.hash) {
|
metadata
CHANGED
|
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
|
4
4
|
prerelease: false
|
|
5
5
|
segments:
|
|
6
6
|
- 0
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
version: 0.
|
|
7
|
+
- 3
|
|
8
|
+
- 0
|
|
9
|
+
version: 0.3.0
|
|
10
10
|
platform: ruby
|
|
11
11
|
authors:
|
|
12
12
|
- Alex R. Young
|
|
@@ -170,6 +170,7 @@ files:
|
|
|
170
170
|
- lib/jschat/http/public/javascripts/app/helpers/text_helper.js
|
|
171
171
|
- lib/jschat/http/public/javascripts/app/lib/split.js
|
|
172
172
|
- lib/jschat/http/public/javascripts/app/models/cookie.js
|
|
173
|
+
- lib/jschat/http/public/javascripts/app/models/user.js
|
|
173
174
|
- lib/jschat/http/public/javascripts/app/protocol/change.js
|
|
174
175
|
- lib/jschat/http/public/javascripts/app/protocol/chat_request.js
|
|
175
176
|
- lib/jschat/http/public/javascripts/app/protocol/display.js
|