mirror of
https://github.com/mastodon/mastodon.git
synced 2024-08-20 21:08:15 -07:00
Compare commits
7 commits
ac30d45992
...
14104ad987
Author | SHA1 | Date | |
---|---|---|---|
|
14104ad987 | ||
|
a50c8e951f | ||
|
2c1e75727d | ||
|
a4812f6ef5 | ||
|
7ab706061d | ||
|
bd4c5f792e | ||
|
c4f7b8b625 |
8 changed files with 65 additions and 52 deletions
|
@ -8,37 +8,39 @@ class Api::V1::MarkersController < Api::BaseController
|
|||
|
||||
def index
|
||||
with_read_replica do
|
||||
@markers = current_user.markers.where(timeline: Array(params[:timeline])).index_by(&:timeline)
|
||||
@markers = current_user_markers
|
||||
end
|
||||
|
||||
render json: serialize_map(@markers)
|
||||
render json: marker_timeline_presenter, serializer: REST::MarkerTimelineSerializer
|
||||
end
|
||||
|
||||
def create
|
||||
Marker.transaction do
|
||||
@markers = {}
|
||||
|
||||
resource_params.each_pair do |timeline, timeline_params|
|
||||
@markers[timeline] = current_user.markers.find_or_create_by(timeline: timeline)
|
||||
@markers[timeline].update!(timeline_params)
|
||||
end
|
||||
end
|
||||
|
||||
render json: serialize_map(@markers)
|
||||
@markers = create_markers_from_params
|
||||
render json: marker_timeline_presenter, serializer: REST::MarkerTimelineSerializer
|
||||
rescue ActiveRecord::StaleObjectError
|
||||
render json: { error: 'Conflict during update, please try again' }, status: 409
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def serialize_map(map)
|
||||
serialized = {}
|
||||
|
||||
map.each_pair do |key, value|
|
||||
serialized[key] = ActiveModelSerializers::SerializableResource.new(value, serializer: REST::MarkerSerializer).as_json
|
||||
def marker_timeline_presenter
|
||||
MarkerTimelinePresenter.new(@markers)
|
||||
end
|
||||
|
||||
Oj.dump(serialized)
|
||||
def current_user_markers
|
||||
current_user.markers.where(timeline: Array(params[:timeline]))
|
||||
end
|
||||
|
||||
def create_markers_from_params
|
||||
[].tap do |markers|
|
||||
Marker.transaction do
|
||||
resource_params.each_pair do |timeline, timeline_params|
|
||||
current_user.markers.find_or_create_by(timeline: timeline).tap do |marker|
|
||||
marker.update!(timeline_params)
|
||||
markers << marker
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def resource_params
|
||||
|
|
|
@ -60,7 +60,7 @@ export interface BaseNotificationGroupJSON {
|
|||
|
||||
interface NotificationGroupWithStatusJSON extends BaseNotificationGroupJSON {
|
||||
type: NotificationWithStatusType;
|
||||
status: ApiStatusJSON;
|
||||
status_id: string;
|
||||
}
|
||||
|
||||
interface NotificationWithStatusJSON extends BaseNotificationJSON {
|
||||
|
|
|
@ -49,22 +49,15 @@ export const FilteredNotificationsBanner: React.FC = () => {
|
|||
<span>
|
||||
<FormattedMessage
|
||||
id='filtered_notifications_banner.pending_requests'
|
||||
defaultMessage='Notifications from {count, plural, =0 {no one} one {one person} other {# people}} you may know'
|
||||
defaultMessage='From {count, plural, =0 {no one} one {one person} other {# people}} you may know'
|
||||
values={{ count: policy.summary.pending_requests_count }}
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className='filtered-notifications-banner__badge'>
|
||||
<div className='filtered-notifications-banner__badge__badge'>
|
||||
{toCappedNumber(policy.summary.pending_notifications_count)}
|
||||
</div>
|
||||
<FormattedMessage
|
||||
id='filtered_notifications_banner.mentions'
|
||||
defaultMessage='{count, plural, one {mention} other {mentions}}'
|
||||
values={{ count: policy.summary.pending_notifications_count }}
|
||||
/>
|
||||
</div>
|
||||
</Link>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -300,8 +300,7 @@
|
|||
"filter_modal.select_filter.subtitle": "Use an existing category or create a new one",
|
||||
"filter_modal.select_filter.title": "Filter this post",
|
||||
"filter_modal.title.status": "Filter a post",
|
||||
"filtered_notifications_banner.mentions": "{count, plural, one {mention} other {mentions}}",
|
||||
"filtered_notifications_banner.pending_requests": "Notifications from {count, plural, =0 {no one} one {one person} other {# people}} you may know",
|
||||
"filtered_notifications_banner.pending_requests": "From {count, plural, =0 {no one} one {one person} other {# people}} you may know",
|
||||
"filtered_notifications_banner.title": "Filtered notifications",
|
||||
"firehose.all": "All",
|
||||
"firehose.local": "This server",
|
||||
|
|
|
@ -124,9 +124,9 @@ export function createNotificationGroupFromJSON(
|
|||
case 'mention':
|
||||
case 'poll':
|
||||
case 'update': {
|
||||
const { status, ...groupWithoutStatus } = group;
|
||||
const { status_id: statusId, ...groupWithoutStatus } = group;
|
||||
return {
|
||||
statusId: status.id,
|
||||
statusId,
|
||||
sampleAccountIds,
|
||||
...groupWithoutStatus,
|
||||
};
|
||||
|
|
|
@ -10170,20 +10170,6 @@ noscript {
|
|||
}
|
||||
}
|
||||
|
||||
&__badge {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
border-radius: 999px;
|
||||
background: var(--background-border-color);
|
||||
color: $darker-text-color;
|
||||
padding: 4px;
|
||||
padding-inline-end: 8px;
|
||||
gap: 6px;
|
||||
font-weight: 500;
|
||||
font-size: 11px;
|
||||
line-height: 16px;
|
||||
word-break: keep-all;
|
||||
|
||||
&__badge {
|
||||
background: $ui-button-background-color;
|
||||
color: $white;
|
||||
|
@ -10191,7 +10177,6 @@ noscript {
|
|||
padding: 2px 8px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.notification-request {
|
||||
display: flex;
|
||||
|
|
23
app/presenters/marker_timeline_presenter.rb
Normal file
23
app/presenters/marker_timeline_presenter.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class MarkerTimelinePresenter
|
||||
include ActiveModel::Model
|
||||
|
||||
alias read_attribute_for_serialization send
|
||||
|
||||
attr_reader :markers
|
||||
|
||||
def initialize(markers)
|
||||
@markers = markers
|
||||
end
|
||||
|
||||
Marker::TIMELINES.each do |timeline|
|
||||
define_method timeline.to_sym do
|
||||
markers.find { |marker| marker.timeline == timeline }
|
||||
end
|
||||
end
|
||||
|
||||
def timeline_present?(value)
|
||||
markers.map(&:timeline).include?(value)
|
||||
end
|
||||
end
|
11
app/serializers/rest/marker_timeline_serializer.rb
Normal file
11
app/serializers/rest/marker_timeline_serializer.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class REST::MarkerTimelineSerializer < ActiveModel::Serializer
|
||||
Marker::TIMELINES.each do |timeline|
|
||||
has_one timeline.to_sym,
|
||||
if: -> { timeline_present?(timeline) },
|
||||
serializer: REST::MarkerSerializer
|
||||
end
|
||||
|
||||
delegate :timeline_present?, to: :object
|
||||
end
|
Loading…
Reference in a new issue