Skip to content

Commit

Permalink
XEP-0084: User Avatars
Browse files Browse the repository at this point in the history
Co-authored-by: vanitasvitae <vanitasvitae@fsfe.org>
  • Loading branch information
ramabit and vanitasvitae committed Jul 30, 2019
1 parent eecd5b7 commit f51edff
Show file tree
Hide file tree
Showing 15 changed files with 1,301 additions and 1 deletion.
2 changes: 1 addition & 1 deletion documentation/extensions/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Smack Extensions and currently supported XEPs of smack-extensions
| Advanced Message Processing | [XEP-0079](https://xmpp.org/extensions/xep-0079.html) | n/a | Enables entities to request, and servers to perform, advanced processing of XMPP message stanzas. |
| User Location | [XEP-0080](https://xmpp.org/extensions/xep-0080.html) | n/a | Enabled communicating information about the current geographical or physical location of an entity. |
| XMPP Date Time Profiles | [XEP-0082](https://xmpp.org/extensions/xep-0082.html) | n/a | Standardization of Date and Time representation in XMPP. |
| User Avatar | [XEP-0084](https://xmpp.org/extensions/xep-0084.html) | 1.1.2 | Allows to exchange user avatars, which are small images or icons associated with human users. |
| Chat State Notifications | [XEP-0085](https://xmpp.org/extensions/xep-0085.html) | n/a | Communicating the status of a user in a chat session. |
| [Time Exchange](time.md) | [XEP-0090](https://xmpp.org/extensions/xep-0090.html) | n/a | Allows local time information to be shared between users. |
| Software Version | [XEP-0092](https://xmpp.org/extensions/xep-0092.html) | n/a | Retrieve and announce the software application of an XMPP entity. |
Expand Down Expand Up @@ -78,7 +79,6 @@ Smack Extensions and currently supported XEPs of smack-extensions
| [Group Chat Invitations](invitation.md) | n/a | n/a | Send invitations to other users to join a group chat room. |
| [Jive Properties](properties.md) | n/a | n/a | TODO |


Experimental Smack Extensions and currently supported XEPs of smack-experimental
--------------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.io.IOException;
import java.io.Writer;
import java.net.URL;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
Expand Down Expand Up @@ -344,6 +345,13 @@ public XmlStringBuilder optAttribute(String name, Number number) {
return this;
}

public XmlStringBuilder optAttribute(String name, URL url) {
if (url != null) {
attribute(name, url.toExternalForm());
}
return this;
}

/**
* Add the given attribute if {@code value => 0}.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/**
*
* Copyright 2017 Fernando Ramirez, 2019 Paul Schaub
*
* 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.
*/
package org.jivesoftware.smackx.avatar;

import java.net.URL;

/**
* User Avatar metadata info model class.
*
* @author Fernando Ramirez
* @author Paul Schaub
* @see <a href="http://xmpp.org/extensions/xep-0084.html">XEP-0084: User
* Avatar</a>
*/
public class MetadataInfo {

public static final int MAX_HEIGHT = 65536;
public static final int MAX_WIDTH = 65536;

private final String id;
private final URL url;
private final long bytes;
private final String type;
private final int height;
private final int width;

/**
* MetadataInfo constructor.
*
* @param id
* @param url
* @param bytes
* @param type
* @param pixelsHeight
* @param pixelsWidth
*/
public MetadataInfo(String id, URL url, long bytes, String type, int pixelsHeight, int pixelsWidth) {
this.id = id;
this.url = url;
this.bytes = bytes;
this.type = type;
if (pixelsHeight < 0 || pixelsHeight > MAX_HEIGHT) {
throw new IllegalArgumentException("Image height value must be between 0 and 65536.");
}
if (pixelsWidth < 0 || pixelsWidth > MAX_HEIGHT) {
throw new IllegalArgumentException("Image width value must be between 0 and 65536.");
}
this.height = pixelsHeight;
this.width = pixelsWidth;
}

/**
* Get the id.
*
* @return the id
*/
public String getId() {
return id;
}

/**
* Get the url of the avatar image.
*
* @return the url
*/
public URL getUrl() {
return url;
}

/**
* Get the amount of bytes.
*
* @return the amount of bytes
*/
public long getBytes() {
return bytes;
}

/**
* Get the type.
*
* @return the type
*/
public String getType() {
return type;
}

/**
* Get the height in pixels.
*
* @return the height in pixels
*/
public int getHeight() {
return height;
}

/**
* Get the width in pixels.
*
* @return the width in pixels
*/
public int getWidth() {
return width;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
*
* Copyright 2017 Fernando Ramirez
*
* 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.
*/
package org.jivesoftware.smackx.avatar;

import java.util.HashMap;

/**
* User Avatar metadata pointer model class.
*
* @author Fernando Ramirez
* @see <a href="http://xmpp.org/extensions/xep-0084.html">XEP-0084: User
* Avatar</a>
*/
public class MetadataPointer {

private final String namespace;
private final HashMap<String, Object> fields;

/**
* Metadata Pointer constructor.
*
* @param namespace
* @param fields
*/
public MetadataPointer(String namespace, HashMap<String, Object> fields) {
this.namespace = namespace;
this.fields = fields;
}

/**
* Get the namespace.
*
* @return the namespace
*/
public String getNamespace() {
return namespace;
}

/**
* Get the fields.
*
* @return the fields
*/
public HashMap<String, Object> getFields() {
return fields;
}

}
Loading

0 comments on commit f51edff

Please sign in to comment.