mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 01:47:22 +08:00
FIX: mbox import should respect date order after grouping
This commit is contained in:
parent
4b332513b4
commit
ebb16bfafc
|
@ -46,17 +46,21 @@ class ImportScripts::Mbox < ImportScripts::Base
|
||||||
msg_id = mail['Message-ID'].to_s
|
msg_id = mail['Message-ID'].to_s
|
||||||
reply_to = mail['In-Reply-To'].to_s
|
reply_to = mail['In-Reply-To'].to_s
|
||||||
title = clean_title(mail['Subject'].to_s)
|
title = clean_title(mail['Subject'].to_s)
|
||||||
|
date = Time.parse(mail['date'].to_s).to_i
|
||||||
|
|
||||||
if reply_to.present?
|
if reply_to.present?
|
||||||
topic = topic_lookup[reply_to] || reply_to
|
topic = topic_lookup[reply_to] || reply_to
|
||||||
topic_lookup[msg_id] = topic
|
topic_lookup[msg_id] = topic
|
||||||
replies << {id: msg_id, topic: topic, file: filename, title: title}
|
replies << {id: msg_id, topic: topic, file: filename, title: title, date: date}
|
||||||
else
|
else
|
||||||
topics << {id: msg_id, file: filename, title: title}
|
topics << {id: msg_id, file: filename, title: title, date: date}
|
||||||
topic_titles[title] ||= msg_id
|
topic_titles[title] ||= msg_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
replies.sort! {|a, b| a[:date] <=> b[:date]}
|
||||||
|
topics.sort! {|a, b| a[:date] <=> b[:date]}
|
||||||
|
|
||||||
# Replies without parents should be hoisted to topics
|
# Replies without parents should be hoisted to topics
|
||||||
to_hoist = []
|
to_hoist = []
|
||||||
replies.each do |r|
|
replies.each do |r|
|
||||||
|
@ -65,7 +69,7 @@ class ImportScripts::Mbox < ImportScripts::Base
|
||||||
|
|
||||||
to_hoist.each do |h|
|
to_hoist.each do |h|
|
||||||
replies.delete(h)
|
replies.delete(h)
|
||||||
topics << {id: h[:id], file: h[:file], title: h[:title]}
|
topics << {id: h[:id], file: h[:file], title: h[:title], date: h[:date]}
|
||||||
topic_titles[h[:title]] ||= h[:id]
|
topic_titles[h[:title]] ||= h[:id]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -78,9 +82,13 @@ class ImportScripts::Mbox < ImportScripts::Base
|
||||||
|
|
||||||
to_group.each do |t|
|
to_group.each do |t|
|
||||||
topics.delete(t)
|
topics.delete(t)
|
||||||
replies << {id: t[:id], topic: topic_titles[t[:title]], file: t[:file], title: t[:title]}
|
replies << {id: t[:id], topic: topic_titles[t[:title]], file: t[:file], title: t[:title], date: t[:date]}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
replies.sort! {|a, b| a[:date] <=> b[:date]}
|
||||||
|
topics.sort! {|a, b| a[:date] <=> b[:date]}
|
||||||
|
|
||||||
|
|
||||||
File.write(USER_INDEX_PATH, {users: users}.to_json)
|
File.write(USER_INDEX_PATH, {users: users}.to_json)
|
||||||
File.write(TOPIC_INDEX_PATH, {topics: topics}.to_json)
|
File.write(TOPIC_INDEX_PATH, {topics: topics}.to_json)
|
||||||
File.write(REPLY_INDEX_PATH, {replies: replies}.to_json)
|
File.write(REPLY_INDEX_PATH, {replies: replies}.to_json)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user