use of de.pixart.messenger.entities.Contact in project Pix-Art-Messenger by kriztan.
the class StartConversationActivity method filterContacts.
protected void filterContacts(String needle) {
this.contacts.clear();
for (Account account : xmppConnectionService.getAccounts()) {
if (account.getStatus() != Account.State.DISABLED) {
for (Contact contact : account.getRoster().getContacts()) {
Presence.Status s = contact.getShownStatus();
if (contact.showInRoster() && contact.match(this, needle) && (!this.mHideOfflineContacts || (needle != null && !needle.trim().isEmpty()) || s.compareTo(Presence.Status.OFFLINE) < 0)) {
this.contacts.add(contact);
}
}
}
}
Collections.sort(this.contacts);
mContactsAdapter.notifyDataSetChanged();
}
use of de.pixart.messenger.entities.Contact in project Pix-Art-Messenger by kriztan.
the class StartConversationActivity method handleJid.
private boolean handleJid(Invite invite) {
List<Contact> contacts = xmppConnectionService.findContacts(invite.getJid(), invite.account);
if (invite.isAction(XmppUri.ACTION_JOIN)) {
Conversation muc = xmppConnectionService.findFirstMuc(invite.getJid());
if (muc != null) {
switchToConversation(muc, invite.getBody(), false);
return true;
} else {
showJoinConferenceDialog(invite.getJid().toBareJid().toString());
return false;
}
} else if (contacts.size() == 0) {
showCreateContactDialog(invite.getJid().toString(), invite);
return false;
} else if (contacts.size() == 1) {
Contact contact = contacts.get(0);
if (!invite.isSafeSource() && invite.hasFingerprints()) {
displayVerificationWarningDialog(contact, invite);
} else {
if (invite.hasFingerprints()) {
if (xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints())) {
Toast.makeText(this, R.string.verified_fingerprints, Toast.LENGTH_SHORT).show();
}
}
if (invite.account != null) {
xmppConnectionService.getShortcutService().report(contact);
}
switchToConversation(contact, invite.getBody());
}
return true;
} else {
if (mMenuSearchView != null) {
mMenuSearchView.expandActionView();
mSearchEditText.setText("");
mSearchEditText.append(invite.getJid().toString());
filter(invite.getJid().toString());
} else {
mInitialJid = invite.getJid().toString();
}
return true;
}
}
use of de.pixart.messenger.entities.Contact in project Pix-Art-Messenger by kriztan.
the class ConferenceDetailsActivity method onCreateContextMenu.
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
Object tag = v.getTag();
if (tag instanceof User) {
getMenuInflater().inflate(R.menu.muc_details_context, menu);
final User user = (User) tag;
final User self = mConversation.getMucOptions().getSelf();
final Jid jid = user.getFullJid();
this.mSelectedUser = user;
String name;
final Contact contact = user.getContact();
if (contact != null && contact.showInRoster()) {
name = contact.getDisplayName();
} else if (user.getRealJid() != null) {
name = user.getRealJid().toBareJid().toString();
} else {
name = user.getName();
}
menu.setHeaderTitle(name);
MenuItem sendPrivateMessage = menu.findItem(R.id.send_private_message);
MenuItem highlightInMuc = menu.findItem(R.id.highlight_in_muc);
if (user.getRealJid() != null) {
MenuItem startConversation = menu.findItem(R.id.start_conversation);
MenuItem giveMembership = menu.findItem(R.id.give_membership);
MenuItem removeMembership = menu.findItem(R.id.remove_membership);
MenuItem giveAdminPrivileges = menu.findItem(R.id.give_admin_privileges);
MenuItem removeAdminPrivileges = menu.findItem(R.id.remove_admin_privileges);
MenuItem removeFromRoom = menu.findItem(R.id.remove_from_room);
MenuItem banFromConference = menu.findItem(R.id.ban_from_conference);
MenuItem invite = menu.findItem(R.id.invite);
startConversation.setVisible(true);
if (user.getRole() == MucOptions.Role.NONE) {
invite.setVisible(true);
}
if (jid != null && !jid.isBareJid()) {
if (mConversation.getMucOptions().isUserInRoom(jid)) {
sendPrivateMessage.setVisible(true);
} else {
sendPrivateMessage.setVisible(false);
}
}
if (self.getAffiliation().ranks(MucOptions.Affiliation.ADMIN) && self.getAffiliation().outranks(user.getAffiliation())) {
if (mAdvancedMode) {
if (user.getAffiliation() != MucOptions.Affiliation.ADMIN) {
giveAdminPrivileges.setVisible(true);
} else {
removeAdminPrivileges.setVisible(true);
}
} else {
removeFromRoom.setVisible(true);
}
if (user.getAffiliation() == MucOptions.Affiliation.NONE) {
giveMembership.setVisible(true);
} else {
removeMembership.setVisible(true);
}
banFromConference.setVisible(true);
}
} else {
if (jid != null && !jid.isBareJid()) {
if (mConversation.getMucOptions().isUserInRoom(jid)) {
sendPrivateMessage.setVisible(true);
} else {
sendPrivateMessage.setVisible(false);
}
}
highlightInMuc.setVisible(self.getRole().ranks(MucOptions.Role.PARTICIPANT));
}
}
super.onCreateContextMenu(menu, v, menuInfo);
}
use of de.pixart.messenger.entities.Contact in project Pix-Art-Messenger by kriztan.
the class ConversationFragment method sendPgpMessage.
protected void sendPgpMessage(final Message message) {
final XmppConnectionService xmppService = activity.xmppConnectionService;
final Contact contact = message.getConversation().getContact();
if (!activity.hasPgp()) {
activity.showInstallPgpDialog();
return;
}
if (conversation.getAccount().getPgpSignature() == null) {
activity.announcePgp(conversation.getAccount(), conversation, null, activity.onOpenPGPKeyPublished);
return;
}
if (!mSendingPgpMessage.compareAndSet(false, true)) {
Log.d(Config.LOGTAG, "sending pgp message already in progress");
}
if (conversation.getMode() == Conversation.MODE_SINGLE) {
if (contact.getPgpKeyId() != 0) {
xmppService.getPgpEngine().hasKey(contact, new UiCallback<Contact>() {
@Override
public void userInputRequried(PendingIntent pi, Contact contact) {
startPendingIntent(pi, REQUEST_ENCRYPT_MESSAGE);
}
@Override
public void success(Contact contact) {
encryptTextMessage(message);
}
@Override
public void error(int error, Contact contact) {
activity.runOnUiThread(() -> Toast.makeText(activity, R.string.unable_to_connect_to_keychain, Toast.LENGTH_SHORT).show());
mSendingPgpMessage.set(false);
}
});
} else {
showNoPGPKeyDialog(false, (dialog, which) -> {
conversation.setNextEncryption(Message.ENCRYPTION_NONE);
xmppService.updateConversation(conversation);
message.setEncryption(Message.ENCRYPTION_NONE);
xmppService.sendMessage(message);
messageSent();
});
}
} else {
if (conversation.getMucOptions().pgpKeysInUse()) {
if (!conversation.getMucOptions().everybodyHasKeys()) {
Toast warning = Toast.makeText(getActivity(), R.string.missing_public_keys, Toast.LENGTH_LONG);
warning.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
warning.show();
}
encryptTextMessage(message);
} else {
showNoPGPKeyDialog(true, (dialog, which) -> {
conversation.setNextEncryption(Message.ENCRYPTION_NONE);
message.setEncryption(Message.ENCRYPTION_NONE);
xmppService.updateConversation(conversation);
xmppService.sendMessage(message);
messageSent();
});
}
}
}
use of de.pixart.messenger.entities.Contact in project Pix-Art-Messenger by kriztan.
the class ConversationFragment method attachFile.
public void attachFile(final int attachmentChoice) {
if (attachmentChoice == ATTACHMENT_CHOICE_TAKE_FROM_CAMERA) {
if (!hasStorageAndCameraPermission(attachmentChoice)) {
return;
}
} else if (attachmentChoice != ATTACHMENT_CHOICE_LOCATION) {
if (!Config.ONLY_INTERNAL_STORAGE && !hasStoragePermission(attachmentChoice)) {
return;
}
}
if (attachmentChoice == ATTACHMENT_CHOICE_RECORD_VOICE) {
if (!activity.hasMicPermission(attachmentChoice)) {
return;
}
}
if (attachmentChoice == ATTACHMENT_CHOICE_LOCATION) {
if (!activity.hasLocationPermission(attachmentChoice)) {
return;
}
}
try {
activity.getPreferences().edit().putString(RECENTLY_USED_QUICK_ACTION, SendButtonAction.of(attachmentChoice).toString()).apply();
} catch (IllegalArgumentException e) {
// just do not save
}
final int encryption = conversation.getNextEncryption();
final int mode = conversation.getMode();
if (encryption == Message.ENCRYPTION_PGP) {
if (activity.hasPgp()) {
if (mode == Conversation.MODE_SINGLE && conversation.getContact().getPgpKeyId() != 0) {
activity.xmppConnectionService.getPgpEngine().hasKey(conversation.getContact(), new UiCallback<Contact>() {
@Override
public void userInputRequried(PendingIntent pi, Contact contact) {
startPendingIntent(pi, attachmentChoice);
}
@Override
public void success(Contact contact) {
selectPresenceToAttachFile(attachmentChoice);
}
@Override
public void error(int error, Contact contact) {
activity.replaceToast(getString(error));
}
});
} else if (mode == Conversation.MODE_MULTI && conversation.getMucOptions().pgpKeysInUse()) {
if (!conversation.getMucOptions().everybodyHasKeys()) {
getActivity().runOnUiThread(() -> {
Toast warning = Toast.makeText(activity, R.string.missing_public_keys, Toast.LENGTH_LONG);
warning.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
warning.show();
});
}
selectPresenceToAttachFile(attachmentChoice);
} else {
final ConversationFragment fragment = (ConversationFragment) getFragmentManager().findFragmentByTag("conversation");
if (fragment != null) {
fragment.showNoPGPKeyDialog(false, (dialog, which) -> {
conversation.setNextEncryption(Message.ENCRYPTION_NONE);
activity.xmppConnectionService.updateConversation(conversation);
selectPresenceToAttachFile(attachmentChoice);
});
}
}
} else {
activity.showInstallPgpDialog();
}
} else {
if (encryption != Message.ENCRYPTION_AXOLOTL || !trustKeysIfNeeded(REQUEST_TRUST_KEYS_MENU, attachmentChoice)) {
selectPresenceToAttachFile(attachmentChoice);
}
}
}
Aggregations