public void onNotify(JID jid, String id) {
    Contact contact = ContactList.getInstance().get(jid).orElse(null);
    if (contact == null) {
      LOGGER.warning("can't find contact with jid:" + jid);
      return;
    }

    if (id.isEmpty()) {
      // contact disabled avatar publishing
      // TODO
    }

    Avatar avatar = contact.getAvatar().orElse(null);
    if (avatar != null && avatar.id.equals(id))
      // avatar is not new
      return;

    mClient.requestAvatar(jid, id);
  }
  public void onData(JID jid, String id, byte[] avatarData) {
    LOGGER.info("new avatar, jid: " + jid + " id: " + id);

    if (avatarData.length > MAX_SIZE) LOGGER.info("avatar data too long: " + avatarData.length);

    Contact contact = ContactList.getInstance().get(jid).orElse(null);
    if (contact == null) {
      LOGGER.warning("can't find contact with jid:" + jid);
      return;
    }

    if (!id.equals(DigestUtils.sha1Hex(avatarData))) {
      LOGGER.warning("this is not what we wanted");
      return;
    }

    BufferedImage img = MediaUtils.readImage(avatarData).orElse(null);
    if (img == null) return;

    contact.setAvatar(new Avatar(id, img));
  }
  private void confirmNewKey(final Contact contact, final PGPUtils.PGPCoderKey key) {
    WebPanel panel = new GroupPanel(GAP_DEFAULT, false);
    panel.setOpaque(false);

    panel.add(new WebLabel(Tr.tr("Received new key for contact")).setBoldFont());
    panel.add(new WebSeparator(true, true));

    panel.add(new WebLabel(Tr.tr("Contact:")));
    String contactText = Utils.name(contact) + " " + Utils.jid(contact.getJID(), 30, true);
    panel.add(new WebLabel(contactText).setBoldFont());

    panel.add(new WebLabel(Tr.tr("Key fingerprint:")));
    WebTextArea fpArea = Utils.createFingerprintArea();
    fpArea.setText(Utils.fingerprint(key.fingerprint));
    panel.add(fpArea);

    String expl =
        Tr.tr(
            "When declining the key further communication to and from this contact will be blocked.");
    WebTextArea explArea = new WebTextArea(expl, 3, 30);
    explArea.setEditable(false);
    explArea.setLineWrap(true);
    explArea.setWrapStyleWord(true);
    panel.add(explArea);

    WebNotificationPopup popup =
        NotificationManager.showNotification(
            panel,
            NotificationOption.accept,
            NotificationOption.decline,
            NotificationOption.cancel);
    popup.setClickToClose(false);
    popup.addNotificationListener(
        new NotificationListener() {
          @Override
          public void optionSelected(NotificationOption option) {
            switch (option) {
              case accept:
                mControl.acceptKey(contact, key);
                break;
              case decline:
                mControl.declineKey(contact);
            }
          }

          @Override
          public void accepted() {}

          @Override
          public void closed() {}
        });
  }
 private static String contactText(Contact contact) {
   return Utils.name(contact, 20) + " < " + Utils.jid(contact.getJID(), 30) + " >";
 }