use of eu.siacs.conversations.utils.XmppUri in project Conversations by siacs.
the class OmemoActivity method onActivityResult.
@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (requestCode == ScanActivity.REQUEST_SCAN_QR_CODE && resultCode == RESULT_OK) {
String result = intent.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT);
XmppUri uri = new XmppUri(result == null ? "" : result);
if (xmppConnectionServiceBound) {
processFingerprintVerification(uri);
} else {
this.mPendingFingerprintVerificationUri = uri;
}
}
}
use of eu.siacs.conversations.utils.XmppUri in project Conversations by siacs.
the class PresenceParser method processConferencePresence.
private void processConferencePresence(PresencePacket packet, Conversation conversation) {
MucOptions mucOptions = conversation.getMucOptions();
final Jid jid = conversation.getAccount().getJid();
final Jid from = packet.getFrom();
if (!from.isBareJid()) {
final String type = packet.getAttribute("type");
final Element x = packet.findChild("x", Namespace.MUC_USER);
Avatar avatar = Avatar.parsePresence(packet.findChild("x", "vcard-temp:x:update"));
final List<String> codes = getStatusCodes(x);
if (type == null) {
if (x != null) {
Element item = x.findChild("item");
if (item != null && !from.isBareJid()) {
mucOptions.setError(MucOptions.Error.NONE);
MucOptions.User user = parseItem(conversation, item, from);
if (codes.contains(MucOptions.STATUS_CODE_SELF_PRESENCE) || (codes.contains(MucOptions.STATUS_CODE_ROOM_CREATED) && jid.equals(InvalidJid.getNullForInvalid(item.getAttributeAsJid("jid"))))) {
if (mucOptions.setOnline()) {
mXmppConnectionService.getAvatarService().clear(mucOptions);
}
if (mucOptions.setSelf(user)) {
Log.d(Config.LOGTAG, "role or affiliation changed");
mXmppConnectionService.databaseBackend.updateConversation(conversation);
}
mXmppConnectionService.persistSelfNick(user);
invokeRenameListener(mucOptions, true);
}
boolean isNew = mucOptions.updateUser(user);
final AxolotlService axolotlService = conversation.getAccount().getAxolotlService();
Contact contact = user.getContact();
if (isNew && user.getRealJid() != null && mucOptions.isPrivateAndNonAnonymous() && (contact == null || !contact.mutualPresenceSubscription()) && axolotlService.hasEmptyDeviceList(user.getRealJid())) {
axolotlService.fetchDeviceIds(user.getRealJid());
}
if (codes.contains(MucOptions.STATUS_CODE_ROOM_CREATED) && mucOptions.autoPushConfiguration()) {
Log.d(Config.LOGTAG, mucOptions.getAccount().getJid().asBareJid() + ": room '" + mucOptions.getConversation().getJid().asBareJid() + "' created. pushing default configuration");
mXmppConnectionService.pushConferenceConfiguration(mucOptions.getConversation(), IqGenerator.defaultChannelConfiguration(), null);
}
if (mXmppConnectionService.getPgpEngine() != null) {
Element signed = packet.findChild("x", "jabber:x:signed");
if (signed != null) {
Element status = packet.findChild("status");
String msg = status == null ? "" : status.getContent();
long keyId = mXmppConnectionService.getPgpEngine().fetchKeyId(mucOptions.getAccount(), msg, signed.getContent());
if (keyId != 0) {
user.setPgpKeyId(keyId);
}
}
}
if (avatar != null) {
avatar.owner = from;
if (mXmppConnectionService.getFileBackend().isAvatarCached(avatar)) {
if (user.setAvatar(avatar)) {
mXmppConnectionService.getAvatarService().clear(user);
}
if (user.getRealJid() != null) {
final Contact c = conversation.getAccount().getRoster().getContact(user.getRealJid());
c.setAvatar(avatar);
mXmppConnectionService.syncRoster(conversation.getAccount());
mXmppConnectionService.getAvatarService().clear(c);
mXmppConnectionService.updateRosterUi();
}
} else if (mXmppConnectionService.isDataSaverDisabled()) {
mXmppConnectionService.fetchAvatar(mucOptions.getAccount(), avatar);
}
}
}
}
} else if (type.equals("unavailable")) {
final boolean fullJidMatches = from.equals(mucOptions.getSelf().getFullJid());
if (x.hasChild("destroy") && fullJidMatches) {
Element destroy = x.findChild("destroy");
final Jid alternate = destroy == null ? null : InvalidJid.getNullForInvalid(destroy.getAttributeAsJid("jid"));
mucOptions.setError(MucOptions.Error.DESTROYED);
if (alternate != null) {
Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": muc destroyed. alternate location " + alternate);
}
} else if (codes.contains(MucOptions.STATUS_CODE_SHUTDOWN) && fullJidMatches) {
mucOptions.setError(MucOptions.Error.SHUTDOWN);
} else if (codes.contains(MucOptions.STATUS_CODE_SELF_PRESENCE)) {
if (codes.contains(MucOptions.STATUS_CODE_KICKED)) {
mucOptions.setError(MucOptions.Error.KICKED);
} else if (codes.contains(MucOptions.STATUS_CODE_BANNED)) {
mucOptions.setError(MucOptions.Error.BANNED);
} else if (codes.contains(MucOptions.STATUS_CODE_LOST_MEMBERSHIP)) {
mucOptions.setError(MucOptions.Error.MEMBERS_ONLY);
} else if (codes.contains(MucOptions.STATUS_CODE_AFFILIATION_CHANGE)) {
mucOptions.setError(MucOptions.Error.MEMBERS_ONLY);
} else if (codes.contains(MucOptions.STATUS_CODE_SHUTDOWN)) {
mucOptions.setError(MucOptions.Error.SHUTDOWN);
} else if (!codes.contains(MucOptions.STATUS_CODE_CHANGED_NICK)) {
mucOptions.setError(MucOptions.Error.UNKNOWN);
Log.d(Config.LOGTAG, "unknown error in conference: " + packet);
}
} else if (!from.isBareJid()) {
Element item = x.findChild("item");
if (item != null) {
mucOptions.updateUser(parseItem(conversation, item, from));
}
MucOptions.User user = mucOptions.deleteUser(from);
if (user != null) {
mXmppConnectionService.getAvatarService().clear(user);
}
}
} else if (type.equals("error")) {
final Element error = packet.findChild("error");
if (error == null) {
return;
}
if (error.hasChild("conflict")) {
if (mucOptions.online()) {
invokeRenameListener(mucOptions, false);
} else {
mucOptions.setError(MucOptions.Error.NICK_IN_USE);
}
} else if (error.hasChild("not-authorized")) {
mucOptions.setError(MucOptions.Error.PASSWORD_REQUIRED);
} else if (error.hasChild("forbidden")) {
mucOptions.setError(MucOptions.Error.BANNED);
} else if (error.hasChild("registration-required")) {
mucOptions.setError(MucOptions.Error.MEMBERS_ONLY);
} else if (error.hasChild("resource-constraint")) {
mucOptions.setError(MucOptions.Error.RESOURCE_CONSTRAINT);
} else if (error.hasChild("remote-server-timeout")) {
mucOptions.setError(MucOptions.Error.REMOTE_SERVER_TIMEOUT);
} else if (error.hasChild("gone")) {
final String gone = error.findChildContent("gone");
final Jid alternate;
if (gone != null) {
final XmppUri xmppUri = new XmppUri(gone);
if (xmppUri.isValidJid()) {
alternate = xmppUri.getJid();
} else {
alternate = null;
}
} else {
alternate = null;
}
mucOptions.setError(MucOptions.Error.DESTROYED);
if (alternate != null) {
Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": muc destroyed. alternate location " + alternate);
}
} else {
final String text = error.findChildContent("text");
if (text != null && text.contains("attribute 'to'")) {
if (mucOptions.online()) {
invokeRenameListener(mucOptions, false);
} else {
mucOptions.setError(MucOptions.Error.INVALID_NICK);
}
} else {
mucOptions.setError(MucOptions.Error.UNKNOWN);
Log.d(Config.LOGTAG, "unknown error in conference: " + packet);
}
}
}
}
}
use of eu.siacs.conversations.utils.XmppUri in project Conversations by siacs.
the class EditAccountActivity method onStart.
@Override
protected void onStart() {
super.onStart();
final Intent intent = getIntent();
final int theme = findTheme();
if (this.mTheme != theme) {
recreate();
} else if (intent != null) {
try {
this.jidToEdit = Jid.ofEscaped(intent.getStringExtra("jid"));
} catch (final IllegalArgumentException | NullPointerException ignored) {
this.jidToEdit = null;
}
final Uri data = intent.getData();
final XmppUri xmppUri = data == null ? null : new XmppUri(data);
final boolean scanned = intent.getBooleanExtra("scanned", false);
if (jidToEdit != null && xmppUri != null && xmppUri.hasFingerprints()) {
if (scanned) {
if (xmppConnectionServiceBound) {
processFingerprintVerification(xmppUri, false);
} else {
this.pendingUri = xmppUri;
}
} else {
displayVerificationWarningDialog(xmppUri);
}
}
boolean init = intent.getBooleanExtra("init", false);
boolean openedFromNotification = intent.getBooleanExtra(EXTRA_OPENED_FROM_NOTIFICATION, false);
Log.d(Config.LOGTAG, "extras " + intent.getExtras());
this.mForceRegister = intent.hasExtra(EXTRA_FORCE_REGISTER) ? intent.getBooleanExtra(EXTRA_FORCE_REGISTER, false) : null;
Log.d(Config.LOGTAG, "force register=" + mForceRegister);
this.mInitMode = init || this.jidToEdit == null;
this.messageFingerprint = intent.getStringExtra("fingerprint");
if (!mInitMode) {
this.binding.accountRegisterNew.setVisibility(View.GONE);
setTitle(getString(R.string.account_details));
configureActionBar(getSupportActionBar(), !openedFromNotification);
} else {
this.binding.avater.setVisibility(View.GONE);
configureActionBar(getSupportActionBar(), !(init && Config.MAGIC_CREATE_DOMAIN == null));
if (mForceRegister != null) {
if (mForceRegister) {
setTitle(R.string.register_new_account);
} else {
setTitle(R.string.add_existing_account);
}
} else {
setTitle(R.string.action_add_account);
}
}
}
SharedPreferences preferences = getPreferences();
mUseTor = QuickConversationsService.isConversations() && preferences.getBoolean("use_tor", getResources().getBoolean(R.bool.use_tor));
this.mShowOptions = mUseTor || (QuickConversationsService.isConversations() && preferences.getBoolean("show_connection_options", getResources().getBoolean(R.bool.show_connection_options)));
this.binding.namePort.setVisibility(mShowOptions ? View.VISIBLE : View.GONE);
if (mForceRegister != null) {
this.binding.accountRegisterNew.setVisibility(View.GONE);
}
}
use of eu.siacs.conversations.utils.XmppUri in project Conversations by siacs.
the class ChooseContactActivity method handleActivityResult.
private void handleActivityResult(ActivityResult activityResult) {
if (activityResult.resultCode == RESULT_OK && activityResult.requestCode == ScanActivity.REQUEST_SCAN_QR_CODE) {
String result = activityResult.data.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT);
XmppUri uri = new XmppUri(Strings.nullToEmpty(result));
if (uri.isValidJid()) {
showEnterJidDialog(uri);
}
}
}
Aggregations