Search in sources :

Example 1 with SsiCommand

use of net.kano.joscar.snaccmd.ssi.SsiCommand in project Openfire by igniterealtime.

the class SSIHierarchy method setIcon.

/**
     * Updates the avatar of the entity owning this instance on the network.
     */
public void setIcon(final String type, final byte[] data) {
    this.pendingAvatar = data;
    try {
        final MessageDigest digest = MessageDigest.getInstance("MD5");
        digest.update(data);
        final ExtraInfoData eid = new ExtraInfoData(ExtraInfoData.FLAG_HASH_PRESENT, ByteBlock.wrap(digest.digest()));
        final SsiCommand request;
        final IconItem newIconItem;
        if (icon != null) {
            newIconItem = new IconItem(icon);
            newIconItem.setIconInfo(eid);
            request = new ModifyItemsCmd(newIconItem.toSsiItem());
        } else {
            newIconItem = new IconItem(IconItem.NAME_DEFAULT, this.getNextBuddyId(SsiItem.GROUP_ROOT), eid);
            request = new CreateItemsCmd(newIconItem.toSsiItem());
        }
        request(new PreModCmd());
        request(request);
        request(new PostModCmd());
        this.icon = newIconItem;
    } catch (NoSuchAlgorithmException e) {
        Log.error("No algorithm found for MD5 checksum??");
    }
}
Also used : PostModCmd(net.kano.joscar.snaccmd.ssi.PostModCmd) SsiCommand(net.kano.joscar.snaccmd.ssi.SsiCommand) IconItem(net.kano.joscar.ssiitem.IconItem) PreModCmd(net.kano.joscar.snaccmd.ssi.PreModCmd) CreateItemsCmd(net.kano.joscar.snaccmd.ssi.CreateItemsCmd) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest) ModifyItemsCmd(net.kano.joscar.snaccmd.ssi.ModifyItemsCmd) ExtraInfoData(net.kano.joscar.snaccmd.ExtraInfoData)

Aggregations

MessageDigest (java.security.MessageDigest)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ExtraInfoData (net.kano.joscar.snaccmd.ExtraInfoData)1 CreateItemsCmd (net.kano.joscar.snaccmd.ssi.CreateItemsCmd)1 ModifyItemsCmd (net.kano.joscar.snaccmd.ssi.ModifyItemsCmd)1 PostModCmd (net.kano.joscar.snaccmd.ssi.PostModCmd)1 PreModCmd (net.kano.joscar.snaccmd.ssi.PreModCmd)1 SsiCommand (net.kano.joscar.snaccmd.ssi.SsiCommand)1 IconItem (net.kano.joscar.ssiitem.IconItem)1