Search in sources :

Example 6 with Contact

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);
}
Also used : Account(eu.siacs.conversations.entities.Account) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Contact(eu.siacs.conversations.entities.Contact)

Example 7 with Contact

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;
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) Conversation(eu.siacs.conversations.entities.Conversation) Contact(eu.siacs.conversations.entities.Contact)

Example 8 with Contact

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();
}
Also used : AlertDialog(android.app.AlertDialog) OnClickListener(android.content.DialogInterface.OnClickListener) Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.jid.Jid) DialogInterface(android.content.DialogInterface) Builder(android.app.AlertDialog.Builder) Builder(android.app.AlertDialog.Builder) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) Contact(eu.siacs.conversations.entities.Contact)

Example 9 with Contact

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;
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Intent(android.content.Intent) Conversation(eu.siacs.conversations.entities.Conversation) Contact(eu.siacs.conversations.entities.Contact)

Example 10 with Contact

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);
}
Also used : Contact(eu.siacs.conversations.entities.Contact)

Aggregations

Contact (eu.siacs.conversations.entities.Contact)32 Account (eu.siacs.conversations.entities.Account)9 Jid (eu.siacs.conversations.xmpp.jid.Jid)9 Conversation (eu.siacs.conversations.entities.Conversation)8 Element (eu.siacs.conversations.xml.Element)7 SuppressLint (android.annotation.SuppressLint)5 DialogInterface (android.content.DialogInterface)5 OnClickListener (android.content.DialogInterface.OnClickListener)4 AlertDialog (android.app.AlertDialog)3 Message (eu.siacs.conversations.entities.Message)3 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)3 Builder (android.app.AlertDialog.Builder)2 PendingIntent (android.app.PendingIntent)2 Intent (android.content.Intent)2 Point (android.graphics.Point)2 Uri (android.net.Uri)2 MenuItem (android.view.MenuItem)2 View (android.view.View)2 Toast (android.widget.Toast)2 AxolotlService (eu.siacs.conversations.crypto.axolotl.AxolotlService)2