mirror of
https://ghfast.top/https://github.com/discourse/discourse-cakeday.git
synced 2026-07-15 11:36:33 +08:00
The "anniversary" date is called the "cakedate" and the "birthday" date is called the "birthdate". Hence most of the changes on the front-end to account for the name changes. FIX: the anniversary is based on the users.created_at column which is a "timestamp without a timezone" so we need to apply the current_user's timezone to filter and show the date properly. We now always use the current_user's timezone that is stored on the server, rather than using the "timezone offset" sent by the client. FIX: leap years were not accounted for. Understandably as it's quite tricky... FIX: the ordering of the anniversary and birthday controllers now uses only informations that is shown to the user. No more sorting by likes which were not shown in the UI and made the sorting appear random/broken to the user. Now the sort is the date formatted with the american date format (aka "MMDDYYYY") and uses the `username_lower` for tiebreaks. FIX: the 'cakeday-test-disconnected' wasn't working because the filename did not end in '-test.js' and so wasn't picked up by qunit. I renamed it and fixed it. Not entirely sure it's _that_ useful though. Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
33 lines
1 KiB
Ruby
33 lines
1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module DiscourseCakeday
|
|
class AnniversariesController < CakedayController
|
|
before_action :ensure_cakeday_enabled
|
|
|
|
def index
|
|
column_sql = "created_at"
|
|
|
|
# The users.created_at column is a "timestamp without timezone"
|
|
# so we need to convert the "point in time" to the current user's timezone
|
|
# for proper filtering and display (otherwise you might get off by ones
|
|
# if you live in ~~the future~~ Fiji or in ~~the past~~ Hawaii)
|
|
if @timezone.present? && @timezone != "UTC"
|
|
column_sql += " AT TIME ZONE 'UTC' AT TIME ZONE '#{@timezone}'"
|
|
end
|
|
|
|
users, total, more_params = cakedays_by(column_sql, at_least_one_year_old: true)
|
|
|
|
render_json_dump(
|
|
anniversaries: serialize_data(users, CakedayUserSerializer),
|
|
total_rows_anniversaries: total,
|
|
load_more_anniversaries: anniversaries_path(more_params),
|
|
)
|
|
end
|
|
|
|
private
|
|
|
|
def ensure_cakeday_enabled
|
|
raise Discourse::NotFound if !SiteSetting.cakeday_enabled
|
|
end
|
|
end
|
|
end
|