use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.
the class SmsDatabase method insertMessageOutbox.
@Override
public long insertMessageOutbox(long threadId, OutgoingTextMessage message, boolean forceSms, long date, InsertListener insertListener) {
SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
long type = Types.BASE_SENDING_TYPE;
if (message.isKeyExchange())
type |= Types.KEY_EXCHANGE_BIT;
else if (message.isSecureMessage())
type |= (Types.SECURE_MESSAGE_BIT | Types.PUSH_MESSAGE_BIT);
else if (message.isEndSession())
type |= Types.END_SESSION_BIT;
if (forceSms)
type |= Types.MESSAGE_FORCE_SMS_BIT;
if (message.isIdentityVerified())
type |= Types.KEY_EXCHANGE_IDENTITY_VERIFIED_BIT;
else if (message.isIdentityDefault())
type |= Types.KEY_EXCHANGE_IDENTITY_DEFAULT_BIT;
RecipientId recipientId = message.getRecipient().getId();
Map<RecipientId, EarlyReceiptCache.Receipt> earlyDeliveryReceipts = earlyDeliveryReceiptCache.remove(date);
ContentValues contentValues = new ContentValues(6);
contentValues.put(RECIPIENT_ID, recipientId.serialize());
contentValues.put(THREAD_ID, threadId);
contentValues.put(BODY, message.getMessageBody());
contentValues.put(DATE_RECEIVED, System.currentTimeMillis());
contentValues.put(DATE_SENT, date);
contentValues.put(READ, 1);
contentValues.put(TYPE, type);
contentValues.put(SUBSCRIPTION_ID, message.getSubscriptionId());
contentValues.put(EXPIRES_IN, message.getExpiresIn());
contentValues.put(DELIVERY_RECEIPT_COUNT, Stream.of(earlyDeliveryReceipts.values()).mapToLong(EarlyReceiptCache.Receipt::getCount).sum());
contentValues.put(RECEIPT_TIMESTAMP, Stream.of(earlyDeliveryReceipts.values()).mapToLong(EarlyReceiptCache.Receipt::getTimestamp).max().orElse(-1));
long messageId = db.insert(TABLE_NAME, null, contentValues);
if (insertListener != null) {
insertListener.onComplete();
}
if (!message.isIdentityVerified() && !message.isIdentityDefault()) {
SignalDatabase.threads().setLastScrolled(threadId, 0);
SignalDatabase.threads().setLastSeenSilently(threadId);
}
SignalDatabase.threads().setHasSentSilently(threadId, true);
ApplicationDependencies.getDatabaseObserver().notifyMessageInsertObservers(threadId, new MessageId(messageId, false));
if (!message.isIdentityVerified() && !message.isIdentityDefault()) {
TrimThreadJob.enqueueAsync(threadId);
}
return messageId;
}
use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.
the class ThreadDatabase method deleteConversation.
public void deleteConversation(long threadId) {
SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
RecipientId recipientIdForThreadId = getRecipientIdForThreadId(threadId);
db.beginTransaction();
try {
SignalDatabase.sms().deleteThread(threadId);
SignalDatabase.mms().deleteThread(threadId);
SignalDatabase.drafts().clearDrafts(threadId);
db.delete(TABLE_NAME, ID_WHERE, new String[] { threadId + "" });
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
notifyConversationListListeners();
notifyConversationListeners(threadId);
ConversationUtil.clearShortcuts(context, Collections.singleton(recipientIdForThreadId));
}
use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.
the class ThreadDatabase method getAllThreadRecipients.
@NonNull
public Set<RecipientId> getAllThreadRecipients() {
SQLiteDatabase db = databaseHelper.getSignalReadableDatabase();
Set<RecipientId> ids = new HashSet<>();
try (Cursor cursor = db.query(TABLE_NAME, new String[] { RECIPIENT_ID }, null, null, null, null, null)) {
while (cursor.moveToNext()) {
ids.add(RecipientId.from(CursorUtil.requireString(cursor, RECIPIENT_ID)));
}
}
return ids;
}
use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.
the class ThreadDatabase method getExtrasFor.
@Nullable
private Extra getExtrasFor(@NonNull MessageRecord record) {
Recipient threadRecipient = record.isOutgoing() ? record.getRecipient() : getRecipientForThreadId(record.getThreadId());
boolean messageRequestAccepted = RecipientUtil.isMessageRequestAccepted(context, record.getThreadId(), threadRecipient);
RecipientId individualRecipientId = record.getIndividualRecipient().getId();
// noinspection ConstantConditions
if (!messageRequestAccepted && threadRecipient != null) {
if (threadRecipient.isPushGroup()) {
if (threadRecipient.isPushV2Group()) {
MessageRecord.InviteAddState inviteAddState = record.getGv2AddInviteState();
if (inviteAddState != null) {
RecipientId from = RecipientId.from(ACI.from(inviteAddState.getAddedOrInvitedBy()), null);
if (inviteAddState.isInvited()) {
Log.i(TAG, "GV2 invite message request from " + from);
return Extra.forGroupV2invite(from, individualRecipientId);
} else {
Log.i(TAG, "GV2 message request from " + from);
return Extra.forGroupMessageRequest(from, individualRecipientId);
}
}
Log.w(TAG, "Falling back to unknown message request state for GV2 message");
return Extra.forMessageRequest(individualRecipientId);
} else {
RecipientId recipientId = SignalDatabase.mmsSms().getGroupAddedBy(record.getThreadId());
if (recipientId != null) {
return Extra.forGroupMessageRequest(recipientId, individualRecipientId);
}
}
}
return Extra.forMessageRequest(individualRecipientId);
}
if (record.isRemoteDelete()) {
return Extra.forRemoteDelete(individualRecipientId);
} else if (record.isViewOnce()) {
return Extra.forViewOnce(individualRecipientId);
} else if (record.isMms() && ((MmsMessageRecord) record).getSlideDeck().getStickerSlide() != null) {
StickerSlide slide = Objects.requireNonNull(((MmsMessageRecord) record).getSlideDeck().getStickerSlide());
return Extra.forSticker(slide.getEmoji(), individualRecipientId);
} else if (record.isMms() && ((MmsMessageRecord) record).getSlideDeck().getSlides().size() > 1) {
return Extra.forAlbum(individualRecipientId);
}
if (threadRecipient != null && threadRecipient.isGroup()) {
return Extra.forDefault(individualRecipientId);
}
return null;
}
use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.
the class ThreadDatabase method setForcedUnread.
public void setForcedUnread(@NonNull Collection<Long> threadIds) {
SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
List<RecipientId> recipientIds = Collections.emptyList();
db.beginTransaction();
try {
SqlUtil.Query query = SqlUtil.buildCollectionQuery(ID, threadIds);
ContentValues contentValues = new ContentValues();
contentValues.put(READ, ReadStatus.FORCED_UNREAD.serialize());
db.update(TABLE_NAME, contentValues, query.getWhere(), query.getWhereArgs());
recipientIds = getRecipientIdsForThreadIds(threadIds);
SignalDatabase.recipients().markNeedsSyncWithoutRefresh(recipientIds);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
for (RecipientId id : recipientIds) {
Recipient.live(id).refresh();
}
StorageSyncHelper.scheduleSyncForDataChange();
notifyConversationListListeners();
}
}
Aggregations