mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 09:17:44 +00:00
Always send a friend request if we're not friends.
Pass down isFriendRequest to message sender.
This commit is contained in:
parent
2c35ed2177
commit
7d33a9cc8f
@ -146,6 +146,7 @@ import org.thoughtcrime.securesms.giph.ui.GiphyActivity;
|
|||||||
import org.thoughtcrime.securesms.linkpreview.LinkPreview;
|
import org.thoughtcrime.securesms.linkpreview.LinkPreview;
|
||||||
import org.thoughtcrime.securesms.linkpreview.LinkPreviewRepository;
|
import org.thoughtcrime.securesms.linkpreview.LinkPreviewRepository;
|
||||||
import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel;
|
import org.thoughtcrime.securesms.linkpreview.LinkPreviewViewModel;
|
||||||
|
import org.thoughtcrime.securesms.loki.LokiFriendRequestMessage;
|
||||||
import org.thoughtcrime.securesms.mediasend.MediaSendActivity;
|
import org.thoughtcrime.securesms.mediasend.MediaSendActivity;
|
||||||
import org.thoughtcrime.securesms.mediasend.Media;
|
import org.thoughtcrime.securesms.mediasend.Media;
|
||||||
import org.thoughtcrime.securesms.jobs.MultiDeviceBlockedUpdateJob;
|
import org.thoughtcrime.securesms.jobs.MultiDeviceBlockedUpdateJob;
|
||||||
@ -2147,6 +2148,10 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
ApplicationContext.getInstance(context).getTypingStatusSender().onTypingStopped(threadId);
|
ApplicationContext.getInstance(context).getTypingStatusSender().onTypingStopped(threadId);
|
||||||
} else {
|
} else {
|
||||||
message = new OutgoingTextMessage(recipient, messageBody, expiresIn, subscriptionId);
|
message = new OutgoingTextMessage(recipient, messageBody, expiresIn, subscriptionId);
|
||||||
|
|
||||||
|
// Loki - Always send friend requests if we're not friends with the user
|
||||||
|
int friendRequestStatus = DatabaseFactory.getThreadDatabase(context).getFriendRequestStatus(threadId);
|
||||||
|
message.setIsFriendRequest(friendRequestStatus != ThreadDatabase.LokiFriendRequestStatus.FRIENDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
Permissions.with(this)
|
Permissions.with(this)
|
||||||
|
@ -72,6 +72,9 @@ public class SmsDatabase extends MessagingDatabase {
|
|||||||
public static final String SUBJECT = "subject";
|
public static final String SUBJECT = "subject";
|
||||||
public static final String SERVICE_CENTER = "service_center";
|
public static final String SERVICE_CENTER = "service_center";
|
||||||
|
|
||||||
|
// Loki
|
||||||
|
public static final String IS_FRIEND_REQUEST = "is_friend_request";
|
||||||
|
|
||||||
public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" + ID + " integer PRIMARY KEY, " +
|
public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" + ID + " integer PRIMARY KEY, " +
|
||||||
THREAD_ID + " INTEGER, " + ADDRESS + " TEXT, " + ADDRESS_DEVICE_ID + " INTEGER DEFAULT 1, " + PERSON + " INTEGER, " +
|
THREAD_ID + " INTEGER, " + ADDRESS + " TEXT, " + ADDRESS_DEVICE_ID + " INTEGER DEFAULT 1, " + PERSON + " INTEGER, " +
|
||||||
DATE_RECEIVED + " INTEGER, " + DATE_SENT + " INTEGER, " + PROTOCOL + " INTEGER, " + READ + " INTEGER DEFAULT 0, " +
|
DATE_RECEIVED + " INTEGER, " + DATE_SENT + " INTEGER, " + PROTOCOL + " INTEGER, " + READ + " INTEGER DEFAULT 0, " +
|
||||||
@ -79,7 +82,7 @@ public class SmsDatabase extends MessagingDatabase {
|
|||||||
DELIVERY_RECEIPT_COUNT + " INTEGER DEFAULT 0," + SUBJECT + " TEXT, " + BODY + " TEXT, " +
|
DELIVERY_RECEIPT_COUNT + " INTEGER DEFAULT 0," + SUBJECT + " TEXT, " + BODY + " TEXT, " +
|
||||||
MISMATCHED_IDENTITIES + " TEXT DEFAULT NULL, " + SERVICE_CENTER + " TEXT, " + SUBSCRIPTION_ID + " INTEGER DEFAULT -1, " +
|
MISMATCHED_IDENTITIES + " TEXT DEFAULT NULL, " + SERVICE_CENTER + " TEXT, " + SUBSCRIPTION_ID + " INTEGER DEFAULT -1, " +
|
||||||
EXPIRES_IN + " INTEGER DEFAULT 0, " + EXPIRE_STARTED + " INTEGER DEFAULT 0, " + NOTIFIED + " DEFAULT 0, " +
|
EXPIRES_IN + " INTEGER DEFAULT 0, " + EXPIRE_STARTED + " INTEGER DEFAULT 0, " + NOTIFIED + " DEFAULT 0, " +
|
||||||
READ_RECEIPT_COUNT + " INTEGER DEFAULT 0, " + UNIDENTIFIED + " INTEGER DEFAULT 0);";
|
READ_RECEIPT_COUNT + " INTEGER DEFAULT 0, " + UNIDENTIFIED + " INTEGER DEFAULT 0," + IS_FRIEND_REQUEST + "INTEGER DEFAULT 0);";
|
||||||
|
|
||||||
public static final String[] CREATE_INDEXS = {
|
public static final String[] CREATE_INDEXS = {
|
||||||
"CREATE INDEX IF NOT EXISTS sms_thread_id_index ON " + TABLE_NAME + " (" + THREAD_ID + ");",
|
"CREATE INDEX IF NOT EXISTS sms_thread_id_index ON " + TABLE_NAME + " (" + THREAD_ID + ");",
|
||||||
@ -640,6 +643,7 @@ public class SmsDatabase extends MessagingDatabase {
|
|||||||
contentValues.put(EXPIRES_IN, message.getExpiresIn());
|
contentValues.put(EXPIRES_IN, message.getExpiresIn());
|
||||||
contentValues.put(DELIVERY_RECEIPT_COUNT, Stream.of(earlyDeliveryReceipts.values()).mapToLong(Long::longValue).sum());
|
contentValues.put(DELIVERY_RECEIPT_COUNT, Stream.of(earlyDeliveryReceipts.values()).mapToLong(Long::longValue).sum());
|
||||||
contentValues.put(READ_RECEIPT_COUNT, Stream.of(earlyReadReceipts.values()).mapToLong(Long::longValue).sum());
|
contentValues.put(READ_RECEIPT_COUNT, Stream.of(earlyReadReceipts.values()).mapToLong(Long::longValue).sum());
|
||||||
|
contentValues.put(IS_FRIEND_REQUEST, message.isFriendRequest() ? 1 : 0);
|
||||||
|
|
||||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||||
long messageId = db.insert(TABLE_NAME, ADDRESS, contentValues);
|
long messageId = db.insert(TABLE_NAME, ADDRESS, contentValues);
|
||||||
@ -866,6 +870,7 @@ public class SmsDatabase extends MessagingDatabase {
|
|||||||
long expireStarted = cursor.getLong(cursor.getColumnIndexOrThrow(SmsDatabase.EXPIRE_STARTED));
|
long expireStarted = cursor.getLong(cursor.getColumnIndexOrThrow(SmsDatabase.EXPIRE_STARTED));
|
||||||
String body = cursor.getString(cursor.getColumnIndexOrThrow(SmsDatabase.BODY));
|
String body = cursor.getString(cursor.getColumnIndexOrThrow(SmsDatabase.BODY));
|
||||||
boolean unidentified = cursor.getInt(cursor.getColumnIndexOrThrow(SmsDatabase.UNIDENTIFIED)) == 1;
|
boolean unidentified = cursor.getInt(cursor.getColumnIndexOrThrow(SmsDatabase.UNIDENTIFIED)) == 1;
|
||||||
|
boolean isFriendRequest = cursor.getInt(cursor.getColumnIndexOrThrow(SmsDatabase.IS_FRIEND_REQUEST)) == 1;
|
||||||
|
|
||||||
if (!TextSecurePreferences.isReadReceiptsEnabled(context)) {
|
if (!TextSecurePreferences.isReadReceiptsEnabled(context)) {
|
||||||
readReceiptCount = 0;
|
readReceiptCount = 0;
|
||||||
@ -879,7 +884,7 @@ public class SmsDatabase extends MessagingDatabase {
|
|||||||
addressDeviceId,
|
addressDeviceId,
|
||||||
dateSent, dateReceived, deliveryReceiptCount, type,
|
dateSent, dateReceived, deliveryReceiptCount, type,
|
||||||
threadId, status, mismatches, subscriptionId,
|
threadId, status, mismatches, subscriptionId,
|
||||||
expiresIn, expireStarted, readReceiptCount, unidentified);
|
expiresIn, expireStarted, readReceiptCount, unidentified, isFriendRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<IdentityKeyMismatch> getMismatches(String document) {
|
private List<IdentityKeyMismatch> getMismatches(String document) {
|
||||||
|
@ -36,9 +36,25 @@ import java.util.List;
|
|||||||
* @author Moxie Marlinspike
|
* @author Moxie Marlinspike
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class SmsMessageRecord extends MessageRecord {
|
public class SmsMessageRecord extends MessageRecord {
|
||||||
|
|
||||||
|
// Loki
|
||||||
|
private final boolean isFriendRequest;
|
||||||
|
|
||||||
|
public SmsMessageRecord(long id,
|
||||||
|
String body, Recipient recipient,
|
||||||
|
Recipient individualRecipient,
|
||||||
|
int recipientDeviceId,
|
||||||
|
long dateSent, long dateReceived,
|
||||||
|
int deliveryReceiptCount,
|
||||||
|
long type, long threadId,
|
||||||
|
int status, List<IdentityKeyMismatch> mismatches,
|
||||||
|
int subscriptionId, long expiresIn, long expireStarted,
|
||||||
|
int readReceiptCount, boolean unidentified)
|
||||||
|
{
|
||||||
|
this(id, body, recipient, individualRecipient, recipientDeviceId, dateSent, dateReceived, deliveryReceiptCount, type, threadId, status, mismatches, subscriptionId, expiresIn, expireStarted, readReceiptCount, unidentified, false);
|
||||||
|
}
|
||||||
|
|
||||||
public SmsMessageRecord(long id,
|
public SmsMessageRecord(long id,
|
||||||
String body, Recipient recipient,
|
String body, Recipient recipient,
|
||||||
Recipient individualRecipient,
|
Recipient individualRecipient,
|
||||||
@ -48,18 +64,22 @@ public class SmsMessageRecord extends MessageRecord {
|
|||||||
long type, long threadId,
|
long type, long threadId,
|
||||||
int status, List<IdentityKeyMismatch> mismatches,
|
int status, List<IdentityKeyMismatch> mismatches,
|
||||||
int subscriptionId, long expiresIn, long expireStarted,
|
int subscriptionId, long expiresIn, long expireStarted,
|
||||||
int readReceiptCount, boolean unidentified)
|
int readReceiptCount, boolean unidentified, boolean isFriendRequest)
|
||||||
{
|
{
|
||||||
super(id, body, recipient, individualRecipient, recipientDeviceId,
|
super(id, body, recipient, individualRecipient, recipientDeviceId,
|
||||||
dateSent, dateReceived, threadId, status, deliveryReceiptCount, type,
|
dateSent, dateReceived, threadId, status, deliveryReceiptCount, type,
|
||||||
mismatches, new LinkedList<>(), subscriptionId,
|
mismatches, new LinkedList<>(), subscriptionId,
|
||||||
expiresIn, expireStarted, readReceiptCount, unidentified);
|
expiresIn, expireStarted, readReceiptCount, unidentified);
|
||||||
|
this.isFriendRequest = isFriendRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getType() {
|
public long getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Loki
|
||||||
|
public boolean isFriendRequest() { return isFriendRequest; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SpannableString getDisplayBody(@NonNull Context context) {
|
public SpannableString getDisplayBody(@NonNull Context context) {
|
||||||
if (SmsDatabase.Types.isFailedDecryptType(type)) {
|
if (SmsDatabase.Types.isFailedDecryptType(type)) {
|
||||||
|
@ -170,6 +170,7 @@ public class PushTextSendJob extends PushSendJob implements InjectableType {
|
|||||||
.withExpiration((int)(message.getExpiresIn() / 1000))
|
.withExpiration((int)(message.getExpiresIn() / 1000))
|
||||||
.withProfileKey(profileKey.orNull())
|
.withProfileKey(profileKey.orNull())
|
||||||
.asEndSessionMessage(message.isEndSession())
|
.asEndSessionMessage(message.isEndSession())
|
||||||
|
.asFriendRequest(message.isFriendRequest())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
if (address.getNumber().equals(TextSecurePreferences.getLocalNumber(context))) {
|
if (address.getNumber().equals(TextSecurePreferences.getLocalNumber(context))) {
|
||||||
|
@ -9,6 +9,7 @@ public class OutgoingTextMessage {
|
|||||||
private final String message;
|
private final String message;
|
||||||
private final int subscriptionId;
|
private final int subscriptionId;
|
||||||
private final long expiresIn;
|
private final long expiresIn;
|
||||||
|
private boolean isFriendRequest = false;
|
||||||
|
|
||||||
public OutgoingTextMessage(Recipient recipient, String message, int subscriptionId) {
|
public OutgoingTextMessage(Recipient recipient, String message, int subscriptionId) {
|
||||||
this(recipient, message, 0, subscriptionId);
|
this(recipient, message, 0, subscriptionId);
|
||||||
@ -68,6 +69,9 @@ public class OutgoingTextMessage {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isFriendRequest() { return isFriendRequest; }
|
||||||
|
public void setIsFriendRequest(boolean value) { this.isFriendRequest = value; }
|
||||||
|
|
||||||
public static OutgoingTextMessage from(SmsMessageRecord record) {
|
public static OutgoingTextMessage from(SmsMessageRecord record) {
|
||||||
if (record.isSecure()) {
|
if (record.isSecure()) {
|
||||||
return new OutgoingEncryptedMessage(record.getRecipient(), record.getBody(), record.getExpiresIn());
|
return new OutgoingEncryptedMessage(record.getRecipient(), record.getBody(), record.getExpiresIn());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user