Browse Source

Add basic support of XEP-0472: Pubsub Social Feed with Gallery view and toggle in the Communities

pull/1171/head
Timothée Jaussoin 3 years ago
parent
commit
c9e970537f
  1. 24
      app/Info.php
  2. 20
      app/helpers/UtilsHelper.php
  3. 2
      app/widgets/Blog/Blog.php
  4. 4
      app/widgets/CommunitiesServer/_communitiesserver.tpl
  5. 39
      app/widgets/CommunityConfig/_communityconfig.tpl
  6. 5
      app/widgets/CommunityConfig/locales.ini
  7. 6
      app/widgets/CommunityData/_communitydata_card.tpl
  8. 10
      app/widgets/CommunityPosts/CommunityPosts.php
  9. 21
      database/migrations/20230303224825_add_type_to_infos_table.php
  10. 14
      doap.xml

24
app/Info.php

@ -228,44 +228,49 @@ class Info extends Model
return 'desktop_windows';
}
public function hasFeature(string $feature)
public function hasFeature(string $feature): bool
{
return (in_array($feature, unserialize($this->attributes['features'])));
}
public function isJingleAudio()
public function isGallery(): bool
{
return $this->type == 'urn:xmpp:pubsub-social-gallery:0';
}
public function isJingleAudio(): bool
{
return $this->hasFeature('urn:xmpp:jingle:apps:rtp:audio')
&& $this->hasFeature('urn:xmpp:jingle-message:0');
}
public function isJingleVideo()
public function isJingleVideo(): bool
{
return $this->hasFeature('urn:xmpp:jingle:apps:rtp:video')
&& $this->hasFeature('urn:xmpp:jingle-message:0');
}
public function isMAM()
public function isMAM(): bool
{
return $this->hasFeature('urn:xmpp:mam:1');
}
public function isMAM2()
public function isMAM2(): bool
{
return $this->hasFeature('urn:xmpp:mam:2');
}
public function hasMAM()
public function hasMAM(): bool
{
return $this->isMAM() || $this->isMAM2();
}
public function hasStanzaId()
public function hasStanzaId(): bool
{
return $this->hasFeature('urn:xmpp:sid:0');
}
public function hasExternalServices()
public function hasExternalServices(): bool
{
return $this->hasFeature('urn:xmpp:extdisco:2');
}
@ -354,6 +359,9 @@ class Info extends Model
case 'pubsub#title':
$this->name = (string)$field->value;
break;
case 'pubsub#type':
$this->type = (string)$field->value;
break;
case 'pubsub#creation_date':
$this->created = toSQLDate($field->value);
break;

20
app/helpers/UtilsHelper.php

@ -153,25 +153,6 @@ function getClientTypes()
];
}
/**
* Check if Posts collection is gallery
*/
function isPostGallery($postCollection): bool
{
// For now we detect if a node is a gallery if all the publications have an attached picture
// and if the post contents are short.
$shortCount = 0;
$gallery = $postCollection->every(function ($post) use (&$shortCount) {
if ($post->isShort()) $shortCount++;
return $post->picture != null;
});
if ($gallery && $shortCount < $postCollection->count()/2) $gallery = false;
return $gallery;
}
/**
* Resolve infos from a Posts collection
*/
@ -582,6 +563,7 @@ function varToIcons(string $var)
'pubsub#notify_delete' => 'delete',
'pubsub#notify_retract' => 'delete_sweep',
'pubsub#persist_items' => 'save',
'pubsub#type' => 'space_dashboard',
'pubsub#deliver_notifications' => 'notifications_active',
// Muc

2
app/widgets/Blog/Blog.php

@ -168,7 +168,7 @@ class Blog extends Base
}
if ($this->_posts !== null) {
$this->_gallery = isPostGallery($this->_posts);
$this->_gallery = $this->_item && $this->_item->isGallery();
}
}

4
app/widgets/CommunitiesServer/_communitiesserver.tpl

@ -71,6 +71,10 @@
</span>
</p>
<p class="line">
{if="$value->isGallery()"}
<i class="material-icons">grid_view</i>
·
{/if}
{if="$value->published"}
<i class="material-icons">update</i>
{$value->published|strtotime|prepareDate:true}

39
app/widgets/CommunityConfig/_communityconfig.tpl

