refactor: add in new recipient details for auto download based off the isTrusted flag for previous 1o1 chats, remove some legacy protobuf and recompile

pull/1403/head
0x330a 3 years ago
parent 8378565505
commit 516344280a

@ -66,7 +66,7 @@ class ConversationSettingsActivity: PassphraseRequiredActionBarActivity(), View.
binding.notificationSettings.setOnClickListener(this)
binding.back.setOnClickListener(this)
binding.autoDownloadMediaSwitch.setOnCheckedChangeListener { _, isChecked ->
viewModel.setTrusted(isChecked)
viewModel.setAutoDownloadAttachments(isChecked)
updateRecipientDisplay()
}
}
@ -108,7 +108,7 @@ class ConversationSettingsActivity: PassphraseRequiredActionBarActivity(), View.
)
// Set auto-download state
val trusted = viewModel.isTrusted()
val trusted = viewModel.autoDownloadAttachments()
binding.autoDownloadMediaSwitch.isChecked = trusted
// Set notification type

@ -26,15 +26,10 @@ class ConversationSettingsViewModel(
storage.setThreadPinned(threadId, !isPinned)
}
fun isTrusted() = recipient?.let { recipient ->
storage.isContactTrusted(recipient)
} ?: false
fun autoDownloadAttachments() = isTrusted()
fun autoDownloadAttachments() = recipient?.let { recipient -> storage.shouldAutoDownloadAttachments(recipient) } ?: false
fun setTrusted(isTrusted: Boolean) {
val recipient = recipient ?: return
storage.setContactTrusted(recipient, isTrusted)
fun setAutoDownloadAttachments(shouldDownload: Boolean) {
recipient?.let { recipient -> storage.setAutoDownloadAttachments(recipient, shouldDownload) }
}
fun isUserGroupAdmin(): Boolean = recipient?.let { recipient ->

@ -230,7 +230,7 @@ class VisibleMessageView : LinearLayout {
glide,
thread,
searchQuery,
message.isOutgoing || isGroupThread || (contact?.isTrusted ?: false)
message.isOutgoing || (thread.autoDownloadAttachments)
)
binding.messageContentView.delegate = delegate
onDoubleTap = { binding.messageContentView.onContentDoubleTap?.invoke() }

@ -62,13 +62,14 @@ public class RecipientDatabase extends Database {
private static final String UNIDENTIFIED_ACCESS_MODE = "unidentified_access_mode";
private static final String FORCE_SMS_SELECTION = "force_sms_selection";
private static final String NOTIFY_TYPE = "notify_type"; // all, mentions only, none
private static final String AUTO_DOWNLOAD = "auto_download"; // 1 / 0 flag for whether to auto-download in a conversation
private static final String[] RECIPIENT_PROJECTION = new String[] {
BLOCK, APPROVED, APPROVED_ME, NOTIFICATION, CALL_RINGTONE, VIBRATE, CALL_VIBRATE, MUTE_UNTIL, COLOR, SEEN_INVITE_REMINDER, DEFAULT_SUBSCRIPTION_ID, EXPIRE_MESSAGES, REGISTERED,
PROFILE_KEY, SYSTEM_DISPLAY_NAME, SYSTEM_PHOTO_URI, SYSTEM_PHONE_LABEL, SYSTEM_CONTACT_URI,
SIGNAL_PROFILE_NAME, SIGNAL_PROFILE_AVATAR, PROFILE_SHARING, NOTIFICATION_CHANNEL,
UNIDENTIFIED_ACCESS_MODE,
FORCE_SMS_SELECTION, NOTIFY_TYPE,
FORCE_SMS_SELECTION, NOTIFY_TYPE, AUTO_DOWNLOAD,
};
static final List<String> TYPED_RECIPIENT_PROJECTION = Stream.of(RECIPIENT_PROJECTION)
@ -107,6 +108,17 @@ public class RecipientDatabase extends Database {
"ADD COLUMN " + NOTIFY_TYPE + " INTEGER DEFAULT 0;";
}
public static String getCreateAutoDownloadCommand() {
return "ALTER TABLE "+ TABLE_NAME + " " +
"ADD COLUMN " + AUTO_DOWNLOAD + " INTEGER DEFAULT 0;";
}
public static String getUpdateAutoDownloadValuesCommand() {
return "UPDATE "+TABLE_NAME+" SET "+AUTO_DOWNLOAD+" = 1 "+
"WHERE "+ADDRESS+" IN (SELECT "+SessionContactDatabase.sessionContactTable+"."+SessionContactDatabase.sessionID+" "+
"FROM "+SessionContactDatabase.sessionContactTable+" WHERE ("+SessionContactDatabase.isTrusted+" != 0))";
}
public static String getCreateApprovedCommand() {
return "ALTER TABLE "+ TABLE_NAME + " " +
"ADD COLUMN " + APPROVED + " INTEGER DEFAULT 0;";
@ -179,6 +191,7 @@ public class RecipientDatabase extends Database {
int callVibrateState = cursor.getInt(cursor.getColumnIndexOrThrow(CALL_VIBRATE));
long muteUntil = cursor.getLong(cursor.getColumnIndexOrThrow(MUTE_UNTIL));
int notifyType = cursor.getInt(cursor.getColumnIndexOrThrow(NOTIFY_TYPE));
boolean autoDownloadAttachments = cursor.getInt(cursor.getColumnIndexOrThrow(AUTO_DOWNLOAD)) == 1;
String serializedColor = cursor.getString(cursor.getColumnIndexOrThrow(COLOR));
int defaultSubscriptionId = cursor.getInt(cursor.getColumnIndexOrThrow(DEFAULT_SUBSCRIPTION_ID));
int expireMessages = cursor.getInt(cursor.getColumnIndexOrThrow(EXPIRE_MESSAGES));
@ -215,7 +228,7 @@ public class RecipientDatabase extends Database {
}
return Optional.of(new RecipientSettings(blocked, approved, approvedMe, muteUntil,
notifyType,
notifyType, autoDownloadAttachments,
Recipient.VibrateState.fromId(messageVibrateState),
Recipient.VibrateState.fromId(callVibrateState),
Util.uri(messageRingtone), Util.uri(callRingtone),

@ -11,7 +11,7 @@ import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
class SessionContactDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) {
companion object {
private const val sessionContactTable = "session_contact_database"
const val sessionContactTable = "session_contact_database"
const val sessionID = "session_id"
const val name = "name"
const val nickname = "nickname"
@ -69,7 +69,6 @@ class SessionContactDatabase(context: Context, helper: SQLCipherOpenHelper) : Da
contentValues.put(profilePictureEncryptionKey, Base64.encodeBytes(it))
}
contentValues.put(threadID, contact.threadID)
contentValues.put(isTrusted, if (contact.isTrusted) 1 else 0)
database.insertOrUpdate(sessionContactTable, contentValues, "$sessionID = ?", arrayOf( contact.sessionID ))
notifyConversationListListeners()
}
@ -85,7 +84,6 @@ class SessionContactDatabase(context: Context, helper: SQLCipherOpenHelper) : Da
contact.profilePictureEncryptionKey = Base64.decode(it)
}
contact.threadID = cursor.getLong(threadID)
contact.isTrusted = cursor.getInt(isTrusted) != 0
return contact
}
@ -100,7 +98,6 @@ class SessionContactDatabase(context: Context, helper: SQLCipherOpenHelper) : Da
contact.profilePictureEncryptionKey = Base64.decode(it)
}
contact.threadID = cursor.getLong(cursor.getColumnIndexOrThrow(threadID))
contact.isTrusted = cursor.getInt(cursor.getColumnIndexOrThrow(isTrusted)) != 0
return contact
}

@ -685,19 +685,15 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
}
}
override fun isContactTrusted(recipient: Recipient): Boolean {
val sessionID = recipient.address.toString()
val contactDb = DatabaseComponent.get(context).sessionContactDatabase()
val contact = contactDb.getContactWithSessionID(sessionID) ?: return false
return contact.isTrusted
override fun shouldAutoDownloadAttachments(recipient: Recipient): Boolean {
TODO("Not yet implemented")
}
override fun setContactTrusted(recipient: Recipient, isTrusted: Boolean) {
val sessionID = recipient.address.toString()
val contactDb = DatabaseComponent.get(context).sessionContactDatabase()
val contact = contactDb.getContactWithSessionID(sessionID) ?: return
val threadID = DatabaseComponent.get(context).threadDatabase().getThreadIdIfExistsFor(recipient)
contactDb.setContactIsTrusted(contact, isTrusted, threadID)
override fun setAutoDownloadAttachments(
recipient: Recipient,
shouldAutoDownloadAttachments: Boolean
) {
TODO("Not yet implemented")
}
override fun getLastUpdated(threadID: Long): Long {

@ -75,9 +75,10 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
private static final int lokiV36 = 57;
private static final int lokiV37 = 58;
private static final int lokiV38 = 59;
private static final int lokiV39 = 60;
// Loki - onUpgrade(...) must be updated to use Loki version numbers if Signal makes any database changes
private static final int DATABASE_VERSION = lokiV38;
private static final int DATABASE_VERSION = lokiV39;
private static final String DATABASE_NAME = "signal.db";
private final Context context;
@ -414,6 +415,11 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
db.execSQL(EmojiSearchDatabase.CREATE_EMOJI_SEARCH_TABLE_COMMAND);
}
if (oldVersion < lokiV39) {
db.execSQL(RecipientDatabase.getCreateAutoDownloadCommand());
db.execSQL(RecipientDatabase.getUpdateAutoDownloadValuesCommand());
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();

@ -163,8 +163,8 @@ interface StorageProtocol {
fun getRecipientForThread(threadId: Long): Recipient?
fun getRecipientSettings(address: Address): RecipientSettings?
fun addContacts(contacts: List<ConfigurationMessage.Contact>)
fun isContactTrusted(recipient: Recipient): Boolean
fun setContactTrusted(recipient: Recipient, isTrusted: Boolean)
fun shouldAutoDownloadAttachments(recipient: Recipient): Boolean
fun setAutoDownloadAttachments(recipient: Recipient, shouldAutoDownloadAttachments: Boolean)
// Attachments
fun getAttachmentDataUri(attachmentId: AttachmentId): Uri

@ -19,10 +19,6 @@ class Contact(val sessionID: String) {
* The ID of the thread associated with this contact.
*/
var threadID: Long? = null
/**
* This flag is used to determine whether we should auto-download files sent by this contact.
*/
var isTrusted = false
// region Name
/**

@ -99,7 +99,7 @@ class AttachmentDownloadJob(val attachmentID: Long, val databaseMessageID: Long)
handleFailure(Error.NoSender, null)
return
}
if (!threadRecipient.isGroupRecipient && (!contact.isTrusted && storage.getUserPublicKey() != sender)) {
if (!threadRecipient.isGroupRecipient && (!threadRecipient.autoDownloadAttachments && storage.getUserPublicKey() != sender)) {
// if we aren't receiving a group message, a message from ourselves (self-send) and the contact sending is not trusted:
// do not continue, but do not fail
return

@ -1,7 +1,5 @@
package org.session.libsession.messaging.messages
import com.google.protobuf.ByteString
import org.session.libsession.utilities.GroupUtil
import org.session.libsignal.protos.SignalServiceProtos
abstract class Message {
@ -28,12 +26,4 @@ abstract class Message {
abstract fun toProto(): SignalServiceProtos.Content?
fun setGroupContext(dataMessage: SignalServiceProtos.DataMessage.Builder) {
val groupProto = SignalServiceProtos.GroupContext.newBuilder()
val groupID = GroupUtil.doubleEncodeGroupID(recipient!!)
groupProto.id = ByteString.copyFrom(GroupUtil.getDecodedGroupIDAsData(groupID))
groupProto.type = SignalServiceProtos.GroupContext.Type.DELIVER
dataMessage.group = groupProto.build()
}
}

@ -172,8 +172,6 @@ class ClosedGroupControlMessage() : ControlMessage() {
val contentProto = SignalServiceProtos.Content.newBuilder()
val dataMessageProto = DataMessage.newBuilder()
dataMessageProto.closedGroupControlMessage = closedGroupControlMessage.build()
// Group context
setGroupContext(dataMessageProto)
contentProto.dataMessage = dataMessageProto.build()
return contentProto.build()
} catch (e: Exception) {

@ -1,9 +1,7 @@
package org.session.libsession.messaging.messages.control
import org.session.libsession.messaging.MessagingModuleConfiguration
import org.session.libsession.messaging.messages.visible.VisibleMessage
import org.session.libsignal.utilities.Log
import org.session.libsignal.protos.SignalServiceProtos
import org.session.libsignal.utilities.Log
class ExpirationTimerUpdate() : ControlMessage() {
/** In the case of a sync message, the public key of the person the message was targeted at.
@ -56,15 +54,6 @@ class ExpirationTimerUpdate() : ControlMessage() {
if (syncTarget != null) {
dataMessageProto.syncTarget = syncTarget
}
// Group context
if (MessagingModuleConfiguration.shared.storage.isClosedGroup(recipient!!)) {
try {
setGroupContext(dataMessageProto)
} catch(e: Exception) {
Log.w(VisibleMessage.TAG, "Couldn't construct visible message proto from: $this")
return null
}
}
val contentProto = SignalServiceProtos.Content.newBuilder()
try {
contentProto.dataMessage = dataMessageProto.build()

@ -129,15 +129,6 @@ class VisibleMessage : Message() {
Recipient.from(context, Address.fromSerialized(recipient!!), false).expireMessages
}
dataMessage.expireTimer = expiration
// Group context
if (storage.isClosedGroup(recipient!!)) {
try {
setGroupContext(dataMessage)
} catch (e: Exception) {
Log.w(TAG, "Couldn't construct visible message proto from: $this")
return null
}
}
// Sync target
if (syncTarget != null) {
dataMessage.syncTarget = syncTarget

@ -83,6 +83,7 @@ public class Recipient implements RecipientModifiedListener {
private @Nullable Uri callRingtone = null;
public long mutedUntil = 0;
public int notifyType = 0;
private boolean autoDownloadAttachments = false;
private boolean blocked = false;
private boolean approved = false;
private boolean approvedMe = false;
@ -161,6 +162,7 @@ public class Recipient implements RecipientModifiedListener {
this.unidentifiedAccessMode = stale.unidentifiedAccessMode;
this.forceSmsSelection = stale.forceSmsSelection;
this.notifyType = stale.notifyType;
this.autoDownloadAttachments = stale.autoDownloadAttachments;
this.participants.clear();
this.participants.addAll(stale.participants);
@ -191,6 +193,7 @@ public class Recipient implements RecipientModifiedListener {
this.unidentifiedAccessMode = details.get().unidentifiedAccessMode;
this.forceSmsSelection = details.get().forceSmsSelection;
this.notifyType = details.get().notifyType;
this.autoDownloadAttachments = details.get().autoDownloadAttachments;
this.participants.clear();
this.participants.addAll(details.get().participants);
@ -227,6 +230,7 @@ public class Recipient implements RecipientModifiedListener {
Recipient.this.unidentifiedAccessMode = result.unidentifiedAccessMode;
Recipient.this.forceSmsSelection = result.forceSmsSelection;
Recipient.this.notifyType = result.notifyType;
Recipient.this.autoDownloadAttachments = result.autoDownloadAttachments;
Recipient.this.participants.clear();
Recipient.this.participants.addAll(result.participants);
@ -264,6 +268,7 @@ public class Recipient implements RecipientModifiedListener {
this.callRingtone = details.callRingtone;
this.mutedUntil = details.mutedUntil;
this.notifyType = details.notifyType;
this.autoDownloadAttachments = details.autoDownloadAttachments;
this.blocked = details.blocked;
this.approved = details.approved;
this.approvedMe = details.approvedMe;
@ -581,6 +586,18 @@ public class Recipient implements RecipientModifiedListener {
notifyListeners();
}
public boolean getAutoDownloadAttachments() {
return autoDownloadAttachments;
}
public void setAutoDownloadAttachments(boolean autoDownloadAttachments) {
synchronized (this) {
this.autoDownloadAttachments = autoDownloadAttachments;
}
notifyListeners();
}
public synchronized boolean isBlocked() {
return blocked;
}
@ -829,6 +846,7 @@ public class Recipient implements RecipientModifiedListener {
private final boolean approvedMe;
private final long muteUntil;
private final int notifyType;
private final boolean autoDownloadAttachments;
private final VibrateState messageVibrateState;
private final VibrateState callVibrateState;
private final Uri messageRingtone;
@ -851,6 +869,7 @@ public class Recipient implements RecipientModifiedListener {
public RecipientSettings(boolean blocked, boolean approved, boolean approvedMe, long muteUntil,
int notifyType,
boolean autoDownloadAttachments,
@NonNull VibrateState messageVibrateState,
@NonNull VibrateState callVibrateState,
@Nullable Uri messageRingtone,
@ -876,6 +895,7 @@ public class Recipient implements RecipientModifiedListener {
this.approvedMe = approvedMe;
this.muteUntil = muteUntil;
this.notifyType = notifyType;
this.autoDownloadAttachments = autoDownloadAttachments;
this.messageVibrateState = messageVibrateState;
this.callVibrateState = callVibrateState;
this.messageRingtone = messageRingtone;
@ -921,6 +941,10 @@ public class Recipient implements RecipientModifiedListener {
return notifyType;
}
public boolean getAutoDownloadAttachments() {
return autoDownloadAttachments;
}
public @NonNull VibrateState getMessageVibrateState() {
return messageVibrateState;
}

@ -159,6 +159,7 @@ class RecipientProvider {
@Nullable final Uri callRingtone;
final long mutedUntil;
final int notifyType;
final boolean autoDownloadAttachments;
@Nullable final VibrateState messageVibrateState;
@Nullable final VibrateState callVibrateState;
final boolean blocked;
@ -191,6 +192,7 @@ class RecipientProvider {
this.callRingtone = settings != null ? settings.getCallRingtone() : null;
this.mutedUntil = settings != null ? settings.getMuteUntil() : 0;
this.notifyType = settings != null ? settings.getNotifyType() : 0;
this.autoDownloadAttachments = settings != null && settings.getAutoDownloadAttachments();
this.messageVibrateState = settings != null ? settings.getMessageVibrateState() : null;
this.callVibrateState = settings != null ? settings.getCallVibrateState() : null;
this.blocked = settings != null && settings.isBlocked();

@ -171,7 +171,6 @@ message DataMessage {
optional string body = 1;
repeated AttachmentPointer attachments = 2;
optional GroupContext group = 3;
optional uint32 flags = 4;
optional uint32 expireTimer = 5;
optional bytes profileKey = 6;
@ -288,23 +287,3 @@ message AttachmentPointer {
optional string caption = 11;
optional string url = 101;
}
message GroupContext {
enum Type {
UNKNOWN = 0;
UPDATE = 1;
DELIVER = 2;
QUIT = 3;
REQUEST_INFO = 4;
}
// @required
optional bytes id = 1;
// @required
optional Type type = 2;
optional string name = 3;
repeated string members = 4;
optional AttachmentPointer avatar = 5;
repeated string admins = 6;
}

Loading…
Cancel
Save