use of org.whispersystems.signalservice.api.push.SignalServiceAddress in project libsignal-service-java by signalapp.
the class SignalServiceMessageSender method createGroupContent.
private GroupContext createGroupContent(SignalServiceGroup group) throws IOException {
GroupContext.Builder builder = GroupContext.newBuilder();
builder.setId(ByteString.copyFrom(group.getGroupId()));
if (group.getType() != SignalServiceGroup.Type.DELIVER) {
if (group.getType() == SignalServiceGroup.Type.UPDATE)
builder.setType(GroupContext.Type.UPDATE);
else if (group.getType() == SignalServiceGroup.Type.QUIT)
builder.setType(GroupContext.Type.QUIT);
else if (group.getType() == SignalServiceGroup.Type.REQUEST_INFO)
builder.setType(GroupContext.Type.REQUEST_INFO);
else
throw new AssertionError("Unknown type: " + group.getType());
if (group.getName().isPresent()) {
builder.setName(group.getName().get());
}
if (group.getMembers().isPresent()) {
for (SignalServiceAddress address : group.getMembers().get()) {
if (address.getNumber().isPresent()) {
builder.addMembersE164(address.getNumber().get());
}
GroupContext.Member.Builder memberBuilder = GroupContext.Member.newBuilder();
if (address.getUuid().isPresent()) {
memberBuilder.setUuid(address.getUuid().get().toString());
}
if (address.getNumber().isPresent()) {
memberBuilder.setE164(address.getNumber().get());
}
builder.addMembers(memberBuilder.build());
}
}
if (group.getAvatar().isPresent()) {
if (group.getAvatar().get().isStream()) {
builder.setAvatar(createAttachmentPointer(group.getAvatar().get().asStream()));
} else {
builder.setAvatar(createAttachmentPointer(group.getAvatar().get().asPointer()));
}
}
} else {
builder.setType(GroupContext.Type.DELIVER);
}
return builder.build();
}
use of org.whispersystems.signalservice.api.push.SignalServiceAddress in project libsignal-service-java by signalapp.
the class SignalServiceMessageReceiver method retrieveMessages.
public List<SignalServiceEnvelope> retrieveMessages(MessageReceivedCallback callback) throws IOException {
List<SignalServiceEnvelope> results = new LinkedList<>();
List<SignalServiceEnvelopeEntity> entities = socket.getMessages();
for (SignalServiceEnvelopeEntity entity : entities) {
SignalServiceEnvelope envelope;
if (entity.hasSource() && entity.getSourceDevice() > 0) {
SignalServiceAddress address = new SignalServiceAddress(UuidUtil.parseOrNull(entity.getSourceUuid()), entity.getSourceE164());
envelope = new SignalServiceEnvelope(entity.getType(), Optional.of(address), entity.getSourceDevice(), entity.getTimestamp(), entity.getMessage(), entity.getContent(), entity.getServerTimestamp(), entity.getServerUuid());
} else {
envelope = new SignalServiceEnvelope(entity.getType(), entity.getTimestamp(), entity.getMessage(), entity.getContent(), entity.getServerTimestamp(), entity.getServerUuid());
}
callback.onMessage(envelope);
results.add(envelope);
if (envelope.hasUuid())
socket.acknowledgeMessage(envelope.getUuid());
else
socket.acknowledgeMessage(entity.getSourceE164(), entity.getTimestamp());
}
return results;
}
use of org.whispersystems.signalservice.api.push.SignalServiceAddress in project Signal-Android by signalapp.
the class GroupV1MessageProcessor method handleGroupCreate.
@Nullable
private static Long handleGroupCreate(@NonNull Context context, @NonNull SignalServiceContent content, @NonNull SignalServiceGroup group, boolean outgoing) {
GroupDatabase database = SignalDatabase.groups();
GroupId.V1 id = GroupId.v1orThrow(group.getGroupId());
GroupContext.Builder builder = createGroupContext(group);
builder.setType(GroupContext.Type.UPDATE);
SignalServiceAttachment avatar = group.getAvatar().orNull();
List<RecipientId> members = new LinkedList<>();
if (group.getMembers().isPresent()) {
for (SignalServiceAddress member : group.getMembers().get()) {
members.add(Recipient.externalGV1Member(member).getId());
}
}
database.create(id, group.getName().orNull(), members, avatar != null && avatar.isPointer() ? avatar.asPointer() : null, null);
Recipient sender = Recipient.externalHighTrustPush(context, content.getSender());
if (sender.isSystemContact() || sender.isProfileSharing()) {
Log.i(TAG, "Auto-enabling profile sharing because 'adder' is trusted. contact: " + sender.isSystemContact() + ", profileSharing: " + sender.isProfileSharing());
SignalDatabase.recipients().setProfileSharing(Recipient.externalGroupExact(context, id).getId(), true);
}
return storeMessage(context, content, group, builder.build(), outgoing);
}
use of org.whispersystems.signalservice.api.push.SignalServiceAddress in project Signal-Android by signalapp.
the class SendRetryReceiptJob method onRun.
@Override
protected void onRun() throws Exception {
Recipient recipient = Recipient.resolved(recipientId);
if (recipient.isUnregistered()) {
Log.w(TAG, recipient.getId() + " not registered!");
return;
}
SignalServiceAddress address = RecipientUtil.toSignalServiceAddress(context, recipient);
Optional<UnidentifiedAccessPair> access = UnidentifiedAccessUtil.getAccessFor(context, recipient);
Optional<byte[]> group = groupId.transform(GroupId::getDecodedId);
Log.i(TAG, "Sending retry receipt for " + errorMessage.getTimestamp() + " to " + recipientId + ", device: " + errorMessage.getDeviceId());
ApplicationDependencies.getSignalServiceMessageSender().sendRetryReceipt(address, access, group, errorMessage);
}
use of org.whispersystems.signalservice.api.push.SignalServiceAddress in project Signal-Android by signalapp.
the class SendViewedReceiptJob method onRun.
@Override
public void onRun() throws IOException, UntrustedIdentityException {
if (!Recipient.self().isRegistered()) {
throw new NotPushRegisteredException();
}
if (!TextSecurePreferences.isReadReceiptsEnabled(context)) {
Log.w(TAG, "Read receipts not enabled!");
return;
}
if (messageSentTimestamps.isEmpty()) {
Log.w(TAG, "No sync timestamps!");
return;
}
if (!RecipientUtil.isMessageRequestAccepted(context, threadId)) {
Log.w(TAG, "Refusing to send receipts to untrusted recipient");
return;
}
Recipient recipient = Recipient.resolved(recipientId);
if (recipient.isSelf()) {
Log.i(TAG, "Not sending view receipt to self.");
return;
}
if (recipient.isBlocked()) {
Log.w(TAG, "Refusing to send receipts to blocked recipient");
return;
}
if (recipient.isGroup()) {
Log.w(TAG, "Refusing to send receipts to group");
return;
}
if (recipient.isUnregistered()) {
Log.w(TAG, recipient.getId() + " not registered!");
return;
}
SignalServiceMessageSender messageSender = ApplicationDependencies.getSignalServiceMessageSender();
SignalServiceAddress remoteAddress = RecipientUtil.toSignalServiceAddress(context, recipient);
SignalServiceReceiptMessage receiptMessage = new SignalServiceReceiptMessage(SignalServiceReceiptMessage.Type.VIEWED, messageSentTimestamps, timestamp);
SendMessageResult result = messageSender.sendReceipt(remoteAddress, UnidentifiedAccessUtil.getAccessFor(context, Recipient.resolved(recipientId)), receiptMessage);
if (Util.hasItems(messageIds)) {
SignalDatabase.messageLog().insertIfPossible(recipientId, timestamp, result, ContentHint.IMPLICIT, messageIds);
}
}
Aggregations