mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-09 18:29:45 +02:00
Add Stanza.setNewStanzaId() and ensureStanzaIdSet()
Also deprecate setStanzaId() since it was not clear if this would create a new stanza ID or just ensure that one is set.
This commit is contained in:
parent
133ee29150
commit
e23babf147
4 changed files with 39 additions and 9 deletions
|
@ -138,9 +138,43 @@ public abstract class Stanza implements TopLevelStreamElement {
|
|||
*
|
||||
* @return the stanza id.
|
||||
* @since 4.2
|
||||
* @deprecated use {@link #setNewStanzaId()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
// TODO: Remove in Smack 4.5.
|
||||
public String setStanzaId() {
|
||||
if (!hasStanzaIdSet()) {
|
||||
return ensureStanzaIdSet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new stanza ID even if there is already one set.
|
||||
*
|
||||
* @return the stanza id.
|
||||
* @since 4.4
|
||||
*/
|
||||
public String setNewStanzaId() {
|
||||
return ensureStanzaIdSet(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure a stanza id is set.
|
||||
*
|
||||
* @return the stanza id.
|
||||
* @since 4.4
|
||||
*/
|
||||
public String ensureStanzaIdSet() {
|
||||
return ensureStanzaIdSet(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that a stanza ID is set.
|
||||
*
|
||||
* @param forceNew force a new ID even if there is already one set.
|
||||
* @return the stanza ID.
|
||||
* @since 4.4
|
||||
*/
|
||||
private String ensureStanzaIdSet(boolean forceNew) {
|
||||
if (forceNew || !hasStanzaIdSet()) {
|
||||
setStanzaId(StanzaIdUtil.newStanzaId());
|
||||
}
|
||||
return getStanzaId();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue