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);
}
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);
}
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;
}
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);
}
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);
}
Aggregations