Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
042852ec
Commit
042852ec
authored
Jan 05, 2019
by
Sadposter
Committed by
kaniini
Jan 05, 2019
Browse files
Add check to prevent multiple follow notifications from the same user
parent
8d047c7a
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/notification.ex
View file @
042852ec
...
...
@@ -109,7 +109,12 @@ def create_notifications(_), do: {:ok, []}
# TODO move to sql, too.
def
create_notification
(%
Activity
{}
=
activity
,
%
User
{}
=
user
)
do
unless
User
.
blocks?
(
user
,
%{
ap_id:
activity
.
data
[
"actor"
]})
or
user
.
ap_id
==
activity
.
data
[
"actor"
]
do
user
.
ap_id
==
activity
.
data
[
"actor"
]
or
(
activity
.
data
[
"type"
]
==
"Follow"
and
Enum
.
any?
(
Notification
.
for_user
(
user
),
fn
notif
->
notif
.
activity
.
data
[
"type"
]
==
"Follow"
and
notif
.
activity
.
data
[
"actor"
]
==
activity
.
data
[
"actor"
]
end
))
do
notification
=
%
Notification
{
user_id:
user
.
id
,
activity:
activity
}
{
:ok
,
notification
}
=
Repo
.
insert
(
notification
)
Pleroma
.
Web
.
Streamer
.
stream
(
"user"
,
notification
)
...
...
test/notification_test.exs
View file @
042852ec
...
...
@@ -46,6 +46,43 @@ test "it doesn't create a notification for user if he is the activity author" do
assert
nil
==
Notification
.
create_notification
(
activity
,
author
)
end
test
"it doesn't create a notification for follow-unfollow-follow chains"
do
user
=
insert
(
:user
)
followed_user
=
insert
(
:user
)
{
:ok
,
_
,
_
,
activity
}
=
TwitterAPI
.
follow
(
user
,
%{
"user_id"
=>
followed_user
.
id
})
Notification
.
create_notification
(
activity
,
followed_user
)
TwitterAPI
.
unfollow
(
user
,
%{
"user_id"
=>
followed_user
.
id
})
{
:ok
,
_
,
_
,
activity_dupe
}
=
TwitterAPI
.
follow
(
user
,
%{
"user_id"
=>
followed_user
.
id
})
assert
nil
==
Notification
.
create_notification
(
activity_dupe
,
followed_user
)
end
test
"it doesn't create a notification for like-unlike-like chains"
do
user
=
insert
(
:user
)
liked_user
=
insert
(
:user
)
{
:ok
,
status
}
=
TwitterAPI
.
create_status
(
liked_user
,
%{
"status"
=>
"Yui is best yuru"
})
{
:ok
,
fav_status
}
=
TwitterAPI
.
fav
(
user
,
status
.
id
)
Notification
.
create_notification
(
fav_status
,
liked_user
)
TwitterAPI
.
unfav
(
user
,
status
.
id
)
{
:ok
,
dupe
}
=
TwitterAPI
.
fav
(
user
,
status
.
id
)
assert
nil
==
Notification
.
create_notification
(
dupe
,
liked_user
)
end
test
"it doesn't create a notification for repeat-unrepeat-repeat chains"
do
user
=
insert
(
:user
)
retweeted_user
=
insert
(
:user
)
{
:ok
,
status
}
=
TwitterAPI
.
create_status
(
retweeted_user
,
%{
"status"
=>
"Send dupe notifications to the shadow realm"
})
{
:ok
,
retweeted_activity
}
=
TwitterAPI
.
repeat
(
user
,
status
.
id
)
Notification
.
create_notification
(
retweeted_activity
,
retweeted_user
)
TwitterAPI
.
unrepeat
(
user
,
status
.
id
)
{
:ok
,
dupe
}
=
TwitterAPI
.
repeat
(
user
,
status
.
id
)
assert
nil
==
Notification
.
create_notification
(
dupe
,
retweeted_user
)
end
end
describe
"get notification"
do
...
...
Sergey Suprunenko
@ssuprunenko
mentioned in issue
#1069 (closed)
·
Jul 06, 2019
mentioned in issue
#1069 (closed)
mentioned in issue #1069
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment