Search in sources :

Example 1 with GroupCallUpdateDetails

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

the class MessageRecord method getGroupCallUpdateDescription.

@NonNull
public static UpdateDescription getGroupCallUpdateDescription(@NonNull Context context, @NonNull String body, boolean withTime) {
    GroupCallUpdateDetails groupCallUpdateDetails = GroupCallUpdateDetailsUtil.parse(body);
    List<ServiceId> joinedMembers = Stream.of(groupCallUpdateDetails.getInCallUuidsList()).map(UuidUtil::parseOrNull).withoutNulls().map(ServiceId::from).toList();
    UpdateDescription.StringFactory stringFactory = new GroupCallUpdateMessageFactory(context, joinedMembers, withTime, groupCallUpdateDetails);
    return UpdateDescription.mentioning(joinedMembers, stringFactory, R.drawable.ic_video_16);
}
Also used : GroupCallUpdateDetails(org.thoughtcrime.securesms.database.model.databaseprotos.GroupCallUpdateDetails) ServiceId(org.whispersystems.signalservice.api.push.ServiceId) NonNull(androidx.annotation.NonNull)

Example 2 with GroupCallUpdateDetails

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

the class SmsDatabase method insertOrUpdateGroupCall.

@Override
public void insertOrUpdateGroupCall(@NonNull RecipientId groupRecipientId, @NonNull RecipientId sender, long timestamp, @Nullable String messageGroupCallEraId) {
    SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
    long threadId;
    try {
        db.beginTransaction();
        Recipient recipient = Recipient.resolved(groupRecipientId);
        threadId = SignalDatabase.threads().getOrCreateThreadIdFor(recipient);
        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) {
                GroupCallUpdateDetails groupCallUpdateDetails = GroupCallUpdateDetailsUtil.parse(record.getBody());
                sameEraId = groupCallUpdateDetails.getEraId().equals(messageGroupCallEraId) && !Util.isEmpty(messageGroupCallEraId);
                if (!sameEraId) {
                    String body = GroupCallUpdateDetailsUtil.createUpdatedBody(groupCallUpdateDetails, Collections.emptyList(), false);
                    ContentValues contentValues = new ContentValues();
                    contentValues.put(BODY, body);
                    db.update(TABLE_NAME, contentValues, ID_WHERE, SqlUtil.buildArgs(record.getId()));
                }
            }
        }
        if (!sameEraId && !Util.isEmpty(messageGroupCallEraId)) {
            byte[] updateDetails = GroupCallUpdateDetails.newBuilder().setEraId(Util.emptyIfNull(messageGroupCallEraId)).setStartedCallUuid(Recipient.resolved(sender).requireServiceId().toString()).setStartedCallTimestamp(timestamp).addAllInCallUuids(Collections.emptyList()).setIsCallFull(false).build().toByteArray();
            String body = Base64.encodeBytes(updateDetails);
            ContentValues values = new ContentValues();
            values.put(RECIPIENT_ID, sender.serialize());
            values.put(ADDRESS_DEVICE_ID, 1);
            values.put(DATE_RECEIVED, timestamp);
            values.put(DATE_SENT, timestamp);
            values.put(READ, 0);
            values.put(BODY, body);
            values.put(TYPE, Types.GROUP_CALL_TYPE);
            values.put(THREAD_ID, threadId);
            db.insert(TABLE_NAME, null, values);
            SignalDatabase.threads().incrementUnread(threadId, 1);
        }
        SignalDatabase.threads().update(threadId, true);
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
    notifyConversationListeners(threadId);
    TrimThreadJob.enqueueAsync(threadId);
}
Also used : ContentValues(android.content.ContentValues) GroupCallUpdateDetails(org.thoughtcrime.securesms.database.model.databaseprotos.GroupCallUpdateDetails) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) Recipient(org.thoughtcrime.securesms.recipients.Recipient)

Example 3 with GroupCallUpdateDetails

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

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)

Example 4 with GroupCallUpdateDetails

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

the class MessageRecord method getGroupCallUpdateDescription.

@NonNull
public static UpdateDescription getGroupCallUpdateDescription(@NonNull Context context, @NonNull String body, boolean withTime) {
    GroupCallUpdateDetails groupCallUpdateDetails = GroupCallUpdateDetailsUtil.parse(body);
    List<ServiceId> joinedMembers = Stream.of(groupCallUpdateDetails.getInCallUuidsList()).map(UuidUtil::parseOrNull).withoutNulls().map(ServiceId::from).toList();
    UpdateDescription.StringFactory stringFactory = new GroupCallUpdateMessageFactory(context, joinedMembers, withTime, groupCallUpdateDetails);
    return UpdateDescription.mentioning(joinedMembers, stringFactory, R.drawable.ic_video_16);
}
Also used : GroupCallUpdateDetails(org.thoughtcrime.securesms.database.model.databaseprotos.GroupCallUpdateDetails) ServiceId(org.whispersystems.signalservice.api.push.ServiceId) NonNull(androidx.annotation.NonNull)

Example 5 with GroupCallUpdateDetails

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

the class SmsDatabase method insertOrUpdateGroupCall.

@Override
public void insertOrUpdateGroupCall(@NonNull RecipientId groupRecipientId, @NonNull RecipientId sender, long timestamp, @Nullable String messageGroupCallEraId) {
    SQLiteDatabase db = databaseHelper.getSignalWritableDatabase();
    long threadId;
    try {
        db.beginTransaction();
        Recipient recipient = Recipient.resolved(groupRecipientId);
        threadId = SignalDatabase.threads().getOrCreateThreadIdFor(recipient);
        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) {
                GroupCallUpdateDetails groupCallUpdateDetails = GroupCallUpdateDetailsUtil.parse(record.getBody());
                sameEraId = groupCallUpdateDetails.getEraId().equals(messageGroupCallEraId) && !Util.isEmpty(messageGroupCallEraId);
                if (!sameEraId) {
                    String body = GroupCallUpdateDetailsUtil.createUpdatedBody(groupCallUpdateDetails, Collections.emptyList(), false);
                    ContentValues contentValues = new ContentValues();
                    contentValues.put(BODY, body);
                    db.update(TABLE_NAME, contentValues, ID_WHERE, SqlUtil.buildArgs(record.getId()));
                }
            }
        }
        if (!sameEraId && !Util.isEmpty(messageGroupCallEraId)) {
            byte[] updateDetails = GroupCallUpdateDetails.newBuilder().setEraId(Util.emptyIfNull(messageGroupCallEraId)).setStartedCallUuid(Recipient.resolved(sender).requireServiceId().toString()).setStartedCallTimestamp(timestamp).addAllInCallUuids(Collections.emptyList()).setIsCallFull(false).build().toByteArray();
            String body = Base64.encodeBytes(updateDetails);
            ContentValues values = new ContentValues();
            values.put(RECIPIENT_ID, sender.serialize());
            values.put(ADDRESS_DEVICE_ID, 1);
            values.put(DATE_RECEIVED, timestamp);
            values.put(DATE_SENT, timestamp);
            values.put(READ, 0);
            values.put(BODY, body);
            values.put(TYPE, Types.GROUP_CALL_TYPE);
            values.put(THREAD_ID, threadId);
            db.insert(TABLE_NAME, null, values);
            SignalDatabase.threads().incrementUnread(threadId, 1);
        }
        SignalDatabase.threads().update(threadId, true);
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
    notifyConversationListeners(threadId);
    TrimThreadJob.enqueueAsync(threadId);
}
Also used : ContentValues(android.content.ContentValues) GroupCallUpdateDetails(org.thoughtcrime.securesms.database.model.databaseprotos.GroupCallUpdateDetails) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) Recipient(org.thoughtcrime.securesms.recipients.Recipient)

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