Update signals to user-statistics are now sent properly

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@122597 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-01-28 14:28:06 +00:00
parent 62220fa99c
commit e21b0d9e94
3 changed files with 111 additions and 52 deletions

View File

@ -11,6 +11,7 @@ import org.gcube.portlets.user.gcubewidgets.client.ClientScopeHelper;
import org.gcube.portlets.user.newsfeed.client.event.PageBusEvents;
import org.gcube.portlets.user.newsfeed.client.panels.NewsFeedPanel;
import org.jsonmaker.gwt.client.Jsonizer;
import org.jsonmaker.gwt.client.base.Defaults;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
@ -67,8 +68,7 @@ public class NewsFeed implements EntryPoint {
mainPanel.addJustAddedFeed(feed);
// alert the User statistics portlet to increment the number of user's posts
// TODO
// pageBusAdapter.PageBusPublish(PageBusEvents.postIncrement, "", Defaults.STRING_JSONIZER);
pageBusAdapter.PageBusPublish(PageBusEvents.postIncrement, "", Defaults.STRING_JSONIZER);
} catch (PageBusAdapterException e) {
e.printStackTrace();

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import net.eliasbalasis.tibcopagebus4gwt.client.PageBusAdapterException;
import org.gcube.portal.databook.client.GCubeSocialNetworking;
import org.gcube.portal.databook.client.util.Encoder;
@ -16,6 +17,7 @@ import org.gcube.portal.databook.shared.Like;
import org.gcube.portal.databook.shared.PrivacyLevel;
import org.gcube.portal.databook.shared.UserInfo;
import org.gcube.portlets.user.newsfeed.client.FilterType;
import org.gcube.portlets.user.newsfeed.client.NewsFeed;
import org.gcube.portlets.user.newsfeed.client.NewsService;
import org.gcube.portlets.user.newsfeed.client.NewsServiceAsync;
import org.gcube.portlets.user.newsfeed.client.event.AddCommentEvent;
@ -30,6 +32,7 @@ import org.gcube.portlets.user.newsfeed.client.event.EditCommentEvent;
import org.gcube.portlets.user.newsfeed.client.event.EditCommentEventHandler;
import org.gcube.portlets.user.newsfeed.client.event.OpenFeedEvent;
import org.gcube.portlets.user.newsfeed.client.event.OpenFeedEventHandler;
import org.gcube.portlets.user.newsfeed.client.event.PageBusEvents;
import org.gcube.portlets.user.newsfeed.client.event.SeeCommentsEvent;
import org.gcube.portlets.user.newsfeed.client.event.SeeCommentsEventHandler;
import org.gcube.portlets.user.newsfeed.client.event.SeeLikesEvent;
@ -58,6 +61,7 @@ import org.gcube.portlets.widgets.userselection.client.events.SelectedUserEvent;
import org.gcube.portlets.widgets.userselection.client.events.SelectedUserEventHandler;
import org.gcube.portlets.widgets.userselection.client.events.UsersFetchedEvent;
import org.gcube.portlets.widgets.userselection.shared.ItemSelectableBean;
import org.jsonmaker.gwt.client.base.Defaults;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.RunAsyncCallback;
@ -542,11 +546,33 @@ public class NewsFeedPanel extends Composite {
final TweetTemplate tt = new TweetTemplate(myUserInfo, feed, eventBus, true);
newsPanel.insert(tt, 0); //insert in the view
allUpdates.add(0, feed); //insert in the model
//timer for the transition
Timer t = new Timer() {
@Override
public void run() {
tt.setcontentAreaStyle("visible");
// alert the user-statistics portlet to update statistics in case
// one or more feed belongs to user himself
if(tt.isUser()){
try{
NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.postIncrement, "", Defaults.STRING_JSONIZER);
int numComments = tt.numberOfComments();
int numLikes = tt.numberOfLikes();
for(int i = 0; i < numComments; i++)
NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.commentsIncrement, "", Defaults.STRING_JSONIZER);
for(int i = 0; i < numLikes; i++)
NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.likesIncrement, "", Defaults.STRING_JSONIZER);
}catch (PageBusAdapterException ex) {
GWT.log(ex.toString());
}
}
}
};
t.schedule(100);
@ -889,12 +915,26 @@ public class NewsFeedPanel extends Composite {
public void onSuccess(Boolean result) {
if (!result) {
doShowSessionExpired();
} else{
// alert the User statistics portlet to increment the number of likes got
if(owner.isUser()){
try {
NewsFeed.pageBusAdapter.PageBusPublish(
PageBusEvents.likesIncrement
, ""
, Defaults.STRING_JSONIZER);
} catch (PageBusAdapterException ex) {
GWT.log(ex.toString());
}
}
}
}
});
}
protected void doUnLike(TweetTemplate owner, String feedId) {
protected void doUnLike(final TweetTemplate owner, String feedId) {
newsService.unlike(feedId, owner.getMyFeedText(), owner.getMyFeedUserId(), new AsyncCallback<Boolean>() {
@Override
public void onFailure(Throwable caught) {}
@ -902,6 +942,20 @@ public class NewsFeedPanel extends Composite {
public void onSuccess(Boolean result) {
if (!result) {
doShowSessionExpired();
}else{
// alert the User statistics portlet to decrement the number of likes got
if(owner.isUser()){
try {
NewsFeed.pageBusAdapter.PageBusPublish(
PageBusEvents.likesDecrement
, ""
, Defaults.STRING_JSONIZER);
} catch (PageBusAdapterException ex) {
GWT.log(ex.toString());
}
}
}
}
});
@ -970,15 +1024,14 @@ public class NewsFeedPanel extends Composite {
owner.updateCommentsNumberCount();
owner.showAddCommentForm(false);
/*if(owner.isUser()){
* TODO
if(owner.isUser()){
// alert the User statistics portlet to increment the number of comments got
try {
NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.commentsIncrement, "", Defaults.STRING_JSONIZER);
} catch (PageBusAdapterException e) {
GWT.log(e.toString());
}
}*/
}
}
}
else {
@ -1054,14 +1107,14 @@ public class NewsFeedPanel extends Composite {
doShowComments(owner, false);
owner.updateCommentsNumberCount();
/*if(owner.isUser()){ TODO
if(owner.isUser()){
// alert the User statistics portlet to decrement the number of comments got
try {
NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.commentsDecrement, "", Defaults.STRING_JSONIZER);
} catch (PageBusAdapterException ex) {
GWT.log(ex.toString());
}
}*/
}
} else
Window.alert("Comment could not be deleted, please try again in a short while.");
}
@ -1083,16 +1136,25 @@ public class NewsFeedPanel extends Composite {
if (result) {
toDelete.removeFromParent();
// alert the user-statistics portlet to reduce the number of likes and replies
// there were
/*if(toDelete.isUser()){
int numComments = toDelete.get
try {
NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.commentsDecrement, "", Defaults.STRING_JSONIZER);
} catch (PageBusAdapterException ex) {
if(toDelete.isUser()){
try{
// alert the User statistics portlet to decrement the number of user's posts
NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.postDecrement, "", Defaults.STRING_JSONIZER);
// alert the same portlet to decrement the number of likes/replies, if any
int numComments = toDelete.numberOfComments();
int numLikes = toDelete.numberOfLikes();
for(int i = 0; i < numComments; i++)
NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.commentsDecrement, "", Defaults.STRING_JSONIZER);
for(int i = 0; i < numLikes; i++)
NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.likesDecrement, "", Defaults.STRING_JSONIZER);
}catch (PageBusAdapterException ex) {
GWT.log(ex.toString());
}
}*/
}
} else
Window.alert("Feed could not be deleted, please try again in a short while.");
}

