mirror of
https://github.com/oxen-io/session-android.git
synced 2025-05-07 13:57:06 +00:00
handle database for message deleted by unsend request
This commit is contained in:
parent
23a61299ac
commit
8b6b02911f
@ -179,7 +179,10 @@ class DatabaseAttachmentProvider(context: Context, helper: SQLCipherOpenHelper)
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun updateMessageAsDeleted(messageID: Long) {
|
override fun updateMessageAsDeleted(messageID: Long) {
|
||||||
TODO("Not yet implemented")
|
val smsDatabase = DatabaseFactory.getSmsDatabase(context)
|
||||||
|
val mmsDatabase = DatabaseFactory.getMmsDatabase(context)
|
||||||
|
smsDatabase.markAsDeleted(messageID)
|
||||||
|
mmsDatabase.markAsDeleted(messageID)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getServerHashForMessage(messageID: Long): String? {
|
override fun getServerHashForMessage(messageID: Long): String? {
|
||||||
|
@ -28,9 +28,9 @@ class DeletedMessageView : LinearLayout {
|
|||||||
|
|
||||||
// region Updating
|
// region Updating
|
||||||
fun bind(message: MessageRecord, @ColorInt textColor: Int) {
|
fun bind(message: MessageRecord, @ColorInt textColor: Int) {
|
||||||
assert(message.deleted)
|
assert(message.isDeleted)
|
||||||
deleteTextView.text = context.getString(R.string.deleted_message)
|
deleteTitleTextView.text = context.getString(R.string.deleted_message)
|
||||||
deleteTextView.setTextColor(textColor)
|
deleteTitleTextView.setTextColor(textColor)
|
||||||
deletedMessageViewIconImageView.imageTintList = ColorStateList.valueOf(textColor)
|
deletedMessageViewIconImageView.imageTintList = ColorStateList.valueOf(textColor)
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
|
@ -76,7 +76,7 @@ class VisibleMessageContentView : LinearLayout {
|
|||||||
mainContainer.removeAllViews()
|
mainContainer.removeAllViews()
|
||||||
onContentClick = null
|
onContentClick = null
|
||||||
onContentDoubleTap = null
|
onContentDoubleTap = null
|
||||||
if (message.deleted) {
|
if (message.isDeleted) {
|
||||||
val deletedMessageView = DeletedMessageView(context)
|
val deletedMessageView = DeletedMessageView(context)
|
||||||
deletedMessageView.bind(message, VisibleMessageContentView.getTextColor(context,message))
|
deletedMessageView.bind(message, VisibleMessageContentView.getTextColor(context,message))
|
||||||
mainContainer.addView(deletedMessageView)
|
mainContainer.addView(deletedMessageView)
|
||||||
|
@ -38,6 +38,8 @@ public abstract class MessagingDatabase extends Database implements MmsSmsColumn
|
|||||||
public abstract void markAsSent(long messageId, boolean secure);
|
public abstract void markAsSent(long messageId, boolean secure);
|
||||||
public abstract void markUnidentified(long messageId, boolean unidentified);
|
public abstract void markUnidentified(long messageId, boolean unidentified);
|
||||||
|
|
||||||
|
public abstract void markAsDeleted(long messageId);
|
||||||
|
|
||||||
public void addMismatchedIdentity(long messageId, Address address, IdentityKey identityKey) {
|
public void addMismatchedIdentity(long messageId, Address address, IdentityKey identityKey) {
|
||||||
try {
|
try {
|
||||||
addToDocument(messageId, MISMATCHED_IDENTITIES,
|
addToDocument(messageId, MISMATCHED_IDENTITIES,
|
||||||
|
@ -391,6 +391,22 @@ public class MmsDatabase extends MessagingDatabase {
|
|||||||
db.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {String.valueOf(messageId)});
|
db.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {String.valueOf(messageId)});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void markAsDeleted(long messageId) {
|
||||||
|
SQLiteDatabase database = databaseHelper.getWritableDatabase();
|
||||||
|
ContentValues contentValues = new ContentValues();
|
||||||
|
contentValues.put(READ, 1);
|
||||||
|
contentValues.put(BODY, "");
|
||||||
|
database.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {String.valueOf(messageId)});
|
||||||
|
|
||||||
|
AttachmentDatabase attachmentDatabase = DatabaseFactory.getAttachmentDatabase(context);
|
||||||
|
ThreadUtils.queue(() -> attachmentDatabase.deleteAttachmentsForMessage(messageId));
|
||||||
|
|
||||||
|
long threadId = getThreadIdForMessage(messageId);
|
||||||
|
updateMailboxBitmask(messageId, Types.BASE_TYPE_MASK, Types.BASE_DELETED_TYPE, Optional.of(threadId));
|
||||||
|
notifyConversationListeners(threadId);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void markExpireStarted(long messageId) {
|
public void markExpireStarted(long messageId) {
|
||||||
markExpireStarted(messageId, System.currentTimeMillis());
|
markExpireStarted(messageId, System.currentTimeMillis());
|
||||||
|
@ -40,6 +40,7 @@ public interface MmsSmsColumns {
|
|||||||
protected static final long BASE_PENDING_SECURE_SMS_FALLBACK = 25;
|
protected static final long BASE_PENDING_SECURE_SMS_FALLBACK = 25;
|
||||||
protected static final long BASE_PENDING_INSECURE_SMS_FALLBACK = 26;
|
protected static final long BASE_PENDING_INSECURE_SMS_FALLBACK = 26;
|
||||||
public static final long BASE_DRAFT_TYPE = 27;
|
public static final long BASE_DRAFT_TYPE = 27;
|
||||||
|
protected static final long BASE_DELETED_TYPE = 28;
|
||||||
|
|
||||||
protected static final long[] OUTGOING_MESSAGE_TYPES = {BASE_OUTBOX_TYPE, BASE_SENT_TYPE,
|
protected static final long[] OUTGOING_MESSAGE_TYPES = {BASE_OUTBOX_TYPE, BASE_SENT_TYPE,
|
||||||
BASE_SENDING_TYPE, BASE_SENT_FAILED_TYPE,
|
BASE_SENDING_TYPE, BASE_SENT_FAILED_TYPE,
|
||||||
@ -152,6 +153,8 @@ public interface MmsSmsColumns {
|
|||||||
return (type & BASE_TYPE_MASK) == BASE_INBOX_TYPE;
|
return (type & BASE_TYPE_MASK) == BASE_INBOX_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isDeletedMessage(long type) { return (type & BASE_TYPE_MASK) == BASE_DELETED_TYPE; }
|
||||||
|
|
||||||
public static boolean isJoinedType(long type) {
|
public static boolean isJoinedType(long type) {
|
||||||
return (type & BASE_TYPE_MASK) == JOINED_TYPE;
|
return (type & BASE_TYPE_MASK) == JOINED_TYPE;
|
||||||
}
|
}
|
||||||
|
@ -183,6 +183,16 @@ public class SmsDatabase extends MessagingDatabase {
|
|||||||
db.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {String.valueOf(id)});
|
db.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {String.valueOf(id)});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void markAsDeleted(long messageId) {
|
||||||
|
SQLiteDatabase database = databaseHelper.getWritableDatabase();
|
||||||
|
ContentValues contentValues = new ContentValues();
|
||||||
|
contentValues.put(READ, 1);
|
||||||
|
contentValues.put(BODY, "");
|
||||||
|
database.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {String.valueOf(messageId)});
|
||||||
|
updateTypeBitmask(messageId, Types.BASE_TYPE_MASK, Types.BASE_DELETED_TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void markExpireStarted(long id) {
|
public void markExpireStarted(long id) {
|
||||||
markExpireStarted(id, System.currentTimeMillis());
|
markExpireStarted(id, System.currentTimeMillis());
|
||||||
|
@ -117,6 +117,7 @@ public abstract class DisplayRecord {
|
|||||||
public boolean isMissedCall() {
|
public boolean isMissedCall() {
|
||||||
return SmsDatabase.Types.isMissedCall(type);
|
return SmsDatabase.Types.isMissedCall(type);
|
||||||
}
|
}
|
||||||
|
public boolean isDeleted() { return MmsSmsColumns.Types.isDeletedMessage(type); }
|
||||||
|
|
||||||
public boolean isControlMessage() {
|
public boolean isControlMessage() {
|
||||||
return isGroupUpdateMessage() || isExpirationTimerUpdate() || isDataExtractionNotification();
|
return isGroupUpdateMessage() || isExpirationTimerUpdate() || isDataExtractionNotification();
|
||||||
|
@ -49,7 +49,6 @@ public abstract class MessageRecord extends DisplayRecord {
|
|||||||
private final long expireStarted;
|
private final long expireStarted;
|
||||||
private final boolean unidentified;
|
private final boolean unidentified;
|
||||||
public final long id;
|
public final long id;
|
||||||
public final boolean deleted;
|
|
||||||
|
|
||||||
public abstract boolean isMms();
|
public abstract boolean isMms();
|
||||||
public abstract boolean isMmsNotification();
|
public abstract boolean isMmsNotification();
|
||||||
@ -72,7 +71,6 @@ public abstract class MessageRecord extends DisplayRecord {
|
|||||||
this.expiresIn = expiresIn;
|
this.expiresIn = expiresIn;
|
||||||
this.expireStarted = expireStarted;
|
this.expireStarted = expireStarted;
|
||||||
this.unidentified = unidentified;
|
this.unidentified = unidentified;
|
||||||
this.deleted = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getId() {
|
public long getId() {
|
||||||
@ -105,9 +103,7 @@ public abstract class MessageRecord extends DisplayRecord {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SpannableString getDisplayBody(@NonNull Context context) {
|
public SpannableString getDisplayBody(@NonNull Context context) {
|
||||||
if (this.deleted) {
|
if (isGroupUpdateMessage()) {
|
||||||
return new SpannableString("This message has been deleted."); // TODO: localize
|
|
||||||
} else if (isGroupUpdateMessage()) {
|
|
||||||
UpdateMessageData updateMessageData = UpdateMessageData.Companion.fromJSON(getBody());
|
UpdateMessageData updateMessageData = UpdateMessageData.Companion.fromJSON(getBody());
|
||||||
return new SpannableString(UpdateMessageBuilder.INSTANCE.buildGroupUpdateMessage(context, updateMessageData, getIndividualRecipient().getAddress().serialize(), isOutgoing()));
|
return new SpannableString(UpdateMessageBuilder.INSTANCE.buildGroupUpdateMessage(context, updateMessageData, getIndividualRecipient().getAddress().serialize(), isOutgoing()));
|
||||||
} else if (isExpirationTimerUpdate()) {
|
} else if (isExpirationTimerUpdate()) {
|
||||||
|
@ -6,21 +6,23 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:padding="@dimen/medium_spacing"
|
android:padding="@dimen/small_spacing"
|
||||||
android:gravity="center">
|
android:gravity="center">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/deletedMessageViewIconImageView"
|
android:id="@+id/deletedMessageViewIconImageView"
|
||||||
android:layout_width="24dp"
|
android:layout_width="16dp"
|
||||||
android:layout_height="24dp"
|
android:layout_height="16dp"
|
||||||
|
android:layout_marginStart="@dimen/small_spacing"
|
||||||
android:src="?menu_trash_icon"
|
android:src="?menu_trash_icon"
|
||||||
app:tint="@color/text" />
|
app:tint="@color/text" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/documentTitleTextView"
|
android:id="@+id/deleteTitleTextView"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="4dp"
|
android:layout_marginStart="4dp"
|
||||||
|
android:layout_marginEnd="@dimen/small_spacing"
|
||||||
android:textSize="@dimen/very_small_font_size"
|
android:textSize="@dimen/very_small_font_size"
|
||||||
android:textColor="@color/text"
|
android:textColor="@color/text"
|
||||||
tools:text="This message has been deleted"
|
tools:text="This message has been deleted"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user