Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F7687591
user_note.ex
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
user_note.ex
View Options
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule
Pleroma.UserNote
do
use
Ecto.Schema
import
Ecto.Changeset
import
Ecto.Query
alias
Pleroma.Repo
alias
Pleroma.User
alias
Pleroma.UserNote
schema
"user_notes"
do
belongs_to
(
:source
,
User
,
type
:
FlakeId.Ecto.CompatType
)
belongs_to
(
:target
,
User
,
type
:
FlakeId.Ecto.CompatType
)
field
(
:comment
,
:string
)
timestamps
()
end
def
changeset
(%
UserNote
{}
=
user_note
,
params
\\
%{})
do
user_note
|>
cast
(
params
,
[
:source_id
,
:target_id
,
:comment
])
|>
validate_required
([
:source_id
,
:target_id
])
end
def
show
(%
User
{}
=
source
,
%
User
{}
=
target
)
do
with
%
UserNote
{}
=
note
<-
UserNote
|>
where
(
source_id
:
^
source
.
id
,
target_id
:
^
target
.
id
)
|>
Repo
.
one
()
do
note
.
comment
else
_
->
""
end
end
def
create
(%
User
{}
=
source
,
%
User
{}
=
target
,
comment
)
do
%
UserNote
{}
|>
changeset
(%{
source_id
:
source
.
id
,
target_id
:
target
.
id
,
comment
:
comment
})
|>
Repo
.
insert
(
on_conflict
:
{
:replace
,
[
:comment
]},
conflict_target
:
[
:source_id
,
:target_id
]
)
end
end
File Metadata
Details
Attached
Mime Type
text/x-ruby
Expires
Wed, Sep 3, 10:18 PM (1 d, 5 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
437531
Default Alt Text
user_note.ex (1 KB)
Attached To
Mode
rPUBE pleroma-upstream
Attached
Detach File
Event Timeline
Log In to Comment