From 63484ee17a857ad0c4c33f196bfa8d825621c509 Mon Sep 17 00:00:00 2001 From: ThibG Date: Thu, 23 Aug 2018 16:39:22 +0200 Subject: Do not check for file existence when serializing ActivityPub actor (#8386) When serializing an ActivityPub actor, Mastodon checks for the existence of the avatar/header files. This is not necessary, only check if avatar/header is set. https://github.com/thoughtbot/paperclip/blob/fd8bf49d3895de2904b43f95d11af0736fbd0f5b/README.md#checking-a-file-exists --- app/serializers/activitypub/actor_serializer.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/serializers') diff --git a/app/serializers/activitypub/actor_serializer.rb b/app/serializers/activitypub/actor_serializer.rb index 41c9aa44e..5054bd683 100644 --- a/app/serializers/activitypub/actor_serializer.rb +++ b/app/serializers/activitypub/actor_serializer.rb @@ -93,11 +93,11 @@ class ActivityPub::ActorSerializer < ActiveModel::Serializer end def avatar_exists? - object.avatar.exists? + object.avatar? end def header_exists? - object.header.exists? + object.header? end def manually_approves_followers -- cgit From 7786e1357bbe456243679c91f88679cdd260fa8f Mon Sep 17 00:00:00 2001 From: ThibG Date: Thu, 23 Aug 2018 21:44:27 +0200 Subject: Only display web push notifications after API call (fixes #7902) (#8396) * Only display web push notifications after API call (fixes #7902) * Decode then truncate instead of truncating then decoding in webpush serializer --- .../service_worker/web_push_notifications.js | 20 +++++++++++--------- app/serializers/web/notification_serializer.rb | 4 ++-- 2 files changed, 13 insertions(+), 11 deletions(-) (limited to 'app/serializers') diff --git a/app/javascript/mastodon/service_worker/web_push_notifications.js b/app/javascript/mastodon/service_worker/web_push_notifications.js index 3318bbadc..d61d916b1 100644 --- a/app/javascript/mastodon/service_worker/web_push_notifications.js +++ b/app/javascript/mastodon/service_worker/web_push_notifications.js @@ -80,15 +80,7 @@ const handlePush = (event) => { // Placeholder until more information can be loaded event.waitUntil( - notify({ - title, - body, - icon, - tag: notification_id, - timestamp: new Date(), - badge: '/badge.png', - data: { access_token, preferred_locale, url: '/web/notifications' }, - }).then(() => fetchFromApi(`/api/v1/notifications/${notification_id}`, 'get', access_token)).then(notification => { + fetchFromApi(`/api/v1/notifications/${notification_id}`, 'get', access_token).then(notification => { const options = {}; options.title = formatMessage(`notification.${notification.type}`, preferred_locale, { name: notification.account.display_name.length > 0 ? notification.account.display_name : notification.account.username }); @@ -112,6 +104,16 @@ const handlePush = (event) => { } return notify(options); + }).catch(() => { + return notify({ + title, + body, + icon, + tag: notification_id, + timestamp: new Date(), + badge: '/badge.png', + data: { access_token, preferred_locale, url: '/web/notifications' }, + }); }) ); }; diff --git a/app/serializers/web/notification_serializer.rb b/app/serializers/web/notification_serializer.rb index 43ba4d92a..ee83ec8b2 100644 --- a/app/serializers/web/notification_serializer.rb +++ b/app/serializers/web/notification_serializer.rb @@ -33,7 +33,7 @@ class Web::NotificationSerializer < ActiveModel::Serializer end def body - str = truncate(strip_tags(object.target_status&.spoiler_text&.presence || object.target_status&.text || object.from_account.note), length: 140) - HTMLEntities.new.decode(str.to_str) # Do not encode entities, since this value will not be used in HTML + str = strip_tags(object.target_status&.spoiler_text&.presence || object.target_status&.text || object.from_account.note) + truncate(HTMLEntities.new.decode(str.to_str), length: 140) # Do not encode entities, since this value will not be used in HTML end end -- cgit