Search in sources :

Example 1 with GroupContext

use of org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext in project Signal-Android by WhisperSystems.

the class PushGroupSendJob method deliver.

private void deliver(MasterSecret masterSecret, OutgoingMediaMessage message, long filterRecipientId) throws IOException, RecipientFormattingException, InvalidNumberException, EncapsulatedExceptions, UndeliverableMessageException {
    SignalServiceMessageSender messageSender = messageSenderFactory.create();
    byte[] groupId = GroupUtil.getDecodedId(message.getRecipients().getPrimaryRecipient().getNumber());
    Recipients recipients = DatabaseFactory.getGroupDatabase(context).getGroupMembers(groupId, false);
    List<Attachment> scaledAttachments = scaleAttachments(masterSecret, MediaConstraints.PUSH_CONSTRAINTS, message.getAttachments());
    List<SignalServiceAttachment> attachmentStreams = getAttachmentsFor(masterSecret, scaledAttachments);
    List<SignalServiceAddress> addresses;
    if (filterRecipientId >= 0)
        addresses = getPushAddresses(filterRecipientId);
    else
        addresses = getPushAddresses(recipients);
    if (message.isGroup()) {
        OutgoingGroupMediaMessage groupMessage = (OutgoingGroupMediaMessage) message;
        GroupContext groupContext = groupMessage.getGroupContext();
        SignalServiceAttachment avatar = attachmentStreams.isEmpty() ? null : attachmentStreams.get(0);
        SignalServiceGroup.Type type = groupMessage.isGroupQuit() ? SignalServiceGroup.Type.QUIT : SignalServiceGroup.Type.UPDATE;
        SignalServiceGroup group = new SignalServiceGroup(type, groupId, groupContext.getName(), groupContext.getMembersList(), avatar);
        SignalServiceDataMessage groupDataMessage = new SignalServiceDataMessage(message.getSentTimeMillis(), group, null, null);
        messageSender.sendMessage(addresses, groupDataMessage);
    } else {
        SignalServiceGroup group = new SignalServiceGroup(groupId);
        SignalServiceDataMessage groupMessage = new SignalServiceDataMessage(message.getSentTimeMillis(), group, attachmentStreams, message.getBody(), false, (int) (message.getExpiresIn() / 1000), message.isExpirationUpdate());
        messageSender.sendMessage(addresses, groupMessage);
    }
}
Also used : Recipients(org.thoughtcrime.securesms.recipients.Recipients) SignalServiceMessageSender(org.whispersystems.signalservice.api.SignalServiceMessageSender) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) OutgoingGroupMediaMessage(org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) SignalServiceGroup(org.whispersystems.signalservice.api.messages.SignalServiceGroup) GroupContext(org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext)

Example 2 with GroupContext

use of org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext in project Signal-Android by WhisperSystems.

the class ConversationActivity method handleLeavePushGroup.

private void handleLeavePushGroup() {
    if (getRecipients() == null) {
        Toast.makeText(this, getString(R.string.ConversationActivity_invalid_recipient), Toast.LENGTH_LONG).show();
        return;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(R.string.ConversationActivity_leave_group));
    builder.setIconAttribute(R.attr.dialog_info_icon);
    builder.setCancelable(true);
    builder.setMessage(getString(R.string.ConversationActivity_are_you_sure_you_want_to_leave_this_group));
    builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            Context self = ConversationActivity.this;
            try {
                byte[] groupId = GroupUtil.getDecodedId(getRecipients().getPrimaryRecipient().getNumber());
                DatabaseFactory.getGroupDatabase(self).setActive(groupId, false);
                GroupContext context = GroupContext.newBuilder().setId(ByteString.copyFrom(groupId)).setType(GroupContext.Type.QUIT).build();
                OutgoingGroupMediaMessage outgoingMessage = new OutgoingGroupMediaMessage(getRecipients(), context, null, System.currentTimeMillis(), 0);
                MessageSender.send(self, masterSecret, outgoingMessage, threadId, false);
                DatabaseFactory.getGroupDatabase(self).remove(groupId, TextSecurePreferences.getLocalNumber(self));
                initializeEnabledCheck();
            } catch (IOException e) {
                Log.w(TAG, e);
                Toast.makeText(self, R.string.ConversationActivity_error_leaving_group, Toast.LENGTH_LONG).show();
            }
        }
    });
    builder.setNegativeButton(R.string.no, null);
    builder.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) GroupContext(org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext) Context(android.content.Context) OutgoingGroupMediaMessage(org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage) DialogInterface(android.content.DialogInterface) IOException(java.io.IOException) GroupContext(org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext)

Example 3 with GroupContext

use of org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext in project Signal-Android by WhisperSystems.

the class GroupManager method sendGroupUpdate.

private static GroupActionResult sendGroupUpdate(@NonNull Context context, @NonNull MasterSecret masterSecret, @NonNull byte[] groupId, @NonNull Set<String> e164numbers, @Nullable String groupName, @Nullable byte[] avatar) {
    Attachment avatarAttachment = null;
    String groupRecipientId = GroupUtil.getEncodedId(groupId);
    Recipients groupRecipient = RecipientFactory.getRecipientsFromString(context, groupRecipientId, false);
    GroupContext.Builder groupContextBuilder = GroupContext.newBuilder().setId(ByteString.copyFrom(groupId)).setType(GroupContext.Type.UPDATE).addAllMembers(e164numbers);
    if (groupName != null)
        groupContextBuilder.setName(groupName);
    GroupContext groupContext = groupContextBuilder.build();
    if (avatar != null) {
        Uri avatarUri = SingleUseBlobProvider.getInstance().createUri(avatar);
        avatarAttachment = new UriAttachment(avatarUri, ContentType.IMAGE_PNG, AttachmentDatabase.TRANSFER_PROGRESS_DONE, avatar.length);
    }
    OutgoingGroupMediaMessage outgoingMessage = new OutgoingGroupMediaMessage(groupRecipient, groupContext, avatarAttachment, System.currentTimeMillis(), 0);
    long threadId = MessageSender.send(context, masterSecret, outgoingMessage, -1, false);
    return new GroupActionResult(groupRecipient, threadId);
}
Also used : OutgoingGroupMediaMessage(org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage) Recipients(org.thoughtcrime.securesms.recipients.Recipients) UriAttachment(org.thoughtcrime.securesms.attachments.UriAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) ByteString(com.google.protobuf.ByteString) UriAttachment(org.thoughtcrime.securesms.attachments.UriAttachment) Uri(android.net.Uri) GroupContext(org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext)

Aggregations

OutgoingGroupMediaMessage (org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage)3 GroupContext (org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext)3 Attachment (org.thoughtcrime.securesms.attachments.Attachment)2 Recipients (org.thoughtcrime.securesms.recipients.Recipients)2 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 Uri (android.net.Uri)1 AlertDialog (android.support.v7.app.AlertDialog)1 ByteString (com.google.protobuf.ByteString)1 IOException (java.io.IOException)1 UriAttachment (org.thoughtcrime.securesms.attachments.UriAttachment)1 SignalServiceMessageSender (org.whispersystems.signalservice.api.SignalServiceMessageSender)1 SignalServiceAttachment (org.whispersystems.signalservice.api.messages.SignalServiceAttachment)1 SignalServiceDataMessage (org.whispersystems.signalservice.api.messages.SignalServiceDataMessage)1 SignalServiceGroup (org.whispersystems.signalservice.api.messages.SignalServiceGroup)1 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)1