" +
- "We're sorry, it seems you used an invalid character, please check the hashtag
"));
- return;
- }
- showFeedsByHashtag(hashtag);
- filterPanel.removeFilterSelected();
- }
- else if (getSearchParam() != null) {
- String query = "";
- try {
- query = Encoder.decode(getSearchParam());
- currentQuery = query;
- } catch (Exception e) {
- newsPanel.clear();
- newsPanel.add(new HTML("
" +
- "We're sorry, it seems you used an invalid character, please check the query
"));
- return;
- }
- // show
- isSearch = true;
- showFeedsSearch(query, 0, SEARCHED_FEEDS_TO_SHOW);
- filterPanel.removeFilterSelected();
- }else if(getShowUserStatisticParam() != null){
- String action = "";
- try {
- action = Encoder.decode(getShowUserStatisticParam());
- relatedFeedsToUserStatisticsToShow = ShowUserStatisticAction.valueOf(action);
- } catch (Exception e) {
- newsPanel.clear();
- newsPanel.add(new HTML("
" +
- "We're sorry, it seems you used an invalid character
"));
- return;
- }
- isFeedsRelatedToStatistics = true;
- showUserStatisticsRelatedFeeds(relatedFeedsToUserStatisticsToShow, 0, FEEDS_RELATED_TO_USER_STATISTICS_TO_SHOW);
- filterPanel.removeFilterSelected();
- }
- else {
- if (!result.isInfrastructure())
- filterPanelWrapper.setVisible(getFeedToShowId() == null);
- showAllUpdatesFeeds();
- }
- currentFilter = FilterType.ALL_UPDATES;
- }
- //adjustments in the UI Depending on the scope
- if (result.isInfrastructure()) {
- //filterPanelWrapper.setVisible(getFeedToShowId() == null);
- showFeedTimelineSource = result.isShowTimelineSourceLabel();
- isInfrastructure = true;
- filterPanelWrapper.setVisible(getFeedToShowId() == null);
- }
- }
- });
-
- feedsTimer = new Timer() {
- @Override
- public void run() {
- checkForNewUpdates();
- }
- };
- feedsTimer.scheduleRepeating(delayMillis);
-
- //this is for the automatic scroll of feeds
- Window.addWindowScrollHandler(new ScrollHandler() {
- @Override
- public void onWindowScroll(ScrollEvent event) {
- if (showMoreWidget != null) {
- boolean isInView = isScrolledIntoView(showMoreWidget);
- if (isInView) {
- eventBus.fireEvent(new ShowMoreUpdatesEvent());
- }
- }
- }
- });
- }
-
- /**
- * stop the feeds timer (when session expires)
- */
- private void doStopFeedsTimer() {
- feedsTimer.cancel();
- }
- /**
- *
- */
- private void checkForNewUpdates() {
- switch (currentFilter) {
- case ALL_UPDATES:
- checkAllUpdatesFeeds();
- break;
- case CONNECTIONS:
- showOnlyConnectionsFeeds();
- break;
- case MINE:
- showOnlyMyPosts();
- break;
- case RECENT_COMMENTS:
- checkAllUpdatesFeeds();
- break;
- default:
- break;
- }
- }
- /**
- * check if it has to show just one feed
- * @return
- */
- private String getFeedToShowId() {
- return Window.Location.getParameter(GET_OID_PARAMETER);
- }
- /**
- * check if it has to show the feeds given an hashtag
- * @return
- */
- private String getHashtagParam() {
- return Window.Location.getParameter(Encoder.encode(GCubeSocialNetworking.HASHTAG_OID));
- }
-
- /**
- * Check if some user statistic related feeds must be shown
- * @return
- */
- private String getShowUserStatisticParam(){
- return Window.Location.getParameter(Encoder.encode(GCubeSocialNetworking.SHOW_STATISTICS_ACTION_OID));
- }
-
- /**
- * check if it has to show the feeds given a query
- * @return
- */
- private String getSearchParam() {
- return Window.Location.getParameter(Encoder.encode(GCubeSocialNetworking.SEARCH_OID));
- }
-
- /**
- * used from notification referrals (see this Post)
- * @param postKey
- */
- private void showSinglePost(String postKey) {
- newsPanel.clear();
- newsService.getSinglePost(postKey, new AsyncCallback
() {
- @Override
- public void onSuccess(EnhancedFeed result) {
- if (result.getFeed().getType() == FeedType.DISABLED) {
- final String profilePageURL = GCubePortalConstants.PREFIX_GROUP_URL + extractOrgFriendlyURL(Location.getHref()) +GCubePortalConstants.USER_PROFILE_FRIENDLY_URL;
- String usrLink = ""+result.getFeed().getFullName()+
- " ";
- newsPanel.add(new HTML("" +
- "We're sorry, "+ usrLink +" removed the post in the meantime!
"));
- } else {
- mainPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
- newsPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
- newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
- newsPanel.add(new ResultsFor("selected post", ""));
- newsPanel.setHeight("");
- newsPanel.add(new TweetTemplate(true, true, myUserInfo, result, eventBus));
- }
- newsPanel.add(new Image(spacer));
- }
- @Override
- public void onFailure(Throwable caught) {
- showProblems();
- }
-
- });
- }
- /**
- * check for updates
- */
- private void checkAllUpdatesFeeds() {
- newsService.getUserSettings(new AsyncCallback() {
- @Override
- public void onFailure(Throwable caught) {
- doStopFeedsTimer();
- }
- @Override
- public void onSuccess(UserSettings result) {
- if (result.getUserInfo().getUsername().equals(NewsConstants.TEST_USER)) {
- doStopFeedsTimer();
- doShowSessionExpired();
- }
- /**
- * this check avoids the 2 tabs open in 2 different scope, if the previous tab was open at VRE Level and then antoher
- * is open at infra level the first tab stops checking for updates
- */
- if (result.getCurrentScope().compareTo(currentScope) == 0) {
- newsService.getAllUpdateUserFeeds(NewsConstants.FEEDS_NO_PER_CATEGORY, new AsyncCallback>() {
- @Override
- public void onSuccess(ArrayList feeds) {
- if (feeds != null && allUpdates.size() > 0) {
-
- Date myLastUpdateTime = allUpdates.get(0).getFeed().getTime(); //this is the last update in the View
- GWT.log("Last Mine: "+allUpdates.get(0).getFeed().getDescription());
-
- GWT.log("Last Retr.: "+feeds.get(0).getFeed().getDescription());
-
-
- tempCacheNewUpdates = new ArrayList(); //need to clear it everytime i check (in case someone deleted the updated in the meanwhile)
-
- //check if there are new updates (enter the while) and put them in a temporary cache for displaying on user click
-
- int i = 0;
- while (i < feeds.size() && feeds.get(i).getFeed().getTime().after(myLastUpdateTime)) {
- tempCacheNewUpdates.add(feeds.get(i));
- i++;
- }
-
- /* currNewUpdatesNo keeps the number of updates to be added on user clicks,
- * i keeps the total number as it arrives,
- * if they differ you got to refresh the updates to show the new number
- */
- if (currNewUpdatesNo < i) {
- //add the current "show new updates" alert panel if not present
- if (newsFeedAlert == null) {
- newsFeedAlert = new NewFeedsAvailable(i, eventBus);
- newUpdatesPanel.add(newsFeedAlert);
- }
- else //update it otherwise
- newsFeedAlert.updateNewUpdatesNo(i);
-
- currNewUpdatesNo = i;
- }
- }
- }
- @Override
- public void onFailure(Throwable caught) {}
- });
- }
- }
- });
- }
- /**
- * get the hashtagged feeds
- * @param hashtag to look for
- */
- private void showFeedsByHashtag(final String hashtag) {
- showLoader();
- newsService.getUserSettings(new AsyncCallback() {
- @Override
- public void onFailure(Throwable caught) {
- doStopFeedsTimer();
- }
- @Override
- public void onSuccess(UserSettings result) {
- if (result.getUserInfo().getUsername().equals(NewsConstants.TEST_USER)) {
- doStopFeedsTimer();
- doShowSessionExpired();
- } else {
- /**
- * this check avoids the 2 tabs open in 2 different scope, if the previous tab was open at VRE Level and then antoher
- * is open at infra level the first tab stops checking for updates
- */
- if (result.getCurrentScope().compareTo(currentScope) == 0) {
- newsService.getPostsByHashtag(hashtag, new AsyncCallback>() {
- @Override
- public void onSuccess(ArrayList posts) {
- filterPanelWrapper.setVisible(false);
- newsPanel.clear();
- if (posts != null) {
- if (posts.size() == 0) {
- newsPanel.add(new ResultsFor("results for", hashtag));
- newsPanel.add(new HTML("" +
- "Sorry, looks like we found no updates with topic: " + hashtag +"
"));
- isFirstTweet = true;
- }
- else {
- newsPanel.setHeight("");
- newsPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
- newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
- newsPanel.add(new ResultsFor("results for", hashtag));
- for (EnhancedFeed feed : posts) {
- newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, feed, eventBus)); //in the view
- }
- if (posts.size() < 5) {
- newsPanel.add(new Image(spacer));
- }
- isFirstTweet = false;
- }
- } else {
- showProblems();
- }
- }
- @Override
- public void onFailure(Throwable caught) {
- showProblems();
- }
- });
- }
- }
- }
- });
- }
-
- /**
- * Called when a user wants to show some feeds related to her statistics
- */
- private void showUserStatisticsRelatedFeeds(final ShowUserStatisticAction relatedFeedsToUserStatisticsToShow, final int from, final int to) {
-
- // show loader while waiting
- showLoader();
-
- // stop asking for feeds
- doStopFeedsTimer();
-
- final String actionToPrint = relatedFeedsToUserStatisticsToShow.getHumanFriendlyAction();
-
- newsService.getUserSettings(new AsyncCallback() {
- @Override
- public void onFailure(Throwable caught) {
- }
- @Override
- public void onSuccess(UserSettings result) {
- if (result.getUserInfo().getUsername().equals(NewsConstants.TEST_USER)) {
- doShowSessionExpired();
- } else {
- /**
- * this check avoids the 2 tabs open in 2 different scope, if the previous tab was open at VRE Level and then antoher
- * is open at infra level the first tab stops checking for updates
- */
- if (result.getCurrentScope().compareTo(currentScope) == 0) {
- newsService.getPostsRelatedToUserStatistics(relatedFeedsToUserStatisticsToShow, from, to, new AsyncCallback>() {
-
- @Override
- public void onSuccess(ArrayList posts) {
-
- filterPanelWrapper.setVisible(false);
- newsPanel.clear();
- if (posts != null) {
-
- GWT.log("Retrieved " + posts.size() + " hits for search.");
- if (posts.size() == 0) {
- newsPanel.add(new ResultsFor("", actionToPrint));
- newsPanel.add(new HTML("" +
- "Sorry, looks like we found no match for action : " + actionToPrint +"
"));
- }
- else {
- newsPanel.setHeight("");
- newsPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
- newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
- newsPanel.add(new ResultsFor("", actionToPrint));
- for (EnhancedFeed feed : posts) {
- newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, feed, eventBus)); //in the view
- // save them (they will be used when asking more feeds)
- allUpdates.add(feed);
- }
- if (posts.size() < 5) {
- newsPanel.add(new Image(spacer));
- }
-
- // add widget to lookup more feeds: if the size of the returned data is less
- // than the required disable this feature.
- if(posts.size() == FEEDS_RELATED_TO_USER_STATISTICS_TO_SHOW){
- showMoreWidget = new ShowMoreFeeds(eventBus);
- showMoreUpdatesPanel.add(showMoreWidget);
- newsPanel.add(showMoreUpdatesPanel);
- }
- }
- } else {
- showProblems();
- }
- }
- @Override
- public void onFailure(Throwable caught) {
- showProblems();
- }
- });
- }
- }
- }
- });
- }
-
- /**
- * Called when a user search something
- */
- private void showFeedsSearch(final String query, final int from, final int to) {
-
- // show loader while waiting
- showLoader();
-
- // stop asking for feeds
- doStopFeedsTimer();
-
- newsService.getUserSettings(new AsyncCallback() {
- @Override
- public void onFailure(Throwable caught) {
- }
- @Override
- public void onSuccess(UserSettings result) {
- if (result.getUserInfo().getUsername().equals(NewsConstants.TEST_USER)) {
- doShowSessionExpired();
- } else {
- /**
- * this check avoids the 2 tabs open in 2 different scope, if the previous tab was open at VRE Level and then antoher
- * is open at infra level the first tab stops checking for updates
- */
- if (result.getCurrentScope().compareTo(currentScope) == 0) {
- newsService.getPostsByQuery(query, from, to, new AsyncCallback>() {
- @Override
- public void onSuccess(ArrayList posts) {
- filterPanelWrapper.setVisible(false);
- newsPanel.clear();
- if (posts != null) {
-
- GWT.log("Retrieved " + posts.size() + " hits for search.");
- if (posts.size() == 0) {
- newsPanel.add(new ResultsFor("Results for query: ", query));
- newsPanel.add(new HTML("" +
- "Sorry, looks like we found no match for: " + query +"
"));
- }
- else {
- newsPanel.setHeight("");
- newsPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
- newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
- newsPanel.add(new ResultsFor("Results for query: ", query));
- for (EnhancedFeed feed : posts) {
- newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, feed, eventBus)); //in the view
- // save them (they will be used when asking more feeds)
- allUpdates.add(feed);
- }
- if (posts.size() < 5) {
- newsPanel.add(new Image(spacer));
- }
-
- // add widget to lookup more feeds: if the size of the returned data is less
- // than the required disable this feature.
- if(posts.size() == SEARCHED_FEEDS_TO_SHOW){
- showMoreWidget = new ShowMoreFeeds(eventBus);
- showMoreUpdatesPanel.add(showMoreWidget);
- newsPanel.add(showMoreUpdatesPanel);
- }
- }
- } else {
- showProblems();
- }
- }
- @Override
- public void onFailure(Throwable caught) {
- showProblems();
- }
- });
- }
- }
- }
- });
- }
-
- /**
- * called when a user click on the are new updates
- */
- protected void doShowCachedNewUpdates() {
- newUpdatesPanel.clear(); //remove the alert panel
- newsFeedAlert = null; //reset the alert panel and other needed vars
- currNewUpdatesNo = 0;
-
- //need to put them in reverse order;
- for (int i = tempCacheNewUpdates.size(); i > 0; i--) {
- EnhancedFeed feed = tempCacheNewUpdates.get(i-1);
- 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");
- }
- };
- t.schedule(100);
- }
- //after that I remove the ($updatesNo) from Window Title
- String currTitle = Document.get().getTitle();
- Document.get().setTitle(currTitle.startsWith("(") ? currTitle.substring(4) : currTitle);
- }
-
- /**
- * used when adding directly a feed from the UI (IPC)
- * @param userid
- * @param fullName
- * @param thumbURL
- * @param description
- */
- public void addJustAddedFeed(ClientPost cFeed) {
-
- // build up the feed
- Feed feed = new Feed(
- cFeed.key,
- FeedType.SHARE,
- cFeed.userid,
- cFeed.time,
- "",
- cFeed.uri,
- cFeed.linkUrlThumbnail,
- cFeed.description,
- PrivacyLevel.CONNECTION,
- cFeed.fullName,
- cFeed.email,
- cFeed.thumbnailURL,
- cFeed.linkTitle,
- cFeed.linkDescription,
- cFeed.linkHost);
-
- // set multi-attachments property
- boolean multiAttachments = (cFeed.attachments != null) ? cFeed.attachments.length > 0 : false;
- feed.setMultiFileUpload(multiAttachments);
-
- //false because he could not have liked this yet and true because is the current user's
- EnhancedFeed toAdd = new EnhancedFeed(feed, false, true);
-
- ArrayList attachments = null;
- if (multiAttachments) {
- attachments = new ArrayList<>(cFeed.attachments.length);
- for (int i = 0; i >() {
- @Override
- public void onSuccess(ArrayList feeds) {
- newsPanel.clear();
- if (feeds != null) {
- if (feeds.size() == 0) {
- if (!isInfrastructure) {
- newsPanel.add(new HTML("" +
- "Looks like nobody posted anything yet. Are you willing to be the first?
" +
- "You may begin by posting a message!
"));
- } else {
- newsPanel.add(new HTML("" +
- "Looks like we've got nothing for you at the moment.
" +
- "You may begin by joining some of the available " +
- "
"+vreLabel+"s.
"));
- }
- isFirstTweet = true;
- }
- else {
- newsPanel.setHeight("");
- newsPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
- newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
-
- for (EnhancedFeed feed : feeds) {
- newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, feed, eventBus)); //in the view
- allUpdates.add(feed); //in the model
- }
- if (feeds.size() < 5) {
- newsPanel.add(new Image(spacer));
- }
- //if you are showing more than feedsMaxPerCategory-1 feeds there is probably more
- if (feeds.size() >= NewsConstants.FEEDS_MAX_PER_CATEGORY-1 && (!isInfrastructure)) {
- GWT.log("Show MORE " + NewsConstants.FEEDS_NO_PER_CATEGORY);
- showMoreWidget = new ShowMoreFeeds(eventBus);
- showMoreUpdatesPanel.add(showMoreWidget);
- newsPanel.add(showMoreUpdatesPanel);
- }
- isFirstTweet = false;
- }
- } else {
- showProblems();
- }
-
- }
-
- @Override
- public void onFailure(Throwable caught) {
- newsPanel.clear();
- newsPanel.add(new HTML("" +
- "Ops! There were problems while retrieving your feeds!.
" +
- "Please try again in a short while.
"));
- }
- });
- }
- /**
- * called when a user scroll down the page to the bottom
- */
- protected void doShowMoreUpdates() {
-
- showMoreUpdatesPanel.remove(0);
- loadingImage.getElement().getStyle().setMargin(10, Unit.PX);
- showMoreUpdatesPanel.add(loadingIcon);
-
- if(isSearch){
-
- GWT.log("Going to request more feeds for this search");
-
- // start position
- int start = allUpdates.size();
-
- GWT.log("StartingPoint = " + start);
- newsService.getPostsByQuery(currentQuery, start, SEARCHED_FEEDS_TO_SHOW , new AsyncCallback>() {
- @Override
- public void onSuccess(ArrayList posts){
- newsPanel.remove(showMoreUpdatesPanel);
- if (posts != null) {
- GWT.log("There are " + posts.size() + " more feeds");
-
- for (EnhancedFeed feed : posts) {
- // avoid to insert same data
- if(!isFeedPresent(feed)){
- newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, feed, eventBus)); //in the view
- allUpdates.add(feed);
- }
- }
-
- // clear panel
- showMoreUpdatesPanel.clear();
-
- // check if we can ask for other data
- if(posts.size() == SEARCHED_FEEDS_TO_SHOW){
- GWT.log("It seems there are no more feeds for this query. Stop asking further");
- showMoreWidget = new ShowMoreFeeds(eventBus);
- showMoreUpdatesPanel.add(showMoreWidget);
- newsPanel.add(showMoreUpdatesPanel);
- }else{
- showMoreWidget = null;
- }
- }
- }
- @Override
- public void onFailure(Throwable caught) {
- showMoreUpdatesPanel.clear();
- newsPanel.add(new HTML("" +
- "Ops! There were problems while retrieving your feeds!.
" +
- "Please try again in a short while.
"));
- }
- });
- }else if(isFeedsRelatedToStatistics){
- GWT.log("Going to request more feeds for this user's statisics");
-
- // start position
- int start = allUpdates.size();
-
- GWT.log("StartingPoint = " + start);
- newsService.getPostsRelatedToUserStatistics(relatedFeedsToUserStatisticsToShow, start, FEEDS_RELATED_TO_USER_STATISTICS_TO_SHOW , new AsyncCallback>() {
- @Override
- public void onSuccess(ArrayList posts){
- newsPanel.remove(showMoreUpdatesPanel);
- if (posts != null) {
- GWT.log("There are " + posts.size() + " more feeds");
-
- for (EnhancedFeed feed : posts) {
- // avoid to insert same data
- if(!isFeedPresent(feed)){
- newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, feed, eventBus)); //in the view
- allUpdates.add(feed);
- }
- }
-
- // clear panel
- showMoreUpdatesPanel.clear();
-
- // check if we can ask for other data
- if(posts.size() == FEEDS_RELATED_TO_USER_STATISTICS_TO_SHOW){
- GWT.log("It seems there are no more feeds for this query. Stop asking further");
- showMoreWidget = new ShowMoreFeeds(eventBus);
- showMoreUpdatesPanel.add(showMoreWidget);
- newsPanel.add(showMoreUpdatesPanel);
- }else{
- showMoreWidget = null;
- }
- }
- }
- @Override
- public void onFailure(Throwable caught) {
- showMoreUpdatesPanel.clear();
- newsPanel.add(new HTML("" +
- "Ops! There were problems while retrieving your feeds!.
" +
- "Please try again in a short while.
"));
- }
- });
- }
- else{
- final int quantity = 10;
- loadMorePosts(quantity, false);
- }
- }
- /**
- *
- * @param quantity
- */
- public void loadMorePosts(final int quantity, boolean isSortingByLastCommentedposts) {
- int from = (fromStartingPoint == null) ? allUpdates.size()+1 : fromStartingPoint;
- if (isSortingByLastCommentedposts) {
- showLoader();
- if ((from == 0))
- from = 1;
- }
-
- GWT.log("StartingPoint = " + from);
- newsService.getMorePosts(from, quantity, new AsyncCallback() {
- @Override
- public void onSuccess(MorePostsBean rangeFeeds) {
- newsPanel.remove(showMoreUpdatesPanel);
- if (rangeFeeds.getPosts() != null) {
- fromStartingPoint = rangeFeeds.getLastReturnedFeedTimelineIndex();
- int c = 1;
- for (EnhancedFeed post : rangeFeeds.getPosts()) {
- if (!isFeedPresent(post)) { //avoid possible duplicates
- newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, post, eventBus)); //in the view
- allUpdates.add(post); //in the model
- }
- c++;
- }
- if (c >= quantity) { //there could be more feeds
- GWT.log("there could be more feeds");
- showMoreUpdatesPanel.clear();
- showMoreWidget = new ShowMoreFeeds(eventBus);
- showMoreUpdatesPanel.add(showMoreWidget);
- newsPanel.add(showMoreUpdatesPanel);
- }
- if (isSortingByLastCommentedposts) {
- sortCurrentPostsByLatestComment();
- showMoreUpdatesPanel.clear();
- showMoreWidget = null;
- if (getAllUpdatesSize() > 99)
- newsPanel.add(new HTML(LIMIT_REACHED_FOR_SORTING_COMMENTS_TEXT));
- }
- }
- }
- @Override
- public void onFailure(Throwable caught) {
- showMoreUpdatesPanel.clear();
- newsPanel.add(new HTML("" +
- "Ops! There were problems while retrieving your feeds!.
" +
- "Please try again in a short while.
"));
- }
- });
- }
- /**
- * @param widget the widget to check
- * @returnn true if the widget is in the visible part of the page
- */
- private boolean isScrolledIntoView(Widget widget) {
- if (widget != null) {
- int docViewTop = Window.getScrollTop();
- int docViewBottom = docViewTop + Window.getClientHeight();
- int elemTop = widget.getAbsoluteTop();
- int elemBottom = elemTop + widget.getOffsetHeight();
- return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
- }
- return false;
- }
-
- private boolean isFeedPresent(EnhancedFeed toCheck) {
- for (EnhancedFeed feed : allUpdates) {
- if (feed.getFeed().getKey().compareTo(toCheck.getFeed().getKey()) == 0)
- return true;
- }
- return false;
- }
- /**
- * Only User Connections
- */
- public void showOnlyConnectionsFeeds() {
- showLoader();
- newsService.getOnlyConnectionsUserPosts(new AsyncCallback>() {
- @Override
- public void onSuccess(ArrayList feeds) {
- if (feeds != null) {
- newsPanel.clear();
- if (feeds.size() == 0) {
- //TODO: provide actual link for Making some friends
- newsPanel.add(new HTML("" +
- "Looks like we've got nothing for you at the moment.
" +
- "You may begin by adding some friend!
"));
- isFirstTweet = true;
- }
- else {
- newsPanel.setHeight("");
- newsPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
- newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
- for (EnhancedFeed feed : feeds)
- newsPanel.add(new TweetTemplate(false, false, myUserInfo, feed, eventBus));
- if (feeds.size() < 5) {
- newsPanel.add(new Image(spacer));
- }
- isFirstTweet = false;
- }
- } else
- showProblems();
-
- }
-
- @Override
- public void onFailure(Throwable caught) {
- loadingImage.setUrl(warning);
- newsPanel.add(new HTML("Ops! There were problems while retrieving your feeds! Please try again in a short while"));
- }
- });
- }
- /**
- * Only User Feeds
- */
- public void showOnlyMyPosts() {
- showLoader();
- newsService.getOnlyMyUserPosts(new AsyncCallback>() {
- @Override
- public void onSuccess(ArrayList posts) {
- if (posts != null) {
- newsPanel.clear();
- if (posts.size() == 0) {
- newsPanel.add(new HTML("" +
- "Looks like we've got nothing for you at the moment.
" +
- "You may begin by sharing an update!
"));
- isFirstTweet = true;
- }
- else {
- newsPanel.setHeight("");
- newsPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
- newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
- for (EnhancedFeed feed : posts)
- newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, feed, eventBus));
- if (posts.size() < 5) {
- newsPanel.add(new Image(spacer));
- }
- isFirstTweet = false;
- }
- } else
- showProblems();
-
- }
-
- @Override
- public void onFailure(Throwable caught) {
- loadingImage.setUrl(warning);
- newsPanel.add(new HTML("Ops! There were problems while retrieving your feeds! Please try again in a short while"));
- }
- });
- }
- /**
- * Only User Liked Posts
- */
- public void showOnlyLikedPosts() {
- showLoader();
- newsService.getOnlyLikedPosts(new AsyncCallback>() {
- @Override
- public void onSuccess(ArrayList posts) {
- if (posts != null) {
- newsPanel.clear();
- if (posts.size() == 0) {
- newsPanel.add(new HTML("" +
- "Looks like we've got nothing for you at the moment.
" +
- "Set an update as your favorite to see it here
"));
- isFirstTweet = true;
- }
- else {
- newsPanel.setHeight("");
- newsPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
- newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
- for (EnhancedFeed feed : posts)
- newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, feed, eventBus));
- if (posts.size() < 5) {
- newsPanel.add(new Image(spacer));
- }
- isFirstTweet = false;
- }
- } else
- showProblems();
-
- }
-
- @Override
- public void onFailure(Throwable caught) {
- loadingImage.setUrl(warning);
- newsPanel.add(new HTML("Ops! There were problems while retrieving your feeds! Please try again in a short while"));
- }
- });
- }
- /**:
- * Sort the posts per recent comment
- */
- private void sortCurrentPostsByLatestComment() {
- showLoader();
- GWT.log(" number of posts " + allUpdates.size());
- ArrayList latestComments = new ArrayList<>();
- //thePostsMap is need so that later it is faster to get the post by id
- HashMap theCommentedPostsMap = new HashMap<>();
- for (EnhancedFeed post : allUpdates) {
- ArrayList postComments = post.getComments();
- if (postComments != null && !postComments.isEmpty()) {
- theCommentedPostsMap.put(post.getFeed().getKey(), post);
- Comment latest = postComments.get(postComments.size()-1);
- latestComments.add(latest); //get the latest
- }
- }
- //sort the comments
- Collections.sort(latestComments, Collections.reverseOrder());
- ArrayList sortedPostsByLatestComment = new ArrayList<>();
- // evaluate unique posts' ids
- HashSet postIds = new HashSet();
- for (Comment comment : latestComments) {
- String postId = comment.getFeedid();
- if(!postIds.contains(postId)){
- postIds.add(postId);
- sortedPostsByLatestComment.add(theCommentedPostsMap.get(postId));
- }
- }
- //at this point the sortedPostsByLatestComment list contains only the commented posts in the right order
- //we need to add the remaining posts of the page in the latest post order
- for (EnhancedFeed post : allUpdates) {
- if (!theCommentedPostsMap.containsKey(post.getFeed().getKey()))
- sortedPostsByLatestComment.add(post);
- }
- newsPanel.clear();
- if (sortedPostsByLatestComment.size() == 0) {
- newsPanel.add(new HTML("" +
- "Looks like we've got nothing for you at the moment.
" +
- "Set an update as your favorite to see it here
"));
- isFirstTweet = true;
- }
- else {
- newsPanel.setHeight("");
- newsPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
- newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
- for (EnhancedFeed feed : sortedPostsByLatestComment)
- newsPanel.add(new TweetTemplate(false, showFeedTimelineSource, myUserInfo, feed, eventBus));
- if (sortedPostsByLatestComment.size() < 5) {
- newsPanel.add(new Image(spacer));
- }
- isFirstTweet = false;
- }
-
-
- }
-
-
-
-
- private void showLoader() {
- newsPanel.clear();
- newsPanel.setWidth("100%");
- newsPanel.setHeight("300px");
- newsPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER);
- newsPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
- newsPanel.add(new Image(loading));
- }
-
- private void showProblems() {
- newsPanel.clear();
- newsPanel.add(new HTML("" +
- "Ops! There were problems while retrieving your feeds!.
" +
- "Looks like we are not able to communicate with the infrastructure,
(or your session expired)
please try again in a short while or refresh the page.
"));
- }
-
- private void doAddLike(final TweetTemplate owner, final String feedId) {
- newsService.like(feedId, owner.getMyFeedText(), owner.getMyFeedUserId(), new AsyncCallback() {
- @Override
- public void onFailure(Throwable caught) {}
- @Override
- public void onSuccess(Boolean result) {
- if (!result) {
- doShowSessionExpired();
- }
- }
- });
- }
-
- protected void doUnLike(final TweetTemplate owner, String feedId) {
- newsService.unlike(feedId, owner.getMyFeedText(), owner.getMyFeedUserId(), new AsyncCallback() {
- @Override
- public void onFailure(Throwable caught) {}
- @Override
- public void onSuccess(Boolean result) {
- if (!result) {
- doShowSessionExpired();
- }
- }
- });
-
- }
-
- private void doShowSessionExpired() {
-
- }
-
- private void doShowLikes(final String postId) {
- final UserSelectionDialog dlg = new UserSelectionDialog("People who set this as Favorite", eventBus);
- dlg.center();
- dlg.show();
-
- newsService.getAllLikesByPost(postId, new AsyncCallback>() {
- @Override
- public void onFailure(Throwable caught) {
- Window.alert("People who liked this could not be retrieved: " + caught.getMessage());
- }
-
- @Override
- public void onSuccess(ArrayList result) {
- ArrayList toShow = new ArrayList();
- for (Like like : result) {
- toShow.add(new ItemSelectableBean(like.getUserid(), like.getFullName(), like.getThumbnailURL()));
- }
- eventBus.fireEvent(new UsersFetchedEvent(toShow));
- }
- });
- }
-
- private void doAddComment(final TweetTemplate owner, String text, HashSet mentionedUsers) {
- owner.showCommentingPreloader(true);
- newsService.comment(owner.getFeedKey(), text, mentionedUsers, owner.getMyFeedUserId(), owner.isAppFeed(), new AsyncCallback() {
- @Override
- public void onFailure(Throwable caught) {
- owner.showCommentingPreloader(true);
- Window.alert("Could not deliver this comment: " + caught.getMessage());
- }
- @Override
- public void onSuccess(OperationResult result) {
- owner.showCommentingPreloader(false);
- if (result != null) {
- if (!result.isSuccess()) {
- Window.alert("Could not deliver this comment. Please try again in a short while.");
- }
- else {
- Comment comment = (Comment) result.getComment();
- owner.addComment(new SingleComment(comment, owner, (comment.getUserid().equals(myUserInfo.getUsername()))));
- owner.setCommentingDisabled(false);
- owner.updateCommentsNumberCount();
- owner.showAddCommentForm(false);
-
- // 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 {
- Window.alert("Could not deliver this comment. Please try again in a short while.");
- }
- }
- });
- }
-
- private void doEditComment(final TweetTemplate owner, Comment edited, final HTMLPanel commentPanel) {
- newsService.editComment(edited, new AsyncCallback() {
- @Override
- public void onFailure(Throwable caught) {
- Window.alert("Could not edit this comment: " + caught.getMessage());
- }
-
- @Override
- public void onSuccess(OperationResult result) {
- if (result != null) {
- if (!result.isSuccess()) {
- //CheckSession.showLogoutDialog();
- }
- else {
- Comment comment = (Comment) result.getComment();
- owner.updateSingleComment(comment, commentPanel);
- owner.setCommentingDisabled(false);
- }
- }
- else {
- Window.alert("Could not deliver this comment. Please try again in a short while.");
- }
- }
- });
-
-
- }
-
- private void doShowComments(final TweetTemplate owner, final boolean commentForm2Add) {
- owner.showLoadingComments();
- newsService.getAllCommentsByPost(owner.getFeedKey(), new AsyncCallback>() {
-
- @Override
- public void onFailure(Throwable caught) {
- Window.alert("Comments could not be retrieved: " + caught.getMessage());
- }
-
- @Override
- public void onSuccess(ArrayList comments) {
- owner.clearComments();
- for (Comment comment :comments)
- owner.addComment(new SingleComment(comment, owner,(comment.getUserid().equals(myUserInfo.getUsername()))));
- owner.setCommentsFetched(true);
- if (commentForm2Add)
- owner.showAddCommentForm(false);
- owner.updateCommentsNumberCount();
- owner.showAddCommentForm(false);
- }
- });
-
- }
-
-
- protected void doDeleteComment(final TweetTemplate owner, String commentId) {
- newsService.deleteComment(commentId, owner.getFeedKey(), new AsyncCallback() {
- @Override
- public void onFailure(Throwable caught) {
- Window.alert("Comment could not be deleted: " + caught.getMessage());
-
- }
- @Override
- public void onSuccess(Boolean result) {
- if (result) {
- doShowComments(owner, false);
- owner.updateCommentsNumberCount();
-
- } else
- Window.alert("Comment could not be deleted, please try again in a short while.");
- }
- });
-
- }
-
- private void doDeletePost(final TweetTemplate toDelete) {
- if (Window.confirm("Are you sure you want to delete this post?")) {
- newsService.deletePost(toDelete.getFeedKey(), new AsyncCallback() {
-
- @Override
- public void onFailure(Throwable caught) {
- Window.alert("Feed could not be deleted: " + caught.getMessage());
- }
-
- @Override
- public void onSuccess(Boolean result) {
- if (result) {
- toDelete.removeFromParent();
- } else
- Window.alert("Feed could not be deleted, please try again in a short while.");
- }
- });
- }
- }
-
- private void doShowFeed(final TweetTemplate toShow) {
- String feedKey = toShow.getFeedKey();
- Window.Location.assign(Window.Location.getHref() + ((Window.Location.getHref().contains("?")) ? "&oid="+feedKey : "?oid="+feedKey));
- }
-
- public int getAllUpdatesSize() {
- return allUpdates.size();
- }
-
- /**
- * set the filter type status for automatic reloading of tweets
- * @param currentFilter
- */
- public void setCurrentFilter(FilterType currentFilter) {
- this.currentFilter = currentFilter;
- }
- /**
- *
- * @return the current scope on the client
- */
- public static String getCurrentScope() {
- return currentScope;
- }
-
- public static String extractOrgFriendlyURL(String portalURL) {
- String groupRegEx = "/group/";
- if (portalURL.contains(groupRegEx)) {
- String[] splits = portalURL.split(groupRegEx);
- String friendlyURL = splits[1];
- if (friendlyURL.contains("/")) {
- friendlyURL = friendlyURL.split("/")[0];
- } else {
- friendlyURL = friendlyURL.split("\\?")[0].split("\\#")[0];
- }
- return "/"+friendlyURL;
- }
- return null;
- }
-}
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AddCommentTemplate.java b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AddCommentTemplate.java
deleted file mode 100644
index a1bc3e4..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AddCommentTemplate.java
+++ /dev/null
@@ -1,260 +0,0 @@
-package org.gcube.portlets.user.newsfeed.client.ui;
-
-
-import org.gcube.portal.databook.shared.Comment;
-import org.gcube.portal.databook.shared.UserInfo;
-import org.gcube.portlets.user.gcubewidgets.client.elements.Div;
-import org.gcube.portlets.user.newsfeed.client.event.AddCommentEvent;
-import org.gcube.portlets.user.newsfeed.client.event.EditCommentEvent;
-
-import com.github.gwtbootstrap.client.ui.Button;
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.event.dom.client.ClickEvent;
-import com.google.gwt.event.dom.client.KeyPressEvent;
-import com.google.gwt.event.shared.HandlerManager;
-import com.google.gwt.event.shared.HandlerRegistration;
-import com.google.gwt.uibinder.client.UiBinder;
-import com.google.gwt.uibinder.client.UiFactory;
-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.ClosingHandler;
-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.Widget;
-
-public class AddCommentTemplate extends Composite {
-
- interface CommentTemplateUiBinder extends UiBinder {
- }
-
- private static CommentTemplateUiBinder uiBinder = GWT.create(CommentTemplateUiBinder.class);
-
-
- public final static String COMMENT_TEXT = "Write a comment, use @ to mention someone";
- public final static String ERROR_UPDATE_TEXT = "Looks like empty to me!";
- public static final String avatar_default = GWT.getModuleBaseURL() + "../images/Avatar_default.png";
-
- private TweetTemplate owner;
- private HandlerManager eventBus;
- private boolean isEditing = false;
- private HTMLPanel commentPanel;
- private Comment toEdit;
- private ClosingHandler closingHandler;
- private HandlerRegistration handlerRegistration;
-
- @UiField HTMLPanel mainPanel;
- @UiField Image avatarImage;
- @UiField SuperPosedTextArea commentTextArea;
- @UiField Div highlighterDIV;
- @UiField Button submitButton;
- @UiField Button cancelButton; //obsolete
-
-
- /**
- * called on add comment
- * @param caller
- * @param myUserInfo
- * @param eventBus
- */
- public AddCommentTemplate(TweetTemplate caller, UserInfo myUserInfo, HandlerManager eventBus) {
- initWidget(uiBinder.createAndBindUi(this));
- this.eventBus = eventBus;
- owner = caller;
- avatarImage.setPixelSize(30, 30);
- avatarImage.setUrl(myUserInfo.getAvatarId());
- submitButton.setVisible(false);
- cancelButton.setVisible(false);
- commentTextArea.setHeight("30px");
- commentTextArea.setContext(owner.getVREContext());
- }
- /**
- * called on edit comment
- * @param caller
- * @param editText
- */
- public AddCommentTemplate(TweetTemplate caller, Comment toEdit, HTMLPanel commentPanel) {
- initWidget(uiBinder.createAndBindUi(this));
- this.eventBus = caller.getEventBus();
- this.commentPanel = commentPanel;
- isEditing = true;
- this.toEdit = toEdit;
-
- String commentText = new HTML(toEdit.getText()).getText();
- //replace the < & and >
- commentText = commentText.replaceAll("<","<").replaceAll(">",">");
- commentText = commentText.replaceAll("&","&");
-
- owner = caller;
- commentTextArea.setContext(owner.getVREContext());
- avatarImage.setPixelSize(30, 30);
- avatarImage.setUrl(caller.getMyUserInfo().getAvatarId());
- commentTextArea.setText(commentText);
- mainPanel.removeStyleName("comment-hidden");
- mainPanel.setStyleName("single-comment");
- commentTextArea.addStyleName("comment-dark-color");
- submitButton.setText("Edit");
- closingHandler = new Window.ClosingHandler() {
- public void onWindowClosing(Window.ClosingEvent closingEvent) {
- String currentText = commentTextArea.getText();
- if(!currentText.isEmpty()){
- closingEvent.setMessage("Do you really want to leave the page?");
- }
- }
- };
- handlerRegistration = Window.addWindowClosingHandler(closingHandler);
-
- }
-
-
-
- /** Used by AddCommentTemplate to instantiate SuperPosedTextArea */
- @UiFactory SuperPosedTextArea build() {
- return new SuperPosedTextArea(highlighterDIV);
- }
-
- public void setFocus() {
- commentTextArea.setFocus(true);
- submitButton.setVisible(true);
- cancelButton.setVisible(true);
- //it needs a timer otherwise it won't work
- Timer t = new Timer() {
- @Override
- public void run() {
- setCaretPositionToBegin(commentTextArea.getAreaId());
- closingHandler = new Window.ClosingHandler() {
- public void onWindowClosing(Window.ClosingEvent closingEvent) {
- String currentText = commentTextArea.getText();
- if(!currentText.isEmpty()){
- closingEvent.setMessage("Do you really want to leave the page?");
- }
- }
- };
- handlerRegistration = Window.addWindowClosingHandler(closingHandler);
- }
- };
- t.schedule(200);
-
- }
-
-
- @UiHandler("submitButton")
- void onSubmitClick(ClickEvent e) {
- String userComment = commentTextArea.getText().trim();
- if (userComment.equals(COMMENT_TEXT) || userComment.equals(ERROR_UPDATE_TEXT) || userComment.equals("")) {
- commentTextArea.addStyleName("nwfeed-error");
- commentTextArea.setText(ERROR_UPDATE_TEXT);
- return;
- }
- if (isEditing) {
- toEdit.setText(escapeHtml(commentTextArea.getText()));
- eventBus.fireEvent(new EditCommentEvent(owner, toEdit, commentPanel));
- }
- else { //it is ok to add this comment
- eventBus.fireEvent(new AddCommentEvent(owner, escapeHtml(commentTextArea.getText()), commentTextArea.getMentionedUsers()));
- }
- this.getWidget().setVisible(false);
- owner.setCommentingDisabled(false);
- handlerRegistration.removeHandler();
- GWT.log(" handlerRegistration.removeHandler();");
- }
-
- /**
- * called when pasting. it tries to avoid pasting long non spaced strings
- * @param linkToCheck
- */
- private boolean checkTextLength(String textToCheck) {
-
- String [] parts = textToCheck.split("\\s");
- // check the length of tokens
- for( String item : parts ) {
- if (!item.startsWith("http") && !item.startsWith("ftp")) { //url are accepted as they can be trunked
- if (item.length() > 50) {
- return false;
- }
- }
- }
- return true;
- }
-
- @UiHandler("cancelButton")
- void onCancelClick(ClickEvent e) {
- this.getWidget().setVisible(false);
- owner.setCommentingDisabled(false);
- if (isEditing) {
- commentPanel.clear();
- SingleComment sc = new SingleComment(toEdit, owner, true);
- commentPanel.add(sc);
- }
- handlerRegistration.removeHandler();
- }
-
-
- @UiHandler("commentTextArea")
- void onCommentClick(ClickEvent e) {
- if (commentTextArea.getText().equals(COMMENT_TEXT) || commentTextArea.getText().equals(ERROR_UPDATE_TEXT) ) {
- commentTextArea.setText("");
- commentTextArea.addStyleName("comment-dark-color");
- commentTextArea.removeStyleName("nwfeed-error");
- }
- submitButton.setVisible(true);
- cancelButton.setVisible(true);
- closingHandler = new Window.ClosingHandler() {
- public void onWindowClosing(Window.ClosingEvent closingEvent) {
- String currentText = commentTextArea.getText();
- if(!currentText.isEmpty()){
- closingEvent.setMessage("Do you really want to leave the page?");
- }
- }
- };
- handlerRegistration = Window.addWindowClosingHandler(closingHandler);
- }
-
- @UiHandler("commentTextArea")
- void onCommentKeyPress(KeyPressEvent e) {
- if (commentTextArea.getText().equals(COMMENT_TEXT) || commentTextArea.getText().equals(ERROR_UPDATE_TEXT) ) {
- commentTextArea.setText("");
- commentTextArea.addStyleName("comment-dark-color");
- commentTextArea.removeStyleName("nwfeed-error");
- }
- }
- /**
- * Escape an html string. Escaping data received from the client helps to
- * prevent cross-site script vulnerabilities.
- *
- * @param html the html string to escape
- * @return the escaped string
- */
- private String escapeHtml(String html) {
- if (html == null) {
- return null;
- }
- return html.replaceAll("&", "&").replaceAll("<", "<")
- .replaceAll(">", ">");
- }
- /**
- * this position the caret at the begin in a TextArea
- * @param myAreaId the unique identifier of the textarea
- */
- public static native void setCaretPositionToBegin(String myAreaId) /*-{
- var elem = $doc.getElementById(myAreaId);
- if(elem != null) {
- if(elem.createTextRange) {
- var range = elem.createTextRange();
- range.move('character', 0);
- range.select();
- }
- else {
- if(elem.selectionStart) {
- elem.focus();
- elem.setSelectionRange(0, 0);
- }
- else
- elem.focus();
- }
- }
- }-*/;
-}
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AddCommentTemplate.ui.xml b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AddCommentTemplate.ui.xml
deleted file mode 100644
index 695e24f..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AddCommentTemplate.ui.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AttachmentPreviewer.java b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AttachmentPreviewer.java
deleted file mode 100644
index 419ddb7..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AttachmentPreviewer.java
+++ /dev/null
@@ -1,187 +0,0 @@
-package org.gcube.portlets.user.newsfeed.client.ui;
-
-import org.gcube.portal.databook.shared.Attachment;
-import org.gcube.portlets.widgets.imagepreviewerwidget.client.EnhancedImage;
-import org.gcube.portlets.widgets.imagepreviewerwidget.client.ui.Carousel;
-
-import com.github.gwtbootstrap.client.ui.Image;
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.dom.client.Style.Cursor;
-import com.google.gwt.dom.client.Style.Unit;
-import com.google.gwt.event.dom.client.ClickEvent;
-import com.google.gwt.event.dom.client.ClickHandler;
-import com.google.gwt.uibinder.client.UiBinder;
-import com.google.gwt.uibinder.client.UiField;
-import com.google.gwt.user.client.ui.Anchor;
-import com.google.gwt.user.client.ui.Composite;
-import com.google.gwt.user.client.ui.HTMLPanel;
-import com.google.gwt.user.client.ui.Label;
-import com.google.gwt.user.client.ui.Widget;
-
-/**
- * Class to show an attached file.
- * @author Costantino Perciante at ISTI-CNR
- *
- */
-public class AttachmentPreviewer extends Composite {
-
- private static AttachmentPreviewerUiBinder uiBinder = GWT
- .create(AttachmentPreviewerUiBinder.class);
-
- interface AttachmentPreviewerUiBinder extends
- UiBinder {
- }
-
- public AttachmentPreviewer() {
- initWidget(uiBinder.createAndBindUi(this));
- }
-
- @UiField
- HTMLPanel attachmentContainer;
-
- @UiField
- Image imagePreview;
-
- @UiField
- Label fileNameLabel;
-
- @UiField
- Anchor downloadLabel;
-
- @UiField
- Anchor showPreviewLabel;
-
- @UiField
- Label labelSeparator;
-
- // save attachment
- private Attachment attachment;
-
- // carousel reference
- private Carousel carousel;
-
- // enhanced image associated with this carousel
- private EnhancedImage img;
-
- public AttachmentPreviewer(Attachment a) {
-
- // init
- initWidget(uiBinder.createAndBindUi(this));
-
- // save the attachment
- attachment = a;
-
- // set image preview
- imagePreview.setUrl(a.getThumbnailURL());
- imagePreview.setStyleName("image-preview-attachment");
-
- // set file name (be careful on file name length)
- String shownName = a.getName().length() > 21 ? a.getName().substring(0, 18) + "..." : a.getName();
- fileNameLabel.setText(shownName);
- fileNameLabel.setTitle(a.getName());
-
- // download label
- downloadLabel.setText("Download");
- downloadLabel.setHref(attachment.getUri());
- downloadLabel.setTarget("_blank");
-
-
- // preview in case of an image
- if(a.getMimeType().contains("image/")){
-
- showPreviewLabel.setText("Show");
- showPreviewLabel.addClickHandler(new ClickHandler() {
-
- @Override
- public void onClick(ClickEvent event) {
-
- if(img != null)
- carousel.show(img);
-
- }
- });
-
- }else{
-
- // hide the show button and the separator label
- showPreviewLabel.setVisible(false);
- labelSeparator.setVisible(false);
- }
-
- // style links
- downloadLabel.addStyleName("link");
- showPreviewLabel.addStyleName("link");
-
- }
-
- /**
- * Change the width of this container.
- * @param newWidth
- * @param unit
- */
- public void changeAttachmentWidth(int newWidth, Unit unit){
-
- attachmentContainer.getElement().getStyle().setWidth(newWidth, unit);
-
- }
-
- /**
- * Open the carousel when the user clicks on the preview's image.
- * @param carousel
- */
- public void onImageClickOpenCarousel(final Carousel carousel) {
-
- // save it
- this.carousel = carousel;
-
- // change cursor type on hover
- imagePreview.getElement().getStyle().setCursor(Cursor.POINTER);
-
- // change tooltipe
- imagePreview.setTitle("Click for a preview");
-
- // add handler
- imagePreview.addClickHandler(new ClickHandler() {
-
- @Override
- public void onClick(ClickEvent event) {
-
- carousel.show();
-
- }
- });
- }
-
- /**
- * Open the carousel and show this enhancedImage when the user clicks on the preview's image.
- * @param carousel
- * @param enhancedImage the image to show
- */
- public void onImageClickOpenCarousel(final Carousel carousel, final EnhancedImage enhancedImage) {
-
- // save the carousel ref.
- this.carousel = carousel;
-
- // save img ref
- this.img = enhancedImage;
-
- // change cursor type on hover
- imagePreview.getElement().getStyle().setCursor(Cursor.POINTER);
-
- // change tooltipe
- imagePreview.setTitle("Click for a preview");
-
- // add handler
- imagePreview.addClickHandler(new ClickHandler() {
-
- @Override
- public void onClick(ClickEvent event) {
-
- if(img != null)
- carousel.show(img);
-
- }
- });
- }
-
-}
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AttachmentPreviewer.ui.xml b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AttachmentPreviewer.ui.xml
deleted file mode 100644
index 688d434..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AttachmentPreviewer.ui.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-
-
-
- .container-style {
- padding: 5px;
- font-family: 'lucida grande', tahoma, verdana, arial, sans-serif;
- background-clip: border-box;
- background-color: #FBFBFB;
- background-image: none;
- border: 1px solid #DDD;
- border-radius: 4px;
- margin: 5px;
- display: inline-block;
- width: 95%;
- height: 60px;
- overflow: hidden;
- }
-
- .label-filename-style {
- overflow-x: hidden;
- margin-left: 5px;
- }
-
- .label-show {
- font-weight: bold;
- margin-left: 5px;
- }
-
- .label-download {
- font-weight: bold;
- margin-left: 5px;
- margin-right: 5px;
- }
-
- .display-inline-style {
- display: inline-block;
- margin-right: 5px;
- }
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
\ No newline at end of file
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AvatarReplacement.java b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AvatarReplacement.java
deleted file mode 100644
index c58c9d5..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AvatarReplacement.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package org.gcube.portlets.user.newsfeed.client.ui;
-
-import java.util.HashMap;
-
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.uibinder.client.UiBinder;
-import com.google.gwt.uibinder.client.UiField;
-import com.google.gwt.user.client.Random;
-import com.google.gwt.user.client.ui.Composite;
-import com.google.gwt.user.client.ui.HTML;
-import com.google.gwt.user.client.ui.Widget;
-
-public class AvatarReplacement extends Composite {
-
- private static NoAvatarUiBinder uiBinder = GWT.create(NoAvatarUiBinder.class);
-
- /**
- * to maintain the color assigned to an avatar replacement, for each page load
- * this hashmap maintain the assigned users color, chosen reandomly at the beginning
- */
- public static final HashMap avatarReplacementAssignedColors = new HashMap();
-
- interface NoAvatarUiBinder extends UiBinder {
- }
-
- @UiField HTML avatarBox;
- /**
- * the random colors
- */
- private String[] randomColors = {
- "#8e8e93",
- "#ff2d55",
- "#ff3b30",
- "#ff9500",
- "#ffcc00",
- "#4cd964",
- "#5ac8fa",
- "#34aadc",
- "#007aff",
- "#5856d6"
- };
-
-
- public AvatarReplacement() {
- initWidget(uiBinder.createAndBindUi(this));
- }
-
- public void setInitials(String username, String firstName, String lastName) {
- pickRandomColor(username);
- String first = "A";
- if (firstName != null && firstName.trim().length() > 0)
- first = firstName.trim().substring(0, 1);
- String second = "Z";
- if (lastName != null && lastName.trim().length() > 0)
- second = lastName.trim().substring(0, 1);
- avatarBox.setText(first+second);
- }
- /**
- * randomize of does not find it, else color is maintained through all the session
- * @param username
- */
- private void pickRandomColor(String username) {
- if (! avatarReplacementAssignedColors.containsKey(username)) {
- String randomColor = randomColors[Random.nextInt(randomColors.length)];
- avatarBox.getElement().getStyle().setBackgroundColor(randomColor);
- avatarReplacementAssignedColors.put(username, randomColor);
- } else
- avatarBox.getElement().getStyle().setBackgroundColor(avatarReplacementAssignedColors.get(username));
- }
-
-
-}
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AvatarReplacement.ui.xml b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AvatarReplacement.ui.xml
deleted file mode 100644
index 8bb8fcd..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AvatarReplacement.ui.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
- .avatar-frame {
- border-radius: 2em;
- border: 1px solid #E6E6E6;
- padding: 2px;
- }
-
- .avatar-replacement {
- border-radius: 2em;
- display: table-cell;
- text-align: center;
- vertical-align: middle;
- font-family: "HelveticaNeue-Light", "Helvetica Neue Light",
- "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
- font-weight: 300;
- font-size: 22px;
- padding: 0;
- color: #FFF;
- }
-
-
-
-
-
\ No newline at end of file
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AvatarReplacement4Comments.java b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AvatarReplacement4Comments.java
deleted file mode 100644
index b377a0c..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AvatarReplacement4Comments.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package org.gcube.portlets.user.newsfeed.client.ui;
-
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.uibinder.client.UiBinder;
-import com.google.gwt.uibinder.client.UiField;
-import com.google.gwt.user.client.Random;
-import com.google.gwt.user.client.ui.Composite;
-import com.google.gwt.user.client.ui.HTML;
-import com.google.gwt.user.client.ui.Widget;
-
-public class AvatarReplacement4Comments extends Composite {
-
- private static NoAvatarUiBinder uiBinder = GWT.create(NoAvatarUiBinder.class);
-
- interface NoAvatarUiBinder extends UiBinder {
- }
-
- @UiField HTML avatarBox;
- /**
- * the random colors
- */
- private String[] randomColors = {
- "#8e8e93",
- "#ff2d55",
- "#ff3b30",
- "#ff9500",
- "#ffcc00",
- "#4cd964",
- "#5ac8fa",
- "#34aadc",
- "#007aff",
- "#5856d6"
- };
-
-
- public AvatarReplacement4Comments() {
- initWidget(uiBinder.createAndBindUi(this));
- }
-
- public void setInitials(String username, String firstName, String lastName) {
- pickRandomColor(username);
- String first = "A";
- if (firstName != null && firstName.trim().length() > 0)
- first = firstName.trim().substring(0, 1);
- String second = "Z";
- if (lastName != null && lastName.trim().length() > 0)
- second = lastName.trim().substring(0, 1);
- avatarBox.setText(first+second);
- }
- /**
- * randomize of does not find it, else color is maintained through all the session
- * @param username
- */
- private void pickRandomColor(String username) {
- if (! AvatarReplacement.avatarReplacementAssignedColors.containsKey(username)) {
- String randomColor = randomColors[Random.nextInt(randomColors.length)];
- avatarBox.getElement().getStyle().setBackgroundColor(randomColor);
- AvatarReplacement.avatarReplacementAssignedColors.put(username, randomColor);
- } else
- avatarBox.getElement().getStyle().setBackgroundColor(AvatarReplacement.avatarReplacementAssignedColors.get(username));
- }
-
-
-}
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AvatarReplacement4Comments.ui.xml b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AvatarReplacement4Comments.ui.xml
deleted file mode 100644
index c492de3..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/AvatarReplacement4Comments.ui.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-
- .avatar-frame {
- border-radius: 2em;
- border: 1px solid #E6E6E6;
- padding: 2px;
- }
- .avatar-replacement {
- display: table-cell;
- border-radius: 2em;
- text-align: center;
- vertical-align: middle;
- font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
- font-weight: 300;
- font-size: 12px;
- padding: 0;
- color: #FFF;
- }
-
-
-
-
-
\ No newline at end of file
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/FilterPanel.java b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/FilterPanel.java
deleted file mode 100644
index 912ea95..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/FilterPanel.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package org.gcube.portlets.user.newsfeed.client.ui;
-
-import org.gcube.portlets.user.newsfeed.client.FilterType;
-import org.gcube.portlets.user.newsfeed.client.NewsServiceAsync;
-import org.gcube.portlets.user.newsfeed.client.panels.NewsFeedPanel;
-import org.gcube.portlets.user.newsfeed.shared.UserSettings;
-
-import com.github.gwtbootstrap.client.ui.Dropdown;
-import com.github.gwtbootstrap.client.ui.NavLink;
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.event.dom.client.ClickEvent;
-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.Window;
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.google.gwt.user.client.ui.Composite;
-import com.google.gwt.user.client.ui.Widget;
-
-public class FilterPanel extends Composite {
-
- private static FilterPanelUiBinder uiBinder = GWT
- .create(FilterPanelUiBinder.class);
-
- interface FilterPanelUiBinder extends UiBinder {
- }
-
- protected static final String ERROR_MESSAGE = "Ops! we encountered some problems, server is not responding, please try again in a short while.";
- protected static final String SESSION_EXPIRED = "Your session has expired, please log out and login again";
-
- NewsFeedPanel caller;
- NewsServiceAsync service;
- @UiField NavLink allUpdatesLink;
- @UiField NavLink recentCommentsLink;
- @UiField Dropdown sortByDD;
-
- public FilterPanel(NewsFeedPanel caller, NewsServiceAsync newsService) {
- initWidget(uiBinder.createAndBindUi(this));
- this.caller = caller;
- this.service = newsService;
- }
-
-
- public void removeFilterSelected() {
- allUpdatesLink.setActive(false);
- recentCommentsLink.setActive(false);
- }
-
- @UiHandler("recentCommentsLink")
- void onRecentCommentsLinkClick(ClickEvent e) {
- allUpdatesLink.setDisabled(false);
- recentCommentsLink.setDisabled(true);
- sortByDD.setText("newest Comment");
- caller.setCurrentFilter(FilterType.RECENT_COMMENTS);
- int loadedPostsInView = caller.getAllUpdatesSize() + 1;
- int quantity = loadedPostsInView < 100 ? 100 - loadedPostsInView : loadedPostsInView;
- caller.loadMorePosts(quantity, true);
- }
-
- @UiHandler("allUpdatesLink")
- void onAllUpdatesClick(ClickEvent e) {
- allUpdatesLink.setDisabled(true);
- recentCommentsLink.setDisabled(false);
- sortByDD.setText("newest Post");
- caller.setCurrentFilter(FilterType.ALL_UPDATES);
- service.getUserSettings(new AsyncCallback() {
- @Override
- public void onFailure(Throwable caught) {
- Window.alert(ERROR_MESSAGE);
- }
-
- @Override
- public void onSuccess(UserSettings result) {
- if (result.getUserInfo().getUsername().equals("test.user")) {
- Window.alert(SESSION_EXPIRED);
- }
- else
- caller.showAllUpdatesFeeds();
- }
- });
- }
-
-}
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/FilterPanel.ui.xml b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/FilterPanel.ui.xml
deleted file mode 100644
index 6d2bf2f..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/FilterPanel.ui.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
- .margin {
- margin-bottom: 0 !important;
- margin-top: -15px !important;
- }
-
-
-
- Show sorted by:
-
- newest Post
- newest Comment
-
-
-
-
\ No newline at end of file
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/LinkPreviewer.java b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/LinkPreviewer.java
deleted file mode 100644
index 03672ff..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/LinkPreviewer.java
+++ /dev/null
@@ -1,113 +0,0 @@
-package org.gcube.portlets.user.newsfeed.client.ui;
-
-import org.gcube.portlets.widgets.imagepreviewerwidget.client.ui.Carousel;
-
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.dom.client.Style.Cursor;
-import com.google.gwt.event.dom.client.ClickEvent;
-import com.google.gwt.event.dom.client.ClickHandler;
-import com.google.gwt.uibinder.client.UiBinder;
-import com.google.gwt.uibinder.client.UiField;
-import com.google.gwt.user.client.ui.Composite;
-import com.google.gwt.user.client.ui.HTML;
-import com.google.gwt.user.client.ui.Image;
-import com.google.gwt.user.client.ui.Widget;
-
-/**
- * Link Previewer class to show a link a preview.
- * @author Costantino Perciante at ISTI-CNR
- * @author Massimiliano Assante at ISTI-CNR
- */
-public class LinkPreviewer extends Composite {
-
- // is the preview image still there ?
- private boolean imageRemoved = false;
-
- @UiField
- HTML titleArea;
- @UiField
- HTML urlText;
- @UiField
- HTML descText;
- @UiField
- Image image;
-
- // saved file name
- private final String fileName;
-
- private static LinkPreviewUiBinder uiBinder = GWT
- .create(LinkPreviewUiBinder.class);
-
- interface LinkPreviewUiBinder extends UiBinder {
- }
-
- public LinkPreviewer(String title, String titleDesc, String host, String linkThumbUrl, String url) {
- initWidget(uiBinder.createAndBindUi(this));
- if (linkThumbUrl == null || linkThumbUrl.equals("null")){
-
- image.removeFromParent();
- imageRemoved = true;
-
- }
- else {
-
- image.setUrl(linkThumbUrl);
- image.setWidth("80px");
-
- }
-
- // save the filename info
- fileName = title;
- titleArea.setHTML(""+title+" - " + host+ "");
- urlText.setHTML((url.length() > 70) ? url.substring(0, 70)+"..." : url);
- String desc = titleDesc;
- descText.setHTML((desc.length() > 256) ? desc.substring(0, 256)+"..." : desc);
-
- }
-
- /**
- * Open the carousel when the user clicks on the preview's image.
- * @param carousel
- */
- public void onImageClickOpenCarousel(final Carousel carousel) {
-
- if(imageRemoved)
- return;
-
- // change cursor type on hover
- image.getElement().getStyle().setCursor(Cursor.POINTER);
-
- // add handler
- image.addClickHandler(new ClickHandler() {
-
- @Override
- public void onClick(ClickEvent event) {
-
- carousel.show();
-
- }
- });
- }
-
- /**
- * Open the carousel when the user clicks on the previews' file name.
- * @param carousel
- */
- public void onFileNameClickOpenCarousel(final Carousel carousel) {
-
- String nameToShow = fileName.length() > 40 ? fileName.substring(0, 40) + "..." : fileName;
- titleArea.setHTML(""+ nameToShow +"");
- titleArea.setTitle(fileName);
-
- titleArea.addClickHandler(new ClickHandler() {
-
- @Override
- public void onClick(ClickEvent event) {
-
- carousel.show();
-
- }
- });
-
- }
-}
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/LinkPreviewer.ui.xml b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/LinkPreviewer.ui.xml
deleted file mode 100644
index 17df84c..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/LinkPreviewer.ui.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-
-
-
-
-
- |
-
-
-
-
-
-
-
-
-
-
- |
-
-
-
-
\ No newline at end of file
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/LoadingText.java b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/LoadingText.java
deleted file mode 100644
index c00cbe4..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/LoadingText.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package org.gcube.portlets.user.newsfeed.client.ui;
-
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.uibinder.client.UiBinder;
-import com.google.gwt.user.client.ui.Composite;
-import com.google.gwt.user.client.ui.Widget;
-
-public class LoadingText extends Composite {
-
- private static LoadingTextUiBinder uiBinder = GWT
- .create(LoadingTextUiBinder.class);
-
- interface LoadingTextUiBinder extends UiBinder {
- }
-
- public LoadingText() {
- initWidget(uiBinder.createAndBindUi(this));
- }
-}
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/LoadingText.ui.xml b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/LoadingText.ui.xml
deleted file mode 100644
index 4235f32..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/LoadingText.ui.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
- Please wait
-
- Contacting infrastructure services ...
-
-
-
-
\ No newline at end of file
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/NewFeedsAvailable.java b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/NewFeedsAvailable.java
deleted file mode 100644
index 64d5452..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/NewFeedsAvailable.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package org.gcube.portlets.user.newsfeed.client.ui;
-
-import org.gcube.portlets.user.newsfeed.client.event.ShowNewUpdatesEvent;
-
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.dom.client.Document;
-import com.google.gwt.event.dom.client.ClickEvent;
-import com.google.gwt.event.shared.HandlerManager;
-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.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.Widget;
-
-public class NewFeedsAvailable extends Composite {
-
- private static NewFeedsAvailableUiBinder uiBinder = GWT
- .create(NewFeedsAvailableUiBinder.class);
-
- interface NewFeedsAvailableUiBinder extends
-
- UiBinder {
- }
-
- private HandlerManager eventBus;
-
- @UiField HTML caption;
- @UiField HTMLPanel panel;
-
-
- public NewFeedsAvailable(int newUpdatesNo, HandlerManager eventBus) {
- initWidget(uiBinder.createAndBindUi(this));
- this.eventBus = eventBus;
- if (newUpdatesNo > 0) {
- updateNewUpdatesNo(newUpdatesNo);
- //create the fade transition effect
- Timer t = new Timer() {
- @Override
- public void run() {
- caption.addStyleName("new-feeds-show");
- }
- };
- t.schedule(100);
- }
- else throw new IllegalArgumentException("newUpdatesNo must be greater than 0");
- }
-
- public void updateNewUpdatesNo(int newUpdatesNo) {
- String messageToShow = newUpdatesNo > 1 ? "See " + newUpdatesNo + " new Updates" : "See 1 new Update";
- caption.setHTML(messageToShow);
- setBrowserWindowTitle(newUpdatesNo);
- }
-
- public static void setBrowserWindowTitle (int newUpdatesNo) {
- if (Document.get() != null) {
- String currTitle = Document.get().getTitle();
- if (currTitle.startsWith("(")) {
- String newTitle = "(" + newUpdatesNo + currTitle.substring(2);
- Document.get().setTitle(newTitle);
- }
- else
- Document.get().setTitle ("("+newUpdatesNo+") " + currTitle);
- }
- }
-
- @UiHandler("caption")
- void onClick(ClickEvent e) {
- eventBus.fireEvent(new ShowNewUpdatesEvent());
- }
-}
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/NewFeedsAvailable.ui.xml b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/NewFeedsAvailable.ui.xml
deleted file mode 100644
index 743c429..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/NewFeedsAvailable.ui.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/Placeholder.java b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/Placeholder.java
deleted file mode 100644
index 8391e99..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/Placeholder.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package org.gcube.portlets.user.newsfeed.client.ui;
-import com.google.gwt.core.shared.GWT;
-import com.google.gwt.dom.client.Style.Unit;
-import com.google.gwt.event.dom.client.ClickEvent;
-import com.google.gwt.event.dom.client.ClickHandler;
-import com.google.gwt.user.client.Window;
-import com.google.gwt.user.client.ui.Anchor;
-import com.google.gwt.user.client.ui.FlowPanel;
-import com.google.gwt.user.client.ui.SimplePanel;
-import com.google.gwt.user.client.ui.Widget;
-import com.google.gwt.user.client.ui.WidgetCollection;
-/**
- * This panel will contain the attachments/previews
- * @author Massimiliano Assante at ISTI CNR
- * @author Costantino Perciante at ISTI CNR
- *
- */
-public class Placeholder extends FlowPanel {
-
- private static final String SHOW_OTHER_ATTACHMENTS_LABEL = "Show All";
-
- // check if we need to show more attachments
- private boolean appendShowMoreLabel;
-
- /**
- * Modified version of the add method.
- */
- public void add(AttachmentPreviewer atPrev){
-
- // retrieve the list of children
- WidgetCollection listOfChildren = this.getChildren();
-
- // check the size
- int size = listOfChildren.size();
-
- // look at NewsFeed.css ...
- if(Window.getClientWidth() <= 1128){
-
- add((Widget)atPrev);
- atPrev.changeAttachmentWidth(92, Unit.PCT);
- }
- else if(size % 2 == 0){
- // in this case the next attachment we are going to add remains with the same width
- add((Widget)atPrev);
- GWT.log("added without changing size");
- }
- else{
- // we need to change the length of the last element added and of this new one
- ((AttachmentPreviewer) listOfChildren.get(size -1)).changeAttachmentWidth(45, Unit.PCT);
- atPrev.changeAttachmentWidth(45, Unit.PCT);
-
- // add it finally
- add((Widget)atPrev);
- }
-
- if(size >= 4){
- // ok, we are going to add the 5th attachment and so forth but we hide them..
- atPrev.setVisible(false);
-
- // remember to add the button to let the user show them later
- appendShowMoreLabel = true;
- }
- }
-
- /**
- * Append "Show All" label to the post template.
- */
- public void appendShowMoreLabel(){
-
- if(appendShowMoreLabel){
-
- final WidgetCollection listOfChildren = this.getChildren();
-
- final SimplePanel sp = new SimplePanel();
- sp.setStyleName("centered");
-
- final Anchor showMoreAttachments = new Anchor(SHOW_OTHER_ATTACHMENTS_LABEL);
- showMoreAttachments.setTitle("Show all the attached files");
- showMoreAttachments.setStyleName("link");
- sp.add(showMoreAttachments);
-
- showMoreAttachments.addClickHandler(new ClickHandler() {
-
- @Override
- public void onClick(ClickEvent event) {
-
- // retrieve the list of attachmentPreviewers and show them
- for(Widget w: listOfChildren){
- w.setVisible(true);
- }
-
- sp.setVisible(false);
-
- }
- });
-
- // show the panel
- this.add(sp);
- }
- }
-}
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/ResultsFor.java b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/ResultsFor.java
deleted file mode 100644
index e953050..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/ResultsFor.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package org.gcube.portlets.user.newsfeed.client.ui;
-
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.dom.client.Style.Cursor;
-import com.google.gwt.event.dom.client.ClickEvent;
-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.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.Widget;
-
-public class ResultsFor extends Composite {
-
- private static ResultsForUiBinder uiBinder = GWT
- .create(ResultsForUiBinder.class);
-
- interface ResultsForUiBinder extends UiBinder {
- }
-
- @UiField HTML allUpdatesLink;
- @UiField HTML resultForDiv;
- public ResultsFor(String prefix, String hashtag) {
- initWidget(uiBinder.createAndBindUi(this));
- allUpdatesLink.setHTML("All Posts");
- allUpdatesLink.getElement().getStyle().setCursor(Cursor.POINTER);
- resultForDiv.setHTML(prefix + " " + hashtag + "");
- resultForDiv.setStyleName("filter-selected");
- }
-
- @UiHandler("allUpdatesLink")
- void onAllUpdatesClick(ClickEvent e) {
- String href = Location.getHref();
- if (href.contains("?"))
- href = href.substring(0, href.indexOf("?"));
- Location.assign(href);
- }
-
-}
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/ResultsFor.ui.xml b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/ResultsFor.ui.xml
deleted file mode 100644
index 36a403e..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/ResultsFor.ui.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/SharePostDialog.java b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/SharePostDialog.java
deleted file mode 100644
index bbdf850..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/SharePostDialog.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package org.gcube.portlets.user.newsfeed.client.ui;
-
-import com.github.gwtbootstrap.client.ui.Button;
-import com.github.gwtbootstrap.client.ui.ListBox;
-import com.github.gwtbootstrap.client.ui.Modal;
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.event.dom.client.ClickEvent;
-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.Window;
-import com.google.gwt.user.client.ui.Composite;
-import com.google.gwt.user.client.ui.Widget;
-
-public class SharePostDialog extends Composite {
-
- private static SharePostDialogUiBinder uiBinder = GWT
- .create(SharePostDialogUiBinder.class);
-
- interface SharePostDialogUiBinder extends UiBinder {
- }
-
- public SharePostDialog(TweetTemplate toShare) {
- initWidget(uiBinder.createAndBindUi(this));
-
- input.addItem("devVRE", "devVRE");
- input.addItem("devVRE2", "devVRE");
- input.addItem("devVRE3", "devVRE");
-
-
- }
-
- @UiField Button sharePostButton;
- @UiField Button cancel;
- @UiField Modal modalWindow;
- @UiField ListBox input;
-
- @UiHandler("sharePostButton")
- void onClick(ClickEvent e) {
- Window.alert("Hello!");
- }
-
- @UiHandler("cancel")
- void onCancelClick(ClickEvent e) {
- modalWindow.hide();
- }
-
- public void openModal() {
- GWT.log("OpenModal");
- modalWindow.show();
- }
-
-}
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/SharePostDialog.ui.xml b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/SharePostDialog.ui.xml
deleted file mode 100644
index 5a06a90..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/SharePostDialog.ui.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
- .important {
- font-weight: bold;
- }
-
-
-
-
-
-
-
-
- Cancel
- Send Invite
-
-
-
-
\ No newline at end of file
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/ShowMoreFeeds.java b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/ShowMoreFeeds.java
deleted file mode 100644
index 43cfa0f..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/ShowMoreFeeds.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package org.gcube.portlets.user.newsfeed.client.ui;
-
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.dom.client.Style.Unit;
-import com.google.gwt.event.shared.HandlerManager;
-import com.google.gwt.uibinder.client.UiBinder;
-import com.google.gwt.uibinder.client.UiField;
-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.Widget;
-
-public class ShowMoreFeeds extends Composite {
-
- private static NewFeedsAvailableUiBinder uiBinder = GWT
- .create(NewFeedsAvailableUiBinder.class);
-
- interface NewFeedsAvailableUiBinder extends
-
- UiBinder {
- }
-
- @UiField HTML caption;
- @UiField HTMLPanel panel;
-
- public ShowMoreFeeds(HandlerManager eventBus) {
- initWidget(uiBinder.createAndBindUi(this));
- panel.getElement().getStyle().setMarginTop(10, Unit.PX);
- caption.addStyleName("new-feeds-show");
- caption.getElement().getStyle().setBackgroundColor("transparent");
- caption.getElement().getStyle().setFontSize(14, Unit.PX);
- caption.setHTML("Show more feeds");
- //done after
- //panel.getElement().getStyle().setVisibility(Visibility.HIDDEN);
- }
-
-
-}
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/ShowMoreFeeds.ui.xml b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/ShowMoreFeeds.ui.xml
deleted file mode 100644
index 743c429..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/ShowMoreFeeds.ui.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/SingleComment.java b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/SingleComment.java
deleted file mode 100644
index cf0ad16..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/SingleComment.java
+++ /dev/null
@@ -1,186 +0,0 @@
-package org.gcube.portlets.user.newsfeed.client.ui;
-
-import java.util.Date;
-
-import org.gcube.common.portal.GCubePortalConstants;
-import org.gcube.portal.databook.client.GCubeSocialNetworking;
-import org.gcube.portal.databook.client.util.Encoder;
-import org.gcube.portal.databook.shared.Comment;
-import org.gcube.portlets.user.newsfeed.client.event.DeleteCommentEvent;
-import org.gcube.portlets.user.newsfeed.client.panels.NewsFeedPanel;
-
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.event.dom.client.ClickEvent;
-import com.google.gwt.event.dom.client.MouseOutEvent;
-import com.google.gwt.event.dom.client.MouseOverEvent;
-import com.google.gwt.i18n.client.DateTimeFormat;
-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.Event;
-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.Widget;
-
-public class SingleComment extends Composite {
-
- private static SingleCommentUiBinder uiBinder = GWT
- .create(SingleCommentUiBinder.class);
-
- interface SingleCommentUiBinder extends UiBinder {
- }
- private static final int MAX_SHOWTEXT_LENGTH = 450;
-
- private boolean isUsers = false;
- private TweetTemplate owner;
- private String myCommentid;
- private Comment myComment;
-
- @UiField HTMLPanel mainPanel;
- @UiField Image avatarImage;
- @UiField AvatarReplacement4Comments avatarReplacement;
- @UiField HTML commentText;
- @UiField HTML timeArea;
- @UiField HTML closeImage;
- @UiField HTML editImage;
- @UiField HTML seeMore;
-
- public SingleComment(Comment toShow, TweetTemplate owner, boolean isUsers) {
- initWidget(uiBinder.createAndBindUi(this));
- sinkEvents(Event.ONPASTE);
- this.owner = owner;
- this.isUsers = isUsers;
- this.myComment = toShow;
- myCommentid = toShow.getKey();
- avatarImage.setPixelSize(30, 30);
- avatarImage.setUrl(toShow.getThumbnailURL());
-
- //check if the user has his own avatar
- if (toShow.getThumbnailURL().endsWith("img_id=0") || !toShow.getThumbnailURL().contains("?")) { //it means no avatar is set
- avatarImage.setVisible(false);
- String f = "A";
- String s = "Z";
- if (toShow.getFullName() != null) {
- String[] parts = toShow.getFullName().split("\\s");
- if (parts.length > 0) {
- f = parts[0].toUpperCase();
- s = parts[parts.length-1].toUpperCase();
- } else {
- f = toShow.getFullName().substring(0,1);
- s = toShow.getFullName().substring(1,2);
- }
- }
- avatarReplacement.setInitials(toShow.getUserid(), f, s);
- avatarReplacement.setVisible(true);
- }
-
- String commentToShow = toShow.getText();
-
- //replace the < & and >
- commentToShow = commentToShow.replaceAll("<","<").replaceAll(">",">");
- commentToShow = commentToShow.replaceAll("&","&");
-
-
-
- if (commentToShow.length() > MAX_SHOWTEXT_LENGTH) {
- final int TEXT_TO_SHOW_LENGHT = (commentToShow.length() < 700) ? (commentToShow.length() - (commentToShow.length() / 3)) : 700;
- commentToShow = commentToShow.substring(0, TEXT_TO_SHOW_LENGHT) + "...";
- seeMore.setHTML(" See More ");
- }
- final String profilePageURL = GCubePortalConstants.PREFIX_GROUP_URL + NewsFeedPanel.extractOrgFriendlyURL(Location.getHref()) +GCubePortalConstants.USER_PROFILE_FRIENDLY_URL;
-
- commentText.setHTML(""+toShow.getFullName()+
- " " + commentToShow);
-
- // Comment's data
- Date now = new Date();
- String formattedTime;
- String formattedTimeEdit = null;
-
- if(now.getYear() != toShow.getTime().getYear())
- formattedTime = DateTimeFormat.getFormat("MMMM dd yyyy, h:mm a").format(toShow.getTime());
- else
- formattedTime = DateTimeFormat.getFormat("MMMM dd, h:mm a").format(toShow.getTime());
-
- if(toShow.isEdit()){
- if(now.getYear() != toShow.getLastEditTime().getYear())
- formattedTimeEdit = DateTimeFormat.getFormat("MMMM dd yyyy, h:mm a").format(toShow.getLastEditTime());
- else
- formattedTimeEdit = DateTimeFormat.getFormat("MMMM dd, h:mm a").format(toShow.getLastEditTime());
- }
-
- if(toShow.isEdit())
- timeArea.setHTML(formattedTime +
- " (Last edit on " + formattedTimeEdit + ")");
- else
- timeArea.setHTML(formattedTime);
-
- if (isUsers) {
- closeImage.setStyleName("closeImage");
- closeImage.setTitle("Delete");
- editImage.setStyleName("editImage");
- editImage.setTitle("Edit");
- }
- }
-
- @UiHandler("seeMore")
- void onSeeMoreClick(ClickEvent e) {
- String commentToShow = myComment.getText();
- //replace the < & and >
- commentToShow = commentToShow.replaceAll("<","<").replaceAll(">",">");
- commentToShow = commentToShow.replaceAll("&","&");
-
- final String profilePageURL = GCubePortalConstants.PREFIX_GROUP_URL + NewsFeedPanel.extractOrgFriendlyURL(Location.getHref()) +GCubePortalConstants.USER_PROFILE_FRIENDLY_URL;
-
- commentText.setHTML(""+
- myComment.getFullName()+" " + commentToShow);
- seeMore.setHTML("");
- }
-
-
-
- @UiHandler("closeImage")
- void onDeleteCommentClick(ClickEvent e) {
- if (isUsers)
- owner.getEventBus().fireEvent(new DeleteCommentEvent(owner, myCommentid));
- }
-
- @UiHandler("editImage")
- void onEditCommentClick(ClickEvent e) {
- if (isUsers) {
- AddCommentTemplate addComm = new AddCommentTemplate(owner, myComment, mainPanel);
- mainPanel.getElement().setInnerHTML("");
- mainPanel.add(addComm);
- }
- }
-
-
- @UiHandler("commentText")
- public void onHover(MouseOverEvent event) {
- if (isUsers) {
- closeImage.addStyleName("uiCloseButton");
- editImage.addStyleName("uiEditButton");
- }
- }
-
- @UiHandler("commentText")
- public void onHover(MouseOutEvent event) {
- if (isUsers) {
- closeImage.removeStyleName("uiCloseButton");
- editImage.removeStyleName("uiEditButton");
- }
- }
-
- public String getCommentKey() {
- return myCommentid;
- }
-
-
-}
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/SingleComment.ui.xml b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/SingleComment.ui.xml
deleted file mode 100644
index 82d0fe8..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/SingleComment.ui.xml
+++ /dev/null
@@ -1,34 +0,0 @@
-
-
-
- .important {
- font-weight: bold;
- }
-
-
-
-
-
\ No newline at end of file
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/SuperPosedTextArea.java b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/SuperPosedTextArea.java
deleted file mode 100644
index c6ac00c..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/SuperPosedTextArea.java
+++ /dev/null
@@ -1,233 +0,0 @@
-/**
- *
- */
-package org.gcube.portlets.user.newsfeed.client.ui;
-
-import java.util.HashSet;
-
-import org.gcube.portlets.user.gcubewidgets.client.elements.Div;
-import org.gcube.portlets.user.newsfeed.client.NewsService;
-import org.gcube.portlets.user.newsfeed.client.NewsServiceAsync;
-import org.gcube.portlets.user.newsfeed.shared.MentionedDTO;
-import org.gcube.portlets.widgets.pickitem.client.dialog.PickItemsDialog;
-import org.gcube.portlets.widgets.pickitem.client.events.PickedItemEvent;
-import org.gcube.portlets.widgets.pickitem.client.events.PickedItemEventHandler;
-import org.gcube.portlets.widgets.pickitem.shared.ItemBean;
-
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.dom.client.Element;
-import com.google.gwt.dom.client.NodeList;
-import com.google.gwt.event.dom.client.FocusEvent;
-import com.google.gwt.event.dom.client.FocusHandler;
-import com.google.gwt.event.dom.client.KeyCodes;
-import com.google.gwt.event.dom.client.KeyPressEvent;
-import com.google.gwt.event.dom.client.KeyPressHandler;
-import com.google.gwt.event.shared.HandlerManager;
-import com.google.gwt.user.client.DOM;
-import com.google.gwt.user.client.Event;
-import com.google.gwt.user.client.Random;
-import com.google.gwt.user.client.Timer;
-import com.google.gwt.user.client.ui.TextArea;
-
-/**
- * @author massi
- *
- */
-public class SuperPosedTextArea extends TextArea {
-
- private final NewsServiceAsync newsService = GWT.create(NewsService.class);
-
- private final HandlerManager eventBus = new HandlerManager(null);
-
- private PickItemsDialog pickUserDlg = null;
- private Div highlighterDIV;
- public final static int ARROW_UP = 38;
- public final static int ARROW_DOWN = 40;
- private String context;
- private HashSet mentionedUsers = new HashSet();
-
- private String areaId;
-
- /**
- *
- */
- public SuperPosedTextArea(Div highlighterDIV) {
- sinkEvents(Event.ONPASTE);
- sinkEvents(Event.ONCONTEXTMENU);
- sinkEvents(Event.ONKEYDOWN);
- sinkEvents(Event.ONKEYUP);
- setText(AddCommentTemplate.COMMENT_TEXT);
- this.highlighterDIV = highlighterDIV;
- //needed to give unique identifiers to the Area (for the jQuery plugin)
- areaId = "postTextArea"+Random.nextInt();
- getElement().setAttribute("id", areaId);
- bind();
- Timer t = new Timer() {
- @Override
- public void run() {
- myAutoSize(areaId);
- }
- };
- t.schedule(200);
-
- this.addKeyPressHandler(new KeyPressHandler() {
- @Override
- public void onKeyPress(KeyPressEvent event) {
- if (pickUserDlg != null) {
- int top = getAbsoluteTop();
- int offset = getOffsetHeight();
- int y = getAbsoluteTop()+getOffsetHeight();
- GWT.log("top=" + top + " - offset = " +offset);
- pickUserDlg.onKeyPress(getCursorPos(), event.getUnicodeCharCode(), getAbsoluteLeft(), y, getText());
- }
- }
- });
- this.addFocusHandler(new FocusHandler() {
- @Override
- public void onFocus(FocusEvent event) {
- pickUserDlg = new PickItemsDialog('@', eventBus, 430, context);
- pickUserDlg.withPhoto();
- }
- });
-
- }
- /**
- * This is the way to wrap jQuery plugins into GWT, wrap it in a function and call it.
- */
- public static native void myAutoSize(String myAreaId) /*-{
- function autoSizeArea() {
- $wnd.jQuery('#'+myAreaId).autosize();
- }
- autoSizeArea();
- }-*/;
- /**
- * @param element
- */
- public SuperPosedTextArea(Element element) {
- super(element);
- }
- /**
- *
- * @param context e.g. /gcube/devNext/NextNext
- */
- public void setContext(String context) {
- this.context = context;
- }
-
- /**
- * paste event overridden
- */
- public void onBrowserEvent(Event event) {
- super.onBrowserEvent(event);
- switch (event.getTypeInt()) {
- case Event.ONPASTE: {
- if (getText().equals(AddCommentTemplate.COMMENT_TEXT) || getText().equals(AddCommentTemplate.ERROR_UPDATE_TEXT) ) {
- setText("");
- addStyleName("dark-color");
- removeStyleName("nwfeed-error");
- }
- break;
- }
- case Event.ONKEYUP: {
- injectInDiv(getText());
- pickUserDlg.onKeyUp(event.getKeyCode());
- break;
- }
- case Event.ONCONTEXTMENU: {
- removeSampleText();
- break;
- }
- case Event.ONKEYDOWN: {
- if (pickUserDlg.isShowing()) {
- //avoid the arrow up to move the cursor at the beginning of the textbox and the TAB to move around inputs and enter to go newline
- if (event.getKeyCode() == ARROW_UP || event.getKeyCode() == KeyCodes.KEY_TAB || event.getKeyCode() == KeyCodes.KEY_ENTER) {
- DOM.eventCancelBubble(event, true);
- event.preventDefault();
- return;
- }
- }
- break;
- }
- }
- }
- protected void removeSampleText() {
- if (getText().equals(AddCommentTemplate.COMMENT_TEXT) || getText().equals(AddCommentTemplate.ERROR_UPDATE_TEXT) ) {
- setText("");
- addStyleName("darker-color");
- removeStyleName("nwfeed-error");
- }
- }
- protected void cleanHighlighterDiv() {
- //DOM.getElementById("comment-highlighter").setInnerHTML("");
- highlighterDIV.getElement().setInnerHTML("");
- }
- /**
- * copy what is being written in the text area in the underneath DIV
- * @param textAreaText
- */
- private void injectInDiv(String textAreaText) {
- String text;
- // parse the text:
- // replace all the line braks by
, and all the double spaces by the html version
- text = textAreaText.replaceAll("(\r\n|\n)","
");
- text = text.replaceAll("\\s\\s"," ");
-
- for (MentionedDTO mentionedUser : mentionedUsers) {
- text = text.replaceAll(mentionedUser.value,
- ""+mentionedUser.value+"");
- }
- // re-inject the processed text into the div
- highlighterDIV.getElement().setInnerHTML(text);
- }
-
- /**
- * events binder
- */
- private void bind() {
- eventBus.addHandler(PickedItemEvent.TYPE, new PickedItemEventHandler() {
- @Override
- public void onSelectedItem(PickedItemEvent event) {
-
- String toAdd = event.getSelectedItem().getAlternativeName();
-
- ItemBean ib = event.getSelectedItem();
- String type = ib.isItemGroup() ? "team" : "user";
- MentionedDTO mToAdd = new MentionedDTO(ib.getId(), ib.getAlternativeName(), type);
- mentionedUsers.add(mToAdd);
-
- String preceedingPart = getText().substring(0, event.getItemCursorIndexStart());
- String afterPart = getText().substring(event.getItemCursorIndexEnd()+1);
-
- setText(preceedingPart + toAdd + " " + afterPart);
- injectInDiv(getText());
- }
- });
- }
-
- public HashSet getMentionedUsers() {
- NodeList elems = highlighterDIV.getElement().getElementsByTagName("span");
- HashSet toReturn = new HashSet();
- if (elems != null && elems.getLength() > 0) {
- int elemsNo = elems.getLength();
- for (int i = 0; i < elemsNo; i++) {
- Element el = elems.getItem(i);
- String id = el.getId();
- String type = el.getTitle();
- String value = el.getInnerText();
- MentionedDTO toAdd = new MentionedDTO(id, value, type);
- toReturn.add(toAdd);
- GWT.log(toAdd.toString());
- }
- }
- return toReturn;
- }
- /**
- * return the unique identifier of this textarea, useful for getElementById JS method
- * @return
- */
- public String getAreaId() {
- return areaId;
- }
-
-
-}
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/TweetTemplate.java b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/TweetTemplate.java
deleted file mode 100644
index 045d75e..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/TweetTemplate.java
+++ /dev/null
@@ -1,727 +0,0 @@
-/**
- *
- */
-package org.gcube.portlets.user.newsfeed.client.ui;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.Iterator;
-
-import org.gcube.common.portal.GCubePortalConstants;
-import org.gcube.portal.databook.client.GCubeSocialNetworking;
-import org.gcube.portal.databook.client.util.Encoder;
-import org.gcube.portal.databook.shared.Attachment;
-import org.gcube.portal.databook.shared.Comment;
-import org.gcube.portal.databook.shared.EnhancedFeed;
-import org.gcube.portal.databook.shared.Feed;
-import org.gcube.portal.databook.shared.UserInfo;
-import org.gcube.portlets.user.newsfeed.client.event.AddLikeEvent;
-import org.gcube.portlets.user.newsfeed.client.event.DeletePostEvent;
-import org.gcube.portlets.user.newsfeed.client.event.OpenPostEvent;
-import org.gcube.portlets.user.newsfeed.client.event.SeeCommentsEvent;
-import org.gcube.portlets.user.newsfeed.client.event.SeeLikesEvent;
-import org.gcube.portlets.user.newsfeed.client.event.UnLikeEvent;
-import org.gcube.portlets.user.newsfeed.client.panels.NewsFeedPanel;
-import org.gcube.portlets.widgets.imagepreviewerwidget.client.EnhancedImage;
-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.dom.client.Style.Unit;
-import com.google.gwt.event.dom.client.ClickEvent;
-import com.google.gwt.event.dom.client.ClickHandler;
-import com.google.gwt.event.dom.client.MouseOutEvent;
-import com.google.gwt.event.dom.client.MouseOverEvent;
-import com.google.gwt.event.shared.HandlerManager;
-import com.google.gwt.i18n.client.DateTimeFormat;
-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.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;
-
-/**
- * @author Massimiliano Assante at ISTI-CNR
- * @author Costantino Perciante at ISTI-CNR
- *
- */
-public class TweetTemplate extends Composite {
-
- private static TweetTemplateUiBinder uiBinder = GWT
- .create(TweetTemplateUiBinder.class);
-
- interface TweetTemplateUiBinder extends UiBinder {
- }
-
-
- public static final String loading = GWT.getModuleBaseURL() + "../images/loading-comments.gif";
-
- private static final int MAX_SHOWTEXT_LENGTH = 612;
-
- private EnhancedFeed myPost;
- private UserInfo myUserInfo;
-
- private HandlerManager eventBus;
- private ArrayList myComments;
- private boolean commentingDisabled = false;
- private boolean commentsFetched = false;
- private int totalComments = 0;
- private HTML showAllComments = new HTML();
- private boolean isAppPost = false;
- private HTML submitCommentPreloader = new HTML("");
- private TweetTemplate myInstance;
-
- // Carousel from the image-previewer widget
- private Carousel carousel;
-
- /**
- * tell if this tweet is belonging to the current user
- */
- private boolean isUsers = false;
-
- @UiField
- HTML contentArea;
- @UiField
- HTML postOwnerArea;
- @UiField
- HTML seeMore;
- @UiField
- InlineLabel timeArea;
- @UiField
- InlineLabel separator;
- @UiField
- InlineLabel vreSourceInMetadata;
- @UiField
- HTML likeArea;
- @UiField
- HTML commentArea;
- @UiField
- Image avatarImage;
- @UiField
- AvatarReplacement avatarReplacement;
- @UiField
- HTMLPanel mainHTML;
- @UiField
- Button likesNo;
- @UiField
- Button commentsNo;
- @UiField
- VerticalPanel commentsPanel;
- @UiField
- HTML closeImage;
- @UiField
- HTML openImage;
- @UiField
- VerticalPanel previewPanel;
- @UiField
- Placeholder attachmentPreviewPanel;
- @UiField
- Label messageSeparator;
- /**
- * used when fetching tweets from server
- * @param myUserInfo
- * @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 myPost, HandlerManager eventBus) {
- initWidget(uiBinder.createAndBindUi(this));
- commentsNo.getElement().getStyle().setPaddingTop(0, Unit.PX);
- likesNo.getElement().getStyle().setPaddingTop(0, Unit.PX);
- likesNo.getElement().getStyle().setPaddingRight(2, Unit.PX);
- commentsNo.getElement().getStyle().setPaddingRight(2, Unit.PX);
- likesNo.getElement().getStyle().setPaddingLeft(2, Unit.PX);
- commentsNo.getElement().getStyle().setPaddingLeft(2, Unit.PX);
-
- myInstance = this;
- this.myUserInfo = myUserInfo;
- this.vreSourceInMetadata.setVisible(false);
- this.separator.setVisible(false);
- this.myPost = myPost;
- isAppPost = myPost.getFeed().isApplicationFeed();
- Feed post = myPost.getFeed();
- this.eventBus = eventBus;
- this.isUsers = myPost.isUsers();
- this.carousel = new Carousel();
- myComments = new ArrayList();
-
- if (isUsers || myUserInfo.isAdmin()) {
- closeImage.setStyleName("closeImage");
- closeImage.setTitle(myUserInfo.isAdmin() ? "Delete (Administrator Mode)" : "delete");
- } else {
- closeImage.removeFromParent();
- }
-
- // if there is one attachment or a link preview, maintain backward compatibility
- if (post.getUri() != null && post.getUri().compareTo("") != 0 && post.getLinkTitle() != null && post.getLinkTitle().compareTo("") != 0 && !post.isMultiFileUpload()) {
-
- // hide the attachments panel
- attachmentPreviewPanel.setVisible(false);
-
- LinkPreviewer linkPreviewer = new LinkPreviewer(post.getLinkTitle(), post.getLinkDescription(), post.getLinkHost(), post.getUriThumbnail(), post.getUri());
-
- // enable the image previewer if it is an image (mime)
- if(post.getLinkHost().contains("image/")){
-
- ArrayList listOfEnhancedImages;
-
- EnhancedImage enhancedImage = new EnhancedImage(
- post.getUri(),
- post.getLinkTitle() +
- " (" + post.getLinkDescription() + ", type:" + post.getLinkHost() +")",
- post.getLinkTitle(),
- post.getUri()
- );
-
- listOfEnhancedImages = new ArrayList();
- listOfEnhancedImages.add(enhancedImage);
- carousel.updateImages(listOfEnhancedImages);
-
- // set handler on the linkpreviewer image to show this carousel and on the image title too
- linkPreviewer.onImageClickOpenCarousel(carousel);
- linkPreviewer.onFileNameClickOpenCarousel(carousel);
-
- // remove next and prev buttons of the carousel since we have only an image
- carousel.hideArrows();
-
- }
-
- // add link preview to the preview panel
- previewPanel.add(linkPreviewer);
- }
-
- // in case there are attachments, we have to fill attachmentPreviewPanel instead of the previewPanel
- if(post.isMultiFileUpload()){
-
- // set style to the attachment container
- attachmentPreviewPanel.setStyleName("attachment-preview-container");
-
- // hide link preview panel
- previewPanel.setVisible(false);
-
- // prepare the carousel
- ArrayList listOfEnhancedImages = new ArrayList();
-
- // remember that one attachment is stored in the fields: uri, uriThumbnail, linkTitle, linkDescription, linkHost
- Attachment firstAttachment = new Attachment(
- post.getKey(), // it is meaningless but it's needed
- post.getUri(),
- post.getLinkTitle(),
- post.getLinkDescription(),
- post.getUriThumbnail(),
- post.getLinkHost());
-
- // create first attachment previewer and pass it the carousel
- AttachmentPreviewer firstAttachmentPreviewer = new AttachmentPreviewer(firstAttachment);
-
- // determine if the left/right arrows must be removed
- int imagesAvailableInCarousel = 0;
-
- // check if it is an image
- if(firstAttachment.getMimeType().contains("image/")){
-
- EnhancedImage enhancedImage = new EnhancedImage(
- post.getUri(),
- post.getLinkTitle() +
- " (" + post.getLinkDescription() + ", type:" + post.getLinkHost() +")",
- post.getLinkTitle(),
- post.getUri()
- );
-
- listOfEnhancedImages.add(enhancedImage);
- firstAttachmentPreviewer.onImageClickOpenCarousel(carousel, enhancedImage);
-
- // increment the images
- imagesAvailableInCarousel ++;
-
- }
-
- // add the first attachment to the panel
- attachmentPreviewPanel.add(firstAttachmentPreviewer);
-
- // check the others
- for (Attachment otherAttachment : myPost.getAttachments()) {
-
- AttachmentPreviewer attachmentPreviewer = new AttachmentPreviewer(otherAttachment);
-
- if(otherAttachment.getMimeType().contains("image/")){
-
- EnhancedImage enhancedImage = new EnhancedImage(
- otherAttachment.getUri(),
- otherAttachment.getName() +
- " (" + otherAttachment.getDescription() + ", type:" + post.getLinkHost() +")",
- otherAttachment.getName(),
- otherAttachment.getUri()
- );
-
- listOfEnhancedImages.add(enhancedImage);
-
- // pass the carousel
- attachmentPreviewer.onImageClickOpenCarousel(carousel, enhancedImage);
-
- // increment the images
- imagesAvailableInCarousel ++;
-
- }
-
- // try to build the attachment viewer
- attachmentPreviewPanel.add(attachmentPreviewer);
-
- // hide arrows if there is no more than 1 image
- if(imagesAvailableInCarousel <= 1)
- carousel.hideArrows();
-
- }
-
- // update the carousel's images
- carousel.updateImages(listOfEnhancedImages);
-
- // invoke append label
- attachmentPreviewPanel.appendShowMoreLabel();
- }
-
- openImage.setStyleName("openImage");
- openImage.setTitle("Open this feed separately");
- //show if the user has already liked this or not
- setFavoritedUI(myPost.isLiked());
-
- commentArea.setHTML("" + NewsFeedPanel.COMMENT_LABEL + "");
-
- String postText = post.getDescription();
- String descWithoutHTML = new HTML(postText).getText();
-
- if ( (! postText.startsWith(" MAX_SHOWTEXT_LENGTH && !displaySingle) {
- final int TEXT_TO_SHOW_LENGHT = (descWithoutHTML.length() < 600) ? (postText.length() - (postText.length() / 3)) : 600;
- postText = postText.substring(0, TEXT_TO_SHOW_LENGHT) + "...";
- seeMore.setHTML(" See More ");
- }
-
- avatarImage.setUrl(post.getThumbnailURL());
- avatarImage.setPixelSize(40, 40);
-
- //replace the < & and >
- postText = postText.replaceAll("<","<").replaceAll(">",">");
- postText = postText.replaceAll("&","&");
-
- final String profilePageURL = GCubePortalConstants.PREFIX_GROUP_URL + NewsFeedPanel.extractOrgFriendlyURL(Location.getHref()) +GCubePortalConstants.USER_PROFILE_FRIENDLY_URL;
-
-
-
- if (showTimelineSource && post.getVreid() != null && post.getVreid().compareTo("") != 0) {
- this.vreSourceInMetadata.setVisible(true);
- this.separator.setVisible(true);
- String vreName = post.getVreid().substring(post.getVreid().lastIndexOf("/")+1);
- vreSourceInMetadata.setText(vreName);
- vreSourceInMetadata.addClickHandler(new ClickHandler() {
- @Override
- public void onClick(ClickEvent event) {
- Location.assign("/group/"+vreName.toLowerCase());
- }
- });
- }
-
- if (! isAppPost) {
- // sharePostArea.setHTML("" + NewsFeedPanel.SHARE_FWD_LABEL + "");
- postOwnerArea.setHTML(""+post.getFullName()+"");
- contentArea.setHTML(postText);
-
- //check if the user has his own avatar
- if (post.getThumbnailURL().contains("img_id=0") || !post.getThumbnailURL().contains("?")) { //it means no avatar is set
- avatarImage.setVisible(false);
- String f = "A";
- String s = "Z";
- if (post.getFullName() != null) {
- String[] parts = post.getFullName().split("\\s");
- if (parts.length > 0) {
- f = parts[0].toUpperCase();
- s = parts[parts.length-1].toUpperCase();
- } else {
- f = post.getFullName().substring(0,1);
- s = post.getFullName().substring(1,2);
- }
- }
- avatarReplacement.setInitials(post.getEntityId(), f, s);
- avatarReplacement.setVisible(true);
- }
- }
- else {
- // messageSeparator.setVisible(false);
- postOwnerArea.setHTML(""+post.getFullName()+"");
- contentArea.setHTML(postText);
-
- if (isAppPost) {
- if (myUserInfo.isAdmin())
- closeImage.setTitle("Delete this Application feed (Administrator Only)");
- else
- closeImage.removeFromParent();
- }
- }
-
-
- try {
- Date now = new Date();
- String formattedTime;
- // TODO java.util.Calendar is not yet available in GWT
- if(now.getYear() != post.getTime().getYear())
- formattedTime = DateTimeFormat.getFormat("MMMM dd yyyy, h:mm a").format(post.getTime());
- else
- formattedTime = DateTimeFormat.getFormat("MMMM dd, h:mm a").format(post.getTime());
-
- timeArea.setText(formattedTime);
- String formattedTimeWithYear = DateTimeFormat.getFormat("dd MMMM yyyy h:mm a ").format(post.getTime());
- timeArea.setTitle(formattedTimeWithYear);
- if (! post.getCommentsNo().equals("0")) {
- commentsNo.setVisible(true);
- commentsNo.setText(post.getCommentsNo());
- commentsNo.setTitle(post.getCommentsNo() + " people commented this.");
- }
- if (! post.getLikesNo().equals("0")) {
- likesNo.setVisible(true);
- likesNo.setText(post.getLikesNo());
- likesNo.setTitle("Show People who have " + NewsFeedPanel.LIKED_LABEL + " this.");
- }
- totalComments = Integer.parseInt(post.getCommentsNo());
- }
- catch (NumberFormatException e) {
- totalComments = 0;
- }
- catch (Exception e) {
- timeArea.setText("just now");
- }
- commentsPanel.setStyleName("commentsPanel");
- if (myPost.getComments() != null && myPost.getComments().size() > 0) {
- if (totalComments > 2 && !displaySingle) {
- showAllComments = getShowAllCommentsLink(totalComments);
- commentsPanel.add(showAllComments);
- commentsNo.setVisible(true);
- }
- for (Comment comment : myPost.getComments()) {
- addComment(new SingleComment(comment, this, (comment.getUserid().equals(myUserInfo.getUsername()))));
- }
- showAddCommentForm(false);
- }
- }
-
- /**
- * used when getting tweets from the client
- * @param myUserInfo
- * @param feed
- * @param eventBus
- * @param hidden
- */
- public TweetTemplate(UserInfo myUserInfo, EnhancedFeed feed, HandlerManager eventBus, boolean hidden) {
- this(false, false, myUserInfo, feed, eventBus);
- contentArea.getElement().getParentElement().getParentElement().setClassName("div-table-col content hidden");
- }
-
- @UiHandler("contentArea")
- public void onHover(MouseOutEvent event) {
- if (isUsers)
- closeImage.removeStyleName("uiCloseButton");
- openImage.removeStyleName("uiOpenButton");
- }
-
- @UiHandler("contentArea")
- public void onHover(MouseOverEvent event) {
- if (isUsers) {
- closeImage.addStyleName("uiCloseButton");
- GWT.log("this belong to user");
- }
- openImage.addStyleName("uiOpenButton");
- }
-
- @UiHandler("closeImage")
- void onDeleteFeedClick(ClickEvent e) {
- if (isUsers || myUserInfo.isAdmin()){
- eventBus.fireEvent(new DeletePostEvent(this));
- }
- else {
- GWT.log("not belong to user");
- }
- }
-
- @UiHandler("openImage")
- void onOpenFeedClick(ClickEvent e) {
- eventBus.fireEvent(new OpenPostEvent(this));
- }
-
-
-
-
- @UiHandler("seeMore")
- void onSeeMoreClick(ClickEvent e) {
- String postText = myPost.getFeed().getDescription();
- //replace the < & and >
- postText = postText.replaceAll("<","<").replaceAll(">",">");
- postText = postText.replaceAll("&","&");
-
- contentArea.setHTML(postText);
- seeMore.setHTML("");
- }
-
- private void setFavoritedUI(boolean favorited) {
- if (favorited) {
- likeArea.setHTML("" + NewsFeedPanel.LIKED_LABEL + "");
- likeArea.setTitle("Unlike this");
- }
- else {
- likeArea.setHTML("" + NewsFeedPanel.LIKE_LABEL + "");
- }
- }
-
-
-
- @UiHandler("likeArea")
- void onLikeClick(ClickEvent e) {
- //if is not liked
- if (!likeArea.getText().equals(NewsFeedPanel.LIKED_LABEL)) {
- try {
- int cur = Integer.parseInt(myPost.getFeed().getLikesNo());
- cur++;
- if (cur == 1) {
- myPost.getFeed().setLikesNo("1");
- likesNo.setText("1");
- likesNo.setTitle("People who have " + NewsFeedPanel.LIKED_LABEL + " this");
- likesNo.setVisible(true);
- } else {
- myPost.getFeed().setLikesNo(""+cur);
- likesNo.setText(""+cur);
- likesNo.setVisible(true);
- }
- eventBus.fireEvent(new AddLikeEvent(this, myPost.getFeed().getKey()));
- setFavoritedUI(true);
- }
- catch (NumberFormatException ex) {
- likeArea.setHTML("Error on the server");
- }
- } else {
- //it is liked
- int cur = Integer.parseInt(myPost.getFeed().getLikesNo());
- cur--;
- if (cur == 0) {
- myPost.getFeed().setLikesNo("0");
- likesNo.setText("");
- likesNo.setVisible(false);
- likesNo.setTitle("");
- } else {
- myPost.getFeed().setLikesNo(""+cur);
- likesNo.setText(""+cur);
- likesNo.setVisible(true);
- }
- eventBus.fireEvent(new UnLikeEvent(this, myPost.getFeed().getKey()));
- setFavoritedUI(false);
- }
- }
-
- @UiHandler("commentArea")
- void onAddCommentClick(ClickEvent e) {
- if (! commentingDisabled) {
- if (! commentsFetched && totalComments > 2) { //if so, need to load all comments before adding a comment
- fireSeeComments(true);
- }
- else {
- showAddCommentForm(true);
- }
- }
- else
- GWT.log("Commenting disabled");
- }
-
- public void showAddCommentForm(boolean focus) {
- final AddCommentTemplate toAdd = new AddCommentTemplate(this, myUserInfo, eventBus);
- commentsPanel.add(toAdd);
- commentingDisabled = true;
- final Timer t = new Timer() {
- @Override
- public void run() {
- toAdd.setStyleName("comment-show");
- }
- };
- if (focus)
- toAdd.setFocus();
- t.schedule(10);
- }
-
- private HTML getShowAllCommentsLink(int commentsNo) {
- final HTML toReturn = new HTML("");
- toReturn.addClickHandler(new ClickHandler() {
- @Override
- public void onClick(ClickEvent event) {
- fireSeeComments(false);
- }
- });
- return toReturn;
- }
-
- private void fireSeeComments(boolean commentForm2Add) {
- eventBus.fireEvent(new SeeCommentsEvent(this, commentForm2Add));
- }
-
- @UiHandler("likesNo")
- void onSeeLikes(ClickEvent e) {
- eventBus.fireEvent(new SeeLikesEvent(myPost.getFeed().getKey()));
- }
-
- @UiHandler("commentsNo")
- void onSeeComments(ClickEvent e) {
- fireSeeComments(false);
- }
-
- public void setcontentAreaStyle(String cssclass) {
- contentArea.getElement().getParentElement().getParentElement().setClassName("div-table-col content visible");
- }
-
- public boolean isCommenting() {
- return commentingDisabled;
- }
-
- public void setCommentingDisabled(boolean commenting) {
- this.commentingDisabled = commenting;
- }
- public String getFeedKey() {
- return myPost.getFeed().getKey();
- }
-
- public void remove(Widget w) {
- mainHTML.remove(w);
- }
-
- public void addComment(SingleComment comment) {
- commentsPanel.add(comment);
- myComments.add(comment);
-
- }
- /**
- *
- * @param show true to show a preloader, false to hide it.
- * display a preloader userful when the user is wating for the comment operation to be confirmed by the server
- */
- public void showCommentingPreloader(boolean show) {
- if (show)
- commentsPanel.add(submitCommentPreloader);
- else
- commentsPanel.remove(submitCommentPreloader);
-
- }
-
- public void updateSingleComment(Comment edited, HTMLPanel commentPanel){
-
- commentPanel.clear();
- SingleComment sc = new SingleComment(edited, this, true);
- commentPanel.add(sc);
-
- // replace the new SingleComment in the list
- int index = 0;
- Iterator iterator = this.myComments.iterator();
-
- for (;iterator.hasNext();) {
- SingleComment singleComment = (SingleComment) iterator.next();
-
- if(singleComment.getCommentKey().equals(edited.getKey())){
-
- iterator.remove();
- this.myComments.add(index, sc);
- break;
-
- }
- index ++;
- }
-
- }
-
- public void clearComments() {
- myComments.clear();
- commentsPanel.clear();
- }
-
- public void showLoadingComments() {
- showAllComments.setHTML("");
- }
-
- public boolean isCommentsFetched() {
- return commentsFetched;
- }
-
- public void setCommentsFetched(boolean commentsFetched) {
- this.commentsFetched = commentsFetched;
- }
- public HandlerManager getEventBus() {
- return eventBus;
- }
- public void updateCommentsNumberCount() {
- if (myComments.size() == 1) {
- //commentsNo.setStyleName("show-comments-number");
- commentsNo.setTitle("Persons who have commented this.");
- }
- //commentsNo.setHTML(commentIcon.getElement().toString()+" "+myComments.size());
- commentsNo.setText(""+myComments.size());
- }
- public UserInfo getMyUserInfo() {
- return myUserInfo;
- }
-
- public String getMyFeedUserId() {
- return myPost.getFeed().getEntityId();
- }
-
- public String getMyFeedText() {
- return myPost.getFeed().getDescription();
- }
-
- public boolean isAppFeed() {
- return isAppPost;
- }
-
- public boolean isUser() {
- return isUsers;
- }
-
- /**
- * Returns the number of comments this post has
- * @return
- */
- public int numberOfComments(){
- return myComments.size();
- }
- /**
- * Returns the context of the Post
- * @return the context (scope) of the Post
- */
- public String getVREContext() {
- return this.myPost.getFeed().getVreid();
- }
-
- /**
- * Returns the number of likes this post has
- * @return
- */
- public int numberOfLikes(){
-
- // not so easy
- int ret = 0;
-
- try{
-
- ret = Integer.parseInt(likesNo.getText());
-
- }catch(NumberFormatException e){
-
- GWT.log(e.toString());
- }
-
- return ret;
- }
-
-}
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/TweetTemplate.ui.xml b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/TweetTemplate.ui.xml
deleted file mode 100644
index e572d2c..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/client/ui/TweetTemplate.ui.xml
+++ /dev/null
@@ -1,83 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
- |
-
-
-
-
- ·
-
-
- |
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/server/CustomConfiguration.java b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/server/CustomConfiguration.java
deleted file mode 100644
index f124c7e..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/server/CustomConfiguration.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package org.gcube.portlets.user.newsfeed.server;
-/**
- * custom class to read propety file once
- * @author massi
- *
- */
-public class CustomConfiguration {
- private int refreshTime;
- private String vreLabel;
- private boolean showTimelineSource;
-
- public CustomConfiguration(int refreshTime, String vreLabel,
- boolean showTimelineSource) {
- super();
- this.refreshTime = refreshTime;
- this.vreLabel = vreLabel;
- this.showTimelineSource = showTimelineSource;
- }
-
- public int getRefreshTime() {
- return refreshTime;
- }
-
- public void setRefreshTime(int refreshTime) {
- this.refreshTime = refreshTime;
- }
-
- public String getVreLabel() {
- return vreLabel;
- }
-
- public void setVreLabel(String vreLabel) {
- this.vreLabel = vreLabel;
- }
-
- public boolean isShowTimelineSource() {
- return showTimelineSource;
- }
-
- public void setShowTimelineSource(boolean showTimelineSource) {
- this.showTimelineSource = showTimelineSource;
- }
-
- @Override
- public String toString() {
- return "CustomConfiguration [refreshTime=" + refreshTime
- + ", vreLabel=" + vreLabel + ", showTimelineSource="
- + showTimelineSource + "]";
- }
-
-}
diff --git a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java b/2.8/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java
deleted file mode 100644
index f334882..0000000
--- a/2.8/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java
+++ /dev/null
@@ -1,1231 +0,0 @@
-package org.gcube.portlets.user.newsfeed.server;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Properties;
-import java.util.Set;
-import java.util.UUID;
-
-import javax.servlet.ServletContext;
-
-import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
-import org.gcube.applicationsupportlayer.social.NotificationsManager;
-import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
-import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser;
-import org.gcube.common.portal.GCubePortalConstants;
-import org.gcube.common.portal.PortalContext;
-import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl;
-import org.gcube.portal.databook.server.DatabookStore;
-import org.gcube.portal.databook.shared.Attachment;
-import org.gcube.portal.databook.shared.Comment;
-import org.gcube.portal.databook.shared.EnhancedFeed;
-import org.gcube.portal.databook.shared.Feed;
-import org.gcube.portal.databook.shared.Like;
-import org.gcube.portal.databook.shared.RangeFeeds;
-import org.gcube.portal.databook.shared.ShowUserStatisticAction;
-import org.gcube.portal.databook.shared.UserInfo;
-import org.gcube.portal.databook.shared.ex.ColumnNameNotFoundException;
-import org.gcube.portal.databook.shared.ex.CommentIDNotFoundException;
-import org.gcube.portal.databook.shared.ex.FeedIDNotFoundException;
-import org.gcube.portal.databook.shared.ex.FeedTypeNotFoundException;
-import org.gcube.portal.databook.shared.ex.LikeIDNotFoundException;
-import org.gcube.portal.databook.shared.ex.PrivacyLevelTypeNotFoundException;
-import org.gcube.portal.notifications.bean.GenericItemBean;
-import org.gcube.portal.notifications.thread.CommentNotificationsThread;
-import org.gcube.portal.notifications.thread.LikeNotificationsThread;
-import org.gcube.portal.notifications.thread.MentionNotificationsThread;
-import org.gcube.portlets.user.newsfeed.client.NewsService;
-import org.gcube.portlets.user.newsfeed.shared.MentionedDTO;
-import org.gcube.portlets.user.newsfeed.shared.MorePostsBean;
-import org.gcube.portlets.user.newsfeed.shared.NewsConstants;
-import org.gcube.portlets.user.newsfeed.shared.OperationResult;
-import org.gcube.portlets.user.newsfeed.shared.UserSettings;
-import org.gcube.portlets.widgets.pickitem.shared.ItemBean;
-import org.gcube.social_networking.socialutillibrary.Utils;
-import org.gcube.socialnetworking.social_data_search_client.ElasticSearchClient;
-import org.gcube.socialnetworking.social_data_search_client.ElasticSearchClientImpl;
-import org.gcube.socialnetworking.socialtoken.SocialMessageParser;
-import org.gcube.vomanagement.usermanagement.GroupManager;
-import org.gcube.vomanagement.usermanagement.RoleManager;
-import org.gcube.vomanagement.usermanagement.UserManager;
-import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
-import org.gcube.vomanagement.usermanagement.exception.TeamRetrievalFault;
-import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
-import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
-import org.gcube.vomanagement.usermanagement.exception.VirtualGroupNotExistingException;
-import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
-import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
-import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
-import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
-import org.gcube.vomanagement.usermanagement.model.GCubeTeam;
-import org.gcube.vomanagement.usermanagement.model.GCubeUser;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.gwt.user.server.rpc.RemoteServiceServlet;
-import com.liferay.portal.kernel.exception.PortalException;
-import com.liferay.portal.kernel.exception.SystemException;
-import com.liferay.portal.service.UserLocalServiceUtil;
-
-/**
- * The server side implementation of the RPC service.
- */
-@SuppressWarnings("serial")
-public class NewsServiceImpl extends RemoteServiceServlet implements NewsService {
-
- private static final Logger _log = LoggerFactory.getLogger(NewsServiceImpl.class);
-
- private static final String VRE_LABEL = "VRE_LABEL";
- private static final String SHOW_TIMELINE_SOURCE = "SHOW_TIMELINE_SOURCE";
- private static final String REFRESH_TIME = "REFRESH_TIME";
-
- private static final String SESSION_ADMIN_ATTR = "SESSION_ADMIN_ATTR";
- public static final String NF_ORGANIZATIONUSERS_CACHE = "NF_ORGANIZATIONUSERS_CACHE";
- public static final String LAST_RETRIEVED_TIME = "NF_LAST_RETRIEVED_TIME";
-
- private String APP_ID;
-
- /**
- * Cassandra client
- */
- private DatabookStore store;
-
- /**
- * Elasticsearch client
- */
- private ElasticSearchClient escl;
-
- private final static int MAX_POSTS_NO = 30;
-
- public void init() {
- store = new DBCassandraAstyanaxImpl();
- try {
- escl = new ElasticSearchClientImpl(null);
- _log.info("Elasticsearch connection created");
- } catch (Exception e) {
- escl = null;
- _log.error("Unable to create elasticsearch client connection!!!", e);
- }
-
- APP_ID = this.getClass().getName();
- }
-
- public void destroy() {
- store.closeConnection();
- }
- /**
- *
- * @return true if you're running into the portal, false if in development
- */
- private boolean isWithinPortal() {
- try {
- UserLocalServiceUtil.getService();
- return true;
- }
- catch (com.liferay.portal.kernel.bean.BeanLocatorException ex) {
- _log.trace("Development Mode ON");
- return false;
- }
- }
- /**
- * this is the first method called by the web app
- */
- @Override
- public UserSettings getUserSettings() {
- try {
- PortalContext context = PortalContext.getConfiguration();
- GCubeUser currUser = context.getCurrentUser(getThreadLocalRequest());
- String username = currUser.getUsername();
- String email = currUser.getEmail();
- String fullName = currUser.getFullname();
- String thumbnailURL = currUser.getUserAvatarURL();
-
- String groupName = context.getCurrentGroupName(getThreadLocalRequest());
-
-
- final String profilePageURL =
- GCubePortalConstants.PREFIX_GROUP_URL +
- PortalContext.getConfiguration().getSiteLandingPagePath(getThreadLocalRequest())+
- GCubePortalConstants.USER_PROFILE_FRIENDLY_URL;
- String accountURL = profilePageURL;
-
- UserInfo userInfo = new UserInfo(username, fullName, thumbnailURL, email, accountURL, true, isAdmin(), null);
- CustomConfiguration config = getUserConfiguration();
- UserSettings toReturn = new UserSettings(userInfo, config.getRefreshTime(), groupName, config.getVreLabel(), isInfrastructureScope(), config.isShowTimelineSource());
- return toReturn;
-
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- return new UserSettings();
- }
-
- /**
- * Indicates whether the scope is the whole infrastructure.
- * @return true
if it is, false
otherwise.
- * @throws GroupRetrievalFault
- * @throws UserManagementSystemException
- */
- private boolean isInfrastructureScope() throws UserManagementSystemException, GroupRetrievalFault {
- PortalContext context = PortalContext.getConfiguration();
- String scope = context.getCurrentScope(getThreadLocalRequest());
-
- long groupId = context.getCurrentGroupId(getThreadLocalRequest());
- boolean isInfrastructureScope = new LiferayGroupManager().isRootVO(groupId);
- _log.debug("isInfrastructureScope? " + scope + " groupId=" + groupId + " ? i say " + isInfrastructureScope);
- return isInfrastructureScope;
- }
-
- @Override
- public ArrayList getAllUpdateUserFeeds(int postsNoPerCategory) {
-
- ArrayList toMerge = new ArrayList();
- HashMap feedsMap = new HashMap();
- try {
- GCubeUser currUser = PortalContext.getConfiguration().getCurrentUser(getThreadLocalRequest());
- _log.info("****** retrieving posts for user: " + currUser.getUsername());
- /**
- * this handles the case where the portlet is deployed outside of VREs (regular)
- */
- if (isInfrastructureScope()) {
- _log.debug("****** risInfrastructureScope() = true");
- //VRE Feeds
- GroupManager gm = new LiferayGroupManager();
- for (GCubeGroup group : gm.listGroupsByUserAndSite(currUser.getUserId(), getThreadLocalRequest().getServerName())) {
- if (gm.isVRE(group.getGroupId())) {
- String vreid = gm.getInfrastructureScope(group.getGroupId()); //get the scope
- _log.debug("Reading posts for VRE: " + vreid);
- ArrayList OrganizationFeeds = (ArrayList) store.getRecentFeedsByVRE(vreid, postsNoPerCategory);
- for (Feed post : OrganizationFeeds) {
- feedsMap.put(post.getKey(), post);
- }
- }
- }
-
- //Portal Feeds
- ArrayList portalFeeds = (ArrayList) store.getAllPortalPrivacyLevelFeeds();
- for (Feed post : portalFeeds) {
- feedsMap.put(post.getKey(), post);
- }
- }
- //else must be in a VRE scope
- else {
- PortalContext context = PortalContext.getConfiguration();
- String vreid = context.getCurrentScope(getThreadLocalRequest());
- _log.trace("News Feed in VRE, Reading posts for VRE: " + vreid);
- ArrayList OrganizationFeeds = (ArrayList) store.getRecentFeedsByVRE(vreid, (NewsConstants.FEEDS_MAX_PER_CATEGORY));
- for (Feed post : OrganizationFeeds) {
- feedsMap.put(post.getKey(), post);
- }
- }
-
- for (String key: feedsMap.keySet()) {
- toMerge.add(feedsMap.get(key));
- }
-
- //sort the posts in reverse chronological order
- Collections.sort(toMerge, Collections.reverseOrder());
-
- ArrayList toReturn = new ArrayList();
- //return only posts
- if (toMerge.size() > MAX_POSTS_NO)
- for (int i = 0; i < MAX_POSTS_NO; i++)
- toReturn.add(toMerge.get(i));
- else {
- return enhanceFeeds(toMerge, 2);
- }
- return enhanceFeeds(toReturn, 2);
- } catch (PrivacyLevelTypeNotFoundException e) {
- _log.error("Privacy Level not Found " + e.getMessage());
- e.printStackTrace();
- } catch (FeedTypeNotFoundException e) {
- _log.error("Feed Type not Found " + e.getMessage());
- e.printStackTrace();
- } catch (ColumnNameNotFoundException e) {
- _log.error("Column name not Found " + e.getMessage());
- e.printStackTrace();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- /**
- * return the posts having the hashtag passed as param the user has access on
- * @param hashtag the hashtag to look for including '#'
- */
- @Override
- public ArrayList getPostsByHashtag(String hashtag) {
- PortalContext pContext = PortalContext.getConfiguration();
- String userName = pContext.getCurrentUser(getThreadLocalRequest()).getUsername();
- String currentScope = pContext.getCurrentScope(getThreadLocalRequest());
-
- //in case the portal is restarted and you have the social home open it will get test.user (no callback to set session info)
- //this check just return nothing if that happens
- if (userName.compareTo(NewsConstants.TEST_USER) == 0) {
- _log.debug("Found " + userName + " returning nothing");
- return null;
- }
-
- try {
-
- ArrayList toMerge = new ArrayList();
- HashMap feedsMap = new HashMap();
- String lowerCaseHashtag = hashtag.toLowerCase();
-
- // the contexts of the user
- List contexts = new ArrayList();
-
- //this handles the case where the portlet is deployed outside of VREs (regular)
- if (isInfrastructureScope()) {
-
- GroupManager gm = new LiferayGroupManager();
- UserManager um = new LiferayUserManager();
- GCubeUser user = um.getUserByUsername(userName);
- Set vresInPortal = gm.listGroupsByUserAndSite(user.getUserId(), getThreadLocalRequest().getServerName());
- _log.debug("Contexts in this site are per user " + vresInPortal);
-
- // get the scopes associated with such groups
- for (GCubeGroup gCubeGroup : vresInPortal) {
- contexts.add(gm.getInfrastructureScope(gCubeGroup.getGroupId()));
- }
- }
- else {
-
- contexts.add(currentScope);
-
- }
-
- _log.debug("Contexts for hashtags is " + contexts);
-
- for (String context : contexts) {
- ArrayList posts = (ArrayList) store.getVREFeedsByHashtag(context, lowerCaseHashtag);
- for (Feed post : posts) {
- feedsMap.put(post.getKey(), post);
- }
- }
-
- for (String key: feedsMap.keySet()) {
- toMerge.add(feedsMap.get(key));
- }
-
- //sort the posts in reverse chronological order
- Collections.sort(toMerge, Collections.reverseOrder());
-
- ArrayList toReturn = new ArrayList();
- //return only posts
- if (toMerge.size() > MAX_POSTS_NO)
- for (int i = 0; i < MAX_POSTS_NO; i++)
- toReturn.add(toMerge.get(i));
- else {
- return enhanceFeeds(toMerge, 2);
- }
- return enhanceFeeds(toReturn, 2);
- } catch (PrivacyLevelTypeNotFoundException e) {
- _log.error("Privacy Level not Found ", e);
- } catch (FeedTypeNotFoundException e) {
- _log.error("Feed Type not Found ", e);
- } catch (ColumnNameNotFoundException e) {
- _log.error("Column name not Found ", e);
- } catch (Exception e) {
- _log.error("Error while retrieving posts for hashtag ", e);
- }
- return null;
- }
-
- @Override
- public ArrayList getPostsByQuery(String query, int from, int quantity) {
-
- // TODO : check this error better
- if(escl == null){
- _log.warn("There is no connection to elasticsearch, sorry.");
- return null;
- }
-
- PortalContext pContext = PortalContext.getConfiguration();
- String userName = pContext.getCurrentUser(getThreadLocalRequest()).getUsername();
- String currentScope = pContext.getCurrentScope(getThreadLocalRequest());
-
- try {
-
- //in case the portal is restarted and you have the social home open it will get test.user (no callback to set session info)
- //this check just return nothing if that happens
- if (userName.compareTo(NewsConstants.TEST_USER) == 0) {
- _log.debug("Found " + userName + " returning nothing");
- return null;
- }
-
- // Retrieve user's vres in which we must search
- Set vres = new HashSet();
-
- if (isInfrastructureScope()) {
- UserManager um = new LiferayUserManager();
- GCubeUser currUser = um.getUserByUsername(userName);
- //VRE Feeds
- GroupManager gm = new LiferayGroupManager();
- for (GCubeGroup group : gm.listGroupsByUser(currUser.getUserId())) {
- if (gm.isVRE(group.getGroupId())) {
- String vreid = gm.getInfrastructureScope(group.getGroupId()); //get the scope
- vres.add(vreid);
- }
- }
- }
- //else must be in a VRE scope
- else {
- vres.add(currentScope);
- }
-
- // query elastic search
- List enhancedFeeds = escl.search(query, vres, from, quantity);
-
- // retrieve the ids of liked posts by the user
- List likedPosts = store.getAllLikedFeedIdsByUser(userName);
-
- // update fields "liked" and "isuser"
- for (EnhancedFeed enhancedFeed : enhancedFeeds) {
-
- if(isUsers(enhancedFeed.getFeed(), userName))
- enhancedFeed.setUsers(true);
-
- if(likedPosts.contains(enhancedFeed.getFeed().getKey()))
- enhancedFeed.setLiked(true);
-
- }
-
- return (ArrayList) enhancedFeeds;
-
- }catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
-
- /**
- * return only the user connection posts
- */
- @Override
- public ArrayList getOnlyConnectionsUserPosts() {
- ArrayList toMerge = new ArrayList();
- HashMap feedsMap = new HashMap();
- PortalContext pContext = PortalContext.getConfiguration();
- String userName = pContext.getCurrentUser(getThreadLocalRequest()).getUsername();
-
- try {
- //UserFriends Feeds
- ArrayList userFriendsIds = (ArrayList)store.getFriends(userName);
- for (String userid : userFriendsIds) {
- for (Feed post : store.getRecentFeedsByUser(userid, NewsConstants.FEEDS_NO_PER_CATEGORY)) {
- feedsMap.put(post.getKey(), post);
- }
- }
- for (String key: feedsMap.keySet()) {
- toMerge.add(feedsMap.get(key));
- }
- Collections.sort(toMerge, Collections.reverseOrder());
- ArrayList toReturn = new ArrayList();
- //return only posts
- if (toMerge.size() > MAX_POSTS_NO)
- for (int i = 0; i < MAX_POSTS_NO; i++)
- toReturn.add(toMerge.get(i));
- else
- return enhanceFeeds(toMerge, 2);
-
- } catch (PrivacyLevelTypeNotFoundException e) {
- _log.error("Privacy Level not Found " + e.getMessage());
- e.printStackTrace();
- } catch (FeedTypeNotFoundException e) {
- _log.error("Feed Type not Found " + e.getMessage());
- e.printStackTrace();
- } catch (ColumnNameNotFoundException e) {
- _log.error("Column name not Found " + e.getMessage());
- e.printStackTrace();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- /**
- * return only one post with all the comments
- */
- @Override
- public EnhancedFeed getSinglePost(String postKey) {
- Feed post = null;
- try {
- if (postKey != null) {
- post = store.readFeed(postKey);
- if (post != null) {
- ArrayList toEnhance = new ArrayList();
- toEnhance.add(post);
- return enhanceFeeds(toEnhance, -1).get(0); //-1 all the comments
- }
- }
- } catch (Exception e) {
- _log.debug("Error while trying to fetch post with key " + postKey + " returning nothing");
- return new EnhancedFeed();
- }
- return new EnhancedFeed();
- }
- /**
- * MorePostsBean contains the timeline index of the last returned valid post (because if you delete a feed is stays on in the timeline and is marked deleted)
- * and contains the Feeds
- * @param strat the range start (most recent posts for this vre) has to be greater than 0
- * @param quantity the number of most recent posts for this vre starting from "start" param
- */
- @Override
- public MorePostsBean getMorePosts(int start, int quantity) {
- ArrayList toMerge = new ArrayList();
- HashMap feedsMap = new HashMap();
- PortalContext pContext = PortalContext.getConfiguration();
- String vreid = pContext.getCurrentScope(getThreadLocalRequest());
- _log.debug("\n\nAsking more post for Timeline " + vreid + " from " + start + " get other " + quantity);
- ArrayList organizationFeeds;
- RangeFeeds rangeFeeds = null;
- try {
- rangeFeeds = store.getRecentFeedsByVREAndRange(vreid, start, quantity);
- organizationFeeds = rangeFeeds.getFeeds();
- if (organizationFeeds != null) {
- for (Feed post : organizationFeeds) {
- feedsMap.put(post.getKey(), post);
- }
- }
- }
- catch (Exception e) {
- e.printStackTrace();
- return null;
- }
-
- for (String key: feedsMap.keySet()) {
- toMerge.add(feedsMap.get(key));
- }
- //sort the posts in reverse chronological order
- Collections.sort(toMerge, Collections.reverseOrder());
- ArrayList toReturn = enhanceFeeds(toMerge, 2);
- return new MorePostsBean(rangeFeeds.getLastReturnedFeedTimelineIndex(), toReturn);
- }
-
- @Override
- public ArrayList getOnlyMyUserPosts() {
- PortalContext pContext = PortalContext.getConfiguration();
- String userName = pContext.getCurrentUser(getThreadLocalRequest()).getUsername();
- _log.trace("getOnly UserFeeds for " + userName);
- ArrayList userFeeds = null;
- try {
- userFeeds = (ArrayList) store.getRecentFeedsByUser(userName, 15);
- } catch (Exception e) {
- e.printStackTrace();
- }
- Collections.sort(userFeeds, Collections.reverseOrder());
- return enhanceFeeds(userFeeds, 2);
- }
-
- @Override
- public ArrayList getOnlyLikedPosts() {
- PortalContext pContext = PortalContext.getConfiguration();
- String userName = pContext.getCurrentUser(getThreadLocalRequest()).getUsername();
- _log.trace("getLiked Feeds for " + userName);
- ArrayList userFeeds = null;
- try {
- userFeeds = (ArrayList) store.getAllLikedFeedsByUser(userName, 25);
- } catch (Exception e) {
- e.printStackTrace();
- }
- Collections.sort(userFeeds, Collections.reverseOrder());
- return enhanceFeeds(userFeeds, 2);
- }
-
- @Override
- public boolean like(String postid, String postText, String postOwnerId) {
- boolean likeCommitResult = false;
- UserInfo user = getUserSettings().getUserInfo();
- String username = user.getUsername();
- if (username.compareTo(NewsConstants.TEST_USER) == 0) {
- return false;
- }
-
- Like toLike = new Like(UUID.randomUUID().toString(), user.getUsername(),
- new Date(), postid, user.getFullName(), user.getAvatarId());
- try {
- likeCommitResult = store.like(toLike);
- } catch (FeedIDNotFoundException e) {
- _log.error("Feed not Found for this like " + e.getMessage());
- e.printStackTrace();
- return false;
- }
- //if the like was correctly delivered notify users involved
- if (likeCommitResult) {
- PortalContext pContext = PortalContext.getConfiguration();
- String currScope = pContext.getCurrentScope(getThreadLocalRequest());
- //if the user who liked this post is not the user who posted it notify the poster user (Feed owner)
- if (! user.getUsername().equals(postOwnerId)) {
- NotificationsManager nm = new ApplicationNotificationsManager(
- new SocialNetworkingSite(getThreadLocalRequest()),
- currScope,
- new SocialNetworkingUser(username, user.getEmailaddress(), user.getFullName(), user.getAvatarId()),
- APP_ID);
-
- ArrayList mentionedUsers = new ArrayList<>();
- SocialMessageParser messageParser = new SocialMessageParser(postText);
- String siteLandingPagePath = PortalContext.getConfiguration().getSiteLandingPagePath(getThreadLocalRequest());
- String escapedPostText = messageParser.getParsedMessage(mentionedUsers, siteLandingPagePath);
- boolean nResult = nm.notifyLikedPost(postOwnerId, postid, escapedPostText);
- _log.trace("Like Notification added? " + nResult);
- }
- }
- return likeCommitResult;
- }
-
- @Override
- public boolean unlike(String postid, String postText, String postOwnerId) {
- UserInfo user = getUserSettings().getUserInfo();
- try {
- for (Like like : store.getAllLikesByFeed(postid)) {
- if (like.getUserid().compareTo(user.getUsername()) == 0) {
- _log.trace("Trying unlike of " + postText + " for " + user.getFullName());
- store.unlike(user.getUsername(), like.getKey(), postid);
- return true;
- }
- }
- } catch (FeedIDNotFoundException | PrivacyLevelTypeNotFoundException | FeedTypeNotFoundException | ColumnNameNotFoundException | LikeIDNotFoundException e) {
- _log.error("Either Feed or Like not Found " + e.getMessage());
- e.printStackTrace();
- return false;
- }
- return false;
- }
- /**
- * @param feedid the id of the commented post
- * @param commentText the comment text
- * @param feedOwnerId the username of the user who created the post that was commented
- */
- @Override
- public OperationResult comment(String feedid, String commentText, HashSet mentionedItemsSet, String feedOwnerId, boolean isAppFeed) {
- boolean commentCommitResult = false;
- _log.trace("Trying to add this comment " + commentText);
- UserInfo user = getUserSettings().getUserInfo();
-
- if (user.getUsername().compareTo(NewsConstants.TEST_USER) == 0) {
- return new OperationResult(false, "Session Expired", null);
- }
-
- ArrayList mentionedUsers = new ArrayList<>();
- if (mentionedItemsSet != null && mentionedItemsSet.size() > 0) {
- //copy the set into a list
- ArrayList mentionedItems = new ArrayList();
- mentionedItems.addAll(mentionedItemsSet);
- if (mentionedItemsSet != null && ! mentionedItemsSet.isEmpty()) {
- mentionedUsers = getMentionsBean(mentionedItems);
- }
- }
-
- SocialMessageParser messageParser = new SocialMessageParser(commentText);
- String siteLandingPagePath = PortalContext.getConfiguration().getSiteLandingPagePath(getThreadLocalRequest());
- String escapedCommentText = messageParser.getParsedMessage(mentionedUsers, siteLandingPagePath);
- List hashtags = messageParser.getHashtags();
-
- Comment comment = new Comment(UUID.randomUUID().toString(), user.getUsername(),
- new Date(), feedid, escapedCommentText, user.getFullName(), user.getAvatarId());
- try {
- if (store.addComment(comment))
- commentCommitResult = true;
- } catch (FeedIDNotFoundException e) {
- _log.error("Related post not found for this comment " + e.getMessage());
- e.printStackTrace();
- return new OperationResult(false, "Related post not found for this comment", comment);
- }
-
- try {
- if (hashtags != null && !hashtags.isEmpty())
- store.saveHashTagsComment(comment.getKey(), store.readFeed(comment.getFeedid()).getVreid(), hashtags);
- } catch (CommentIDNotFoundException
- | PrivacyLevelTypeNotFoundException
- | FeedTypeNotFoundException | FeedIDNotFoundException
- | ColumnNameNotFoundException e1) {
- _log.error("Unable to save hashtags for this comment " + e1.getMessage());
- }
-
- //if the comment was correctly delivered && is not an app feed notify users involved
- if (commentCommitResult && isWithinPortal()) {
- PortalContext pContext = PortalContext.getConfiguration();
- String currScope = pContext.getCurrentScope(getThreadLocalRequest());
- //if the user who commented this post is not the user who posted it notify the poster user (Feed owner)
- NotificationsManager nm = new ApplicationNotificationsManager(
- new SocialNetworkingSite(getThreadLocalRequest()),
- currScope,
- new SocialNetworkingUser(user.getUsername(), user.getEmailaddress(), user.getFullName(), user.getAvatarId()),
- APP_ID);
- if (! user.getUsername().equals(feedOwnerId) && (!isAppFeed)) {
- boolean result = nm.notifyOwnCommentReply(feedOwnerId, feedid, escapedCommentText, comment.getKey());
- _log.trace("Comment Notification to post owner added? " + result);
- }
-
- //if there are users who liked this post they get notified, asynchronously with this thread
- ArrayList favorites = getAllLikesByPost(feedid);
- Thread likesThread = new Thread(new LikeNotificationsThread(escapedCommentText, nm, favorites, feedOwnerId, comment.getKey()));
- likesThread.start();
-
- //notify the other users who commented this post (excluding the ones above)
- Thread commentsNotificationthread = new Thread(new CommentNotificationsThread(store, new LiferayUserManager(), user.getUsername(), comment.getFeedid(), escapedCommentText, nm, feedOwnerId, comment.getKey(), favorites));
- commentsNotificationthread.start();
-
- //send the notification to the mentioned users, if any
- if (mentionedUsers != null && mentionedUsers.size() > 0) {
- ArrayList toPass = new ArrayList();
-
-
- // among the mentionedUsers there could be groups of people
- Map uniqueUsersToNotify = new HashMap<>();
- UserManager um = new LiferayUserManager();
-
- for (ItemBean bean : mentionedUsers) {
-
- if(bean.isItemGroup()){
-
- // retrieve the users of this group
- try {
- List teamUsers = um.listUsersByTeam(Long.parseLong(bean.getId()));
-
- for (GCubeUser userTeam : teamUsers) {
- if(!uniqueUsersToNotify.containsKey(userTeam.getUsername()))
- uniqueUsersToNotify.put(userTeam.getUsername(), new ItemBean(userTeam.getUserId()+"",
- userTeam.getUsername(), userTeam.getFullname(), userTeam.getUserAvatarURL()));
- }
-
- } catch (NumberFormatException
- | UserManagementSystemException
- | TeamRetrievalFault | UserRetrievalFault e) {
- _log.error("Unable to retrieve team information", e);
- }
-
- }else{
- // it is a user, just add to the hashmap
- if(!uniqueUsersToNotify.containsKey(bean.getName()))
- uniqueUsersToNotify.put(bean.getName(), bean);
-
- }
- }
-
- // iterate over the hashmap
- Iterator> userMapIterator = uniqueUsersToNotify.entrySet().iterator();
- while (userMapIterator.hasNext()) {
- Map.Entry userEntry = (Map.Entry) userMapIterator
- .next();
- ItemBean userBean = userEntry.getValue();
- toPass.add(new GenericItemBean(userBean.getId(), userBean.getName(), userBean.getAlternativeName(), userBean.getThumbnailURL()));
- }
-
- Thread thread = new Thread(new MentionNotificationsThread(comment.getFeedid(), escapedCommentText, nm, null, toPass));
- thread.start();
- }
- }
- return new OperationResult(true, "OK", comment);
- }
-
- @Override
- public OperationResult editComment(Comment toEdit) {
- Comment edited = null;
- try {
- UserInfo user = getUserSettings().getUserInfo();
- if (user.getUsername().compareTo(NewsConstants.TEST_USER) == 0) {
- return new OperationResult(false, "Session Expired", null);
- }
-
- String vreIdFeed = store.readFeed(toEdit.getFeedid()).getVreid();
-
- // get old hashtags and delete them
- String oldText = store.readCommentById(toEdit.getKey()).getText();
- _log.debug("Old text for this comment is " + oldText);
- List oldHashtags = Utils.getHashTags(Utils.removeHTMLFromText(oldText));
- if (oldHashtags != null && !oldHashtags.isEmpty()) {
- _log.debug("The comment has hashtags, attempting to delete them ... " + oldHashtags.toString());
- boolean deletedHashtag = store.deleteHashTagsComment(toEdit.getKey(), vreIdFeed, oldHashtags);
- _log.debug("deletedHashtag? " + deletedHashtag);
- }
-
- // get new hashtags
- String escapedCommentText = Utils.escapeHtmlAndTransformUrl(toEdit.getText());
- List newHashtags = Utils.getHashTags(escapedCommentText);
- if (newHashtags != null && !newHashtags.isEmpty())
- escapedCommentText = Utils.convertHashtagsAnchorHTML(escapedCommentText, newHashtags);
-
- edited = new Comment(toEdit.getKey(), toEdit.getUserid(),
- toEdit.getTime(), toEdit.getFeedid(), escapedCommentText, user.getFullName(), user.getAvatarId(), true, new Date());
-
- store.editComment(edited);
-
- if (newHashtags != null && !newHashtags.isEmpty())
- store.saveHashTagsComment(edited.getKey(), vreIdFeed, newHashtags);
- } catch (Exception e) {
- e.printStackTrace();
- return new OperationResult(false, "Exception on the server: " + e.getMessage(), null);
- }
- return new OperationResult(true, "OK", edited);
- }
-
- /**
- * this method sorts the Feeds in Chronological Reversed order and adds additional informations such as comments and attachments
- * @param toEnhance
- * @param } catch (Exception e) { the max number of comments you want to get back, -1 to get all
- *
- * @return
- */
- private ArrayList enhanceFeeds(ArrayList toEnhance, int commentsNumberPerFeed) {
- ArrayList toReturn = new ArrayList();
- PortalContext pContext = PortalContext.getConfiguration();
- String userName = pContext.getCurrentUser(getThreadLocalRequest()).getUsername();
-
-
- //patch needed for maintaining mention link backward compatibility (they point to /group/data-e-infrastructure-gateway/profile)
- final String LINK_TO_REPLACE = "data-e-infrastructure-gateway";
- String siteLandinPagePath = PortalContext.getConfiguration().getSiteLandingPagePath(getThreadLocalRequest());
- String tokenTosubstitute = siteLandinPagePath.replace("/group/", "");
-
- ArrayList likedFeeds = (ArrayList) store.getAllLikedFeedIdsByUser(userName);
- boolean skip = false;
- for (Feed feed : toEnhance) {
- //patch needed for maintaining mention link backward compatibility (they point to /group/data-e-infrastructure-gateway/profile)
- String currPostText = feed.getDescription().replace(LINK_TO_REPLACE,tokenTosubstitute);
- feed.setDescription(currPostText);
- boolean isMultiFileUpload = feed.isMultiFileUpload();
- ArrayList attachments = new ArrayList();
- if (isMultiFileUpload) {
- try {
- attachments = (ArrayList) store.getAttachmentsByFeedId(feed.getKey());
- } catch (FeedIDNotFoundException e) {
- _log.error("It looks like sth wrong with this feedid having attachments, could not find feedId = " + feed.getKey() + "\n" + e.getMessage());
- }
- }
-
- skip = false;
- if (! feed.isApplicationFeed()) {
- String thumb = getUserImagePortraitUrlLocal(feed.getEntityId());
- if (thumb == null) {
- _log.warn(feed.getEntityId() + " is not avaialble on this portal, skipping this feed: " + feed.getKey());
- skip = true;
- } else
- feed.setThumbnailURL(thumb);
- }
- //if likedFeeds contains this feed key it means the user already Liked it
- boolean liked = likedFeeds.contains(feed.getKey());
- int commentsNo = 0;
- try {
- commentsNo = Integer.parseInt(feed.getCommentsNo());
- }
- catch (NumberFormatException e) {
- commentsNo = 0;
- _log.error("NumberFormatException while reading comments number " + e.getMessage());
- }
- if (!skip) {
- if (commentsNo == 0) {
- EnhancedFeed toAdd = null;
- //create the enhanced feed
- if (feed.isApplicationFeed()) {
- toAdd = new EnhancedFeed(feed, liked, checkisAdminUser());
- } else
- toAdd = new EnhancedFeed(feed, liked, isUsers(feed, userName));
- toAdd.setAttachments(attachments);
- toReturn.add(toAdd);
- } else {
- ArrayList comments = getAllCommentsByPost(feed.getKey());
- //sort in chronological order
- Collections.sort(comments);
-
- int currCommentsNumber = comments.size();
- //if comments are less than $commentsNumberPerFeed they are the more recent, -1 return all the comments
- if (currCommentsNumber < commentsNumberPerFeed || commentsNumberPerFeed == -1) {
- EnhancedFeed toAdd = new EnhancedFeed(feed, liked, isUsers(feed, userName), comments, attachments);
- toReturn.add(toAdd);
- } else {
- //need to get the last two
- ArrayList comments2Attach = new ArrayList();
- for (int i = currCommentsNumber -commentsNumberPerFeed; i < currCommentsNumber; i++) {
- comments2Attach.add(comments.get(i));
- }
- EnhancedFeed toAdd = new EnhancedFeed(feed, liked, isUsers(feed, userName), comments2Attach, attachments);
- toReturn.add(toAdd);
- }
- }
- }
-
- }
- _log.trace("ENHANCED FEEDS TOTAL= " + toReturn.size() + " for user: " + userName);
- return toReturn;
- }
-
- /**
- * this method is needed because user images portrait change id depending on the portal instance
- * e.g. a post made from iMarine portal would not show the avatarIMage in D4Science.org
- * @param screenname
- * @return the url of the image portrait for this portal instance
- */
- private String getUserImagePortraitUrlLocal(String screenName) {
- if (! isWithinPortal()) {
- return "";
- }
- String thumbnailURL = "";
- try {
- thumbnailURL = new LiferayUserManager().getUserByUsername(screenName).getUserAvatarURL();
- } catch (UserManagementSystemException | UserRetrievalFault e) {
- e.printStackTrace();
- }
- return thumbnailURL;
- }
-
- @Override
- public ArrayList getAllLikesByPost(String postid) {
- ArrayList toReturn = (ArrayList) store.getAllLikesByFeed(postid);
- _log.trace("Asking likes for " + postid);
- for (Like like : toReturn) {
- String thumb = getUserImagePortraitUrlLocal(like.getUserid());
-
- like.setThumbnailURL(thumb == null ? "" : thumb);
- }
- return toReturn;
- }
-
- @Override
- public ArrayList getAllCommentsByPost(String postid) {
- _log.trace("Asking comments for " + postid);
- ArrayList toReturn = (ArrayList