Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mastofe
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Pleroma
mastofe
Commits
9411e8c3
Commit
9411e8c3
authored
9 years ago
by
Eugen Rochko
Browse files
Options
Downloads
Patches
Plain Diff
Feed processing except fetching remote statuses
parent
79baf2fd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/services/process_feed_service.rb
+93
-14
93 additions, 14 deletions
app/services/process_feed_service.rb
app/services/process_interaction_service.rb
+2
-0
2 additions, 0 deletions
app/services/process_interaction_service.rb
with
95 additions
and
14 deletions
app/services/process_feed_service.rb
+
93
−
14
View file @
9411e8c3
class
ProcessFeedService
include
ApplicationHelper
def
call
(
body
,
account
)
xml
=
Nokogiri
::
XML
(
body
)
xml
.
xpath
(
'/xmlns:feed/xmlns:entry'
).
each
do
|
entry
|
uri
=
entry
.
at_xpath
(
'./xmlns:id'
).
content
status
=
Status
.
find_by
(
uri:
uri
)
xml
.
xpath
(
'//xmlns:entry'
).
each
do
|
entry
|
next
unless
[
:note
,
:comment
,
:activity
].
includes?
object_type
(
entry
)
status
=
Status
.
find_by
(
uri:
activity_id
(
entry
))
next
unless
status
.
nil?
status
=
Status
.
new
(
uri:
activity_id
(
entry
),
account:
account
,
text:
content
(
entry
),
created_at:
published
(
entry
),
updated_at:
updated
(
entry
))
if
object_type
(
entry
)
==
:comment
add_reply!
(
entry
,
status
)
elsif
verb
(
entry
)
==
:share
add_reblog!
(
entry
,
status
)
else
add_post!
(
entry
,
status
)
end
end
end
private
def
add_post!
(
entry
,
status
)
status
.
save!
end
def
add_reblog!
(
entry
,
status
)
status
.
reblog
=
find_original_status
(
entry
,
target_id
(
entry
))
end
def
add_reply!
(
entry
,
status
)
status
.
thread
=
find_original_status
(
entry
,
thread_id
(
entry
))
end
next
if
!
status
.
nil?
def
find_original_status
(
xml
,
id
)
return
nil
if
id
.
nil?
status
=
Status
.
new
status
.
account
=
account
status
.
uri
=
uri
status
.
text
=
entry
.
at_xpath
(
'./xmlns:content'
).
content
status
.
created_at
=
entry
.
at_xpath
(
'./xmlns:published'
).
content
status
.
updated_at
=
entry
.
at_xpath
(
'./xmlns:updated'
).
content
status
.
save!
if
local_id?
(
id
)
Status
.
find
(
unique_tag_to_local_id
(
id
,
'Status'
))
else
status
=
Status
.
find_by
(
uri:
id
)
# todo: not everything is a status. there are follows, favourites
# todo: RTs
# account.statuses.create!(reblog: status, uri: activity_uri(xml), url: activity_url(xml), text: content(xml))
if
status
.
nil?
status
=
fetch_remote_status
(
xml
,
id
)
end
status
end
end
def
fetch_remote_status
(
xml
,
id
)
# todo
end
def
local_id?
(
id
)
id
.
start_with?
(
"tag:
#{
LOCAL_DOMAIN
}
"
)
end
def
published
(
xml
)
xml
.
at_xpath
(
'./xmlns:published'
).
content
end
def
updated
(
xml
)
xml
.
at_xpath
(
'./xmlns:updated'
).
content
end
def
content
(
xml
)
xml
.
at_xpath
(
'./xmlns:content'
).
content
end
def
thread_id
(
xml
)
xml
.
at_xpath
(
'./thr:in-reply-to-id'
).
attribute
(
'ref'
).
value
rescue
nil
end
def
target_id
(
xml
)
xml
.
at_xpath
(
'./activity:object/xmlns:id'
).
content
rescue
nil
end
def
activity_id
(
xml
)
entry
.
at_xpath
(
'./xmlns:id'
).
content
end
def
object_type
(
xml
)
xml
.
at_xpath
(
'./activity:object-type'
).
content
.
gsub
(
'http://activitystrea.ms/schema/1.0/'
,
''
).
to_sym
rescue
:note
end
def
verb
(
xml
)
xml
.
at_xpath
(
'./activity:verb'
).
content
.
gsub
(
'http://activitystrea.ms/schema/1.0/'
,
''
).
to_sym
rescue
:post
end
end
This diff is collapsed.
Click to expand it.
app/services/process_interaction_service.rb
+
2
−
0
View file @
9411e8c3
...
...
@@ -46,6 +46,8 @@ class ProcessInteractionService
def
verb
(
xml
)
xml
.
at_xpath
(
'//activity:verb'
).
content
.
gsub
(
'http://activitystrea.ms/schema/1.0/'
,
''
).
to_sym
rescue
:post
end
def
follow!
(
account
,
target_account
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment