use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.
the class XmppConnectionService method fetchConferenceMembers.
private void fetchConferenceMembers(final Conversation conversation) {
final Account account = conversation.getAccount();
final AxolotlService axolotlService = account.getAxolotlService();
final String[] affiliations = { "member", "admin", "owner" };
OnIqPacketReceived callback = new OnIqPacketReceived() {
private int i = 0;
private boolean success = true;
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
final boolean omemoEnabled = conversation.getNextEncryption() == Message.ENCRYPTION_AXOLOTL;
Element query = packet.query("http://jabber.org/protocol/muc#admin");
if (packet.getType() == IqPacket.TYPE.RESULT && query != null) {
for (Element child : query.getChildren()) {
if ("item".equals(child.getName())) {
MucOptions.User user = AbstractParser.parseItem(conversation, child);
if (!user.realJidMatchesAccount()) {
boolean isNew = conversation.getMucOptions().updateUser(user);
Contact contact = user.getContact();
if (omemoEnabled && isNew && user.getRealJid() != null && (contact == null || !contact.mutualPresenceSubscription()) && axolotlService.hasEmptyDeviceList(user.getRealJid())) {
axolotlService.fetchDeviceIds(user.getRealJid());
}
}
}
}
} else {
success = false;
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": could not request affiliation " + affiliations[i] + " in " + conversation.getJid().asBareJid());
}
++i;
if (i >= affiliations.length) {
List<Jid> members = conversation.getMucOptions().getMembers(true);
if (success) {
List<Jid> cryptoTargets = conversation.getAcceptedCryptoTargets();
boolean changed = false;
for (ListIterator<Jid> iterator = cryptoTargets.listIterator(); iterator.hasNext(); ) {
Jid jid = iterator.next();
if (!members.contains(jid) && !members.contains(jid.getDomain())) {
iterator.remove();
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": removed " + jid + " from crypto targets of " + conversation.getName());
changed = true;
}
}
if (changed) {
conversation.setAcceptedCryptoTargets(cryptoTargets);
updateConversation(conversation);
}
}
getAvatarService().clear(conversation);
updateMucRosterUi();
updateConversationUi();
}
}
};
for (String affiliation : affiliations) {
sendIqPacket(account, mIqGenerator.queryAffiliation(conversation, affiliation), callback);
}
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": fetching members for " + conversation.getName());
}
use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.
the class BlocklistActivity method filterContacts.
@Override
protected void filterContacts(final String needle) {
getListItems().clear();
if (account != null) {
for (final Jid jid : account.getBlocklist()) {
ListItem item;
if (jid.isFullJid()) {
item = new RawBlockable(account, jid);
} else {
item = account.getRoster().getContact(jid);
}
if (item.match(this, needle)) {
getListItems().add(item);
}
}
Collections.sort(getListItems());
}
getListItemAdapter().notifyDataSetChanged();
}
use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.
the class ConversationFragment method trustKeysIfNeeded.
protected boolean trustKeysIfNeeded(int requestCode) {
AxolotlService axolotlService = conversation.getAccount().getAxolotlService();
final List<Jid> targets = axolotlService.getCryptoTargets(conversation);
boolean hasUnaccepted = !conversation.getAcceptedCryptoTargets().containsAll(targets);
boolean hasUndecidedOwn = !axolotlService.getKeysWithTrust(FingerprintStatus.createActiveUndecided()).isEmpty();
boolean hasUndecidedContacts = !axolotlService.getKeysWithTrust(FingerprintStatus.createActiveUndecided(), targets).isEmpty();
boolean hasPendingKeys = !axolotlService.findDevicesWithoutSession(conversation).isEmpty();
boolean hasNoTrustedKeys = axolotlService.anyTargetHasNoTrustedKeys(targets);
boolean downloadInProgress = axolotlService.hasPendingKeyFetches(targets);
if (hasUndecidedOwn || hasUndecidedContacts || hasPendingKeys || hasNoTrustedKeys || hasUnaccepted || downloadInProgress) {
axolotlService.createSessionsIfNeeded(conversation);
Intent intent = new Intent(getActivity(), TrustKeysActivity.class);
String[] contacts = new String[targets.size()];
for (int i = 0; i < contacts.length; ++i) {
contacts[i] = targets.get(i).toString();
}
intent.putExtra("contacts", contacts);
intent.putExtra(EXTRA_ACCOUNT, conversation.getAccount().getJid().asBareJid().toEscapedString());
intent.putExtra("conversation", conversation.getUuid());
startActivityForResult(intent, requestCode);
return true;
} else {
return false;
}
}
use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.
the class XmppConnectionService method requestEasyOnboardingInvite.
public void requestEasyOnboardingInvite(final Account account, final EasyOnboardingInvite.OnInviteRequested callback) {
final XmppConnection connection = account.getXmppConnection();
final Jid jid = connection == null ? null : connection.getJidForCommand(Namespace.EASY_ONBOARDING_INVITE);
if (jid == null) {
callback.inviteRequestFailed(getString(R.string.server_does_not_support_easy_onboarding_invites));
return;
}
final IqPacket request = new IqPacket(IqPacket.TYPE.SET);
request.setTo(jid);
final Element command = request.addChild("command", Namespace.COMMANDS);
command.setAttribute("node", Namespace.EASY_ONBOARDING_INVITE);
command.setAttribute("action", "execute");
sendIqPacket(account, request, (a, response) -> {
if (response.getType() == IqPacket.TYPE.RESULT) {
final Element resultCommand = response.findChild("command", Namespace.COMMANDS);
final Element x = resultCommand == null ? null : resultCommand.findChild("x", Namespace.DATA);
if (x != null) {
final Data data = Data.parse(x);
final String uri = data.getValue("uri");
final String landingUrl = data.getValue("landing-url");
if (uri != null) {
final EasyOnboardingInvite invite = new EasyOnboardingInvite(jid.getDomain().toEscapedString(), uri, landingUrl);
callback.inviteRequested(invite);
return;
}
}
callback.inviteRequestFailed(getString(R.string.unable_to_parse_invite));
Log.d(Config.LOGTAG, response.toString());
} else if (response.getType() == IqPacket.TYPE.ERROR) {
callback.inviteRequestFailed(IqParser.errorMessage(response));
} else {
callback.inviteRequestFailed(getString(R.string.remote_server_timeout));
}
});
}
use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.
the class UIHelper method getMessageDisplayName.
public static String getMessageDisplayName(final Message message) {
final Conversational conversation = message.getConversation();
if (message.getStatus() == Message.STATUS_RECEIVED) {
final Contact contact = message.getContact();
if (conversation.getMode() == Conversation.MODE_MULTI) {
if (contact != null) {
return contact.getDisplayName();
} else {
return getDisplayedMucCounterpart(message.getCounterpart());
}
} else {
return contact != null ? contact.getDisplayName() : "";
}
} else {
if (conversation instanceof Conversation && conversation.getMode() == Conversation.MODE_MULTI) {
return ((Conversation) conversation).getMucOptions().getSelf().getName();
} else {
final Account account = conversation.getAccount();
final Jid jid = account.getJid();
final String displayName = account.getDisplayName();
if (Strings.isNullOrEmpty(displayName)) {
return jid.getLocal() != null ? jid.getLocal() : jid.getDomain().toString();
} else {
return displayName;
}
}
}
}
Aggregations