Search in sources :

Example 1 with IncomingIdentityVerifiedMessage

use of org.thoughtcrime.securesms.sms.IncomingIdentityVerifiedMessage in project Signal-Android by signalapp.

the class IdentityUtil method markIdentityVerified.

public static void markIdentityVerified(Context context, Recipient recipient, boolean verified, boolean remote) {
    long time = System.currentTimeMillis();
    MessageDatabase smsDatabase = SignalDatabase.sms();
    GroupDatabase groupDatabase = SignalDatabase.groups();
    try (GroupDatabase.Reader reader = groupDatabase.getGroups()) {
        GroupDatabase.GroupRecord groupRecord;
        while ((groupRecord = reader.getNext()) != null) {
            if (groupRecord.getMembers().contains(recipient.getId()) && groupRecord.isActive() && !groupRecord.isMms()) {
                if (remote) {
                    IncomingTextMessage incoming = new IncomingTextMessage(recipient.getId(), 1, time, -1, time, null, Optional.of(groupRecord.getId()), 0, false, null);
                    if (verified)
                        incoming = new IncomingIdentityVerifiedMessage(incoming);
                    else
                        incoming = new IncomingIdentityDefaultMessage(incoming);
                    smsDatabase.insertMessageInbox(incoming);
                } else {
                    RecipientId recipientId = SignalDatabase.recipients().getOrInsertFromGroupId(groupRecord.getId());
                    Recipient groupRecipient = Recipient.resolved(recipientId);
                    long threadId = SignalDatabase.threads().getOrCreateThreadIdFor(groupRecipient);
                    OutgoingTextMessage outgoing;
                    if (verified)
                        outgoing = new OutgoingIdentityVerifiedMessage(recipient);
                    else
                        outgoing = new OutgoingIdentityDefaultMessage(recipient);
                    SignalDatabase.sms().insertMessageOutbox(threadId, outgoing, false, time, null);
                    SignalDatabase.threads().update(threadId, true);
                }
            }
        }
    }
    if (remote) {
        IncomingTextMessage incoming = new IncomingTextMessage(recipient.getId(), 1, time, -1, time, null, Optional.absent(), 0, false, null);
        if (verified)
            incoming = new IncomingIdentityVerifiedMessage(incoming);
        else
            incoming = new IncomingIdentityDefaultMessage(incoming);
        smsDatabase.insertMessageInbox(incoming);
    } else {
        OutgoingTextMessage outgoing;
        if (verified)
            outgoing = new OutgoingIdentityVerifiedMessage(recipient);
        else
            outgoing = new OutgoingIdentityDefaultMessage(recipient);
        long threadId = SignalDatabase.threads().getOrCreateThreadIdFor(recipient);
        Log.i(TAG, "Inserting verified outbox...");
        SignalDatabase.sms().insertMessageOutbox(threadId, outgoing, false, time, null);
        SignalDatabase.threads().update(threadId, true);
    }
}
Also used : OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) OutgoingIdentityVerifiedMessage(org.thoughtcrime.securesms.sms.OutgoingIdentityVerifiedMessage) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) IncomingIdentityVerifiedMessage(org.thoughtcrime.securesms.sms.IncomingIdentityVerifiedMessage) OutgoingIdentityDefaultMessage(org.thoughtcrime.securesms.sms.OutgoingIdentityDefaultMessage) Recipient(org.thoughtcrime.securesms.recipients.Recipient) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) IncomingIdentityDefaultMessage(org.thoughtcrime.securesms.sms.IncomingIdentityDefaultMessage)

Example 2 with IncomingIdentityVerifiedMessage

use of org.thoughtcrime.securesms.sms.IncomingIdentityVerifiedMessage in project Signal-Android by WhisperSystems.

the class IdentityUtil method markIdentityVerified.

public static void markIdentityVerified(Context context, Recipient recipient, boolean verified, boolean remote) {
    long time = System.currentTimeMillis();
    MessageDatabase smsDatabase = SignalDatabase.sms();
    GroupDatabase groupDatabase = SignalDatabase.groups();
    try (GroupDatabase.Reader reader = groupDatabase.getGroups()) {
        GroupDatabase.GroupRecord groupRecord;
        while ((groupRecord = reader.getNext()) != null) {
            if (groupRecord.getMembers().contains(recipient.getId()) && groupRecord.isActive() && !groupRecord.isMms()) {
                if (remote) {
                    IncomingTextMessage incoming = new IncomingTextMessage(recipient.getId(), 1, time, -1, time, null, Optional.of(groupRecord.getId()), 0, false, null);
                    if (verified)
                        incoming = new IncomingIdentityVerifiedMessage(incoming);
                    else
                        incoming = new IncomingIdentityDefaultMessage(incoming);
                    smsDatabase.insertMessageInbox(incoming);
                } else {
                    RecipientId recipientId = SignalDatabase.recipients().getOrInsertFromGroupId(groupRecord.getId());
                    Recipient groupRecipient = Recipient.resolved(recipientId);
                    long threadId = SignalDatabase.threads().getOrCreateThreadIdFor(groupRecipient);
                    OutgoingTextMessage outgoing;
                    if (verified)
                        outgoing = new OutgoingIdentityVerifiedMessage(recipient);
                    else
                        outgoing = new OutgoingIdentityDefaultMessage(recipient);
                    SignalDatabase.sms().insertMessageOutbox(threadId, outgoing, false, time, null);
                    SignalDatabase.threads().update(threadId, true);
                }
            }
        }
    }
    if (remote) {
        IncomingTextMessage incoming = new IncomingTextMessage(recipient.getId(), 1, time, -1, time, null, Optional.absent(), 0, false, null);
        if (verified)
            incoming = new IncomingIdentityVerifiedMessage(incoming);
        else
            incoming = new IncomingIdentityDefaultMessage(incoming);
        smsDatabase.insertMessageInbox(incoming);
    } else {
        OutgoingTextMessage outgoing;
        if (verified)
            outgoing = new OutgoingIdentityVerifiedMessage(recipient);
        else
            outgoing = new OutgoingIdentityDefaultMessage(recipient);
        long threadId = SignalDatabase.threads().getOrCreateThreadIdFor(recipient);
        Log.i(TAG, "Inserting verified outbox...");
        SignalDatabase.sms().insertMessageOutbox(threadId, outgoing, false, time, null);
        SignalDatabase.threads().update(threadId, true);
    }
}
Also used : OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) OutgoingIdentityVerifiedMessage(org.thoughtcrime.securesms.sms.OutgoingIdentityVerifiedMessage) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) IncomingIdentityVerifiedMessage(org.thoughtcrime.securesms.sms.IncomingIdentityVerifiedMessage) OutgoingIdentityDefaultMessage(org.thoughtcrime.securesms.sms.OutgoingIdentityDefaultMessage) Recipient(org.thoughtcrime.securesms.recipients.Recipient) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) IncomingIdentityDefaultMessage(org.thoughtcrime.securesms.sms.IncomingIdentityDefaultMessage)

Aggregations

GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)2 MessageDatabase (org.thoughtcrime.securesms.database.MessageDatabase)2 Recipient (org.thoughtcrime.securesms.recipients.Recipient)2 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)2 IncomingIdentityDefaultMessage (org.thoughtcrime.securesms.sms.IncomingIdentityDefaultMessage)2 IncomingIdentityVerifiedMessage (org.thoughtcrime.securesms.sms.IncomingIdentityVerifiedMessage)2 IncomingTextMessage (org.thoughtcrime.securesms.sms.IncomingTextMessage)2 OutgoingIdentityDefaultMessage (org.thoughtcrime.securesms.sms.OutgoingIdentityDefaultMessage)2 OutgoingIdentityVerifiedMessage (org.thoughtcrime.securesms.sms.OutgoingIdentityVerifiedMessage)2 OutgoingTextMessage (org.thoughtcrime.securesms.sms.OutgoingTextMessage)2