smart refresh implemented (need actual testing), fix for support ticket #580

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@73014 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2013-04-08 15:25:37 +00:00
parent b496c36a5a
commit 8461589fe7
9 changed files with 150 additions and 60 deletions

View File

@ -30,7 +30,7 @@ public interface NewsService extends RemoteService {
boolean deleteFeed(String feedid);
Comment comment(String feedid, String text, String feedOwnerId);
Comment comment(String feedid, String text, String feedOwnerId, boolean isAppFeed);
Comment editComment(Comment toEdit);

View File

@ -31,7 +31,7 @@ public interface NewsServiceAsync {
void getUserSettings(AsyncCallback<UserSettings> callback);
void comment(String feedid, String text, String feedOwnerId,
AsyncCallback<Comment> callback);
boolean isAppFeed, AsyncCallback<Comment> callback);
void getAllCommentsByFeed(String feedid,
AsyncCallback<ArrayList<Comment>> callback);

View File

@ -0,0 +1,21 @@
package org.gcube.portlets.user.newsfeed.client.event;
import com.google.gwt.event.shared.GwtEvent;
public class ShowNewUpdatesEvent extends GwtEvent<ShowNewUpdatesEventHandler> {
public static Type<ShowNewUpdatesEventHandler> TYPE = new Type<ShowNewUpdatesEventHandler>();
public ShowNewUpdatesEvent() { }
@Override
public Type<ShowNewUpdatesEventHandler> getAssociatedType() {
return TYPE;
}
@Override
protected void dispatch(ShowNewUpdatesEventHandler handler) {
handler.onShowNewUpdatesClick(this);
}
}

View File

@ -0,0 +1,7 @@
package org.gcube.portlets.user.newsfeed.client.event;
import com.google.gwt.event.shared.EventHandler;
public interface ShowNewUpdatesEventHandler extends EventHandler {
void onShowNewUpdatesClick(ShowNewUpdatesEvent event);
}

View File

@ -27,6 +27,8 @@ import org.gcube.portlets.user.newsfeed.client.event.SeeCommentsEvent;
import org.gcube.portlets.user.newsfeed.client.event.SeeCommentsEventHandler;
import org.gcube.portlets.user.newsfeed.client.event.SeeLikesEvent;
import org.gcube.portlets.user.newsfeed.client.event.SeeLikesEventHandler;
import org.gcube.portlets.user.newsfeed.client.event.ShowNewUpdatesEvent;
import org.gcube.portlets.user.newsfeed.client.event.ShowNewUpdatesEventHandler;
import org.gcube.portlets.user.newsfeed.client.event.StopTimerEvent;
import org.gcube.portlets.user.newsfeed.client.event.StopTimerEventHandler;
import org.gcube.portlets.user.newsfeed.client.panels.dialog.LikesDialog;
@ -68,6 +70,8 @@ public class NewsFeedPanel extends Composite {
private HorizontalPanel filterPanel = new HorizontalPanel();
private SimplePanel newUpdatesPanel = new SimplePanel();
private VerticalPanel newsPanel = new VerticalPanel();
private NewFeedsAvailable newsFeedAlert;
private static final String warning = GWT.getModuleBaseURL() + "../images/warning_blue.png";
private static final String spacer = GWT.getModuleBaseURL() + "../images/feeds-spacer.gif";
@ -97,6 +101,14 @@ public class NewsFeedPanel extends Composite {
* events binder
*/
private void bind() {
eventBus.addHandler(ShowNewUpdatesEvent.TYPE, new ShowNewUpdatesEventHandler() {
@Override
public void onShowNewUpdatesClick(ShowNewUpdatesEvent event) {
doShowCachedNewUpdates();
}
});
eventBus.addHandler(StopTimerEvent.TYPE, new StopTimerEventHandler() {
@Override
@ -248,7 +260,7 @@ public class NewsFeedPanel extends Composite {
Date myLastUpdateTime = allUpdates.get(0).getFeed().getTime(); //this is the last update in the View
tempCacheNewUpdates = new ArrayList<EnhancedFeed>(); //need to reset it everytime i check (in case someone deleted the updated in the meanwhile)
tempCacheNewUpdates = new ArrayList<EnhancedFeed>(); //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
@ -263,8 +275,14 @@ public class NewsFeedPanel extends Composite {
* if they differ you got to refresh the updates to show the new number
*/
if (currNewUpdatesNo < i) {
newUpdatesPanel.clear(); //remove the current show update button if present
newUpdatesPanel.add(new NewFeedsAvailable(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;
}
}
@ -275,6 +293,22 @@ public class NewsFeedPanel extends Composite {
}
protected void doShowCachedNewUpdates() {
newUpdatesPanel.clear(); //remove the aler panel
for (EnhancedFeed feed : tempCacheNewUpdates) {
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);
}
}
/**
* All Updates
@ -530,7 +564,7 @@ public class NewsFeedPanel extends Composite {
}
private void doAddComment(final TweetTemplate owner, String text) {
newsService.comment(owner.getFeedKey(), text, owner.getMyFeedUserId(), new AsyncCallback<Comment>() {
newsService.comment(owner.getFeedKey(), text, owner.getMyFeedUserId(), owner.isAppFeed(), new AsyncCallback<Comment>() {
@Override
public void onFailure(Throwable caught) {
Window.alert("Could not deliver this comment: " + caught.getMessage());

View File

@ -1,11 +1,18 @@
package org.gcube.portlets.user.newsfeed.client.templates;
import org.gcube.portlets.user.newsfeed.client.event.ShowNewUpdatesEvent;
import com.google.gwt.core.client.GWT;
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.Window;
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 {
@ -14,12 +21,19 @@ public class NewFeedsAvailable extends Composite {
.create(NewFeedsAvailableUiBinder.class);
interface NewFeedsAvailableUiBinder extends
UiBinder<Widget, NewFeedsAvailable> {
}
private HandlerManager eventBus;
@UiField HTML caption;
@UiField HTMLPanel panel;
public NewFeedsAvailable(int newUpdatesNo) {
public NewFeedsAvailable(int newUpdatesNo, HandlerManager eventBus) {
initWidget(uiBinder.createAndBindUi(this));
this.eventBus = eventBus;
if (newUpdatesNo > 0) {
caption.setHTML(newUpdatesNo > 1 ? "See " + newUpdatesNo + " new Updates" : "See 1 new Update");
//create the fade transition effect
@ -33,4 +47,13 @@ public class NewFeedsAvailable extends Composite {
}
else throw new IllegalArgumentException("newUpdatesNo must be greater than 0");
}
public void updateNewUpdatesNo(int newUpdatesNo) {
caption.setHTML(newUpdatesNo > 1 ? "See " + newUpdatesNo + " new Updates" : "See 1 new Update");
}
@UiHandler("caption")
void onClick(ClickEvent e) {
eventBus.fireEvent(new ShowNewUpdatesEvent());
}
}

View File

@ -1,7 +1,7 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<g:HTMLPanel styleName="new-feeds-container">
<g:HTMLPanel ui:field="panel" styleName="new-feeds-container">
<g:HTML ui:field="caption" styleName="new-feeds-available" />
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -70,6 +70,7 @@ public class TweetTemplate extends Composite {
private int totalComments = 0;
private HTML showAllComments = new HTML();
private boolean isAppFeed = false;
/**
* tell if this tweet is belonging to the current user
*/
@ -396,4 +397,8 @@ public class TweetTemplate extends Composite {
public String getMyFeedText() {
return myFeed.getFeed().getDescription();
}
public boolean isAppFeed() {
return isAppFeed;
}
}

View File

@ -90,8 +90,8 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
if (user == null) {
_log.warn("USER IS NULL setting testing user and Running OUTSIDE PORTAL");
//user = "test.user";
user = "massimiliano.assante";
user = "test.user";
//user = "massimiliano.assante";
}
else {
withinPortal = true;
@ -243,28 +243,28 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
ArrayList<Feed> toMerge = new ArrayList<Feed>();
HashMap<String, Feed> feedsMap = new HashMap<String, Feed>();
ArrayList<Feed> OrganizationFeeds = (ArrayList<Feed>) store.getRecentFeedsByVRE("/gcube/devsec/devVRE", 5);
ArrayList<Feed> OrganizationFeeds = (ArrayList<Feed>) store.getRecentFeedsByVRE("/gcube/devsec/devVRE", 15);
for (Feed feed : OrganizationFeeds) {
feedsMap.put(feed.getKey(), feed);
}
// if (! onlyConnections) {
// //User Own Feeds
// ArrayList<Feed> userFeeds = (ArrayList<Feed>) store.getRecentFeedsByUser(userName, 10);
// for (Feed feed : userFeeds)
// feedsMap.put(feed.getKey(), feed);
// // //Portal Feeds
// ArrayList<Feed> portalFeeds = (ArrayList<Feed>) store.getAllPortalPrivacyLevelFeeds();
// for (Feed feed : portalFeeds)
// feedsMap.put(feed.getKey(), feed);
// }
// //UserFriends Feeds
// ArrayList<String> userFriendsIds = (ArrayList<String>)store.getFriends(userName);
// for (String userid : userFriendsIds) {
// for (Feed feed : store.getRecentFeedsByUser(userid, 10)) {
// feedsMap.put(feed.getKey(), feed);
// }
// }
if (! onlyConnections) {
//User Own Feeds
ArrayList<Feed> userFeeds = (ArrayList<Feed>) store.getRecentFeedsByUser(userName, 10);
for (Feed feed : userFeeds)
feedsMap.put(feed.getKey(), feed);
// //Portal Feeds
ArrayList<Feed> portalFeeds = (ArrayList<Feed>) store.getAllPortalPrivacyLevelFeeds();
for (Feed feed : portalFeeds)
feedsMap.put(feed.getKey(), feed);
}
//UserFriends Feeds
ArrayList<String> userFriendsIds = (ArrayList<String>)store.getFriends(userName);
for (String userid : userFriendsIds) {
for (Feed feed : store.getRecentFeedsByUser(userid, 10)) {
feedsMap.put(feed.getKey(), feed);
}
}
for (String key: feedsMap.keySet()) {
toMerge.add(feedsMap.get(key));
}
@ -331,7 +331,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
* @param feedOwnerId the username of the user who created the post that was commented
*/
@Override
public Comment comment(String feedid, String commentText, String feedOwnerId) {
public Comment comment(String feedid, String commentText, String feedOwnerId, boolean isAppFeed) {
boolean commentCommitResult = false;
_log.trace("Trying to add this comment " + commentText);
UserInfo user = getUserSettings().getUserInfo();
@ -345,11 +345,11 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
e.printStackTrace();
return null;
}
//if the comment was correctly delivered notify users involved
//if the comment was correctly delivered && is not an app feed notify users involved
if (commentCommitResult) {
//if the user who commented this post is not the user who posted it notify the poster user (Feed owner)
NotificationsManager nm = new ApplicationNotificationsManager(getASLSession());
if (! user.getUsername().equals(feedOwnerId)) {
if (! user.getUsername().equals(feedOwnerId) && (!isAppFeed)) {
boolean result = nm.notifyOwnCommentReply(feedOwnerId, feedid, escapeHtml(commentText));
_log.trace("Comment Notification to post owner added? " + result);
}
@ -636,34 +636,34 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService
* @return the refreshingTime in milliseconds
*/
private int getFeedsRefreshTimeInMillis() {
return 15000;
//TODO:
// Properties props = new Properties();
// int toReturn = 0;
// int minutes = 0;
// String propertyfile = "";
// try {
// propertyfile = this.getThreadLocalRequest().getContextPath()+"conf/settings.properties";
// File propsFile = new File(propertyfile);
// FileInputStream fis = new FileInputStream(propsFile);
// props.load( fis);
//
// minutes = Integer.parseInt(props.getProperty("REFRESH_TIME"));
// toReturn = minutes*60*1000;
// }
// //catch exception in case properties file does not exist
// catch(IOException e) {
// toReturn = 300000; //5 minutes
// _log.error("settings.properties file not found under " + propertyfile +", returning 5 minutes");
// return toReturn;
// }
// //catch exception in case the property value isNot a Number
// catch (ClassCastException ex) {
// toReturn = 300000; //5 minutes
// _log.error("REFRESH_TIME must be a number (in minutes) returning 5 minutes");
// return toReturn;
// }
// _log.debug("Returning REFRESH_TIME in millis: " + toReturn + ", (" + minutes + " minutes)");
// return toReturn;
//return 20000; //for testing
Properties props = new Properties();
int toReturn = 0;
int minutes = 0;
String propertyfile = "";
try {
propertyfile = this.getThreadLocalRequest().getContextPath()+"conf/settings.properties";
File propsFile = new File(propertyfile);
FileInputStream fis = new FileInputStream(propsFile);
props.load( fis);
minutes = Integer.parseInt(props.getProperty("REFRESH_TIME"));
toReturn = minutes*60*1000;
}
//catch exception in case properties file does not exist
catch(IOException e) {
toReturn = 300000; //5 minutes
_log.error("settings.properties file not found under " + propertyfile +", returning 5 minutes");
return toReturn;
}
//catch exception in case the property value isNot a Number
catch (ClassCastException ex) {
toReturn = 300000; //5 minutes
_log.error("REFRESH_TIME must be a number (in minutes) returning 5 minutes");
return toReturn;
}
_log.debug("Returning REFRESH_TIME in millis: " + toReturn + ", (" + minutes + " minutes)");
return toReturn;
}
}