Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XEP-0084: User Avatar implementation #107

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions documentation/extensions/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Smack Extensions and currently supported XEPs of smack-extensions
| Advanced Message Processing | [XEP-0079](http://xmpp.org/extensions/xep-0079.html) | Enables entities to request, and servers to perform, advanced processing of XMPP message stanzas. |
| User Location | [XEP-0080](http://xmpp.org/extensions/xep-0080.html) | Enabled communicating information about the current geographical or physical location of an entity. |
| XMPP Date Time Profiles | [XEP-0082](http://xmpp.org/extensions/xep-0082.html) | Standardization of Date and Time representation in XMPP. |
| User Avatar | [XEP-0084](http://xmpp.org/extensions/xep-0084.html) | Allows to exchange user avatars, which are small images or icons associated with human users. |
| Chat State Notifications | [XEP-0085](http://xmpp.org/extensions/xep-0085.html) | Communicating the status of a user in a chat session. |
| [Time Exchange](time.md) | [XEP-0090](http://xmpp.org/extensions/xep-0090.html) | Allows local time information to be shared between users. |
| Software Version | [XEP-0092](http://xmpp.org/extensions/xep-0092.html) | Retrieve and announce the software application of an XMPP entity. |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/**
*
* 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;

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

private final String id;
private final String url;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be of type '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, String url, long bytes, String type, int pixelsHeight, int pixelsWidth) {
this.id = id;
this.url = url;
this.bytes = bytes;
this.type = type;
this.height = pixelsHeight;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

height and width are xs:unsingedByte, thus the constructor should ensure that it's value is within the range of [1,254] and otherwise throw an IllegalArgumentException.

this.width = pixelsWidth;
}

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

/**
* Get the url.
*
* @return the url
*/
public String 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be wrap with Collections.umodifyableList()

}

/**
* 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