Search in sources :

Example 6 with GroupCallUpdateDetails

use of org.thoughtcrime.securesms.database.model.databaseprotos.GroupCallUpdateDetails in project Signal-Android by signalapp.

the class SmsDatabase method updatePreviousGroupCall.

@Override
public boolean updatePreviousGroupCall(long threadId, @Nullable String peekGroupCallEraId, @NonNull Collection<UUID> peekJoinedUuids, boolean isCallFull) {
    SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
    String where = TYPE + " = ? AND " + THREAD_ID + " = ?";
    String[] args = SqlUtil.buildArgs(Types.GROUP_CALL_TYPE, threadId);
    boolean sameEraId = false;
    try (Reader reader = new Reader(db.query(TABLE_NAME, MESSAGE_PROJECTION, where, args, null, null, DATE_RECEIVED + " DESC", "1"))) {
        MessageRecord record = reader.getNext();
        if (record == null) {
            return false;
        }
        GroupCallUpdateDetails groupCallUpdateDetails = GroupCallUpdateDetailsUtil.parse(record.getBody());
        boolean containsSelf = peekJoinedUuids.contains(Recipient.self().requireServiceId().uuid());
        sameEraId = groupCallUpdateDetails.getEraId().equals(peekGroupCallEraId) && !Util.isEmpty(peekGroupCallEraId);
        List<String> inCallUuids = sameEraId ? Stream.of(peekJoinedUuids).map(UUID::toString).toList() : Collections.emptyList();
        String body = GroupCallUpdateDetailsUtil.createUpdatedBody(groupCallUpdateDetails, inCallUuids, isCallFull);
        ContentValues contentValues = new ContentValues();
        contentValues.put(BODY, body);
        if (sameEraId && containsSelf) {
            contentValues.put(READ, 1);
        }
        SqlUtil.Query query = SqlUtil.buildTrueUpdateQuery(ID_WHERE, SqlUtil.buildArgs(record.getId()), contentValues);
        boolean updated = db.update(TABLE_NAME, contentValues, query.getWhere(), query.getWhereArgs()) > 0;
        if (updated) {
            notifyConversationListeners(threadId);
        }
    }
    return sameEraId;
}
Also used : ContentValues(android.content.ContentValues) SqlUtil(org.thoughtcrime.securesms.util.SqlUtil) GroupCallUpdateDetails(org.thoughtcrime.securesms.database.model.databaseprotos.GroupCallUpdateDetails) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) UUID(java.util.UUID)

Aggregations

GroupCallUpdateDetails (org.thoughtcrime.securesms.database.model.databaseprotos.GroupCallUpdateDetails)6 ContentValues (android.content.ContentValues)4 MessageRecord (org.thoughtcrime.securesms.database.model.MessageRecord)4 SmsMessageRecord (org.thoughtcrime.securesms.database.model.SmsMessageRecord)4 NonNull (androidx.annotation.NonNull)2 UUID (java.util.UUID)2 Recipient (org.thoughtcrime.securesms.recipients.Recipient)2 SqlUtil (org.thoughtcrime.securesms.util.SqlUtil)2 ServiceId (org.whispersystems.signalservice.api.push.ServiceId)2