-
Notifications
You must be signed in to change notification settings - Fork 887
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: vanitasvitae <[email protected]>
- Loading branch information
1 parent
5b23b9a
commit 3c31f0c
Showing
18 changed files
with
1,543 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
smack-extensions/src/main/java/org/jivesoftware/smackx/avatar/AvatarMetadataStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* | ||
* Copyright 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 org.jxmpp.jid.EntityBareJid; | ||
|
||
/** | ||
* The {@link AvatarMetadataStore} interface defines methods used by the {@link UserAvatarManager} to determine, | ||
* whether the client already has a local copy of a published avatar or if the user needs to be informed about the | ||
* update in order to download the image. | ||
*/ | ||
public interface AvatarMetadataStore { | ||
|
||
/** | ||
* Determine, if the client already has a copy of the avatar with {@code itemId} available or not. | ||
* | ||
* @param jid {@link EntityBareJid} of the entity that published the avatar. | ||
* @param itemId itemId of the avatar | ||
* | ||
* @return true if the client already has a local copy of the avatar, false otherwise | ||
*/ | ||
boolean hasAvatarAvailable(EntityBareJid jid, String itemId); | ||
|
||
/** | ||
* Mark the tuple (jid, itemId) as available. This means that the client already has a local copy of the avatar | ||
* available and wishes not to be notified about this particular avatar anymore. | ||
* | ||
* @param jid {@link EntityBareJid} of the entity that published the avatar. | ||
* @param itemId itemId of the avatar | ||
*/ | ||
void setAvatarAvailable(EntityBareJid jid, String itemId); | ||
} |
124 changes: 124 additions & 0 deletions
124
smack-extensions/src/main/java/org/jivesoftware/smackx/avatar/MetadataInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/** | ||
* | ||
* 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; | ||
|
||
import org.jivesoftware.smack.datatypes.UInt16; | ||
import org.jivesoftware.smack.datatypes.UInt32; | ||
import org.jivesoftware.smack.util.StringUtils; | ||
|
||
/** | ||
* 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 UInt32 bytes; | ||
private final String type; | ||
private final UInt16 height; | ||
private final UInt16 width; | ||
|
||
/** | ||
* MetadataInfo constructor. | ||
* | ||
* @param id SHA-1 hash of the image data | ||
* @param url http(s) url of the image | ||
* @param bytes size of the image in bytes | ||
* @param type content type of the image | ||
* @param pixelsHeight height of the image in pixels | ||
* @param pixelsWidth width of the image in pixels | ||
*/ | ||
public MetadataInfo(String id, URL url, long bytes, String type, int pixelsHeight, int pixelsWidth) { | ||
this.id = StringUtils.requireNotNullNorEmpty(id, "ID is required."); | ||
this.url = url; | ||
this.bytes = UInt32.from(bytes); | ||
this.type = StringUtils.requireNotNullNorEmpty(type, "Content Type is required."); | ||
if (pixelsHeight < 0 || pixelsHeight > MAX_HEIGHT) { | ||
throw new IllegalArgumentException("Image height value must be between 0 and 65536."); | ||
} | ||
if (pixelsWidth < 0 || pixelsWidth > MAX_WIDTH) { | ||
throw new IllegalArgumentException("Image width value must be between 0 and 65536."); | ||
} | ||
this.height = UInt16.from(pixelsHeight); | ||
this.width = UInt16.from(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 UInt32 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 UInt16 getHeight() { | ||
return height; | ||
} | ||
|
||
/** | ||
* Get the width in pixels. | ||
* | ||
* @return the width in pixels | ||
*/ | ||
public UInt16 getWidth() { | ||
return width; | ||
} | ||
|
||
} |
86 changes: 86 additions & 0 deletions
86
smack-extensions/src/main/java/org/jivesoftware/smackx/avatar/MetadataPointer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* | ||
* 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.Map; | ||
|
||
import org.jivesoftware.smack.util.StringUtils; | ||
|
||
/** | ||
* User Avatar metadata pointer model class. | ||
* A pointer element is used to point to an avatar which is not published via PubSub or HTTP, but provided by a | ||
* third-party service. | ||
* | ||
* @author Fernando Ramirez | ||
* @see <a href="https://xmpp.org/extensions/xep-0084.html">XEP-0084: User Avatar</a> | ||
*/ | ||
public class MetadataPointer { | ||
|
||
private final String namespace; | ||
private final Map<String, Object> fields; | ||
|
||
/** | ||
* Metadata Pointer constructor. | ||
* | ||
* The following example | ||
* <pre> | ||
* {@code | ||
* <pointer> | ||
* <x xmlns='http://example.com/virtualworlds'> | ||
* <game>Ancapistan</game> | ||
* <character>Kropotkin</character> | ||
* </x> | ||
* </pointer> | ||
* } | ||
* </pre> | ||
* can be created by constructing the object like this: | ||
* <pre> | ||
* {@code | ||
* Map fields = new HashMap<>(); | ||
* fields.add("game", "Ancapistan"); | ||
* fields.add("character", "Kropotkin"); | ||
* MetadataPointer pointer = new MetadataPointer("http://example.com/virtualworlds", fields); | ||
* } | ||
* </pre> | ||
* | ||
* @param namespace namespace of the child element of the metadata pointer. | ||
* @param fields fields of the child element as key, value pairs. | ||
*/ | ||
public MetadataPointer(String namespace, Map<String, Object> fields) { | ||
this.namespace = StringUtils.requireNotNullNorEmpty(namespace, "Namespace MUST NOT be null, nor empty."); | ||
this.fields = fields; | ||
} | ||
|
||
/** | ||
* Get the namespace of the pointers child element. | ||
* | ||
* @return the namespace | ||
*/ | ||
public String getNamespace() { | ||
return namespace; | ||
} | ||
|
||
/** | ||
* Get the fields of the pointers child element. | ||
* | ||
* @return the fields | ||
*/ | ||
public Map<String, Object> getFields() { | ||
return fields; | ||
} | ||
|
||
} |
Oops, something went wrong.