Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/assets/javascripts/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ $(() => {
ev.preventDefault();
const $inbox = $('.inbox');
if($inbox.hasClass("is-active")) {
const resp = await QPixel.getJSON(`/users/me/notifications`);
const data = await QPixel.getNotifications();

const data = await resp.json();
const $inboxContainer = $inbox.find(".inbox--container");
$inboxContainer.html('');

Expand Down
10 changes: 10 additions & 0 deletions app/assets/javascripts/qpixel_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,16 @@ window.QPixel = {
return data;
},

getNotifications: async () => {
const resp = await QPixel.getJSON(`/users/me/notifications`, {
headers: { 'Cache-Control': 'no-cache' }
});

const data = await resp.json();

return data;
},

getThreadContent: async (id, options) => {
const inline = options?.inline ?? true;
const showDeleted = options?.showDeleted ?? false;
Expand Down
11 changes: 6 additions & 5 deletions app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,12 @@ def thread
end

def thread_content
fresh_when last_modified: @comment_thread.last_activity_at.utc, etag: @comment_thread

render partial: 'comment_threads/expanded', locals: { inline: params[:inline] == 'true',
show_deleted: params[:show_deleted_comments] == '1',
thread: @comment_thread }
if stale?(last_modified: @comment_thread.last_activity_at.utc)
render partial: 'comment_threads/expanded',
locals: { inline: params[:inline] == 'true',
show_deleted: params[:show_deleted_comments] == '1',
thread: @comment_thread }
end
end

def thread_followers
Expand Down
17 changes: 10 additions & 7 deletions app/controllers/notifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ class NotificationsController < ApplicationController
def index
@notifications = Notification.unscoped.where(user: current_user).paginate(page: params[:page], per_page: 100)
.order(Arel.sql('is_read ASC, created_at DESC'))
respond_to do |format|
format.html { render :index, layout: 'without_sidebar' }
format.json do
render json: (@notifications.to_a.map do |notif|
notif.as_json.merge(content: helpers.render_pings_text(notif.content),
community_name: notif.community_name)
end)

if stale?(@notifications)
respond_to do |format|
format.html { render :index, layout: 'without_sidebar' }
format.json do
render json: (@notifications.to_a.map do |notif|
notif.as_json.merge(content: helpers.render_pings_text(notif.content),
community_name: notif.community_name)
end)
end
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
config.eager_load = false

# Show full error reports and disable caching.
perform_caching = ActiveRecord::Type::Boolean.new.cast(ENV['PERFORM_CACHING'])
config.consider_all_requests_local = true
config.action_controller.perform_caching = ActiveRecord::Type::Boolean.new.cast(ENV['PERFORM_CACHING']) || false
config.action_controller.perform_caching = perform_caching || false
Rack::MiniProfiler.config.disable_caching = !perform_caching

# Enable server timing
config.server_timing = true
Expand Down
7 changes: 6 additions & 1 deletion global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,16 @@ interface QPixel {
getJSON?: (uri: string, options?: Omit<RequestInit, 'method'>) => Promise<Response>;

/**
* Attempts get a JSON reprentation of a comment
* Attempts to get a JSON reprentation of a comment
* @param id id of the comment to get
*/
getComment?: (id: string) => Promise<QPixelComment>

/**
* Attempts to get a list of notifications for the current user
*/
getNotifications?: () => Promise<QPixelNotification[]>

/**
* Attempts to dynamically load thread content
* @param id id of the comment thread
Expand Down