Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pleroma
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
155
Issues
155
List
Board
Labels
Milestones
Merge Requests
23
Merge Requests
23
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Pleroma
pleroma
Commits
a0d732ec
Commit
a0d732ec
authored
Feb 09, 2019
by
Karen Konou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
it works!!
parent
4430a0ad
Pipeline
#7331
failed with stages
in 57 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
15 deletions
+40
-15
notification.ex
lib/pleroma/notification.ex
+2
-0
thread_mute.ex
lib/pleroma/web/thread_mute.ex
+25
-3
thread_mute_test.exs
test/web/thread_mute_test.exs
+13
-12
No files found.
lib/pleroma/notification.ex
View file @
a0d732ec
...
...
@@ -6,6 +6,7 @@ defmodule Pleroma.Notification do
use
Ecto
.
Schema
alias
Pleroma
.
{
User
,
Activity
,
Notification
,
Repo
}
alias
Pleroma
.
Web
.
CommonAPI
.
Utils
alias
Pleroma
.
Web
.
ThreadMute
import
Ecto
.
Query
schema
"
notifications"
do
...
...
@@ -112,6 +113,7 @@ defmodule Pleroma.Notification do
# TODO move to sql, too.
def
create_notification
(%
Activity
{}
=
activity
,
%
User
{}
=
user
)
do
unless
User
.
blocks?
(
user
,
%{
ap_id:
activity
.
data
[
"
actor"
]})
or
ThreadMute
.
muted?
(
user
,
activity
)
or
user
.
ap_id
==
activity
.
data
[
"
actor"
]
or
(
activity
.
data
[
"
type"
]
==
"
Follow"
and
Enum
.
any?
(
Notification
.
for_user
(
user
),
fn
notif
->
...
...
lib/pleroma/web/thread_mute.ex
View file @
a0d732ec
...
...
@@ -4,6 +4,7 @@
defmodule
Pleroma
.
Web
.
ThreadMute
do
use
Ecto
.
Schema
alias
Pleroma
.
Web
.
ThreadMute
alias
Pleroma
.
{
Activity
,
Repo
,
User
}
require
Ecto
.
Query
...
...
@@ -13,16 +14,37 @@ defmodule Pleroma.Web.ThreadMute do
end
def
add_mute
(
user
,
id
)
do
%{
data:
%{
"
context"
=>
context
}}
=
Activity
.
get_by_id
(
id
)
activity
=
Activity
.
get_by_id
(
id
)
context
=
activity
.
data
[
"
context"
]
mute
=
%
Pleroma
.
Web
.
ThreadMute
{
user_id:
user
.
id
,
context:
context
}
Repo
.
insert
(
mute
)
{
:ok
,
activity
}
end
def
remove_mute
(
user
,
id
)
do
user_id
=
Pleroma
.
FlakeId
.
from_string
(
user
.
id
)
%{
data:
%{
"
context"
=>
context
}}
=
Activity
.
get_by_id
(
id
)
activity
=
Activity
.
get_by_id
(
id
)
context
=
activity
.
data
[
"
context"
]
Ecto
.
Query
.
from
(
m
in
"
thread_mutes"
,
where:
m
.
user_id
==
^
user_id
and
m
.
context
==
^
context
)
Ecto
.
Query
.
from
(
m
in
ThreadMute
,
where:
m
.
user_id
==
^
user_id
and
m
.
context
==
^
context
)
|>
Repo
.
delete_all
()
{
:ok
,
activity
}
end
def
muted?
(
user
,
activity
)
do
user_id
=
Pleroma
.
FlakeId
.
from_string
(
user
.
id
)
context
=
activity
.
data
[
"
context"
]
result
=
Ecto
.
Query
.
from
(
m
in
ThreadMute
,
where:
m
.
user_id
==
^
user_id
and
m
.
context
==
^
context
)
|>
Repo
.
all
()
case
result
do
[]
->
false
_
->
true
end
end
end
test/web/thread_mute_test.exs
View file @
a0d732ec
...
...
@@ -10,31 +10,32 @@ defmodule Pleroma.Web.ThreadMuteTest do
describe
"
mute tests"
do
setup
do
user
=
insert
(
:user
,
%{
id:
"
1"
}
)
user
=
insert
(
:user
)
activity
=
insert
(
:note_activity
,
%{
data:
%{
"
context"
=>
"
http://localhost:4000/contexts/361ca23e-ffa7-4773-b981-a355a18dc592"
}
})
activity
=
insert
(
:note_activity
)
[
user:
user
,
activity:
activity
]
end
test
"
add mute"
,
%{
user:
user
,
activity:
activity
}
do
id
=
activity
.
id
{
:ok
,
mute
}
=
add_mute
(
user
,
id
)
assert
mute
.
user_id
==
"
1"
assert
mute
.
context
==
"
http://localhost:4000/contexts/361ca23e-ffa7-4773-b981-a355a18dc592"
{
:ok
,
_activity
}
=
add_mute
(
user
,
id
)
end
test
"
remove mute"
,
%{
user:
user
,
activity:
activity
}
do
id
=
activity
.
id
add_mute
(
user
,
id
)
{
1
,
nil
}
=
remove_mute
(
user
,
id
)
{
:ok
,
_activity
}
=
remove_mute
(
user
,
id
)
end
test
"
check mute"
,
%{
user:
user
,
activity:
activity
}
do
id
=
activity
.
id
add_mute
(
user
,
id
)
assert
muted?
(
user
,
activity
)
remove_mute
(
user
,
id
)
refute
muted?
(
user
,
activity
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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