use of de.pixart.messenger.entities.Contact in project Pix-Art-Messenger by kriztan.
the class ChooseContactActivity method onCreate.
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
filterContacts = new HashSet<>();
String[] contacts = getIntent().getStringArrayExtra("filter_contacts");
if (contacts != null) {
Collections.addAll(filterContacts, contacts);
}
if (getIntent().getBooleanExtra("multiple", false)) {
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
getListView().setMultiChoiceModeListener(new MultiChoiceModeListener() {
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getSearchEditText().getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.select_multiple, menu);
selected = new HashSet<>();
return true;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
switch(item.getItemId()) {
case R.id.selection_submit:
final Intent request = getIntent();
final Intent data = new Intent();
data.putExtra("conversation", request.getStringExtra("conversation"));
String[] selection = getSelectedContactJids();
data.putExtra("contacts", selection);
data.putExtra("multiple", true);
data.putExtra(EXTRA_ACCOUNT, request.getStringExtra(EXTRA_ACCOUNT));
data.putExtra("subject", request.getStringExtra("subject"));
setResult(RESULT_OK, data);
finish();
return true;
}
return false;
}
@Override
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
Contact item = (Contact) getListItems().get(position);
if (checked) {
selected.add(item);
} else {
selected.remove(item);
}
int numSelected = selected.size();
MenuItem selectButton = mode.getMenu().findItem(R.id.selection_submit);
String buttonText = getResources().getQuantityString(R.plurals.select_contact, numSelected, numSelected);
selectButton.setTitle(buttonText);
}
});
}
getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getSearchEditText().getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
final Intent request = getIntent();
final Intent data = new Intent();
final ListItem mListItem = getListItems().get(position);
data.putExtra("contact", mListItem.getJid().toString());
String account = request.getStringExtra(EXTRA_ACCOUNT);
if (account == null && mListItem instanceof Contact) {
account = ((Contact) mListItem).getAccount().getJid().toBareJid().toString();
}
data.putExtra(EXTRA_ACCOUNT, account);
data.putExtra("conversation", request.getStringExtra("conversation"));
data.putExtra("multiple", false);
data.putExtra("subject", request.getStringExtra("subject"));
setResult(RESULT_OK, data);
finish();
}
});
}
use of de.pixart.messenger.entities.Contact in project Pix-Art-Messenger by kriztan.
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", "http://jabber.org/protocol/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(item.getAttributeAsJid("jid")))) {
if (mucOptions.setOnline()) {
mXmppConnectionService.getAvatarService().clear(mucOptions);
}
mucOptions.setSelf(user);
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().toBareJid() + ": room '" + mucOptions.getConversation().getJid().toBareJid() + "' created. pushing default configuration");
mXmppConnectionService.pushConferenceConfiguration(mucOptions.getConversation(), IqGenerator.defaultRoomConfiguration(), 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);
}
} else if (mXmppConnectionService.isDataSaverDisabled()) {
mXmppConnectionService.fetchAvatar(mucOptions.getAccount(), avatar);
}
}
}
}
} else if (type.equals("unavailable")) {
if (codes.contains(MucOptions.STATUS_CODE_SHUTDOWN) && from.equals(mucOptions.getSelf().getFullJid())) {
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 {
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 de.pixart.messenger.entities.Contact in project Pix-Art-Messenger by kriztan.
the class AvatarService method get.
public Bitmap get(Message message, int size, boolean cachedOnly) {
final Conversation conversation = message.getConversation();
if (message.getType() == Message.TYPE_STATUS && message.getCounterparts() != null && message.getCounterparts().size() > 1) {
return get(message.getCounterparts(), size, cachedOnly);
} else if (message.getStatus() == Message.STATUS_RECEIVED) {
Contact c = message.getContact();
if (c != null && (c.getProfilePhoto() != null || c.getAvatar() != null)) {
return get(c, size, cachedOnly);
} else if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
final Jid trueCounterpart = message.getTrueCounterpart();
MucOptions.User user;
if (trueCounterpart != null) {
user = conversation.getMucOptions().findUserByRealJid(trueCounterpart);
} else {
user = conversation.getMucOptions().findUserByFullJid(message.getCounterpart());
}
if (user != null) {
return getImpl(user, size, cachedOnly);
}
} else if (c != null) {
return get(c, size, cachedOnly);
}
Jid tcp = message.getTrueCounterpart();
String seed = tcp != null ? tcp.toBareJid().toString() : null;
return get(UIHelper.getMessageDisplayName(message), seed, size, cachedOnly);
} else {
return get(conversation.getAccount(), size, cachedOnly);
}
}
use of de.pixart.messenger.entities.Contact in project Pix-Art-Messenger by kriztan.
the class AvatarService method getImpl.
private Bitmap getImpl(final MucOptions.User user, final int size, boolean cachedOnly) {
final String KEY = key(user, size);
Bitmap avatar = this.mXmppConnectionService.getBitmapCache().get(KEY);
if (avatar != null || cachedOnly) {
return avatar;
}
if (user.getAvatar() != null) {
avatar = mXmppConnectionService.getFileBackend().getAvatar(user.getAvatar(), size);
}
if (avatar == null) {
Contact contact = user.getContact();
if (contact != null) {
avatar = get(contact, size, cachedOnly);
} else {
String seed = user.getRealJid() != null ? user.getRealJid().toBareJid().toString() : null;
avatar = get(user.getName(), seed, size, cachedOnly);
}
}
this.mXmppConnectionService.getBitmapCache().put(KEY, avatar);
return avatar;
}
use of de.pixart.messenger.entities.Contact in project Pix-Art-Messenger by kriztan.
the class VerifyOTRActivity method verifyWithUri.
protected boolean verifyWithUri(XmppUri uri) {
Contact contact = mConversation.getContact();
if (this.mConversation.getContact().getJid().equals(uri.getJid()) && uri.hasFingerprints()) {
xmppConnectionService.verifyFingerprints(contact, uri.getFingerprints());
Toast.makeText(this, R.string.verified, Toast.LENGTH_SHORT).show();
updateView();
return true;
} else {
Toast.makeText(this, R.string.could_not_verify_fingerprint, Toast.LENGTH_SHORT).show();
return false;
}
}
Aggregations