|
|
|
@ -6,7 +6,6 @@ package org.gcube.portlets.user.newsfeed.client.ui;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import org.gcube.common.portal.GCubePortalConstants;
|
|
|
|
|
import org.gcube.portal.databook.client.GCubeSocialNetworking;
|
|
|
|
@ -28,7 +27,6 @@ import org.gcube.portlets.widgets.imagepreviewerwidget.client.ui.Carousel;
|
|
|
|
|
|
|
|
|
|
import com.github.gwtbootstrap.client.ui.Button;
|
|
|
|
|
import com.google.gwt.core.client.GWT;
|
|
|
|
|
import com.google.gwt.core.client.RunAsyncCallback;
|
|
|
|
|
import com.google.gwt.dom.client.Style.Unit;
|
|
|
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
|
|
|
@ -40,12 +38,12 @@ import com.google.gwt.uibinder.client.UiBinder;
|
|
|
|
|
import com.google.gwt.uibinder.client.UiField;
|
|
|
|
|
import com.google.gwt.uibinder.client.UiHandler;
|
|
|
|
|
import com.google.gwt.user.client.Timer;
|
|
|
|
|
import com.google.gwt.user.client.Window;
|
|
|
|
|
import com.google.gwt.user.client.Window.Location;
|
|
|
|
|
import com.google.gwt.user.client.ui.Composite;
|
|
|
|
|
import com.google.gwt.user.client.ui.HTML;
|
|
|
|
|
import com.google.gwt.user.client.ui.HTMLPanel;
|
|
|
|
|
import com.google.gwt.user.client.ui.Image;
|
|
|
|
|
import com.google.gwt.user.client.ui.InlineLabel;
|
|
|
|
|
import com.google.gwt.user.client.ui.Label;
|
|
|
|
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
|
|
|
|
import com.google.gwt.user.client.ui.Widget;
|
|
|
|
@ -66,9 +64,9 @@ public class TweetTemplate extends Composite {
|
|
|
|
|
|
|
|
|
|
public static final String loading = GWT.getModuleBaseURL() + "../images/loading-comments.gif";
|
|
|
|
|
|
|
|
|
|
private static final int MAX_SHOWTEXT_LENGTH = 256;
|
|
|
|
|
private static final int MAX_SHOWTEXT_LENGTH = 512;
|
|
|
|
|
|
|
|
|
|
private EnhancedFeed myFeed;
|
|
|
|
|
private EnhancedFeed myPost;
|
|
|
|
|
private UserInfo myUserInfo;
|
|
|
|
|
|
|
|
|
|
private HandlerManager eventBus;
|
|
|
|
@ -77,7 +75,7 @@ public class TweetTemplate extends Composite {
|
|
|
|
|
private boolean commentsFetched = false;
|
|
|
|
|
private int totalComments = 0;
|
|
|
|
|
private HTML showAllComments = new HTML();
|
|
|
|
|
private boolean isAppFeed = false;
|
|
|
|
|
private boolean isAppPost = false;
|
|
|
|
|
private HTML submitCommentPreloader = new HTML("<div class=\"more-comment\"><img style=\"padding-right:15px;\"src=\""+ loading +"\" /></div>");
|
|
|
|
|
private TweetTemplate myInstance;
|
|
|
|
|
|
|
|
|
@ -92,16 +90,20 @@ public class TweetTemplate extends Composite {
|
|
|
|
|
@UiField
|
|
|
|
|
HTML contentArea;
|
|
|
|
|
@UiField
|
|
|
|
|
HTML postOwnerArea;
|
|
|
|
|
@UiField
|
|
|
|
|
HTML seeMore;
|
|
|
|
|
@UiField
|
|
|
|
|
HTML timeArea;
|
|
|
|
|
InlineLabel timeArea;
|
|
|
|
|
@UiField
|
|
|
|
|
InlineLabel separator;
|
|
|
|
|
@UiField
|
|
|
|
|
InlineLabel vreSourceInMetadata;
|
|
|
|
|
@UiField
|
|
|
|
|
HTML likeArea;
|
|
|
|
|
@UiField
|
|
|
|
|
HTML commentArea;
|
|
|
|
|
@UiField
|
|
|
|
|
HTML sharePostArea;
|
|
|
|
|
@UiField
|
|
|
|
|
Image avatarImage;
|
|
|
|
|
@UiField
|
|
|
|
|
AvatarReplacement avatarReplacement;
|
|
|
|
@ -118,8 +120,6 @@ public class TweetTemplate extends Composite {
|
|
|
|
|
@UiField
|
|
|
|
|
HTML openImage;
|
|
|
|
|
@UiField
|
|
|
|
|
HTML vreSource;
|
|
|
|
|
@UiField
|
|
|
|
|
VerticalPanel previewPanel;
|
|
|
|
|
@UiField
|
|
|
|
|
Placeholder attachmentPreviewPanel;
|
|
|
|
@ -128,12 +128,12 @@ public class TweetTemplate extends Composite {
|
|
|
|
|
/**
|
|
|
|
|
* used when fetching tweets from server
|
|
|
|
|
* @param myUserInfo
|
|
|
|
|
* @param myFeed
|
|
|
|
|
* @param myPost
|
|
|
|
|
* @param isUsers
|
|
|
|
|
* @param displaySingle tells if you're displaying a single fedd or not
|
|
|
|
|
* @param eventBus
|
|
|
|
|
*/
|
|
|
|
|
public TweetTemplate(boolean displaySingle, boolean showTimelineSource, UserInfo myUserInfo, EnhancedFeed myFeed, HandlerManager eventBus) {
|
|
|
|
|
public TweetTemplate(boolean displaySingle, boolean showTimelineSource, UserInfo myUserInfo, EnhancedFeed myPost, HandlerManager eventBus) {
|
|
|
|
|
initWidget(uiBinder.createAndBindUi(this));
|
|
|
|
|
commentsNo.getElement().getStyle().setPaddingTop(0, Unit.PX);
|
|
|
|
|
likesNo.getElement().getStyle().setPaddingTop(0, Unit.PX);
|
|
|
|
@ -144,12 +144,13 @@ public class TweetTemplate extends Composite {
|
|
|
|
|
|
|
|
|
|
myInstance = this;
|
|
|
|
|
this.myUserInfo = myUserInfo;
|
|
|
|
|
this.vreSource.setVisible(false);
|
|
|
|
|
this.myFeed = myFeed;
|
|
|
|
|
isAppFeed = myFeed.getFeed().isApplicationFeed();
|
|
|
|
|
Feed feed = myFeed.getFeed();
|
|
|
|
|
this.vreSourceInMetadata.setVisible(false);
|
|
|
|
|
this.separator.setVisible(false);
|
|
|
|
|
this.myPost = myPost;
|
|
|
|
|
isAppPost = myPost.getFeed().isApplicationFeed();
|
|
|
|
|
Feed feed = myPost.getFeed();
|
|
|
|
|
this.eventBus = eventBus;
|
|
|
|
|
this.isUsers = myFeed.isUsers();
|
|
|
|
|
this.isUsers = myPost.isUsers();
|
|
|
|
|
this.carousel = new Carousel();
|
|
|
|
|
myComments = new ArrayList<SingleComment>();
|
|
|
|
|
|
|
|
|
@ -248,7 +249,7 @@ public class TweetTemplate extends Composite {
|
|
|
|
|
attachmentPreviewPanel.add(firstAttachmentPreviewer);
|
|
|
|
|
|
|
|
|
|
// check the others
|
|
|
|
|
for (Attachment otherAttachment : myFeed.getAttachments()) {
|
|
|
|
|
for (Attachment otherAttachment : myPost.getAttachments()) {
|
|
|
|
|
|
|
|
|
|
AttachmentPreviewer attachmentPreviewer = new AttachmentPreviewer(otherAttachment);
|
|
|
|
|
|
|
|
|
@ -291,7 +292,7 @@ public class TweetTemplate extends Composite {
|
|
|
|
|
openImage.setStyleName("openImage");
|
|
|
|
|
openImage.setTitle("Open this feed separately");
|
|
|
|
|
//show if the user has already liked this or not
|
|
|
|
|
setFavoritedUI(myFeed.isLiked());
|
|
|
|
|
setFavoritedUI(myPost.isLiked());
|
|
|
|
|
|
|
|
|
|
commentArea.setHTML("<a>" + NewsFeedPanel.COMMENT_LABEL + "</a>");
|
|
|
|
|
|
|
|
|
@ -305,7 +306,7 @@ public class TweetTemplate extends Composite {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
avatarImage.setUrl(feed.getThumbnailURL());
|
|
|
|
|
avatarImage.setPixelSize(50, 50);
|
|
|
|
|
avatarImage.setPixelSize(40, 40);
|
|
|
|
|
|
|
|
|
|
//replace the < & and >
|
|
|
|
|
feedText = feedText.replaceAll("<","<").replaceAll(">",">");
|
|
|
|
@ -313,19 +314,28 @@ public class TweetTemplate extends Composite {
|
|
|
|
|
|
|
|
|
|
final String profilePageURL = GCubePortalConstants.PREFIX_GROUP_URL + NewsFeedPanel.extractOrgFriendlyURL(Location.getHref()) +GCubePortalConstants.USER_PROFILE_FRIENDLY_URL;
|
|
|
|
|
|
|
|
|
|
//show the vreid iff the info is present
|
|
|
|
|
this.vreSource.setVisible(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (showTimelineSource && feed.getVreid() != null && feed.getVreid().compareTo("") != 0) {
|
|
|
|
|
this.vreSourceInMetadata.setVisible(true);
|
|
|
|
|
this.separator.setVisible(true);
|
|
|
|
|
String vreName = feed.getVreid().substring(feed.getVreid().lastIndexOf("/")+1);
|
|
|
|
|
vreSource.setHTML("<a class=\"link\" style=\"font-size: 10px; white-space: nowrap;\" href=\"/group/"+vreName.toLowerCase()+"\">[" +vreName + "]</a>");
|
|
|
|
|
vreSourceInMetadata.setText(vreName);
|
|
|
|
|
vreSourceInMetadata.addClickHandler(new ClickHandler() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
|
Location.assign("/group/"+vreName.toLowerCase());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (! isAppFeed) {
|
|
|
|
|
|
|
|
|
|
if (! isAppPost) {
|
|
|
|
|
// sharePostArea.setHTML("<a>" + NewsFeedPanel.SHARE_FWD_LABEL + "</a>");
|
|
|
|
|
contentArea.setHTML("<a class=\"link\" href=\""+profilePageURL
|
|
|
|
|
postOwnerArea.setHTML("<a class=\"linkProfile\" href=\""+profilePageURL
|
|
|
|
|
+"?"+
|
|
|
|
|
Encoder.encode(GCubeSocialNetworking.USER_PROFILE_OID)+"="+
|
|
|
|
|
Encoder.encode(feed.getEntityId())+"\">"+feed.getFullName()+"</a> " + feedText);
|
|
|
|
|
Encoder.encode(feed.getEntityId())+"\">"+feed.getFullName()+"</a>");
|
|
|
|
|
contentArea.setHTML(feedText);
|
|
|
|
|
|
|
|
|
|
//check if the user has his own avatar
|
|
|
|
|
if (feed.getThumbnailURL().contains("img_id=0") || !feed.getThumbnailURL().contains("?")) { //it means no avatar is set
|
|
|
|
@ -348,17 +358,14 @@ public class TweetTemplate extends Composite {
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// messageSeparator.setVisible(false);
|
|
|
|
|
contentArea.setHTML("<a class=\"link\" href=\""+feed.getUri()+"\">"+feed.getFullName()+"</a> " + feedText);
|
|
|
|
|
if (isAppFeed) {
|
|
|
|
|
postOwnerArea.setHTML("<a class=\"linkProfile\" href=\""+feed.getUri()+"\">"+feed.getFullName()+"</a>");
|
|
|
|
|
contentArea.setHTML(feedText);
|
|
|
|
|
|
|
|
|
|
if (isAppPost) {
|
|
|
|
|
if (myUserInfo.isAdmin())
|
|
|
|
|
closeImage.setTitle("Delete this Application feed (Administrator Only)");
|
|
|
|
|
else
|
|
|
|
|
closeImage.removeFromParent();
|
|
|
|
|
try{
|
|
|
|
|
String vreName = feed.getVreid().substring(feed.getVreid().lastIndexOf("/")+1);
|
|
|
|
|
sharePostArea.setHTML("<a class=\"link\" style=\"white-space: nowrap;\" href=\""+feed.getUri()+"\"> - go App [" +vreName + "] - </a>");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e) {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -372,7 +379,7 @@ public class TweetTemplate extends Composite {
|
|
|
|
|
else
|
|
|
|
|
formattedTime = DateTimeFormat.getFormat("MMMM dd, h:mm a").format(feed.getTime());
|
|
|
|
|
|
|
|
|
|
timeArea.setHTML(formattedTime);
|
|
|
|
|
timeArea.setText(formattedTime);
|
|
|
|
|
String formattedTimeWithYear = DateTimeFormat.getFormat("dd MMMM yyyy h:mm a ").format(feed.getTime());
|
|
|
|
|
timeArea.setTitle(formattedTimeWithYear);
|
|
|
|
|
if (! feed.getCommentsNo().equals("0")) {
|
|
|
|
@ -391,16 +398,16 @@ public class TweetTemplate extends Composite {
|
|
|
|
|
totalComments = 0;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e) {
|
|
|
|
|
timeArea.setHTML("just now");
|
|
|
|
|
timeArea.setText("just now");
|
|
|
|
|
}
|
|
|
|
|
commentsPanel.setStyleName("commentsPanel");
|
|
|
|
|
if (myFeed.getComments() != null && myFeed.getComments().size() > 0) {
|
|
|
|
|
if (myPost.getComments() != null && myPost.getComments().size() > 0) {
|
|
|
|
|
if (totalComments > 2 && !displaySingle) {
|
|
|
|
|
showAllComments = getShowAllCommentsLink(totalComments);
|
|
|
|
|
commentsPanel.add(showAllComments);
|
|
|
|
|
commentsNo.setVisible(true);
|
|
|
|
|
}
|
|
|
|
|
for (Comment comment : myFeed.getComments()) {
|
|
|
|
|
for (Comment comment : myPost.getComments()) {
|
|
|
|
|
addComment(new SingleComment(comment, this, (comment.getUserid().equals(myUserInfo.getUsername()))));
|
|
|
|
|
}
|
|
|
|
|
showAddCommentForm(false);
|
|
|
|
@ -455,7 +462,7 @@ public class TweetTemplate extends Composite {
|
|
|
|
|
|
|
|
|
|
@UiHandler("seeMore")
|
|
|
|
|
void onSeeMoreClick(ClickEvent e) {
|
|
|
|
|
String feedText = myFeed.getFeed().getDescription();
|
|
|
|
|
String feedText = myPost.getFeed().getDescription();
|
|
|
|
|
//replace the < & and >
|
|
|
|
|
feedText = feedText.replaceAll("<","<").replaceAll(">",">");
|
|
|
|
|
feedText = feedText.replaceAll("&","&");
|
|
|
|
@ -465,8 +472,8 @@ public class TweetTemplate extends Composite {
|
|
|
|
|
|
|
|
|
|
contentArea.setHTML("<a class=\"link\"href=\"" + profilePageURL + "?"+
|
|
|
|
|
Encoder.encode(GCubeSocialNetworking.USER_PROFILE_OID)+"="+
|
|
|
|
|
Encoder.encode(myFeed.getFeed().getEntityId())+"\">"+
|
|
|
|
|
myFeed.getFeed().getFullName()+"</a> " + feedText);
|
|
|
|
|
Encoder.encode(myPost.getFeed().getEntityId())+"\">"+
|
|
|
|
|
myPost.getFeed().getFullName()+"</a> " + feedText);
|
|
|
|
|
|
|
|
|
|
seeMore.setHTML("");
|
|
|
|
|
}
|
|
|
|
@ -488,19 +495,19 @@ public class TweetTemplate extends Composite {
|
|
|
|
|
//if is not liked
|
|
|
|
|
if (!likeArea.getText().equals(NewsFeedPanel.LIKED_LABEL)) {
|
|
|
|
|
try {
|
|
|
|
|
int cur = Integer.parseInt(myFeed.getFeed().getLikesNo());
|
|
|
|
|
int cur = Integer.parseInt(myPost.getFeed().getLikesNo());
|
|
|
|
|
cur++;
|
|
|
|
|
if (cur == 1) {
|
|
|
|
|
myFeed.getFeed().setLikesNo("1");
|
|
|
|
|
myPost.getFeed().setLikesNo("1");
|
|
|
|
|
likesNo.setText("1");
|
|
|
|
|
likesNo.setTitle("People who have " + NewsFeedPanel.LIKED_LABEL + " this");
|
|
|
|
|
likesNo.setVisible(true);
|
|
|
|
|
} else {
|
|
|
|
|
myFeed.getFeed().setLikesNo(""+cur);
|
|
|
|
|
myPost.getFeed().setLikesNo(""+cur);
|
|
|
|
|
likesNo.setText(""+cur);
|
|
|
|
|
likesNo.setVisible(true);
|
|
|
|
|
}
|
|
|
|
|
eventBus.fireEvent(new AddLikeEvent(this, myFeed.getFeed().getKey()));
|
|
|
|
|
eventBus.fireEvent(new AddLikeEvent(this, myPost.getFeed().getKey()));
|
|
|
|
|
setFavoritedUI(true);
|
|
|
|
|
}
|
|
|
|
|
catch (NumberFormatException ex) {
|
|
|
|
@ -508,19 +515,19 @@ public class TweetTemplate extends Composite {
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
//it is liked
|
|
|
|
|
int cur = Integer.parseInt(myFeed.getFeed().getLikesNo());
|
|
|
|
|
int cur = Integer.parseInt(myPost.getFeed().getLikesNo());
|
|
|
|
|
cur--;
|
|
|
|
|
if (cur == 0) {
|
|
|
|
|
myFeed.getFeed().setLikesNo("0");
|
|
|
|
|
myPost.getFeed().setLikesNo("0");
|
|
|
|
|
likesNo.setText("");
|
|
|
|
|
likesNo.setVisible(false);
|
|
|
|
|
likesNo.setTitle("");
|
|
|
|
|
} else {
|
|
|
|
|
myFeed.getFeed().setLikesNo(""+cur);
|
|
|
|
|
myPost.getFeed().setLikesNo(""+cur);
|
|
|
|
|
likesNo.setText(""+cur);
|
|
|
|
|
likesNo.setVisible(true);
|
|
|
|
|
}
|
|
|
|
|
eventBus.fireEvent(new UnLikeEvent(this, myFeed.getFeed().getKey()));
|
|
|
|
|
eventBus.fireEvent(new UnLikeEvent(this, myPost.getFeed().getKey()));
|
|
|
|
|
setFavoritedUI(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -539,25 +546,6 @@ public class TweetTemplate extends Composite {
|
|
|
|
|
GWT.log("Commenting disabled");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@UiHandler("sharePostArea")
|
|
|
|
|
void onMessageClick(ClickEvent e) {
|
|
|
|
|
if (! isAppFeed) {
|
|
|
|
|
final List<String> listToLogin = new ArrayList<String>();
|
|
|
|
|
listToLogin.add(myFeed.getFeed().getEntityId());
|
|
|
|
|
GWT.runAsync(new RunAsyncCallback() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onSuccess() {
|
|
|
|
|
SharePostDialog dlg = new SharePostDialog(myInstance);
|
|
|
|
|
dlg.openModal();
|
|
|
|
|
}
|
|
|
|
|
public void onFailure(Throwable reason) {
|
|
|
|
|
Window.alert("Could not load this component: " + reason.getMessage());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void showAddCommentForm(boolean focus) {
|
|
|
|
|
final AddCommentTemplate toAdd = new AddCommentTemplate(this, myUserInfo, eventBus);
|
|
|
|
|
commentsPanel.add(toAdd);
|
|
|
|
@ -590,7 +578,7 @@ public class TweetTemplate extends Composite {
|
|
|
|
|
|
|
|
|
|
@UiHandler("likesNo")
|
|
|
|
|
void onSeeLikes(ClickEvent e) {
|
|
|
|
|
eventBus.fireEvent(new SeeLikesEvent(myFeed.getFeed().getKey()));
|
|
|
|
|
eventBus.fireEvent(new SeeLikesEvent(myPost.getFeed().getKey()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@UiHandler("commentsNo")
|
|
|
|
@ -610,7 +598,7 @@ public class TweetTemplate extends Composite {
|
|
|
|
|
this.commentingDisabled = commenting;
|
|
|
|
|
}
|
|
|
|
|
public String getFeedKey() {
|
|
|
|
|
return myFeed.getFeed().getKey();
|
|
|
|
|
return myPost.getFeed().getKey();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void remove(Widget w) {
|
|
|
|
@ -692,15 +680,15 @@ public class TweetTemplate extends Composite {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getMyFeedUserId() {
|
|
|
|
|
return myFeed.getFeed().getEntityId();
|
|
|
|
|
return myPost.getFeed().getEntityId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getMyFeedText() {
|
|
|
|
|
return myFeed.getFeed().getDescription();
|
|
|
|
|
return myPost.getFeed().getDescription();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isAppFeed() {
|
|
|
|
|
return isAppFeed;
|
|
|
|
|
return isAppPost;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isUser() {
|
|
|
|
@ -719,7 +707,7 @@ public class TweetTemplate extends Composite {
|
|
|
|
|
* @return the context (scope) of the Post
|
|
|
|
|
*/
|
|
|
|
|
public String getVREContext() {
|
|
|
|
|
return this.myFeed.getFeed().getVreid();
|
|
|
|
|
return this.myPost.getFeed().getVreid();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|