StyledFlowPanel infowrapper = new StyledFlowPanel("wrapper");
StyledFlowPanel authorWrapper = new StyledFlowPanel("author-wrapper");
author.setText(activity.getActor().getName());
authorWrapper.add(author);
final OswService service = OswServiceFactory.getService();
boolean isComment=false;
List<AtomReplyTo> recs=activity.getRecipients();
Iterator<AtomReplyTo> itRecipients=recs.iterator();
while (itRecipients.hasNext()){
AtomReplyTo recipient=itRecipients.next();
if (recipient.getHref().contains("?;node"))
isComment=true;
}
if ((!isComment) && (activity.hasRecipients())) {
authorWrapper.add(new StyledLabel("separator", " " + uiText.To() + " "));
Iterator<AtomReplyTo> recipients = activity.getRecipients()
.iterator();
while (recipients.hasNext()) {
final AtomReplyTo recipient = recipients.next();
final String recipientJID = recipient.getHref();
final StyledLabel label = new StyledLabel("link", recipientJID);
label.setTitle(uiText.ViewProfileOf() + recipientJID);
service.getProfile(recipientJID,
new RequestCallback<Profile>() {
@Override
public void onFailure() {
// do nothing
}
@Override
public void onSuccess(Profile result) {
// show display name
final String fullName = result.getFullName();
if (fullName != null && fullName.length() > 0) {
label.setText(fullName);
}
}
});
label.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// get the app instance from the session manager
AbstractApplication app = OswClient.getInstance()
.getCurrentApplication();
ProfileWindow profileWindow = (ProfileWindow) app
.addWindow(ProfileWindow.class.toString(), 1);
profileWindow.setJID(recipientJID);
profileWindow.show();
}
});
authorWrapper.add(label);
if (recipients.hasNext()) {
authorWrapper.add(new StyledLabel("separator", ", "));
}
}
}
statuswrapper.add(statusIcon);
statuswrapper2.add(authorWrapper);
statuswrapper2.add(statusLabel);
statuswrapper.add(statuswrapper2);
infowrapper.add(infoIcon);
infowrapper.add(infoLabel);
flow.add(statuswrapper);
flow.add(attachmentswrapper);
flow.add(infowrapper);
hpanel.add(avatarwrapper);
avatarwrapper.getElement().setAttribute(
"style",
"background-image: url('"
+ OswClient.getInstance().getPreference("theme_folder")
+ "assets/avatar-loader.gif');");
hpanel.add(flow);
hpanel.setCellWidth(avatarwrapper, "40px");
// display who can see your own items
List<String> visibility = new ArrayList<String>();
if (activity.getActor().getUri().equals(
OswServiceFactory.getService().getUserBareJID())) {
// show the acl rule
for (AclRule rule : activity.getAclRules()) {
for (AclAction action : rule.getActions(AclAction.ACTION_VIEW,
AclAction.PERMISSION_GRANT)) {
for (AclSubject subject : rule.getSubjects()) {
if (subject.getType().equals(AclSubject.EVERYONE)) {
visibility.add(uiText.Everyone());
} else if (subject.getType().equals(AclSubject.GROUP)) {
visibility.add(subject.getName());
} else if (subject.getType().equals(AclSubject.PERSON)) {
visibility.add(subject.getName());
}
}
}
}
// and add a special style to show this is your own item
addStyleName("isOwner");
}
statusLabel.setText(" - " + activity.getTitle());
String info = "";
info += getFormattedDate(activity.getPublished());
if (!visibility.isEmpty())
info += " - " + uiText.VisibleTo() + " " + FormatHelper.implode(visibility, ", ");
// if (location != "") info += " - From: " + location;
// if (tags != "") info += " - Tagged: " + tags;
infoLabel.setText(info);
author.setTitle(uiText.ViewProfileOf() + " " + activity.getActor().getUri());
// check for any attachments
for (int i = 0; i < activity.getObjects().size(); i++) {
if (activity.getObjects().get(i).getType().equals(
ActivityObject.PICTURE)) {
addPictureAttachment(activity.getObjects().get(i));
} else if (activity.getObjects().get(i).getType().equals(
ActivityObject.LINK)) {
addLinkAttachment(activity.getObjects().get(i));
}
}
statusActivity.add(hpanel);
add(statusActivity);
// add styles
avatarImage.setStyleName("avatar");
infoLabel.setStyleName("info");
addStyleName("statusActivityWrapper");
// handlers
author.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// get the app instance from the session manager
AbstractApplication app = OswClient.getInstance()
.getCurrentApplication();
ProfileWindow profileWindow = (ProfileWindow) app.addWindow(
ProfileWindow.class.toString(), 1);
profileWindow.setJID(activity.getActor().getUri());
profileWindow.show();
}
});
// Fetch the avatar image
service.getProfile(activity.getActor().getUri(),
new RequestCallback<Profile>() {
@Override
public void onFailure() {
// Do nothing
avatarImage.setUrl(OswClient.getInstance()
.getPreference("theme_folder")
+ "assets/default-avatar.png");
avatarwrapper.getElement().setAttribute("style",
"background-image: none;");
avatarwrapper.add(avatarImage);
}
@Override
public void onSuccess(Profile result) {
String url = result.getPhotoUri();
if (url != null && url.length() > 0) {
avatarImage.setUrl(url);
avatarwrapper.getElement().setAttribute("style",
"background-image: none;");
avatarwrapper.add(avatarImage);
} else {
avatarImage.setUrl(OswClient.getInstance()
.getPreference("theme_folder")
+ "assets/default-avatar-big.png");
avatarwrapper.getElement().setAttribute("style",
"background-image: none;");
avatarwrapper.add(avatarImage);
}
}
});
// Display the presence
if (activity.getActor().getUri().equals(service.getUserBareJID())) {
setPresence(service.getPresence());
} else {
final RosterItem rosterItem = service.getRoster().getItem(
activity.getActor().getUri());
if (rosterItem != null) {
setPresence(rosterItem.getPresence());
rosterItem.registerEventHandler(new Observer<RosterEvent>() {