FIX: calendar details incorrectly returned

This commit is contained in:
Joffrey JAFFEUX 2018-06-10 19:04:51 +02:00
parent b9204e629b
commit 412ae21711
2 changed files with 6 additions and 1 deletions

View File

@ -22,7 +22,7 @@ module DiscourseSimpleCalendar
post_number = post.post_number.to_s
current_details = op.custom_fields[DiscourseSimpleCalendar::CALENDAR_DETAILS_CUSTOM_FIELD] ||= {}
current_details = op.custom_fields[DiscourseSimpleCalendar::CALENDAR_DETAILS_CUSTOM_FIELD] || {}
detail = []
detail[DiscourseSimpleCalendar::MESSAGE_INDEX] = post.excerpt(15, strip_links: true, text_entities: true).tr("\n", " ")
@ -30,6 +30,10 @@ module DiscourseSimpleCalendar
detail[DiscourseSimpleCalendar::FROM_INDEX] = from.iso8601.to_s
detail[DiscourseSimpleCalendar::TO_INDEX] = to.iso8601.to_s if to
# investigate why sometimes it has been saved as an array
if current_details.kind_of?(Array)
current_details = current_details[0]
end
current_details[post_number] = detail
op.custom_fields[DiscourseSimpleCalendar::CALENDAR_DETAILS_CUSTOM_FIELD] = current_details

View File

@ -122,6 +122,7 @@ after_initialize do
attributes :calendar_details
def calendar_details
return nil unless object.is_first_post?
details = post_custom_fields[DiscourseSimpleCalendar::CALENDAR_DETAILS_CUSTOM_FIELD]
Array(details).map do |post_number, detail|