jschat 0.3.1 → 0.3.2
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
CHANGED
@@ -99,6 +99,11 @@ class JsChat::Bridge
|
|
99
99
|
response['messages']
|
100
100
|
end
|
101
101
|
|
102
|
+
def search(phrase, room)
|
103
|
+
response = send_json({ :search => phrase, :room => room })
|
104
|
+
response['messages']
|
105
|
+
end
|
106
|
+
|
102
107
|
def recent_messages(room)
|
103
108
|
send_json({ 'since' => room })['messages']
|
104
109
|
end
|
@@ -333,6 +338,13 @@ get '/lastlog' do
|
|
333
338
|
end
|
334
339
|
end
|
335
340
|
|
341
|
+
get '/search' do
|
342
|
+
load_bridge
|
343
|
+
if @bridge.active?
|
344
|
+
messages_js @bridge.search(params['q'], params['room'])
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
336
348
|
post '/join' do
|
337
349
|
load_bridge
|
338
350
|
@bridge.join params['room']
|
@@ -12,6 +12,7 @@ var UserCommands = {
|
|
12
12
|
help.push(['/join #room_name', 'Joins a room']);
|
13
13
|
help.push(['/part #room_name', 'Leaves a room. Leave room_name blank for the current room']);
|
14
14
|
help.push(['/lastlog', 'Shows recent activity']);
|
15
|
+
help.push(['/search query', 'Searches the logs for this room']);
|
15
16
|
help.push(['/names', 'Refreshes the names list']);
|
16
17
|
help.push(['/name new_name', 'Changes your name']);
|
17
18
|
help.push(['/toggle images', 'Toggles showing of images and videos']);
|
@@ -38,6 +39,17 @@ var UserCommands = {
|
|
38
39
|
}.bind(this));
|
39
40
|
},
|
40
41
|
|
42
|
+
'/search\\s+(.*)': function(query) {
|
43
|
+
query = query[1];
|
44
|
+
this.pausePollers = true;
|
45
|
+
$('messages').innerHTML = '';
|
46
|
+
JsChat.Request.get('/search?q=' + query, function(transport) {
|
47
|
+
Display.add_message('Search results:', 'server');
|
48
|
+
this.displayMessages(transport.responseText);
|
49
|
+
this.pausePollers = false;
|
50
|
+
}.bind(this));
|
51
|
+
},
|
52
|
+
|
41
53
|
'/(name|nick)\\s+(.*)': function(name) {
|
42
54
|
name = name[2];
|
43
55
|
new Ajax.Request('/change-name', {
|
data/lib/jschat/server.rb
CHANGED
@@ -151,6 +151,10 @@ module JsChat
|
|
151
151
|
{ 'display' => 'messages', 'messages' => messages_since(since) }
|
152
152
|
end
|
153
153
|
|
154
|
+
def search(query, limit = 100)
|
155
|
+
{ 'display' => 'messages', 'messages' => message_search(query, limit) }
|
156
|
+
end
|
157
|
+
|
154
158
|
def last_update_time
|
155
159
|
message = JsChat::Storage.driver.lastlog(LASTLOG_DEFAULT, name).last
|
156
160
|
message['time'] if message
|
@@ -165,6 +169,10 @@ module JsChat
|
|
165
169
|
end
|
166
170
|
end
|
167
171
|
|
172
|
+
def message_search(query, limit)
|
173
|
+
JsChat::Storage.driver.search(query, name, limit)
|
174
|
+
end
|
175
|
+
|
168
176
|
def add_to_lastlog(message)
|
169
177
|
if message
|
170
178
|
message['time'] = Time.now.utc
|
@@ -277,6 +285,15 @@ module JsChat
|
|
277
285
|
end
|
278
286
|
end
|
279
287
|
|
288
|
+
def search(query, options = {})
|
289
|
+
room = Room.find options['room']
|
290
|
+
if room and room.users.include? @user
|
291
|
+
room.search query
|
292
|
+
else
|
293
|
+
Error.new(:not_in_room, "Please join this room first")
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
280
297
|
def since(room, options = {})
|
281
298
|
room = Room.find room
|
282
299
|
if room and room.users.include? @user
|
@@ -519,7 +536,7 @@ module JsChat
|
|
519
536
|
input['ip'] ||= get_remote_ip
|
520
537
|
response << send_response(identify(input['identify'], input['ip'], input['session_length']))
|
521
538
|
else
|
522
|
-
%w{lastlog change send join names part since ping list quit times}.each do |command|
|
539
|
+
%w{search lastlog change send join names part since ping list quit times}.each do |command|
|
523
540
|
if @user.name.nil?
|
524
541
|
response << send_response(Error.new(:identity_required, 'Identify first'))
|
525
542
|
return response
|
data/lib/jschat/storage/mongo.rb
CHANGED
@@ -27,6 +27,13 @@ module JsChat::Storage
|
|
27
27
|
@db['events'].find({ :room => room }, { :limit => number, :sort => ['time', Mongo::DESCENDING] }).to_a.reverse
|
28
28
|
end
|
29
29
|
|
30
|
+
def self.search(query, room, limit)
|
31
|
+
query = /\b#{query}\b/i
|
32
|
+
@db['events'].find({ 'message.message' => query },
|
33
|
+
{ :limit => limit, :sort => ['time', Mongo::DESCENDING] }
|
34
|
+
).to_a.reverse
|
35
|
+
end
|
36
|
+
|
30
37
|
# TODO: use twitter oauth for the key
|
31
38
|
def self.find_user(options)
|
32
39
|
@db['users'].find_one(options)
|
data/lib/jschat/storage/null.rb
CHANGED
@@ -14,6 +14,13 @@ module JsChat::Storage
|
|
14
14
|
@messages.select { |m| m['room'] == room }.reverse[0..number].reverse
|
15
15
|
end
|
16
16
|
|
17
|
+
def self.search(query, room, limit)
|
18
|
+
@messages ||= []
|
19
|
+
@messages.select do |m|
|
20
|
+
m['message'] and m['message']['message'].match(query)
|
21
|
+
end.reverse[0..limit].reverse
|
22
|
+
end
|
23
|
+
|
17
24
|
def self.find_user(options)
|
18
25
|
end
|
19
26
|
|