use of eu.siacs.conversations.xmpp.jid.InvalidJidException in project Conversations by siacs.
the class XmppConnectionService method loadPhoneContacts.
public void loadPhoneContacts() {
mContactMergerExecutor.execute(new Runnable() {
@Override
public void run() {
PhoneHelper.loadPhoneContacts(XmppConnectionService.this, new OnPhoneContactsLoadedListener() {
@Override
public void onPhoneContactsLoaded(List<Bundle> phoneContacts) {
Log.d(Config.LOGTAG, "start merging phone contacts with roster");
for (Account account : accounts) {
List<Contact> withSystemAccounts = account.getRoster().getWithSystemAccounts();
for (Bundle phoneContact : phoneContacts) {
Jid jid;
try {
jid = Jid.fromString(phoneContact.getString("jid"));
} catch (final InvalidJidException e) {
continue;
}
final Contact contact = account.getRoster().getContact(jid);
String systemAccount = phoneContact.getInt("phoneid") + "#" + phoneContact.getString("lookup");
contact.setSystemAccount(systemAccount);
boolean needsCacheClean = contact.setPhotoUri(phoneContact.getString("photouri"));
needsCacheClean |= contact.setSystemName(phoneContact.getString("displayname"));
if (needsCacheClean) {
getAvatarService().clear(contact);
}
withSystemAccounts.remove(contact);
}
for (Contact contact : withSystemAccounts) {
contact.setSystemAccount(null);
boolean needsCacheClean = contact.setPhotoUri(null);
needsCacheClean |= contact.setSystemName(null);
if (needsCacheClean) {
getAvatarService().clear(contact);
}
}
}
Log.d(Config.LOGTAG, "finished merging phone contacts");
updateAccountUi();
}
});
}
});
}
use of eu.siacs.conversations.xmpp.jid.InvalidJidException in project Conversations by siacs.
the class MagicCreateActivity method onCreate.
@Override
protected void onCreate(final Bundle savedInstanceState) {
if (getResources().getBoolean(R.bool.portrait_only)) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.magic_create);
mFullJidDisplay = (TextView) findViewById(R.id.full_jid);
mUsername = (EditText) findViewById(R.id.username);
mRandom = new SecureRandom();
Button next = (Button) findViewById(R.id.create_account);
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String username = mUsername.getText().toString();
if (username.contains("@") || username.length() < 3) {
mUsername.setError(getString(R.string.invalid_username));
mUsername.requestFocus();
} else {
mUsername.setError(null);
try {
Jid jid = Jid.fromParts(username.toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null);
Account account = xmppConnectionService.findAccountByJid(jid);
if (account == null) {
account = new Account(jid, createPassword());
account.setOption(Account.OPTION_REGISTER, true);
account.setOption(Account.OPTION_DISABLED, true);
account.setOption(Account.OPTION_MAGIC_CREATE, true);
xmppConnectionService.createAccount(account);
}
Intent intent = new Intent(MagicCreateActivity.this, EditAccountActivity.class);
intent.putExtra("jid", account.getJid().toBareJid().toString());
intent.putExtra("init", true);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
Toast.makeText(MagicCreateActivity.this, R.string.secure_password_generated, Toast.LENGTH_SHORT).show();
startActivity(intent);
} catch (InvalidJidException e) {
mUsername.setError(getString(R.string.invalid_username));
mUsername.requestFocus();
}
}
}
});
mUsername.addTextChangedListener(this);
}
use of eu.siacs.conversations.xmpp.jid.InvalidJidException in project Conversations by siacs.
the class DatabaseBackend method canonicalizeJids.
private void canonicalizeJids(SQLiteDatabase db) {
// migrate db to new, canonicalized JID domainpart representation
// Conversation table
Cursor cursor = db.rawQuery("select * from " + Conversation.TABLENAME, new String[0]);
while (cursor.moveToNext()) {
String newJid;
try {
newJid = Jid.fromString(cursor.getString(cursor.getColumnIndex(Conversation.CONTACTJID))).toPreppedString();
} catch (InvalidJidException ignored) {
Log.e(Config.LOGTAG, "Failed to migrate Conversation CONTACTJID " + cursor.getString(cursor.getColumnIndex(Conversation.CONTACTJID)) + ": " + ignored + ". Skipping...");
continue;
}
String[] updateArgs = { newJid, cursor.getString(cursor.getColumnIndex(Conversation.UUID)) };
db.execSQL("update " + Conversation.TABLENAME + " set " + Conversation.CONTACTJID + " = ? " + " where " + Conversation.UUID + " = ?", updateArgs);
}
cursor.close();
// Contact table
cursor = db.rawQuery("select * from " + Contact.TABLENAME, new String[0]);
while (cursor.moveToNext()) {
String newJid;
try {
newJid = Jid.fromString(cursor.getString(cursor.getColumnIndex(Contact.JID))).toPreppedString();
} catch (InvalidJidException ignored) {
Log.e(Config.LOGTAG, "Failed to migrate Contact JID " + cursor.getString(cursor.getColumnIndex(Contact.JID)) + ": " + ignored + ". Skipping...");
continue;
}
String[] updateArgs = { newJid, cursor.getString(cursor.getColumnIndex(Contact.ACCOUNT)), cursor.getString(cursor.getColumnIndex(Contact.JID)) };
db.execSQL("update " + Contact.TABLENAME + " set " + Contact.JID + " = ? " + " where " + Contact.ACCOUNT + " = ? " + " AND " + Contact.JID + " = ?", updateArgs);
}
cursor.close();
// Account table
cursor = db.rawQuery("select * from " + Account.TABLENAME, new String[0]);
while (cursor.moveToNext()) {
String newServer;
try {
newServer = Jid.fromParts(cursor.getString(cursor.getColumnIndex(Account.USERNAME)), cursor.getString(cursor.getColumnIndex(Account.SERVER)), "mobile").getDomainpart();
} catch (InvalidJidException ignored) {
Log.e(Config.LOGTAG, "Failed to migrate Account SERVER " + cursor.getString(cursor.getColumnIndex(Account.SERVER)) + ": " + ignored + ". Skipping...");
continue;
}
String[] updateArgs = { newServer, cursor.getString(cursor.getColumnIndex(Account.UUID)) };
db.execSQL("update " + Account.TABLENAME + " set " + Account.SERVER + " = ? " + " where " + Account.UUID + " = ?", updateArgs);
}
cursor.close();
}
use of eu.siacs.conversations.xmpp.jid.InvalidJidException in project Conversations by siacs.
the class AbstractParser method parseItem.
public static MucOptions.User parseItem(Conversation conference, Element item, Jid fullJid) {
final String local = conference.getJid().getLocalpart();
final String domain = conference.getJid().getDomainpart();
String affiliation = item.getAttribute("affiliation");
String role = item.getAttribute("role");
String nick = item.getAttribute("nick");
if (nick != null && fullJid == null) {
try {
fullJid = Jid.fromParts(local, domain, nick);
} catch (InvalidJidException e) {
fullJid = null;
}
}
Jid realJid = item.getAttributeAsJid("jid");
MucOptions.User user = new MucOptions.User(conference.getMucOptions(), fullJid);
user.setRealJid(realJid);
user.setAffiliation(affiliation);
user.setRole(role);
return user;
}
use of eu.siacs.conversations.xmpp.jid.InvalidJidException in project Conversations by siacs.
the class ContactDetailsActivity method onCreate.
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
showInactiveOmemo = savedInstanceState != null && savedInstanceState.getBoolean("show_inactive_omemo", false);
if (getIntent().getAction().equals(ACTION_VIEW_CONTACT)) {
try {
this.accountJid = Jid.fromString(getIntent().getExtras().getString(EXTRA_ACCOUNT));
} catch (final InvalidJidException ignored) {
}
try {
this.contactJid = Jid.fromString(getIntent().getExtras().getString("contact"));
} catch (final InvalidJidException ignored) {
}
}
this.messageFingerprint = getIntent().getStringExtra("fingerprint");
setContentView(R.layout.activity_contact_details);
contactJidTv = (TextView) findViewById(R.id.details_contactjid);
accountJidTv = (TextView) findViewById(R.id.details_account);
lastseen = (TextView) findViewById(R.id.details_lastseen);
statusMessage = (TextView) findViewById(R.id.status_message);
send = (CheckBox) findViewById(R.id.details_send_presence);
receive = (CheckBox) findViewById(R.id.details_receive_presence);
badge = (QuickContactBadge) findViewById(R.id.details_contact_badge);
addContactButton = (Button) findViewById(R.id.add_contact_button);
addContactButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
showAddToRosterDialog(contact);
}
});
keys = (LinearLayout) findViewById(R.id.details_contact_keys);
keysWrapper = (LinearLayout) findViewById(R.id.keys_wrapper);
tags = (FlowLayout) findViewById(R.id.tags);
mShowInactiveDevicesButton = (Button) findViewById(R.id.show_inactive_devices);
if (getActionBar() != null) {
getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true);
}
mShowInactiveDevicesButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showInactiveOmemo = !showInactiveOmemo;
populateView();
}
});
}
Aggregations