Skip to content

Commit dbe8e27

Browse files
authored
Merge pull request #1747 from codidact/0valt/815/comment-notification-pings
Properly render comment pings in notifications
2 parents ade1b9f + 80842a0 commit dbe8e27

4 files changed

Lines changed: 23 additions & 2 deletions

File tree

app/assets/javascripts/notifications.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
$(() => {
2+
/**
3+
* @param {QPixelNotification} notification
4+
*/
25
const makeNotification = (notification) => {
36
const template = `<div class="js-notification widget h-m-0 h-m-b-2 ${notification.is_read ? 'read' : 'is-teal'}">
47
<div class="widget--body h-p-2">

app/controllers/notifications_controller.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
# Provides web and API actions relating to user notifications.
22
class NotificationsController < ApplicationController
3+
include CommentsHelper
4+
35
before_action :authenticate_user!, only: [:index]
46

57
def index
68
@notifications = Notification.unscoped.where(user: current_user).paginate(page: params[:page], per_page: 100)
79
.order(Arel.sql('is_read ASC, created_at DESC'))
810
respond_to do |format|
911
format.html { render :index, layout: 'without_sidebar' }
10-
format.json { render json: @notifications, methods: :community_name }
12+
format.json do
13+
render json: (@notifications.to_a.map do |notif|
14+
notif.as_json.merge(content: helpers.render_pings_text(notif.content))
15+
end), methods: :community_name
16+
end
1117
end
1218
end
1319

app/views/notifications/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<% @notifications.each do |notif| %>
77
<div class="notification">
88
<div class="form-caption"><%= CGI.unescape_html(notif.created_at.strftime('%b&nbsp;%-d,&nbsp;%Y&nbsp;at&nbsp;%H:%M')).html_safe %></div>
9-
<a href="<%= notif.link %>"><%= notif.content %></a>
9+
<a href="<%= notif.link %>"><%= render_pings_text(notif.content) %></a>
1010
</div>
1111
<% end %>
1212

global.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ interface QPixelKeyboard {
6565
updateSelected: () => void;
6666
}
6767

68+
type QPixelNotification = {
69+
community_id: number,
70+
community_name: string,
71+
content: string,
72+
created_at: string,
73+
id: number,
74+
is_read: boolean,
75+
link: string,
76+
updated_at: string,
77+
user_id: number
78+
}
79+
6880
type NotificationType = "warning" | "success" | "danger";
6981

7082
type QPixelPopupCallback = (ev: JQuery.ClickEvent, popup: QPixelPopup) => void

0 commit comments

Comments
 (0)