Commit 9fe3b884 authored by Yorre Rajaonarivelo's avatar Yorre Rajaonarivelo
Browse files

update activitypub

parent 91417a0d
......@@ -16,6 +16,8 @@ use News;
use NewsTranslator;
use Organization;
use Person;
use PixelHumain\PixelHumain\modules\citizenToolKit\models\activitypub\ActivitypubObject;
use PixelHumain\PixelHumain\modules\citizenToolKit\models\activitypub\ActivitypubTranslator;
use Project;
use Rest;
use Yii;
......@@ -315,26 +317,33 @@ class GetAction extends \PixelHumain\PixelHumain\components\Action
}
}
if(!empty($where)){
//add news from activitypub
$where = News::addParamsForNewsFromActivitypub($where);
$limit=(@$_POST["indexStep"]) ? $_POST["indexStep"] : 6;
$news= News::getNewsForObjectId($where, array("sharedBy.updated"=>-1), $type, $limit, @$followsArrayIds);
$params["endStream"]=(count($news) == $limit) ? false : true;
foreach ($news as $key => $newsItem) {
if(@$newsItem["type"]){
$newNews=NewsTranslator::convertParamsForNews($newsItem, false, @$followsArrayIds);
if(!empty($newNews))
$news[$key]=$newNews;
else{
$removeNews=true;
$removeNewsArray[$key]=$newsItem;
$removeNewsUpdated=$news[$key];
unset($news[$key]);
if(@$newsItem["type"]){
if($newsItem["type"] === "activitypub"){
$note = ActivitypubObject::getObjectByUUID($newsItem["objectUUID"]);
$news[$key]["note"] = ActivitypubTranslator::noteToNewsMedia($note);
}else{
$newNews=NewsTranslator::convertParamsForNews($newsItem, false, @$followsArrayIds);
if(!empty($newNews))
$news[$key]=$newNews;
else{
$removeNews=true;
$removeNewsArray[$key]=$newsItem;
$removeNewsUpdated=$news[$key];
unset($news[$key]);
}
}
}
}
}
}
// Sort news order by created
$news = News::sortNews($news, array('updated'=>SORT_DESC));
//remove activityStream if user connected can't access his parentRoom (because of room role access)
$news = Cooperation::checkRoleAccessInNews($news);
//TODO : reorganise by created date
......
......@@ -795,5 +795,37 @@ class News {
if(Authorisation::isElementAdmin($parentId, $parentType, $userId)) return true;
if(count(Authorisation::listAdmins($parentId, $parentType, false)) == 0 && Authorisation::canParticipate($userId, $parentType, $parentId)) return true;
}
public static function addParamsForNewsFromActivitypub($params){
$connectedUser = Person::getById(Yii::app()->session["userId"]);
$activitypubEnable = isset($connectedUser["preferences"]["notifications"]["desableActivitypub"]);
if($activitypubEnable){
$activitypubParams = ["type" => "activitypub"];
if(isset($params["sharedBy.updated"]))
$activitypubParams["sharedBy.updated"] = $params["sharedBy.updated"];
$connectedUser_ap_follows = [];
if(isset($connectedUser["links"]["activitypub"]["follows"])){
foreach($connectedUser["links"]["activitypub"]["follows"] as $follow){
$connectedUser_ap_follows[] = $follow["invitorId"];
}
}
$activitypubParams["sharedBy.id"] = [
'$in' => $connectedUser_ap_follows
];
$params = [
'$or' => [
$params,
$activitypubParams
]
];
}
return $params;
}
}
?>
\ No newline at end of file
<style>
.newsContent p{
font-size: 18px !important;
}
.timeline-footer .tpap-actions{
margin: 0;
padding: 10px 0px;
font-weight: 700;
font-size: 18px;
}
.timeline-footer .tpap-actions li{
display: inline-block;
margin-right: 10px;
}
.timeline-footer .tpap-actions li a{
text-decoration: none;
}
.timeline-footer .tpap-actions li a span{
margin-left: 5px;
}
</style>
<div class="timeline-heading text-center ">
<h5 class="text-left srcMedia">
<?php $author = $media["note"]["author"]; ?>
<small>
<img class="pull-left img-circle" src="<?= $author['avatar'] ?>" height="40">
<div class="pull-left padding-5 col-md-7 col-sm-7 text-left" style="line-height: 15px;">
<a href="<?= $author['id'] ?>" target="__blank"><?= $author['name'] ?></a>
<br>
<span class="margin-top-5">
<a href="<?= $author['id'] ?>" target="__blank"><?= $author['address'] ?></a>
</span>
</div>
</small>
<span class="margin-top-10 margin-bottom-10 pull-right">
<small id="time-<?= $key ?>" data-updated="<?= $media["created"]->sec ?>"></small>
</span>
</h5>
</div>
<div class="timeline-body col-xs-12 text-left margin-bottom-15 margin-top-15">
<div class="newsContent no-padding"><?= $media["note"]["content"] ?></div>
<?php foreach($media["note"]["attachments"] as $attachment){ ?>
<div class="bg-white results col-md-12 col-sm-12 col-xs-12 no-padding">
<div class="col-md-12 no-padding margin-top-10 margin-bottom-10">
<a class="thumb-info" href="<?= $attachment ?>" target="__blank">
<img src="<?= $attachment ?>" class="img-responsive"/>
</a>
</div>
</div>
<?php } ?>
</div>
<div class="timeline-footer pull-left col-md-12 col-sm-12 col-xs-12 padding-top-5">
<div class="col-xs-12 pull-left padding-5">
<ul class="tpap-actions">
<li>
<a href="javascript:;" class="newsAddComment" data-media-id="<?= $key ?>" data-type="activitypub">
<i class="fa fa-comment"></i>
<?=($media["note"]["nbReplies"]>0)?'<span>'.$media["note"]["nbReplies"].'</span>':'' ?>
Commentaire
</a>
</li>
<!-- <li><a href="javascript:;" class="letter-blue"><i class="fa fa-thumbs-up"></i><span>5</span> J’aime</span></a></li> -->
</ul>
</div>
<div class="col-md-12 col-sm-12 col-xs-12 no-padding pull-left margin-top-10" id="commentContent<?= $key ?>"></div>
</div>
<script>
$(function(){
$el = $("#time-<?= $key ?>")
$time = directory.showDatetimePost(null, "<?=$key?>", $el.data("updated"))
$el.html($time)
})
</script>
......@@ -102,9 +102,17 @@ if(@$inline && $inline){
}
}
foreach($news as $key => $media){
$class = $pair || ($nbCol == 1) ? "timeline-inverted" : "";
$pair = !$pair;
if(isset($media["type"]) && $media["type"] === "activitypub"){
?>
<li class="<?= $class; ?> <?= $classLi ?> list-news" id="<?= @$media["type"]; ?><?= $key; ?>">
<div class="timeline-panel">
<?= $this->renderPartial('news.views.co.timelinePanelActivitypub', ["key"=>$key, "media"=>$media]) ?>
</div>
</li>
<?php }else{
// Author name and thumb
if(@$media["targetIsAuthor"] || $media["type"]=="activityStream"){
if(@$media["target"]["profilThumbImageUrl"] && $media["target"]["profilThumbImageUrl"] != "")
......@@ -187,7 +195,7 @@ foreach($news as $key => $media){
<?php //} ?>
</div>
</li>
<?php } ?>
<?php }} ?>
<?php if(!(@$isFirst == true) && isset($limitDate) && isset($limitDate["created"])){ ?>
<input class="dateLimit" type="hidden" value="<?php echo (is_string($limitDate["created"])) ? $limitDate["created"] : $limitDate["created"]->sec; ?>">
<?php } ?>
......@@ -221,21 +229,25 @@ foreach($news as $key => $media){
//var viewMode = "<?php echo @$viewMode ?>";
jQuery(document).ready(function() {
$.each(news, function(e,v){
updateNews[e]= v;
if(typeof v._id.$id != "undefined")
if($("#news-list .newsActivityStream"+v._id.$id).length>0)
$("#news-list #news"+v._id.$id).remove();
//do not apply the default behavior if it is activitypub type news
if(v.type !== "activitypub")
return false;
updateNews[e]= v;
if(typeof v._id.$id != "undefined")
if($("#news-list .newsActivityStream"+v._id.$id).length>0)
$("#news-list #news"+v._id.$id).remove();
if(typeof v.object != "undefined"){
if($("#news-list .newsActivityStream"+v.object.id).length>0)
$("#news-list #news"+v.object.id).remove();
if(typeof v.object != "undefined"){
if($("#news-list .newsActivityStream"+v.object.id).length>0)
$("#news-list #news"+v.object.id).remove();
$("#news-list .newsActivityStream"+v.object.id).each(function(b, ob){
if(b>0) {
var parent = $(ob).parent().parent().parent();
parent.remove();
}
});
$("#news-list .newsActivityStream"+v.object.id).each(function(b, ob){
if(b>0) {
var parent = $(ob).parent().parent().parent();
parent.remove();
}
});
if(v.object.type != "news"){
renderType=(v.object.collection=="proposal") ? "directory.coopPanelHtml" :"directory.elementPanelHtml";
var html = directory.showResultsDirectoryHtml(new Array(v.object), renderType);
......@@ -245,6 +257,10 @@ foreach($news as $key => $media){
});
$.each(news, function(e,v){
//do not apply the default behavior if it is activitypub type news
if(v.type !== "activitypub")
return false;
tags = "",
scopes = "",
tagsClass = "",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment