Search in sources :

Example 11 with OutgoingGroupMediaMessage

use of org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage in project Signal-Android by signalapp.

the class MmsDatabase method getOutgoingMessage.

public OutgoingMediaMessage getOutgoingMessage(long messageId) throws MmsException, NoSuchMessageException {
    AttachmentDatabase attachmentDatabase = DatabaseFactory.getAttachmentDatabase(context);
    Cursor cursor = null;
    try {
        cursor = rawQuery(RAW_ID_WHERE, new String[] { String.valueOf(messageId) });
        if (cursor != null && cursor.moveToNext()) {
            long outboxType = cursor.getLong(cursor.getColumnIndexOrThrow(MESSAGE_BOX));
            String body = cursor.getString(cursor.getColumnIndexOrThrow(BODY));
            long timestamp = cursor.getLong(cursor.getColumnIndexOrThrow(NORMALIZED_DATE_SENT));
            int subscriptionId = cursor.getInt(cursor.getColumnIndexOrThrow(SUBSCRIPTION_ID));
            long expiresIn = cursor.getLong(cursor.getColumnIndexOrThrow(EXPIRES_IN));
            List<Attachment> attachments = new LinkedList<>(attachmentDatabase.getAttachmentsForMessage(messageId));
            String address = cursor.getString(cursor.getColumnIndexOrThrow(ADDRESS));
            long threadId = cursor.getLong(cursor.getColumnIndexOrThrow(THREAD_ID));
            int distributionType = DatabaseFactory.getThreadDatabase(context).getDistributionType(threadId);
            Recipient recipient = Recipient.from(context, Address.fromSerialized(address), false);
            if (body != null && (Types.isGroupQuit(outboxType) || Types.isGroupUpdate(outboxType))) {
                return new OutgoingGroupMediaMessage(recipient, body, attachments, timestamp, 0);
            } else if (Types.isExpirationTimerUpdate(outboxType)) {
                return new OutgoingExpirationUpdateMessage(recipient, timestamp, expiresIn);
            }
            OutgoingMediaMessage message = new OutgoingMediaMessage(recipient, body, attachments, timestamp, subscriptionId, expiresIn, distributionType);
            if (Types.isSecureType(outboxType)) {
                return new OutgoingSecureMediaMessage(message);
            }
            return message;
        }
        throw new NoSuchMessageException("No record found for id: " + messageId);
    } catch (IOException e) {
        throw new MmsException(e);
    } finally {
        if (cursor != null)
            cursor.close();
    }
}
Also used : DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) MmsNotificationAttachment(org.thoughtcrime.securesms.attachments.MmsNotificationAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) Recipient(org.thoughtcrime.securesms.recipients.Recipient) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) IOException(java.io.IOException) Cursor(android.database.Cursor) LinkedList(java.util.LinkedList) OutgoingSecureMediaMessage(org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage) MmsException(org.thoughtcrime.securesms.mms.MmsException) OutgoingGroupMediaMessage(org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage) OutgoingExpirationUpdateMessage(org.thoughtcrime.securesms.mms.OutgoingExpirationUpdateMessage)

Example 12 with OutgoingGroupMediaMessage

use of org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage in project Signal-Android by signalapp.

the class ConversationActivity method handleLeavePushGroup.

private void handleLeavePushGroup() {
    if (getRecipient() == 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, (dialog, which) -> {
        Context self = ConversationActivity.this;
        try {
            String groupId = getRecipient().getAddress().toGroupString();
            DatabaseFactory.getGroupDatabase(self).setActive(groupId, false);
            GroupContext context = GroupContext.newBuilder().setId(ByteString.copyFrom(GroupUtil.getDecodedId(groupId))).setType(GroupContext.Type.QUIT).build();
            OutgoingGroupMediaMessage outgoingMessage = new OutgoingGroupMediaMessage(getRecipient(), context, null, System.currentTimeMillis(), 0);
            MessageSender.send(self, outgoingMessage, threadId, false, null);
            DatabaseFactory.getGroupDatabase(self).remove(groupId, Address.fromSerialized(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) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException) GroupContext(org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext)

Aggregations

OutgoingGroupMediaMessage (org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage)12 Attachment (org.thoughtcrime.securesms.attachments.Attachment)6 GroupContext (org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext)6 ByteString (com.google.protobuf.ByteString)5 IOException (java.io.IOException)5 Recipient (org.thoughtcrime.securesms.recipients.Recipient)4 Recipients (org.thoughtcrime.securesms.recipients.Recipients)4 LinkedList (java.util.LinkedList)3 Address (org.thoughtcrime.securesms.database.Address)3 ContentValues (android.content.ContentValues)2 Context (android.content.Context)2 Cursor (android.database.Cursor)2 Uri (android.net.Uri)2 Nullable (android.support.annotation.Nullable)2 AlertDialog (android.support.v7.app.AlertDialog)2 DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)2 MmsNotificationAttachment (org.thoughtcrime.securesms.attachments.MmsNotificationAttachment)2 UriAttachment (org.thoughtcrime.securesms.attachments.UriAttachment)2 InsertResult (org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult)2 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)2