forked from GNUsocial/gnusocial.rocks
113 lines
4.0 KiB
HTML
113 lines
4.0 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=0.86, maximum-scale=5.0, minimum-scale=0.86">
|
|
<link rel="shortcut icon" href="/favicon.ico">
|
|
<link rel="stylesheet" href="https://www.gnusocial.rocks//assets/css/reset.css">
|
|
<link rel="stylesheet" href="https://www.gnusocial.rocks//assets/css/blog.css">
|
|
<link rel='stylesheet' type='text/css' href="https://www.gnusocial.rocks//assets/fonts/opensans/opensans.css"><title>Milestone: ActivityPub - GNU social V3</title>
|
|
</head><body>
|
|
<header>
|
|
<div class="home-menu menu menu-horizontal menu-fixed">
|
|
<a class="menu-heading" href="https://gnusocial.rocks/">
|
|
<img src="../assets/img/gnu-social-logo-invert.svg" alt="GNU social">
|
|
<b>gnu</b>social
|
|
</a>
|
|
</div>
|
|
<div class="sidebar">
|
|
<ul class="menu-list">
|
|
<li class="menu-item menu-selected"><a href="index.html" class="menu-link">Blog Index</a></li>
|
|
<li class="menu-item"><a href="https://code.gnusocial.rocks/" class="menu-link">Repository</a></li>
|
|
<li class="menu-item"><a href="https://coverage.gnusocial.rocks/" class="menu-link">Code Coverage</a></li>
|
|
<li class="menu-item"><a href="https://docs.gnusocial.rocks/" class="menu-link">Documentation</a></li>
|
|
<li class="menu-item"><a href="https://agile.gnusocial.rocks/" class="menu-link">Wiki</a></li>
|
|
<li class="menu-item"><a href="https://kanban.undefinedhackers.net/?controller=BoardViewController&action=readonly&token=d2293e55cabae7cceff9fb496c651328195357d392b9e61a9f229ed6d463" class="menu-link">Roadmap</a></li>
|
|
</ul>
|
|
</div>
|
|
</header>
|
|
|
|
<div class="content-wrapper">
|
|
<div class="content">
|
|
</div></div></div>
|
|
<div id="template-wrapper"><div class="template-unit">
|
|
<!-- entry begin -->
|
|
<h3><a class="ablack" href="milestone-activitypub.html">
|
|
Milestone: ActivityPub
|
|
</a></h3>
|
|
<!-- bashblog_timestamp: #202112052229.51# -->
|
|
<div class="subtitle">December 05, 2021 —
|
|
GNU social development team
|
|
</div>
|
|
<!-- text begin -->
|
|
|
|
<p><a href="https://code.undefinedhackers.net/GNUsocial/gnu-social/src/branch/v3/plugins/ActivityPub">ActivityPub Plugin source</a>.</p>
|
|
|
|
<p>This milestone could be just this, what's different from any other ActivityPub
|
|
plugin? How is it better than v2's?</p>
|
|
|
|
<p>It's better in how it's organised and extensible. See the examples below to have
|
|
an idea.</p>
|
|
|
|
<p>To extend an Activity properties you do:</p>
|
|
|
|
<pre><code>public function onActivityPubValidateActivityStreamsTwoData(string $type_name, array &$validators): bool {
|
|
if ($type_name === '{Type}') {
|
|
$validators['attribute'] = myValidator::class;
|
|
}
|
|
return Event::next;
|
|
}
|
|
</code></pre>
|
|
|
|
<p>The Validator should be of the form:</p>
|
|
|
|
<pre><code>class myValidator extends Plugin\ActivityPub\Util\ModelValidator
|
|
{
|
|
/**
|
|
* Validate Attribute's value
|
|
*
|
|
* @param mixed $value from JSON's attribute
|
|
* @param mixed $container A {Type}
|
|
* @return bool
|
|
* @throws Exception
|
|
*/
|
|
public function validate($value, $container): bool
|
|
{
|
|
// Validate that container is a {Type}
|
|
Util::subclassOf($container, Type\Extended\Object\{Type}::class, true);
|
|
|
|
return {Validation Result};
|
|
</code></pre>
|
|
|
|
<p>To act on received activities do:</p>
|
|
|
|
<pre><code>public function onActivityPubNew{Type}(&$obj): bool {
|
|
</code></pre>
|
|
|
|
<p>To add information to Activities being federated by ActivityPub do:</p>
|
|
|
|
<pre><code>public function ActivityPubAddActivityStreamsTwoData(string $type_name, &$type): bool {
|
|
</code></pre>
|
|
|
|
<p>To implement an ActivityStreams 2.0 representation do:</p>
|
|
|
|
<pre><code>public function onActivityPubActivityStreamsTwoResponse(string $route, arrray $vars, ?TypeResponse &$response = null): bool {
|
|
if ($route === '{Object route}') {
|
|
$response = ModelResponse::handle($vars[{Object}]);
|
|
return Event::stop;
|
|
}
|
|
return Event::next;
|
|
}
|
|
</code></pre>
|
|
|
|
|
|
<!-- text end -->
|
|
<!-- entry end -->
|
|
</div>
|
|
</div></div>
|
|
<footer class="footer l-box is-center">
|
|
This site's source is
|
|
<a href="https://code.undefinedhackers.net/GNUsocial/gnusocial.rocks">hosted here</a>.
|
|
</footer></body></html>
|