use of eu.siacs.conversations.entities.Contact in project Conversations by siacs.
the class DatabaseBackend method writeRoster.
public void writeRoster(final Roster roster) {
final Account account = roster.getAccount();
final SQLiteDatabase db = this.getWritableDatabase();
db.beginTransaction();
for (Contact contact : roster.getContacts()) {
if (contact.getOption(Contact.Options.IN_ROSTER)) {
db.insert(Contact.TABLENAME, null, contact.getContentValues());
} else {
String where = Contact.ACCOUNT + "=? AND " + Contact.JID + "=?";
String[] whereArgs = { account.getUuid(), contact.getJid().toPreppedString() };
db.delete(Contact.TABLENAME, where, whereArgs);
}
}
db.setTransactionSuccessful();
db.endTransaction();
account.setRosterVersion(roster.getVersion());
updateAccount(account);
}
use of eu.siacs.conversations.entities.Contact in project Conversations by siacs.
the class StartConversationActivity method handleJid.
private boolean handleJid(Invite invite) {
Account account = xmppConnectionService.findAccountByJid(invite.getJid());
if (account != null && !account.isOptionSet(Account.OPTION_DISABLED)) {
if (invite.hasFingerprints() && xmppConnectionService.verifyFingerprints(account, invite.getFingerprints())) {
Toast.makeText(this, R.string.verified_fingerprints, Toast.LENGTH_SHORT).show();
}
switchToAccount(account);
finish();
return true;
}
List<Contact> contacts = xmppConnectionService.findContacts(invite.getJid());
if (invite.isMuc()) {
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();
}
}
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 eu.siacs.conversations.entities.Contact in project Conversations by siacs.
the class XmppActivity method showAddToRosterDialog.
protected void showAddToRosterDialog(final Contact contact) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(contact.getJid().toString());
builder.setMessage(getString(R.string.not_in_roster));
builder.setNegativeButton(getString(R.string.cancel), null);
builder.setPositiveButton(getString(R.string.add_contact), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final Jid jid = contact.getJid();
Account account = contact.getAccount();
Contact contact = account.getRoster().getContact(jid);
xmppConnectionService.createContact(contact);
}
});
builder.create().show();
}
use of eu.siacs.conversations.entities.Contact in project Conversations by siacs.
the class GeoHelper method createGeoIntentsFromMessage.
public static ArrayList<Intent> createGeoIntentsFromMessage(Message message) {
final ArrayList<Intent> intents = new ArrayList<>();
Matcher matcher = GEO_URI.matcher(message.getBody());
if (!matcher.matches()) {
return intents;
}
double latitude;
double longitude;
try {
latitude = Double.parseDouble(matcher.group(1));
if (latitude > 90.0 || latitude < -90.0) {
return intents;
}
longitude = Double.parseDouble(matcher.group(2));
if (longitude > 180.0 || longitude < -180.0) {
return intents;
}
} catch (NumberFormatException nfe) {
return intents;
}
final Conversation conversation = message.getConversation();
String label;
if (conversation.getMode() == Conversation.MODE_SINGLE && message.getStatus() == Message.STATUS_RECEIVED) {
try {
label = "(" + URLEncoder.encode(message.getConversation().getName(), "UTF-8") + ")";
} catch (UnsupportedEncodingException e) {
label = "";
}
} else {
label = "";
}
Intent locationPluginIntent = new Intent("eu.siacs.conversations.location.show");
locationPluginIntent.putExtra("latitude", latitude);
locationPluginIntent.putExtra("longitude", longitude);
if (message.getStatus() != Message.STATUS_RECEIVED) {
locationPluginIntent.putExtra("jid", conversation.getAccount().getJid().toString());
locationPluginIntent.putExtra("name", conversation.getAccount().getJid().getLocalpart());
} else {
Contact contact = message.getContact();
if (contact != null) {
locationPluginIntent.putExtra("name", contact.getDisplayName());
locationPluginIntent.putExtra("jid", contact.getJid().toString());
} else {
locationPluginIntent.putExtra("name", UIHelper.getDisplayedMucCounterpart(message.getCounterpart()));
}
}
intents.add(locationPluginIntent);
Intent geoIntent = new Intent(Intent.ACTION_VIEW);
geoIntent.setData(Uri.parse("geo:" + String.valueOf(latitude) + "," + String.valueOf(longitude) + "?q=" + String.valueOf(latitude) + "," + String.valueOf(longitude) + label));
intents.add(geoIntent);
Intent httpIntent = new Intent(Intent.ACTION_VIEW);
httpIntent.setData(Uri.parse("https://maps.google.com/maps?q=loc:" + String.valueOf(latitude) + "," + String.valueOf(longitude) + label));
intents.add(httpIntent);
return intents;
}
use of eu.siacs.conversations.entities.Contact in project Conversations by siacs.
the class StartConversationActivity method openConversationForContact.
protected void openConversationForContact(int position) {
Contact contact = (Contact) contacts.get(position);
openConversationForContact(contact);
}
Aggregations