1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-12-13 00:21:07 +01:00

Add MucBookmarkAutojoinManager

Also add MucConfigFormManager and improve the MUC API (SMACK-648). Bump
to jxmpp 0.5.0-alpha3.

Improve and extend PrivateDataManager and BookmarkManager.
This commit is contained in:
Florian Schmaus 2015-04-21 19:05:22 +02:00
parent 265e5c69d5
commit f274581c27
15 changed files with 690 additions and 102 deletions

View file

@ -28,6 +28,8 @@ import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smackx.iqprivate.PrivateDataManager;
import org.jxmpp.jid.BareJid;
import org.jxmpp.jid.parts.Resourcepart;
/**
@ -109,8 +111,8 @@ public final class BookmarkManager {
* @throws NotConnectedException
* @throws InterruptedException
*/
public void addBookmarkedConference(String name, String jid, boolean isAutoJoin,
String nickname, String password) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
public void addBookmarkedConference(String name, BareJid jid, boolean isAutoJoin,
Resourcepart nickname, String password) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException
{
retrieveBookmarks();
BookmarkedConference bookmark
@ -144,12 +146,12 @@ public final class BookmarkManager {
* @throws IllegalArgumentException thrown when the conference being removed is a shared
* conference
*/
public void removeBookmarkedConference(String jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
public void removeBookmarkedConference(BareJid jid) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
retrieveBookmarks();
Iterator<BookmarkedConference> it = bookmarks.getBookmarkedConferences().iterator();
while(it.hasNext()) {
BookmarkedConference conference = it.next();
if(conference.getJid().equalsIgnoreCase(jid)) {
if(conference.getJid().equals(jid)) {
if(conference.isShared()) {
throw new IllegalArgumentException("Conference is shared and can't be removed");
}
@ -230,6 +232,22 @@ public final class BookmarkManager {
}
}
/**
* Check if the service supports bookmarks using private data.
*
* @return true if the service supports private data, false otherwise.
* @throws NoResponseException
* @throws NotConnectedException
* @throws InterruptedException
* @throws XMPPErrorException
* @see PrivateDataManager#isSupported()
* @since 4.2
*/
public boolean isSupported() throws NoResponseException, NotConnectedException,
XMPPErrorException, InterruptedException {
return privateDataManager.isSupported();
}
private Bookmarks retrieveBookmarks() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
synchronized(bookmarkLock) {
if(bookmarks == null) {

View file

@ -17,6 +17,9 @@
package org.jivesoftware.smackx.bookmarks;
import org.jxmpp.jid.BareJid;
import org.jxmpp.jid.parts.Resourcepart;
/**
* Respresents a Conference Room bookmarked on the server using XEP-0048 Bookmark Storage XEP.
*
@ -26,17 +29,17 @@ public class BookmarkedConference implements SharedBookmark {
private String name;
private boolean autoJoin;
private final String jid;
private final BareJid jid;
private String nickname;
private Resourcepart nickname;
private String password;
private boolean isShared;
protected BookmarkedConference(String jid) {
protected BookmarkedConference(BareJid jid) {
this.jid = jid;
}
protected BookmarkedConference(String name, String jid, boolean autoJoin, String nickname,
protected BookmarkedConference(String name, BareJid jid, boolean autoJoin, Resourcepart nickname,
String password)
{
this.name = name;
@ -78,7 +81,7 @@ public class BookmarkedConference implements SharedBookmark {
*
* @return the full JID of this conference room.
*/
public String getJid() {
public BareJid getJid() {
return jid;
}
@ -88,11 +91,11 @@ public class BookmarkedConference implements SharedBookmark {
*
* @return the nickname to use when joining, null may be returned.
*/
public String getNickname() {
public Resourcepart getNickname() {
return nickname;
}
protected void setNickname(String nickname) {
protected void setNickname(Resourcepart nickname) {
this.nickname = nickname;
}
@ -116,7 +119,7 @@ public class BookmarkedConference implements SharedBookmark {
return false;
}
BookmarkedConference conference = (BookmarkedConference)obj;
return conference.getJid().equalsIgnoreCase(jid);
return conference.getJid().equals(jid);
}
@Override

View file

@ -16,9 +16,12 @@
*/
package org.jivesoftware.smackx.bookmarks;
import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jivesoftware.smackx.iqprivate.packet.PrivateData;
import org.jivesoftware.smackx.iqprivate.provider.PrivateDataProvider;
import org.jxmpp.jid.BareJid;
import org.jxmpp.jid.parts.Resourcepart;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@ -268,7 +271,7 @@ public class Bookmarks implements PrivateData {
private static BookmarkedConference getConferenceStorage(XmlPullParser parser) throws XmlPullParserException, IOException {
String name = parser.getAttributeValue("", "name");
String autojoin = parser.getAttributeValue("", "autojoin");
String jid = parser.getAttributeValue("", "jid");
BareJid jid = ParserUtils.getBareJidAttribute(parser);
BookmarkedConference conf = new BookmarkedConference(jid);
conf.setName(name);
@ -279,7 +282,8 @@ public class Bookmarks implements PrivateData {
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG && "nick".equals(parser.getName())) {
conf.setNickname(parser.nextText());
String nickString = parser.nextText();
conf.setNickname(Resourcepart.from(nickString));
}
else if (eventType == XmlPullParser.START_TAG && "password".equals(parser.getName())) {
conf.setPassword(parser.nextText());