@ -61,6 +61,45 @@
</ul>
<label>{$c->__('communityconfig.publication')}</label>
</div>
<div>
<ul class="list middle labeled fill">
<li>
<span class="primary icon gray">
<i class="material-icons">view_agenda</i>
</span>
<span class="control">
<div class="radio">
<input name="pubsub#type" value="urn:xmpp:pubsub-social-feed:0"
id="pubsub_type_feed" type="radio"
{if="$config['pubsub#type'] == 'urn:xmpp:pubsub-social-feed:0'"}checked{/if}>
<label for="pubsub_type_feed"></label>
</div>
</span>
<div>
<p>{$c->__('communityconfig.type_articles_title')}</p>
<p>{$c->__('communityconfig.type_articles_text')}</p>
</div>
</li>
<li>
<span class="primary icon gray">
<i class="material-icons">grid_view</i>
</span>
<span class="control">
<div class="radio">
<input name="pubsub#type" value="urn:xmpp:pubsub-social-gallery:0"
id="pubsub_type_gallery" type="radio"
{if="$config['pubsub#type'] == 'urn:xmpp:pubsub-social-gallery:0'"}checked{/if}>
<label for="pubsub_type_gallery"></label>
</div>
</span>
<div>
<p>{$c->__('communityconfig.type_gallery_title')}</p>
<p>{$c->__('communityconfig.type_gallery_text')}</p>
</div>
</li>
</ul>
<label>{$c->__('communityconfig.type')}</label>
</div>
{else}
{autoescape="off"}
{$form}

5
app/widgets/CommunityConfig/locales.ini

@ -7,3 +7,8 @@ publish_model_publishers_title = Publishers
publish_model_publishers_text = The publishers can publish
publish_model_subscribers_title = Subscribers
publish_model_subscribers_text = The subscribers can publish
type = Community type
type_articles_title = Articles
type_articles_text = Publish and read articles
type_gallery_title = Gallery
type_gallery_text = Publish and browser pictures

6
app/widgets/CommunityData/_communitydata_card.tpl

@ -57,6 +57,12 @@
<i class="material-icons icon-text">assignment_turned_in</i>
{$c->__('communitydata.publishmodel_subscribers')}
{/if}
{if="$info->isGallery()"}
<br />
<i class="material-icons icon-text">grid_view</i>
{$c->__('communityconfig.type_gallery_title')}
{/if}
</p>
</div>
</li>

10
app/widgets/CommunityPosts/CommunityPosts.php

@ -165,6 +165,10 @@ class CommunityPosts extends Base
}
}
$info = \App\Info::where('server', $origin)
->where('node', $node)
->first();
$view = $this->tpl();
$view->assign('server', $origin);
@ -174,16 +178,14 @@ class CommunityPosts extends Base
$view->assign('posts', $postsWithKeys);
$view->assign('before', $before);
$view->assign('after', $after);
$view->assign('info', \App\Info::where('server', $origin)
->where('node', $node)
->first());
$view->assign('info', $info);
$view->assign('subscription', $this->user->subscriptions()
->where('server', $origin)
->where('node', $node)
->first());
$view->assign('paging', $this->_paging);
$view->assign('gallery', isPostGallery($posts));
$view->assign('gallery', $info && $info->isGallery());
$view->assign('publicposts', ($ids == false)
? \App\Post::where('server', $origin)

21
database/migrations/20230303224825_add_type_to_infos_table.php

@ -0,0 +1,21 @@
<?php
use Movim\Migration;
use Illuminate\Database\Schema\Blueprint;
class AddTypeToInfosTable extends Migration
{
public function up()
{
$this->schema->table('infos', function (Blueprint $table) {
$table->string('type', 256)->nullable()->index();
});
}
public function down()
{
$this->schema->table('infos', function (Blueprint $table) {
$table->dropColumn('type');
});
}
}

14
doap.xml

@ -466,6 +466,13 @@
<xmpp:version>0.2.0</xmpp:version>
</xmpp:SupportedXep>
</implements>
<implements>
<xmpp:SupportedXep>
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0426.html"/>
<xmpp:status>complete</xmpp:status>
<xmpp:version>0.3.0</xmpp:version>
</xmpp:SupportedXep>
</implements>
<implements>
<xmpp:SupportedXep>
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0444.html"/>
@ -480,6 +487,13 @@
<xmpp:version>0.1.0</xmpp:version>
</xmpp:SupportedXep>
</implements>
<implements>
<xmpp:SupportedXep>
<xmpp:xep rdf:resource="https://xmpp.org/extensions/xep-0472.html"/>
<xmpp:status>partial</xmpp:status>
<xmpp:version>0.1.1</xmpp:version>
</xmpp:SupportedXep>
</implements>
<release>
<Version>

Loading…
Cancel
Save