Ejemplo n.º 1
0
  public void sendNewPostMessage(User recipient, Post post) {
    // Short-circuit message creation
    if (!userIsPresent(recipient.getGuid())) return;

    String title = post.getTitle();
    String url = post.getUrl() != null ? post.getUrl().toExternalForm() : null;

    if (url == null) {
      // this particular jabber message protocol has no point without an url
      Log.debug("no url found on post, not sending xmpp message");
      return;
    }

    Viewpoint viewpoint = new UserViewpoint(recipient);

    PostView postView = postingBoard.getPostView(viewpoint, post);
    Set<EntityView> referenced = postingBoard.getReferencedEntities(viewpoint, post);

    Message message = new Message();
    message.setType(Message.Type.normal);
    message.setBody(String.format("%s\n%s", title, url));
    addNewPostExtension(message, postView, referenced);

    sendMessage(recipient.getGuid(), message);
  }
Ejemplo n.º 2
0
  public ExternalAccount lookupExternalAccount(
      Viewpoint viewpoint, User user, ExternalAccountType type) throws NotFoundException {
    if (!em.contains(user.getAccount()))
      throw new RuntimeException("detached account in lookupExternalAccount()");

    // Right now, external accounts are public, unlike email/aim resources which are friends only...
    // so we don't need to use the viewpoint. But here in case we want to add it later.
    ExternalAccount external = user.getAccount().getExternalAccount(type);
    if (external == null)
      throw new NotFoundException("No external account of type " + type + " for user " + user);
    else return external;
  }
Ejemplo n.º 3
0
  public void sendGroupMembershipChange(User recipient, GroupMember groupMember) {
    // Short-circuit message creation
    if (!userIsPresent(recipient.getGuid())) return;

    Viewpoint viewpoint = new UserViewpoint(recipient);

    PersonView memberView =
        personViewer.getPersonView(
            viewpoint, groupMember.getMember(), PersonViewExtra.PRIMARY_RESOURCE);

    GroupView groupView = groupSystem.getGroupView(viewpoint, groupMember.getGroup());

    Message message = new Message();
    message.setType(Message.Type.normal);
    addMembershipChangeExtension(message, groupView, groupMember, memberView);

    sendMessage(recipient.getGuid(), message);
  }
Ejemplo n.º 4
0
  public Set<ExternalAccountView> getExternalAccountViews(Viewpoint viewpoint, User user) {
    // Right now we ignore the viewpoint, so this method is pretty pointless.
    // but if people use it, future code will work properly.

    // be sure the account is attached... the external accounts are lazy-loaded
    if (!em.contains(user.getAccount()))
      throw new RuntimeException("detached account in getExternalAccounts()");

    Set<ExternalAccount> accounts = user.getAccount().getExternalAccounts();
    // logger.debug("{} external accounts for user {}", accounts.size(), user);

    Set<ExternalAccountView> accountViews = new HashSet<ExternalAccountView>();
    for (ExternalAccount account : accounts) {
      if (account.getAccountType() == ExternalAccountType.FACEBOOK) {
        accountViews.add(new ExternalAccountView(account, facebookSystem.getProfileLink(account)));
      } else {
        accountViews.add(new ExternalAccountView(account));
      }
    }

    return accountViews;
  }
Ejemplo n.º 5
0
  @Override
  public String toString() {
    StringBuilder builder = new StringBuilder();
    builder.append("{NoteRepository " + getId() + " owner = ");
    if (owner != null) builder.append(owner.toString());
    else builder.append("null");

    builder.append(" uuid = " + getUuid());

    builder.append("}");

    return builder.toString();
  }