Skip to content

Commit

Permalink
Add notification grouping for reactions
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEssem committed Jul 19, 2024
1 parent 63f5f98 commit a6e87ab
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/javascript/flavours/glitch/api_types/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const allNotificationTypes = [
'follow',
'follow_request',
'favourite',
'reaction',
'reblog',
'mention',
'poll',
Expand All @@ -24,6 +25,7 @@ export const allNotificationTypes = [

export type NotificationWithStatusType =
| 'favourite'
| 'reaction'
| 'reblog'
| 'status'
| 'mention'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { NotificationFollowRequest } from './notification_follow_request';
import { NotificationMention } from './notification_mention';
import { NotificationModerationWarning } from './notification_moderation_warning';
import { NotificationPoll } from './notification_poll';
import { NotificationReaction } from './notification_reaction';
import { NotificationReblog } from './notification_reblog';
import { NotificationSeveredRelationships } from './notification_severed_relationships';
import { NotificationStatus } from './notification_status';
Expand Down Expand Up @@ -61,6 +62,14 @@ export const NotificationGroup: React.FC<{
/>
);
break;
case 'reaction':
content = (
<NotificationReaction
unread={unread}
notification={notificationGroup}
/>
);
break;
case 'severed_relationships':
content = (
<NotificationSeveredRelationships
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { FormattedMessage } from 'react-intl';

import MoodIcon from '@/material-icons/400-24px/mood.svg?react';
import type { NotificationGroupReaction } from 'flavours/glitch/models/notification_group';

import type { LabelRenderer } from './notification_group_with_status';
import { NotificationGroupWithStatus } from './notification_group_with_status';

const labelRenderer: LabelRenderer = (values) => (
<FormattedMessage
id='notification.reaction'
defaultMessage='{name} reacted to your status'
values={values}
/>
);

export const NotificationReaction: React.FC<{
notification: NotificationGroupReaction;
unread: boolean;
}> = ({ notification, unread }) => {
return (
<NotificationGroupWithStatus
type='reaction'
icon={MoodIcon}
iconId='react'
accountIds={notification.sampleAccountIds}
statusId={notification.statusId}
timestamp={notification.latest_page_notification_at}
count={notification.notifications_count}
labelRenderer={labelRenderer}
unread={unread}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { defineMessages, FormattedMessage, useIntl } from 'react-intl';

import HomeIcon from '@/material-icons/400-24px/home-fill.svg?react';
import InsertChartIcon from '@/material-icons/400-24px/insert_chart.svg?react';
import MoodIcon from '@/material-icons/400-24px/mood.svg?react';
import PersonAddIcon from '@/material-icons/400-24px/person_add.svg?react';
import RepeatIcon from '@/material-icons/400-24px/repeat.svg?react';
import ReplyAllIcon from '@/material-icons/400-24px/reply_all.svg?react';
Expand All @@ -23,6 +24,10 @@ const tooltips = defineMessages({
id: 'notifications.filter.favourites',
defaultMessage: 'Favorites',
},
reactions: {
id: 'notifications.filter.reactions',
defaultMessage: 'Reactions',
},
boosts: { id: 'notifications.filter.boosts', defaultMessage: 'Boosts' },
polls: { id: 'notifications.filter.polls', defaultMessage: 'Poll results' },
follows: { id: 'notifications.filter.follows', defaultMessage: 'Follows' },
Expand Down Expand Up @@ -91,6 +96,14 @@ export const FilterBar: React.FC = () => {
>
<Icon id='star' icon={StarIcon} />
</BarButton>
<BarButton
selectedFilter={selectedFilter}
type='reaction'
key='reaction'
title={intl.formatMessage(tooltips.reactions)}
>
<Icon id='react' icon={MoodIcon} />
</BarButton>
<BarButton
selectedFilter={selectedFilter}
type='reblog'
Expand Down
4 changes: 4 additions & 0 deletions app/javascript/flavours/glitch/models/notification_group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface BaseNotification<Type extends NotificationType>

export type NotificationGroupFavourite =
BaseNotificationWithStatus<'favourite'>;
export type NotificationGroupReaction = BaseNotificationWithStatus<'reaction'>;
export type NotificationGroupReblog = BaseNotificationWithStatus<'reblog'>;
export type NotificationGroupStatus = BaseNotificationWithStatus<'status'>;
export type NotificationGroupMention = BaseNotificationWithStatus<'mention'>;
Expand Down Expand Up @@ -76,6 +77,7 @@ export interface NotificationGroupAdminReport

export type NotificationGroup =
| NotificationGroupFavourite
| NotificationGroupReaction
| NotificationGroupReblog
| NotificationGroupStatus
| NotificationGroupMention
Expand Down Expand Up @@ -120,6 +122,7 @@ export function createNotificationGroupFromJSON(

switch (group.type) {
case 'favourite':
case 'reaction':
case 'reblog':
case 'status':
case 'mention':
Expand Down Expand Up @@ -179,6 +182,7 @@ export function createNotificationGroupFromNotificationJSON(

switch (notification.type) {
case 'favourite':
case 'reaction':
case 'reblog':
case 'status':
case 'mention':
Expand Down
4 changes: 4 additions & 0 deletions app/javascript/flavours/glitch/styles/components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10943,6 +10943,10 @@ noscript {
color: $gold-star;
}

&--reaction &__icon {
color: $blurple-300;
}

&--reblog &__icon {
color: $valid-value-color;
}
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/rest/notification_group_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class REST::NotificationGroupSerializer < ActiveModel::Serializer
belongs_to :account_warning, key: :moderation_warning, if: :moderation_warning_event?, serializer: REST::AccountWarningSerializer

def status_type?
[:favourite, :reblog, :status, :mention, :poll, :update].include?(object.type)
[:favourite, :reaction, :reblog, :status, :mention, :poll, :update].include?(object.type)
end

def report_type?
Expand Down
2 changes: 1 addition & 1 deletion app/services/notify_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def call(recipient, type, activity)
private

def notification_group_key
return nil if @notification.filtered || %i(favourite reblog).exclude?(@notification.type)
return nil if @notification.filtered || %i(favourite reaction reblog).exclude?(@notification.type)

type_prefix = "#{@notification.type}-#{@notification.target_status.id}"
redis_key = "notif-group/#{@recipient.id}/#{type_prefix}"
Expand Down

0 comments on commit a6e87ab

Please sign in to comment.