Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F21842011
notification_backfill.ex
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
notification_backfill.ex
View Options
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule
Pleroma.MigrationHelper.NotificationBackfill
do
alias
Pleroma.Object
alias
Pleroma.Repo
alias
Pleroma.User
import
Ecto.Query
def
fill_in_notification_types
do
query
=
from
(
n
in
Pleroma.Notification
,
where
:
is_nil
(
n
.
type
),
preload
:
:activity
)
query
|>
Repo
.
chunk_stream
(
100
)
|>
Enum
.
each
(
fn
notification
->
type
=
notification
.
activity
|>
type_from_activity
()
notification
|>
Ecto.Changeset
.
change
(%{
type
:
type
})
|>
Repo
.
update
()
end
)
end
defp
get_by_ap_id
(
ap_id
)
do
q
=
from
(
u
in
User
,
select
:
u
.
id
)
Repo
.
get_by
(
q
,
ap_id
:
ap_id
)
end
# This is copied over from Notifications to keep this stable.
defp
type_from_activity
(%{
data
:
%{
"type"
=>
type
}}
=
activity
)
do
case
type
do
"Follow"
->
accepted_function
=
fn
activity
->
with
%
User
{}
=
follower
<-
get_by_ap_id
(
activity
.
data
[
"actor"
]),
%
User
{}
=
followed
<-
get_by_ap_id
(
activity
.
data
[
"object"
])
do
Pleroma.FollowingRelationship
.
following?
(
follower
,
followed
)
end
end
if
accepted_function
.
(
activity
)
do
"follow"
else
"follow_request"
end
"Announce"
->
"reblog"
"Like"
->
"favourite"
"Move"
->
"move"
"EmojiReact"
->
"pleroma:emoji_reaction"
# Compatibility with old reactions
"EmojiReaction"
->
"pleroma:emoji_reaction"
"Create"
->
activity
|>
type_from_activity_object
()
t
->
raise
"No notification type for activity type
#{
t
}
"
end
end
defp
type_from_activity_object
(%{
data
:
%{
"type"
=>
"Create"
,
"object"
=>
%{}}}),
do
:
"mention"
defp
type_from_activity_object
(%{
data
:
%{
"type"
=>
"Create"
}}
=
activity
)
do
object
=
Object
.
get_by_ap_id
(
activity
.
data
[
"object"
])
case
object
&&
object
.
data
[
"type"
]
do
"ChatMessage"
->
"pleroma:chat_mention"
_
->
"mention"
end
end
end
File Metadata
Details
Attached
Mime Type
text/x-ruby
Expires
Sat, Dec 27, 11:51 PM (16 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
798622
Default Alt Text
notification_backfill.ex (2 KB)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline
Log In to Comment