View File

@ -418,18 +418,6 @@ public class TweetTemplate extends Composite {
void onDeleteFeedClick(ClickEvent e) {
if (isUsers || myUserInfo.isAdmin()){
eventBus.fireEvent(new DeleteFeedEvent(this));
/*if(isUsers){
try { TODO
// alert the User statistics portlet to decrement the number of user's posts
NewsFeed.pageBusAdapter.PageBusPublish(PageBusEvents.postDecrement, "", Defaults.STRING_JSONIZER);
} catch (PageBusAdapterException e1) {
GWT.log("Unable to send this notification " + e1.toString());
}
}*/
}
else {
GWT.log("not belong to user");
@ -488,18 +476,6 @@ public class TweetTemplate extends Composite {
}
eventBus.fireEvent(new AddLikeEvent(this, myFeed.getFeed().getKey()));
setFavoritedUI(true);
// alert the User statistics portlet to increment the number of likes got TODO
/*if(isUsers){
try {
NewsFeed.pageBusAdapter.PageBusPublish(
PageBusEvents.likesIncrement
, ""
, Defaults.STRING_JSONIZER);
} catch (PageBusAdapterException ex) {
GWT.log(e.toString());
}
}*/
}
catch (NumberFormatException ex) {
likeArea.setHTML("Error on the server");
@ -519,18 +495,6 @@ public class TweetTemplate extends Composite {
}
eventBus.fireEvent(new UnLikeEvent(this, myFeed.getFeed().getKey()));
setFavoritedUI(false);
// alert the User statistics portlet to decrement the number of likes got
/*if(isUsers){ TODO
try {
NewsFeed.pageBusAdapter.PageBusPublish(
PageBusEvents.likesDecrement
, ""
, Defaults.STRING_JSONIZER);
} catch (PageBusAdapterException ex) {
GWT.log(e.toString());
}
}*/
}
}
@ -702,4 +666,37 @@ public class TweetTemplate extends Composite {
public boolean isUser() {
return isUsers;
}
/**
* Returns the number of comments this post has
* @return
*/
public int numberOfComments(){
// quite easy..
return myComments.size();
}
/**
* Returns the number of likes this post has
* @return
*/
public int numberOfLikes(){
// not so easy
int ret = 0;
try{
ret = Integer.parseInt(likesNo.getHTML());
}catch(NumberFormatException e){
GWT.log(e.toString());
}
return ret;
}
}