Skip to content
GitLab
Menu
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
102455bf
Commit
102455bf
authored
May 02, 2017
by
lain
Browse files
Add avatar updating from incoming messages.
parent
945b4b55
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
lib/pleroma/web/ostatus/ostatus.ex
View file @
102455bf
...
...
@@ -90,6 +90,19 @@ def handle_note(entry, doc \\ nil) do
end
end
def
find_make_or_update_user
(
doc
)
do
uri
=
string_from_xpath
(
"//author/uri[1]"
,
doc
)
with
{
:ok
,
user
}
<-
find_or_make_user
(
uri
)
do
avatar
=
make_avatar_object
(
doc
)
if
user
.
avatar
!=
avatar
do
change
=
Ecto
.
Changeset
.
change
(
user
,
%{
avatar:
avatar
})
Repo
.
update
(
change
)
else
{
:ok
,
user
}
end
end
end
def
find_or_make_user
(
uri
)
do
query
=
from
user
in
User
,
where:
user
.
local
==
false
and
fragment
(
"? @> ?"
,
user
.
info
,
^
%{
uri:
uri
})
...
...
@@ -121,8 +134,8 @@ def make_user(uri) do
# TODO: Just takes the first one for now.
def
make_avatar_object
(
author_doc
)
do
href
=
string_from_xpath
(
"/
feed
/author[1]/link[@rel=
\"
avatar
\"
]/@href"
,
author_doc
)
type
=
string_from_xpath
(
"/
feed
/author[1]/link[@rel=
\"
avatar
\"
]/@type"
,
author_doc
)
href
=
string_from_xpath
(
"//author[1]/link[@rel=
\"
avatar
\"
]/@href"
,
author_doc
)
type
=
string_from_xpath
(
"//author[1]/link[@rel=
\"
avatar
\"
]/@type"
,
author_doc
)
if
href
do
%{
...
...
test/fixtures/23211.atom
0 → 100644
View file @
102455bf
This diff is collapsed.
Click to expand it.
test/web/ostatus/ostatus_test.exs
View file @
102455bf
defmodule
Pleroma
.
Web
.
OStatusTest
do
use
Pleroma
.
DataCase
alias
Pleroma
.
Web
.
OStatus
alias
Pleroma
.
Web
.
XML
test
"don't insert create notes twice"
do
incoming
=
File
.
read!
(
"test/fixtures/incoming_note_activity.xml"
)
...
...
@@ -71,6 +72,25 @@ test "tries to use the information in poco fields" do
assert
user
==
user_again
end
test
"find_make_or_update_user takes an author element and returns an updated user"
do
# TODO make test local
uri
=
"https://social.heldscal.la/user/23211"
{
:ok
,
user
}
=
OStatus
.
find_or_make_user
(
uri
)
change
=
Ecto
.
Changeset
.
change
(
user
,
%{
avatar:
nil
})
{
:ok
,
user
}
=
Repo
.
update
(
change
)
refute
user
.
avatar
doc
=
XML
.
parse_document
(
File
.
read!
(
"test/fixtures/23211.atom"
))
[
author
]
=
:xmerl_xpath
.
string
(
'//author[1]'
,
doc
)
{
:ok
,
user
}
=
OStatus
.
find_make_or_update_user
(
author
)
assert
user
.
avatar
[
"type"
]
==
"Image"
{
:ok
,
user_again
}
=
OStatus
.
find_make_or_update_user
(
author
)
assert
user_again
==
user
end
end
describe
"gathering user info from a user id"
do
...
...
Write
Preview
Supports
Markdown
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