fixed full jid for account
This commit is contained in:
parent
87c4fd9050
commit
2b99b694eb
|
@ -1,8 +1,8 @@
|
||||||
package eu.siacs.conversations.entities;
|
package eu.siacs.conversations.entities;
|
||||||
|
|
||||||
import java.security.interfaces.DSAPublicKey;
|
import android.content.ContentValues;
|
||||||
import java.util.List;
|
import android.database.Cursor;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import android.os.SystemClock;
|
||||||
|
|
||||||
import net.java.otr4j.crypto.OtrCryptoEngineImpl;
|
import net.java.otr4j.crypto.OtrCryptoEngineImpl;
|
||||||
import net.java.otr4j.crypto.OtrCryptoException;
|
import net.java.otr4j.crypto.OtrCryptoException;
|
||||||
|
@ -10,6 +10,10 @@ import net.java.otr4j.crypto.OtrCryptoException;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.security.interfaces.DSAPublicKey;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
import eu.siacs.conversations.Config;
|
import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.crypto.OtrEngine;
|
import eu.siacs.conversations.crypto.OtrEngine;
|
||||||
|
@ -18,10 +22,6 @@ import eu.siacs.conversations.xmpp.XmppConnection;
|
||||||
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
||||||
import eu.siacs.conversations.xmpp.jid.Jid;
|
import eu.siacs.conversations.xmpp.jid.Jid;
|
||||||
|
|
||||||
import android.content.ContentValues;
|
|
||||||
import android.database.Cursor;
|
|
||||||
import android.os.SystemClock;
|
|
||||||
|
|
||||||
public class Account extends AbstractEntity {
|
public class Account extends AbstractEntity {
|
||||||
|
|
||||||
public static final String TABLENAME = "accounts";
|
public static final String TABLENAME = "accounts";
|
||||||
|
@ -51,7 +51,8 @@ public class Account extends AbstractEntity {
|
||||||
public static final int STATUS_REGISTRATION_CONFLICT = 8;
|
public static final int STATUS_REGISTRATION_CONFLICT = 8;
|
||||||
public static final int STATUS_REGISTRATION_SUCCESSFULL = 9;
|
public static final int STATUS_REGISTRATION_SUCCESSFULL = 9;
|
||||||
public static final int STATUS_REGISTRATION_NOT_SUPPORTED = 10;
|
public static final int STATUS_REGISTRATION_NOT_SUPPORTED = 10;
|
||||||
|
public List<Conversation> pendingConferenceJoins = new CopyOnWriteArrayList<>();
|
||||||
|
public List<Conversation> pendingConferenceLeaves = new CopyOnWriteArrayList<>();
|
||||||
protected Jid jid;
|
protected Jid jid;
|
||||||
protected String password;
|
protected String password;
|
||||||
protected int options = 0;
|
protected int options = 0;
|
||||||
|
@ -59,19 +60,14 @@ public class Account extends AbstractEntity {
|
||||||
protected int status = -1;
|
protected int status = -1;
|
||||||
protected JSONObject keys = new JSONObject();
|
protected JSONObject keys = new JSONObject();
|
||||||
protected String avatar;
|
protected String avatar;
|
||||||
|
|
||||||
protected boolean online = false;
|
protected boolean online = false;
|
||||||
|
|
||||||
private OtrEngine otrEngine = null;
|
private OtrEngine otrEngine = null;
|
||||||
private XmppConnection xmppConnection = null;
|
private XmppConnection xmppConnection = null;
|
||||||
private Presences presences = new Presences();
|
private Presences presences = new Presences();
|
||||||
private long mEndGracePeriod = 0L;
|
private long mEndGracePeriod = 0L;
|
||||||
private String otrFingerprint;
|
private String otrFingerprint;
|
||||||
private Roster roster = null;
|
private Roster roster = null;
|
||||||
|
|
||||||
private List<Bookmark> bookmarks = new CopyOnWriteArrayList<>();
|
private List<Bookmark> bookmarks = new CopyOnWriteArrayList<>();
|
||||||
public List<Conversation> pendingConferenceJoins = new CopyOnWriteArrayList<>();
|
|
||||||
public List<Conversation> pendingConferenceLeaves = new CopyOnWriteArrayList<>();
|
|
||||||
|
|
||||||
public Account() {
|
public Account() {
|
||||||
this.uuid = "0";
|
this.uuid = "0";
|
||||||
|
@ -83,13 +79,13 @@ public class Account extends AbstractEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Account(final String uuid, final Jid jid,
|
public Account(final String uuid, final Jid jid,
|
||||||
final String password, final int options, final String rosterVersion, final String keys,
|
final String password, final int options, final String rosterVersion, final String keys,
|
||||||
final String avatar) {
|
final String avatar) {
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.jid = jid;
|
this.jid = jid;
|
||||||
if (jid.getResourcepart().isEmpty()) {
|
if (jid.getResourcepart().isEmpty()) {
|
||||||
this.setResource("mobile");
|
this.setResource("mobile");
|
||||||
}
|
}
|
||||||
this.password = password;
|
this.password = password;
|
||||||
this.options = options;
|
this.options = options;
|
||||||
this.rosterVersion = rosterVersion;
|
this.rosterVersion = rosterVersion;
|
||||||
|
@ -101,6 +97,22 @@ public class Account extends AbstractEntity {
|
||||||
this.avatar = avatar;
|
this.avatar = avatar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Account fromCursor(Cursor cursor) {
|
||||||
|
Jid jid = null;
|
||||||
|
try {
|
||||||
|
jid = Jid.fromParts(cursor.getString(cursor.getColumnIndex(USERNAME)),
|
||||||
|
cursor.getString(cursor.getColumnIndex(SERVER)), "mobile");
|
||||||
|
} catch (final InvalidJidException ignored) {
|
||||||
|
}
|
||||||
|
return new Account(cursor.getString(cursor.getColumnIndex(UUID)),
|
||||||
|
jid,
|
||||||
|
cursor.getString(cursor.getColumnIndex(PASSWORD)),
|
||||||
|
cursor.getInt(cursor.getColumnIndex(OPTIONS)),
|
||||||
|
cursor.getString(cursor.getColumnIndex(ROSTERVERSION)),
|
||||||
|
cursor.getString(cursor.getColumnIndex(KEYS)),
|
||||||
|
cursor.getString(cursor.getColumnIndex(AVATAR)));
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isOptionSet(int option) {
|
public boolean isOptionSet(int option) {
|
||||||
return ((options & (1 << option)) != 0);
|
return ((options & (1 << option)) != 0);
|
||||||
}
|
}
|
||||||
|
@ -118,15 +130,15 @@ public class Account extends AbstractEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUsername(final String username) throws InvalidJidException {
|
public void setUsername(final String username) throws InvalidJidException {
|
||||||
jid = Jid.fromParts(username, jid.getDomainpart(), jid.getResourcepart());
|
jid = Jid.fromParts(username, jid.getDomainpart(), jid.getResourcepart());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Jid getServer() {
|
public Jid getServer() {
|
||||||
return jid.toDomainJid();
|
return jid.toDomainJid();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setServer(final String server) throws InvalidJidException {
|
public void setServer(final String server) throws InvalidJidException {
|
||||||
jid = Jid.fromParts(jid.getLocalpart(), server, jid.getResourcepart());
|
jid = Jid.fromParts(jid.getLocalpart(), server, jid.getResourcepart());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPassword() {
|
public String getPassword() {
|
||||||
|
@ -137,10 +149,6 @@ public class Account extends AbstractEntity {
|
||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStatus(final int status) {
|
|
||||||
this.status = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getStatus() {
|
public int getStatus() {
|
||||||
if (isOptionSet(OPTION_DISABLED)) {
|
if (isOptionSet(OPTION_DISABLED)) {
|
||||||
return STATUS_DISABLED;
|
return STATUS_DISABLED;
|
||||||
|
@ -149,6 +157,10 @@ public class Account extends AbstractEntity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setStatus(final int status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean errorStatus() {
|
public boolean errorStatus() {
|
||||||
int s = getStatus();
|
int s = getStatus();
|
||||||
return (s == STATUS_REGISTRATION_FAILED
|
return (s == STATUS_REGISTRATION_FAILED
|
||||||
|
@ -158,22 +170,22 @@ public class Account extends AbstractEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasErrorStatus() {
|
public boolean hasErrorStatus() {
|
||||||
return getXmppConnection() != null && getStatus() > STATUS_NO_INTERNET && (getXmppConnection().getAttempt() >= 2);
|
return getXmppConnection() != null && getStatus() > STATUS_NO_INTERNET && (getXmppConnection().getAttempt() >= 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setResource(final String resource){
|
|
||||||
try {
|
|
||||||
jid = Jid.fromParts(jid.getLocalpart(), jid.getDomainpart(), resource);
|
|
||||||
} catch (final InvalidJidException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getResource() {
|
public String getResource() {
|
||||||
return jid.getResourcepart();
|
return jid.getResourcepart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setResource(final String resource) {
|
||||||
|
try {
|
||||||
|
jid = Jid.fromParts(jid.getLocalpart(), jid.getDomainpart(), resource);
|
||||||
|
} catch (final InvalidJidException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Jid getJid() {
|
public Jid getJid() {
|
||||||
return jid.toBareJid();
|
return jid.toBareJid();
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONObject getKeys() {
|
public JSONObject getKeys() {
|
||||||
|
@ -219,22 +231,6 @@ public class Account extends AbstractEntity {
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Account fromCursor(Cursor cursor) {
|
|
||||||
Jid jid = null;
|
|
||||||
try {
|
|
||||||
jid = Jid.fromParts(cursor.getString(cursor.getColumnIndex(USERNAME)),
|
|
||||||
cursor.getString(cursor.getColumnIndex(SERVER)), "mobile");
|
|
||||||
} catch (final InvalidJidException ignored) {
|
|
||||||
}
|
|
||||||
return new Account(cursor.getString(cursor.getColumnIndex(UUID)),
|
|
||||||
jid,
|
|
||||||
cursor.getString(cursor.getColumnIndex(PASSWORD)),
|
|
||||||
cursor.getInt(cursor.getColumnIndex(OPTIONS)),
|
|
||||||
cursor.getString(cursor.getColumnIndex(ROSTERVERSION)),
|
|
||||||
cursor.getString(cursor.getColumnIndex(KEYS)),
|
|
||||||
cursor.getString(cursor.getColumnIndex(AVATAR)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public OtrEngine getOtrEngine(XmppConnectionService context) {
|
public OtrEngine getOtrEngine(XmppConnectionService context) {
|
||||||
if (otrEngine == null) {
|
if (otrEngine == null) {
|
||||||
otrEngine = new OtrEngine(context, this);
|
otrEngine = new OtrEngine(context, this);
|
||||||
|
@ -251,7 +247,7 @@ public class Account extends AbstractEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Jid getFullJid() {
|
public Jid getFullJid() {
|
||||||
return this.getJid();
|
return this.jid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getOtrFingerprint() {
|
public String getOtrFingerprint() {
|
||||||
|
@ -328,14 +324,14 @@ public class Account extends AbstractEntity {
|
||||||
return this.roster;
|
return this.roster;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBookmarks(List<Bookmark> bookmarks) {
|
|
||||||
this.bookmarks = bookmarks;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Bookmark> getBookmarks() {
|
public List<Bookmark> getBookmarks() {
|
||||||
return this.bookmarks;
|
return this.bookmarks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setBookmarks(List<Bookmark> bookmarks) {
|
||||||
|
this.bookmarks = bookmarks;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasBookmarkFor(final Jid conferenceJid) {
|
public boolean hasBookmarkFor(final Jid conferenceJid) {
|
||||||
for (Bookmark bmark : this.bookmarks) {
|
for (Bookmark bmark : this.bookmarks) {
|
||||||
if (bmark.getJid().equals(conferenceJid.toBareJid())) {
|
if (bmark.getJid().equals(conferenceJid.toBareJid())) {
|
||||||
|
@ -361,30 +357,30 @@ public class Account extends AbstractEntity {
|
||||||
public int getReadableStatusId() {
|
public int getReadableStatusId() {
|
||||||
switch (getStatus()) {
|
switch (getStatus()) {
|
||||||
|
|
||||||
case Account.STATUS_DISABLED:
|
case Account.STATUS_DISABLED:
|
||||||
return R.string.account_status_disabled;
|
return R.string.account_status_disabled;
|
||||||
case Account.STATUS_ONLINE:
|
case Account.STATUS_ONLINE:
|
||||||
return R.string.account_status_online;
|
return R.string.account_status_online;
|
||||||
case Account.STATUS_CONNECTING:
|
case Account.STATUS_CONNECTING:
|
||||||
return R.string.account_status_connecting;
|
return R.string.account_status_connecting;
|
||||||
case Account.STATUS_OFFLINE:
|
case Account.STATUS_OFFLINE:
|
||||||
return R.string.account_status_offline;
|
return R.string.account_status_offline;
|
||||||
case Account.STATUS_UNAUTHORIZED:
|
case Account.STATUS_UNAUTHORIZED:
|
||||||
return R.string.account_status_unauthorized;
|
return R.string.account_status_unauthorized;
|
||||||
case Account.STATUS_SERVER_NOT_FOUND:
|
case Account.STATUS_SERVER_NOT_FOUND:
|
||||||
return R.string.account_status_not_found;
|
return R.string.account_status_not_found;
|
||||||
case Account.STATUS_NO_INTERNET:
|
case Account.STATUS_NO_INTERNET:
|
||||||
return R.string.account_status_no_internet;
|
return R.string.account_status_no_internet;
|
||||||
case Account.STATUS_REGISTRATION_FAILED:
|
case Account.STATUS_REGISTRATION_FAILED:
|
||||||
return R.string.account_status_regis_fail;
|
return R.string.account_status_regis_fail;
|
||||||
case Account.STATUS_REGISTRATION_CONFLICT:
|
case Account.STATUS_REGISTRATION_CONFLICT:
|
||||||
return R.string.account_status_regis_conflict;
|
return R.string.account_status_regis_conflict;
|
||||||
case Account.STATUS_REGISTRATION_SUCCESSFULL:
|
case Account.STATUS_REGISTRATION_SUCCESSFULL:
|
||||||
return R.string.account_status_regis_success;
|
return R.string.account_status_regis_success;
|
||||||
case Account.STATUS_REGISTRATION_NOT_SUPPORTED:
|
case Account.STATUS_REGISTRATION_NOT_SUPPORTED:
|
||||||
return R.string.account_status_regis_not_sup;
|
return R.string.account_status_regis_not_sup;
|
||||||
default:
|
default:
|
||||||
return R.string.account_status_unknown;
|
return R.string.account_status_unknown;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue