use of org.thoughtcrime.securesms.database.GroupDatabase in project Signal-Android by WhisperSystems.
the class PushDecryptJob method handleSynchronizeSentMessage.
private void handleSynchronizeSentMessage(@NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceEnvelope envelope, @NonNull SentTranscriptMessage message, @NonNull Optional<Long> smsMessageId) throws MmsException {
GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context);
Long threadId;
if (message.getMessage().isEndSession()) {
threadId = handleSynchronizeSentEndSessionMessage(masterSecret, message, smsMessageId);
} else if (message.getMessage().isGroupUpdate()) {
threadId = GroupMessageProcessor.process(context, masterSecret, envelope, message.getMessage(), true);
} else if (message.getMessage().isExpirationUpdate()) {
threadId = handleSynchronizeSentExpirationUpdate(masterSecret, message, smsMessageId);
} else if (message.getMessage().getAttachments().isPresent()) {
threadId = handleSynchronizeSentMediaMessage(masterSecret, message, smsMessageId);
} else {
threadId = handleSynchronizeSentTextMessage(masterSecret, message, smsMessageId);
}
if (message.getMessage().getGroupInfo().isPresent() && groupDatabase.isUnknownGroup(message.getMessage().getGroupInfo().get().getGroupId())) {
handleUnknownGroupMessage(envelope, message.getMessage().getGroupInfo().get());
}
if (threadId != null) {
DatabaseFactory.getThreadDatabase(getContext()).setRead(threadId, true);
MessageNotifier.updateNotification(getContext(), masterSecret.getMasterSecret().orNull());
}
MessageNotifier.setLastDesktopActivityTimestamp(message.getTimestamp());
}
use of org.thoughtcrime.securesms.database.GroupDatabase in project Signal-Android by WhisperSystems.
the class IdentityUpdateJob method onRun.
@Override
public void onRun(MasterSecret masterSecret) throws Exception {
Recipient recipient = RecipientFactory.getRecipientForId(context, recipientId, true);
Recipients recipients = RecipientFactory.getRecipientsFor(context, recipient, true);
String number = recipient.getNumber();
long time = System.currentTimeMillis();
SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(context);
ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(context);
GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context);
GroupDatabase.Reader reader = groupDatabase.getGroups();
GroupDatabase.GroupRecord groupRecord;
while ((groupRecord = reader.getNext()) != null) {
if (groupRecord.getMembers().contains(number) && groupRecord.isActive()) {
SignalServiceGroup group = new SignalServiceGroup(groupRecord.getId());
IncomingTextMessage incoming = new IncomingTextMessage(number, 1, time, null, Optional.of(group), 0);
IncomingIdentityUpdateMessage groupUpdate = new IncomingIdentityUpdateMessage(incoming);
smsDatabase.insertMessageInbox(groupUpdate);
}
}
if (threadDatabase.getThreadIdIfExistsFor(recipients) != -1) {
IncomingTextMessage incoming = new IncomingTextMessage(number, 1, time, null, Optional.<SignalServiceGroup>absent(), 0);
IncomingIdentityUpdateMessage individualUpdate = new IncomingIdentityUpdateMessage(incoming);
smsDatabase.insertMessageInbox(individualUpdate);
}
}
use of org.thoughtcrime.securesms.database.GroupDatabase in project Signal-Android by WhisperSystems.
the class PushGroupUpdateJob method onRun.
@Override
public void onRun() throws IOException, UntrustedIdentityException {
SignalServiceMessageSender messageSender = messageSenderFactory.create();
GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context);
GroupRecord record = groupDatabase.getGroup(groupId);
SignalServiceAttachment avatar = null;
if (record == null) {
Log.w(TAG, "No information for group record info request: " + new String(groupId));
return;
}
if (record.getAvatar() != null) {
avatar = SignalServiceAttachmentStream.newStreamBuilder().withContentType("image/jpeg").withStream(new ByteArrayInputStream(record.getAvatar())).withLength(record.getAvatar().length).build();
}
SignalServiceGroup groupContext = SignalServiceGroup.newBuilder(Type.UPDATE).withAvatar(avatar).withId(groupId).withMembers(record.getMembers()).withName(record.getTitle()).build();
SignalServiceDataMessage message = SignalServiceDataMessage.newBuilder().asGroupMessage(groupContext).withTimestamp(System.currentTimeMillis()).build();
messageSender.sendMessage(new SignalServiceAddress(source), message);
}
use of org.thoughtcrime.securesms.database.GroupDatabase in project Signal-Android by WhisperSystems.
the class GroupMessageProcessor method handleGroupCreate.
@Nullable
private static Long handleGroupCreate(@NonNull Context context, @NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceGroup group, boolean outgoing) {
GroupDatabase database = DatabaseFactory.getGroupDatabase(context);
byte[] id = group.getGroupId();
GroupContext.Builder builder = createGroupContext(group);
builder.setType(GroupContext.Type.UPDATE);
SignalServiceAttachment avatar = group.getAvatar().orNull();
database.create(id, group.getName().orNull(), group.getMembers().orNull(), avatar != null && avatar.isPointer() ? avatar.asPointer() : null, envelope.getRelay());
return storeMessage(context, masterSecret, envelope, group, builder.build(), outgoing);
}
use of org.thoughtcrime.securesms.database.GroupDatabase in project Signal-Android by WhisperSystems.
the class AvatarDownloadJob method onRun.
@Override
public void onRun(MasterSecret masterSecret) throws IOException {
GroupDatabase database = DatabaseFactory.getGroupDatabase(context);
GroupDatabase.GroupRecord record = database.getGroup(groupId);
File attachment = null;
try {
if (record != null) {
long avatarId = record.getAvatarId();
String contentType = record.getAvatarContentType();
byte[] key = record.getAvatarKey();
String relay = record.getRelay();
Optional<byte[]> digest = Optional.fromNullable(record.getAvatarDigest());
if (avatarId == -1 || key == null) {
return;
}
if (digest.isPresent()) {
Log.w(TAG, "Downloading group avatar with digest: " + Hex.toString(digest.get()));
}
attachment = File.createTempFile("avatar", "tmp", context.getCacheDir());
attachment.deleteOnExit();
SignalServiceAttachmentPointer pointer = new SignalServiceAttachmentPointer(avatarId, contentType, key, relay, digest);
InputStream inputStream = receiver.retrieveAttachment(pointer, attachment, MAX_AVATAR_SIZE);
Bitmap avatar = BitmapUtil.createScaledBitmap(context, new AttachmentModel(attachment, key), 500, 500);
database.updateAvatar(groupId, avatar);
inputStream.close();
}
} catch (BitmapDecodingException | NonSuccessfulResponseCodeException | InvalidMessageException e) {
Log.w(TAG, e);
} finally {
if (attachment != null)
attachment.delete();
}
}
Aggregations