Added timestamp sort of spool messages.
This commit is contained in:
parent
ceff0d4aba
commit
12acacfc47
1 changed files with 11 additions and 5 deletions
|
@ -61,9 +61,15 @@ module Session
|
||||||
FileUtils.mkpath path
|
FileUtils.mkpath path
|
||||||
data = []
|
data = []
|
||||||
to_delete = []
|
to_delete = []
|
||||||
Dir.foreach( path ) do |entry|
|
files = []
|
||||||
|
Dir.foreach( path ) {|entry|
|
||||||
next if entry == '.' || entry == '..'
|
next if entry == '.' || entry == '..'
|
||||||
File.open( path + '/' + entry, 'rb' ) { |file|
|
files.push entry
|
||||||
|
}
|
||||||
|
files.sort.each {|entry|
|
||||||
|
filename = path + '/' + entry
|
||||||
|
next if !File::exists?( filename )
|
||||||
|
File.open( filename, 'rb' ) { |file|
|
||||||
all = file.read
|
all = file.read
|
||||||
spool = JSON.parse( all )
|
spool = JSON.parse( all )
|
||||||
begin
|
begin
|
||||||
|
@ -86,8 +92,8 @@ module Session
|
||||||
if !timestamp || timestamp < spool['timestamp']
|
if !timestamp || timestamp < spool['timestamp']
|
||||||
|
|
||||||
# spool to recipient list
|
# spool to recipient list
|
||||||
if message_parsed['data']['recipient'] && message_parsed['data']['recipient']['user_id']
|
if message_parsed['data'] && message_parsed['data']['data'] && message_parsed['data']['data']['recipient'] && message_parsed['data']['data']['recipient']['user_id']
|
||||||
message_parsed['data']['recipient']['user_id'].each { |user_id|
|
message_parsed['data']['data']['recipient']['user_id'].each { |user_id|
|
||||||
if current_user_id == user_id
|
if current_user_id == user_id
|
||||||
item = {
|
item = {
|
||||||
:type => 'direct',
|
:type => 'direct',
|
||||||
|
@ -109,7 +115,7 @@ module Session
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
}
|
||||||
to_delete.each {|file|
|
to_delete.each {|file|
|
||||||
File.delete(file)
|
File.delete(file)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue