use of org.thoughtcrime.securesms.sms.IncomingIdentityDefaultMessage 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);
}
}
use of org.thoughtcrime.securesms.sms.IncomingIdentityDefaultMessage 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);
}
}
Aggregations