Permalink
Browse files

changes for commenting

  • Loading branch information...
1 parent e12cb34 commit 84bd0bf94f741d9ec22754dc3f7b1e5ffaf23b23 @lfaggioli lfaggioli committed Aug 24, 2010
@@ -12,6 +12,13 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
+ *
+ * 2010-08-17 Modified by Luca Faggioli Copyright 2010 Openliven S.r.l
+ *
+ * added addEmptyModelMessage so that nothing is shown in the subclass
+ * RepliesPanel when the model is empty and getModelItems() so we can
+ * sort the activities in RepliesPanel (for replies we put the oldest
+ * on the top and the newest at the bottom
*
*/
package org.onesocialweb.gwt.client.ui.widget.activity;
@@ -32,7 +39,7 @@
public abstract class AbstractActivityPanel<T> extends FlowPanel {
- private Stream<T> model;
+ protected Stream<T> model;
private DefaultTaskInfo task;
@@ -50,9 +57,9 @@ public void setModel(Stream<T> model) {
protected void repaint() {
clear();
- List<T> items = model.getItems();
if (model.isReady()) {
+ List<T> items = getModelItems();
if (items.size() > 0) {
// render the items
for (int i = items.size(); i >= 1; i--) {
@@ -61,9 +68,7 @@ protected void repaint() {
}
} else {
// if there are no results
- StyledLabel msg = new StyledLabel("message",
- "There are no status updates available.");
- add(msg);
+ addEmptyModelMessage();
}
if (task != null) {
@@ -99,5 +104,14 @@ public void handleEvent(StreamEvent<T> event) {
}
}
+
+ protected void addEmptyModelMessage() {
+ StyledLabel msg = new StyledLabel("message",
+ "There are no status updates available.");
+ add(msg);
+ }
+ protected List<T> getModelItems() {
+ return model.getItems();
+ }
}
@@ -12,7 +12,10 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
+ * 2010-08-09 Modified by Luca Faggioli Copyright 2010 Openliven S.r.l
+ * added code to handle comments (replies)
+ *
*/
package org.onesocialweb.gwt.client.ui.widget.activity;
@@ -29,13 +32,15 @@
import org.onesocialweb.gwt.client.ui.widget.StyledFlowPanel;
import org.onesocialweb.gwt.client.ui.widget.StyledLabel;
import org.onesocialweb.gwt.client.ui.widget.StyledTooltipImage;
+import org.onesocialweb.gwt.client.ui.widget.compose.CommentPanel;
import org.onesocialweb.gwt.client.ui.window.ProfileWindow;
import org.onesocialweb.gwt.client.util.FormatHelper;
import org.onesocialweb.gwt.service.OswService;
import org.onesocialweb.gwt.service.OswServiceFactory;
import org.onesocialweb.gwt.service.RequestCallback;
import org.onesocialweb.gwt.service.RosterEvent;
import org.onesocialweb.gwt.service.RosterItem;
+import org.onesocialweb.gwt.service.Stream;
import org.onesocialweb.gwt.service.RosterItem.Presence;
import org.onesocialweb.gwt.util.Observer;
import org.onesocialweb.model.acl.AclAction;
@@ -59,18 +64,25 @@
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
+import com.google.gwt.user.client.ui.Widget;
public class ActivityItemView extends FlowPanel implements MouseOverHandler,
HasMouseOverHandlers, MouseOutHandler, HasMouseOutHandlers {
private HTML statusLabel = new HTML();
private HTML infoLabel = new HTML();
+ private final RepliesPanel repliesPanel = new RepliesPanel();
+ private final CommentPanel commentPanel = new CommentPanel();
+
private StyledTooltipImage avatarImage = new StyledTooltipImage("", "link",
"View profile");
private StyledFlowPanel avatarwrapper = new StyledFlowPanel("avatarwrapper");
private StyledTooltipImage infoIcon = new StyledTooltipImage(OswClient
.getInstance().getPreference("theme_folder")
+ "assets/i-info.png", "icon", "");
+ private StyledTooltipImage emptyIcon = new StyledTooltipImage(OswClient
+ .getInstance().getPreference("theme_folder")
+ + "assets/i-empty.png", "icon", "");
private HorizontalPanel hpanel = new HorizontalPanel();
private FlowPanel attachmentswrapper = new StyledFlowPanel("attachments");
private StyledTooltipImage statusIcon = new StyledTooltipImage(OswClient
@@ -81,6 +93,13 @@
private ActivityButtonHandler handler;
private final ActivityEntry activity;
+ protected final StyledFlowPanel replieswrapper = new StyledFlowPanel("author-wrapper");
+
+ private String recipientActivityID = null;
+ //for notification we show the label that "this is a comment
+ //and we prevent the user to comment it itself
+ private boolean commentNotification = false;
+
public ActivityItemView(final ActivityEntry activity) {
this.activity = activity;
@@ -101,7 +120,13 @@ public ActivityItemView(final ActivityEntry activity) {
.iterator();
while (recipients.hasNext()) {
final AtomReplyTo recipient = recipients.next();
- final String recipientJID = recipient.getHref();
+
+ recipientActivityID = extractRecipientActivityID(recipient.getHref());
+ if(recipientActivityID != null) {
+ commentNotification = true;
+ }
+
+ final String recipientJID = extractRecipientJID(recipient.getHref());
final StyledLabel label = new StyledLabel("link", recipientJID);
label.setTitle("View profile of " + recipientJID);
@@ -153,6 +178,9 @@ public void onClick(ClickEvent event) {
flow.add(statuswrapper);
flow.add(attachmentswrapper);
flow.add(infowrapper);
+ flow.add(replieswrapper);
+ replieswrapper.add(emptyIcon);
+
hpanel.add(avatarwrapper);
avatarwrapper.getElement().setAttribute(
@@ -185,12 +213,44 @@ public void onClick(ClickEvent event) {
}
statusLabel.setText(" - " + activity.getTitle());
+
+ if(!commentNotification) {
+ if(activity.hasReplies()) {
+ final StyledLabel repliesLabel = new StyledLabel("replies-link", "Comments: " +
+ activity.getRepliesLink().getCount());
+
+ repliesLabel.addClickHandler(new ClickHandler() {
+ public void onClick(ClickEvent event) {
+ commentPanel.compose(activity);
+ replieswrapper.add(commentPanel);
+ repliesLabel.setVisible(false);
+ }
+ });
+
+ replieswrapper.add(repliesLabel);
+ } else {
+ final StyledLabel repliesLabel = new StyledLabel("replies-link", "Add a comment");
+
+ repliesLabel.addClickHandler(new ClickHandler() {
+ public void onClick(ClickEvent event) {
+ commentPanel.compose(activity);
+ replieswrapper.add(commentPanel);
+ repliesLabel.setVisible(false);
+ }
+ });
+
+ replieswrapper.add(repliesLabel);
+ }
+ }
+
String info = "";
info += getFormattedDate(activity.getPublished());
if (!visibility.isEmpty())
info += " - Visible to: " + FormatHelper.implode(visibility, ", ");
// if (location != "") info += " - From: " + location;
// if (tags != "") info += " - Tagged: " + tags;
+ if(commentNotification)
+ info += " - This is a comment to a previous post";
infoLabel.setText(info);
author.setTitle("View profile of " + activity.getActor().getUri());
@@ -285,6 +345,13 @@ public void handleEvent(RosterEvent event) {
}
}
+
+ public ActivityEntry getActivity() {
+ return activity;
+ }
+
+
+
public void onMouseOver(MouseOverEvent event) {
select();
}
@@ -318,6 +385,19 @@ public void setButtonHandler(ActivityButtonHandler handler) {
this.handler = handler;
}
+ @Override
+ protected void onLoad() {
+ super.onLoad();
+
+ if(commentNotification) {
+ Widget parent = getParent();
+ if(parent instanceof InboxPanel) {
+ InboxPanel inbox = (InboxPanel) parent;
+ inbox.updateActivityReplies(recipientActivityID);
+ }
+ }
+ }
+
private void select() {
addStyleName("selected");
handler.handleShow(this.getAbsoluteTop(), this);
@@ -494,4 +574,36 @@ private void setPresence(Presence presence) {
}
}
+ private String extractRecipientJID(String recipientHref) {
+ if(recipientHref.startsWith("xmpp:")) {
+ int i = recipientHref.indexOf("?");
+ if(i == -1) {
+ return "";
+ }
+ else {
+ return recipientHref.substring(5, i);
+ }
+ }
+ else {
+ return recipientHref;
+ }
+ }
+
+ private String extractRecipientActivityID(String recipientHref) {
+
+ if(recipientHref.startsWith("xmpp:")) {
+ int i = recipientHref.indexOf("item=");
+ if(i == -1) {
+ return null;
+ }
+ else {
+ return recipientHref.substring(i+5);
+ }
+ }
+ else {
+ return null;
+ }
+
+ }
+
}
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2010 Openliven S.r.l.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Author: luca faggioli luca(dot)faggioli(at)openliven(dot)com
+ *
+ */
+package org.onesocialweb.gwt.client.ui.widget.activity;
+
+import org.onesocialweb.model.activity.ActivityEntry;
+
+
+public class FeedItemView extends ActivityItemView {
+
+
+ public FeedItemView(ActivityEntry activity) {
+ super(activity);
+
+ //prevent users to post comments
+ replieswrapper.clear();
+
+ }
+
+
+}
@@ -13,6 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
+ * 2010-08-17 Modified by Luca Faggioli Copyright 2010 Openliven S.r.l
+ * replaced ActivityItemView with FeedItemView in order to prevent users
+ * to post comments to a comment
+ *
*/
package org.onesocialweb.gwt.client.ui.widget.activity;
@@ -37,7 +41,7 @@ public FeedPanel() {
@Override
protected Widget render(ActivityEntry activity) {
- ActivityItemView sa = new ActivityItemView(activity);
+ ActivityItemView sa = new FeedItemView(activity);
sa.setButtonHandler(new ActivityButtonHandler() {
public void handleShow(int top, ActivityItemView sa) {
Oops, something went wrong.

0 comments on commit 84bd0bf

Please sign in to comment.