mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 16:57:50 +00:00
Make group chats a bit more future proof
This commit is contained in:
parent
717a28a446
commit
eb9537f1c1
@ -406,9 +406,9 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
|
||||
if (lokiLongPoller != null) return;
|
||||
String userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(this);
|
||||
if (userHexEncodedPublicKey == null) return;
|
||||
LokiAPIDatabase database = DatabaseFactory.getLokiAPIDatabase(this);
|
||||
LokiAPIDatabase lokiAPIDatabase = DatabaseFactory.getLokiAPIDatabase(this);
|
||||
Context context = this;
|
||||
lokiLongPoller = new LokiLongPoller(userHexEncodedPublicKey, database, new Function1<List<SignalServiceProtos.Envelope>, Unit>() {
|
||||
lokiLongPoller = new LokiLongPoller(userHexEncodedPublicKey, lokiAPIDatabase, new Function1<List<SignalServiceProtos.Envelope>, Unit>() {
|
||||
|
||||
@Override
|
||||
public Unit invoke(List<SignalServiceProtos.Envelope> protos) {
|
||||
@ -430,7 +430,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
|
||||
lokiGroupChatPoller = new LokiGroupChatPoller(this, LokiGroupChatAPI.getPublicChatID());
|
||||
boolean isPublicChatSetUp = TextSecurePreferences.isPublicChatSetUp(this);
|
||||
if (isPublicChatSetUp) return;
|
||||
String id = "loki-group-chat-" + LokiGroupChatAPI.getPublicChatID();
|
||||
String id = LokiGroupChatAPI.getServerURL() + "." + LokiGroupChatAPI.getPublicChatID();
|
||||
GroupManager.createGroup(id, this, new HashSet<>(), null, "Loki Public Chat", false);
|
||||
TextSecurePreferences.markPublicChatSetUp(this);
|
||||
}
|
||||
|
@ -2872,7 +2872,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
try {
|
||||
messageSender.sendMessage(0, address, Optional.absent(), message); // The message ID doesn't matter
|
||||
DatabaseFactory.getLokiThreadDatabase(context).setFriendRequestStatus(this.threadId, LokiThreadFriendRequestStatus.FRIENDS);
|
||||
DatabaseFactory.getLokiMessageFriendRequestDatabase(context).setFriendRequestStatus(friendRequest.id, LokiMessageFriendRequestStatus.REQUEST_ACCEPTED);
|
||||
DatabaseFactory.getLokiMessageDatabase(context).setFriendRequestStatus(friendRequest.id, LokiMessageFriendRequestStatus.REQUEST_ACCEPTED);
|
||||
} catch (Exception e) {
|
||||
Log.d("Loki", "Failed to send background message to: " + contactID + ".");
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ import org.thoughtcrime.securesms.linkpreview.LinkPreviewUtil;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.loki.FriendRequestView;
|
||||
import org.thoughtcrime.securesms.loki.FriendRequestViewDelegate;
|
||||
import org.thoughtcrime.securesms.loki.LokiMessageFriendRequestDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiMessageDatabase;
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests;
|
||||
import org.thoughtcrime.securesms.mms.ImageSlide;
|
||||
import org.thoughtcrime.securesms.mms.PartAuthority;
|
||||
@ -979,8 +979,8 @@ public class ConversationItem extends LinearLayout
|
||||
int spacingBottom = spacingTop;
|
||||
|
||||
boolean isOutgoingStack = current.isOutgoing() && previous.orNull() != null && previous.get().isOutgoing();
|
||||
LokiMessageFriendRequestDatabase friendRequestDatabase = DatabaseFactory.getLokiMessageFriendRequestDatabase(context);
|
||||
boolean isPreviousMessageFriendRequest = previous.orNull() != null && friendRequestDatabase.isFriendRequest(previous.get().id);
|
||||
LokiMessageDatabase lokiMessageDatabase = DatabaseFactory.getLokiMessageDatabase(context);
|
||||
boolean isPreviousMessageFriendRequest = previous.orNull() != null && lokiMessageDatabase.isFriendRequest(previous.get().id);
|
||||
|
||||
if (isOutgoingStack && isPreviousMessageFriendRequest) {
|
||||
spacingTop = readDimen(context, R.dimen.conversation_vertical_message_spacing_default);
|
||||
|
@ -34,9 +34,9 @@ import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
|
||||
import org.thoughtcrime.securesms.loki.LokiAPIDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiPreKeyRecordDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiPreKeyBundleDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiMessageFriendRequestDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiMessageDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiThreadDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiUserDisplayNameDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiUserDatabase;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
|
||||
public class DatabaseFactory {
|
||||
@ -70,9 +70,9 @@ public class DatabaseFactory {
|
||||
private final LokiAPIDatabase lokiAPIDatabase;
|
||||
private final LokiPreKeyRecordDatabase lokiContactPreKeyDatabase;
|
||||
private final LokiPreKeyBundleDatabase lokiPreKeyBundleDatabase;
|
||||
private final LokiMessageFriendRequestDatabase lokiMessageFriendRequestDatabase;
|
||||
private final LokiMessageDatabase lokiMessageDatabase;
|
||||
private final LokiThreadDatabase lokiThreadDatabase;
|
||||
private final LokiUserDisplayNameDatabase lokiUserDisplayNameDatabase;
|
||||
private final LokiUserDatabase lokiUserDatabase;
|
||||
|
||||
public static DatabaseFactory getInstance(Context context) {
|
||||
synchronized (lock) {
|
||||
@ -176,16 +176,16 @@ public class DatabaseFactory {
|
||||
return getInstance(context).lokiPreKeyBundleDatabase;
|
||||
}
|
||||
|
||||
public static LokiMessageFriendRequestDatabase getLokiMessageFriendRequestDatabase(Context context) {
|
||||
return getInstance(context).lokiMessageFriendRequestDatabase;
|
||||
public static LokiMessageDatabase getLokiMessageDatabase(Context context) {
|
||||
return getInstance(context).lokiMessageDatabase;
|
||||
}
|
||||
|
||||
public static LokiThreadDatabase getLokiThreadDatabase(Context context) {
|
||||
return getInstance(context).lokiThreadDatabase;
|
||||
}
|
||||
|
||||
public static LokiUserDisplayNameDatabase getLokiUserDisplayNameDatabase(Context context) {
|
||||
return getInstance(context).lokiUserDisplayNameDatabase;
|
||||
public static LokiUserDatabase getLokiUserDatabase(Context context) {
|
||||
return getInstance(context).lokiUserDatabase;
|
||||
}
|
||||
// endregion
|
||||
|
||||
@ -223,9 +223,9 @@ public class DatabaseFactory {
|
||||
this.lokiAPIDatabase = new LokiAPIDatabase(context, databaseHelper);
|
||||
this.lokiContactPreKeyDatabase = new LokiPreKeyRecordDatabase(context, databaseHelper);
|
||||
this.lokiPreKeyBundleDatabase = new LokiPreKeyBundleDatabase(context, databaseHelper);
|
||||
this.lokiMessageFriendRequestDatabase = new LokiMessageFriendRequestDatabase(context, databaseHelper);
|
||||
this.lokiMessageDatabase = new LokiMessageDatabase(context, databaseHelper);
|
||||
this.lokiThreadDatabase = new LokiThreadDatabase(context, databaseHelper);
|
||||
this.lokiUserDisplayNameDatabase = new LokiUserDisplayNameDatabase(context, databaseHelper);
|
||||
this.lokiUserDatabase = new LokiUserDatabase(context, databaseHelper);
|
||||
}
|
||||
|
||||
public void onApplicationLevelUpgrade(@NonNull Context context, @NonNull MasterSecret masterSecret,
|
||||
|
@ -531,11 +531,6 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
updateMessageBodyAndType(messageId, body, Types.ENCRYPTION_MASK, type);
|
||||
}
|
||||
|
||||
public void updateMessageID(long oldMessageID, long newMessageID) {
|
||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||
db.execSQL("UPDATE " + TABLE_NAME + " SET " + ID + " = ? WHERE " + ID + " = ?", new String[] { newMessageID + "", oldMessageID + "" });
|
||||
}
|
||||
|
||||
private Pair<Long, Long> updateMessageBodyAndType(long messageId, String body, long maskOff, long maskOn) {
|
||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||
db.execSQL("UPDATE " + TABLE_NAME + " SET " + BODY + " = ?, " +
|
||||
|
@ -891,7 +891,7 @@ public class SmsDatabase extends MessagingDatabase {
|
||||
Recipient recipient = Recipient.from(context, address, true);
|
||||
|
||||
// Loki - Check to see if this message was a friend request
|
||||
boolean isFriendRequest = DatabaseFactory.getLokiMessageFriendRequestDatabase(context).isFriendRequest(messageId);
|
||||
boolean isFriendRequest = DatabaseFactory.getLokiMessageDatabase(context).isFriendRequest(messageId);
|
||||
|
||||
return new SmsMessageRecord(messageId, body, recipient,
|
||||
recipient,
|
||||
|
@ -37,10 +37,10 @@ import org.thoughtcrime.securesms.jobs.RefreshPreKeysJob;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.loki.LokiAPIDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiPreKeyRecordDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiMessageFriendRequestDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiMessageDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiPreKeyBundleDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiThreadDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiUserDisplayNameDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiUserDatabase;
|
||||
import org.thoughtcrime.securesms.notifications.NotificationChannels;
|
||||
import org.thoughtcrime.securesms.service.KeyCachingService;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
@ -126,10 +126,10 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
|
||||
db.execSQL(LokiAPIDatabase.getCreateReceivedMessageHashValuesTableCommand());
|
||||
db.execSQL(LokiPreKeyBundleDatabase.getCreateTableCommand());
|
||||
db.execSQL(LokiPreKeyRecordDatabase.getCreateTableCommand());
|
||||
db.execSQL(LokiMessageFriendRequestDatabase.getCreateTableCommand());
|
||||
db.execSQL(LokiMessageDatabase.getCreateTableCommand());
|
||||
db.execSQL(LokiThreadDatabase.getCreateFriendRequestTableCommand());
|
||||
db.execSQL(LokiThreadDatabase.getCreateSessionResetTableCommand());
|
||||
db.execSQL(LokiUserDisplayNameDatabase.getCreateTableCommand());
|
||||
db.execSQL(LokiUserDatabase.getCreateTableCommand());
|
||||
|
||||
executeStatements(db, SmsDatabase.CREATE_INDEXS);
|
||||
executeStatements(db, MmsDatabase.CREATE_INDEXS);
|
||||
|
@ -155,9 +155,10 @@ public class SignalCommunicationModule {
|
||||
TextSecurePreferences.getLocalNumber(context),
|
||||
DatabaseFactory.getLokiAPIDatabase(context),
|
||||
DatabaseFactory.getLokiThreadDatabase(context),
|
||||
DatabaseFactory.getLokiMessageFriendRequestDatabase(context),
|
||||
DatabaseFactory.getLokiMessageDatabase(context),
|
||||
DatabaseFactory.getLokiPreKeyBundleDatabase(context),
|
||||
new TextSecureSessionStore(context));
|
||||
new TextSecureSessionStore(context),
|
||||
DatabaseFactory.getLokiUserDatabase(context));
|
||||
} else {
|
||||
this.messageSender.setMessagePipe(IncomingMessageObserver.getPipe(), IncomingMessageObserver.getUnidentifiedPipe());
|
||||
this.messageSender.setIsMultiDevice(TextSecurePreferences.isMultiDevice(context));
|
||||
|
@ -68,7 +68,7 @@ import org.thoughtcrime.securesms.linkpreview.Link;
|
||||
import org.thoughtcrime.securesms.linkpreview.LinkPreview;
|
||||
import org.thoughtcrime.securesms.linkpreview.LinkPreviewUtil;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.loki.LokiMessageFriendRequestDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiMessageDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiPreKeyBundleDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiPreKeyRecordDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiThreadDatabase;
|
||||
@ -280,9 +280,9 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
Log.d("Loki", "Received a pre key bundle from: " + envelope.getSource() + ".");
|
||||
int registrationID = TextSecurePreferences.getLocalRegistrationId(context);
|
||||
if (registrationID > 0) {
|
||||
LokiPreKeyBundleDatabase preKeyBundleDatabase = DatabaseFactory.getLokiPreKeyBundleDatabase(context);
|
||||
LokiPreKeyBundleDatabase lokiPreKeyBundleDatabase = DatabaseFactory.getLokiPreKeyBundleDatabase(context);
|
||||
PreKeyBundle preKeyBundle = lokiMessage.getPreKeyBundleMessage().getPreKeyBundle(registrationID);
|
||||
preKeyBundleDatabase.setPreKeyBundle(envelope.getSource(), preKeyBundle);
|
||||
lokiPreKeyBundleDatabase.setPreKeyBundle(envelope.getSource(), preKeyBundle);
|
||||
}
|
||||
}
|
||||
if (lokiMessage.getAddressMessage() != null) {
|
||||
@ -293,7 +293,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
// Loki - Get the sender display name if needed
|
||||
Optional<String> senderDisplayName = content.senderDisplayName;
|
||||
if (senderDisplayName.isPresent()) {
|
||||
DatabaseFactory.getLokiUserDisplayNameDatabase(context).setDisplayName(envelope.getSource(), senderDisplayName.get());
|
||||
DatabaseFactory.getLokiUserDatabase(context).setDisplayName(envelope.getSource(), senderDisplayName.get());
|
||||
}
|
||||
|
||||
if (content.getDataMessage().isPresent()) {
|
||||
@ -938,28 +938,28 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
// If we get anything other than a friend request, we can assume that we have a session with the other user
|
||||
if (envelope.isFriendRequest()) { return; }
|
||||
Recipient contactID = Recipient.from(context, Address.fromSerialized(content.getSender()), false);
|
||||
LokiThreadDatabase threadDatabase = DatabaseFactory.getLokiThreadDatabase(context);
|
||||
LokiThreadDatabase lokiThreadDatabase = DatabaseFactory.getLokiThreadDatabase(context);
|
||||
long threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdIfExistsFor(contactID);
|
||||
LokiThreadFriendRequestStatus threadFriendRequestStatus = threadDatabase.getFriendRequestStatus(threadID);
|
||||
LokiThreadFriendRequestStatus threadFriendRequestStatus = lokiThreadDatabase.getFriendRequestStatus(threadID);
|
||||
if (threadFriendRequestStatus == LokiThreadFriendRequestStatus.FRIENDS) { return; }
|
||||
SmsDatabase messageDatabase = DatabaseFactory.getSmsDatabase(context);
|
||||
LokiMessageFriendRequestDatabase messageFriendRequestDatabase = DatabaseFactory.getLokiMessageFriendRequestDatabase(context);
|
||||
LokiMessageDatabase lokiMessageDatabase = DatabaseFactory.getLokiMessageDatabase(context);
|
||||
int messageCount = messageDatabase.getMessageCountForThread(threadID);
|
||||
// If the thread's friend request status is not `FRIENDS`, but we're receiving a message,
|
||||
// it must be a friend request accepted message. Declining a friend request doesn't send a message.
|
||||
threadDatabase.setFriendRequestStatus(threadID, LokiThreadFriendRequestStatus.FRIENDS);
|
||||
lokiThreadDatabase.setFriendRequestStatus(threadID, LokiThreadFriendRequestStatus.FRIENDS);
|
||||
long messageID = messageDatabase.getIDForMessageAtIndex(threadID, messageCount - 1);
|
||||
messageFriendRequestDatabase.setFriendRequestStatus(messageID, LokiMessageFriendRequestStatus.REQUEST_ACCEPTED);
|
||||
lokiMessageDatabase.setFriendRequestStatus(messageID, LokiMessageFriendRequestStatus.REQUEST_ACCEPTED);
|
||||
}
|
||||
|
||||
private void updateFriendRequestStatusIfNeeded(@NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceContent content, @NonNull SignalServiceDataMessage message) {
|
||||
if (!envelope.isFriendRequest()) { return; }
|
||||
Recipient contactID = getMessageDestination(content, message);
|
||||
LokiThreadDatabase threadDatabase = DatabaseFactory.getLokiThreadDatabase(context);
|
||||
LokiThreadDatabase lokiThreadDatabase = DatabaseFactory.getLokiThreadDatabase(context);
|
||||
long threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdIfExistsFor(contactID);
|
||||
LokiThreadFriendRequestStatus threadFriendRequestStatus = threadDatabase.getFriendRequestStatus(threadID);
|
||||
LokiThreadFriendRequestStatus threadFriendRequestStatus = lokiThreadDatabase.getFriendRequestStatus(threadID);
|
||||
SmsDatabase messageDatabase = DatabaseFactory.getSmsDatabase(context);
|
||||
LokiMessageFriendRequestDatabase messageFriendRequestDatabase = DatabaseFactory.getLokiMessageFriendRequestDatabase(context);
|
||||
LokiMessageDatabase lokiMessageDatabase= DatabaseFactory.getLokiMessageDatabase(context);
|
||||
int messageCount = messageDatabase.getMessageCountForThread(threadID);
|
||||
if (threadFriendRequestStatus == LokiThreadFriendRequestStatus.REQUEST_SENT) {
|
||||
// This can happen if Alice sent Bob a friend request, Bob declined, but then Bob changed his
|
||||
@ -972,9 +972,9 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
// before updating Alice's thread's friend request status to `FRIENDS`,
|
||||
// we can end up in a deadlock where both users' threads' friend request statuses are
|
||||
// `REQUEST_SENT`.
|
||||
threadDatabase.setFriendRequestStatus(threadID, LokiThreadFriendRequestStatus.FRIENDS);
|
||||
lokiThreadDatabase.setFriendRequestStatus(threadID, LokiThreadFriendRequestStatus.FRIENDS);
|
||||
long messageID = messageDatabase.getIDForMessageAtIndex(threadID, messageCount - 2); // The message before the one that was just received
|
||||
messageFriendRequestDatabase.setFriendRequestStatus(messageID, LokiMessageFriendRequestStatus.REQUEST_ACCEPTED);
|
||||
lokiMessageDatabase.setFriendRequestStatus(messageID, LokiMessageFriendRequestStatus.REQUEST_ACCEPTED);
|
||||
// Accept the friend request
|
||||
sendBackgroundMessage(content.getSender());
|
||||
} else if (threadFriendRequestStatus != LokiThreadFriendRequestStatus.FRIENDS) {
|
||||
@ -983,9 +983,9 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
// friend request status is reset to `NONE`. Bob now sends Alice a friend
|
||||
// request. Alice's thread's friend request status is reset to
|
||||
// `REQUEST_RECEIVED`.
|
||||
threadDatabase.setFriendRequestStatus(threadID, LokiThreadFriendRequestStatus.REQUEST_RECEIVED);
|
||||
lokiThreadDatabase.setFriendRequestStatus(threadID, LokiThreadFriendRequestStatus.REQUEST_RECEIVED);
|
||||
long messageID = messageDatabase.getIDForMessageAtIndex(threadID, messageCount - 1); // The message that was just received
|
||||
messageFriendRequestDatabase.setFriendRequestStatus(messageID, LokiMessageFriendRequestStatus.REQUEST_PENDING);
|
||||
lokiMessageDatabase.setFriendRequestStatus(messageID, LokiMessageFriendRequestStatus.REQUEST_PENDING);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,7 @@ import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
|
||||
import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
import org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext;
|
||||
import org.whispersystems.signalservice.loki.api.LokiGroupChatAPI;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@ -278,7 +279,7 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType {
|
||||
|
||||
private @NonNull List<Address> getGroupMessageRecipients(String groupId, long messageId) {
|
||||
ArrayList<Address> result = new ArrayList<>();
|
||||
result.add(Address.fromSerialized("network.loki.messenger.publicChat"));
|
||||
result.add(Address.fromSerialized(LokiGroupChatAPI.getServerURL()));
|
||||
return result;
|
||||
|
||||
/*
|
||||
|
@ -28,9 +28,9 @@ class BackgroundPollWorker : PersistentAlarmManagerListener() {
|
||||
override fun onAlarm(context: Context, scheduledTime: Long): Long {
|
||||
if (scheduledTime != 0L) {
|
||||
val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context)
|
||||
val apiDatabase = DatabaseFactory.getLokiAPIDatabase(context)
|
||||
val lokiAPIDatabase = DatabaseFactory.getLokiAPIDatabase(context)
|
||||
try {
|
||||
LokiAPI(userHexEncodedPublicKey, apiDatabase).getMessages().get().forEach {
|
||||
LokiAPI(userHexEncodedPublicKey, lokiAPIDatabase).getMessages().get().forEach {
|
||||
PushContentReceiveJob(context).processEnvelope(SignalServiceEnvelope(it))
|
||||
}
|
||||
} catch (exception: Throwable) {
|
||||
|
@ -106,13 +106,13 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In
|
||||
|
||||
private fun updateUI() {
|
||||
val message = message
|
||||
val database = DatabaseFactory.getLokiMessageFriendRequestDatabase(context)
|
||||
val lokiMessageDatabase = DatabaseFactory.getLokiMessageDatabase(context)
|
||||
val contactID = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(message!!.threadId)!!.address.toString()
|
||||
val contactDisplayName = DatabaseFactory.getLokiUserDisplayNameDatabase(context).getDisplayName(contactID) ?: contactID
|
||||
val contactDisplayName = DatabaseFactory.getLokiUserDatabase(context).getDisplayName(contactID) ?: contactID
|
||||
if (message is MediaMmsMessageRecord && message.quote != null) { visibility = View.GONE; return }
|
||||
val isTextMessage = message is SmsMessageRecord
|
||||
if (!isTextMessage) return
|
||||
val friendRequestStatus = database.getFriendRequestStatus(message.id)
|
||||
val friendRequestStatus = lokiMessageDatabase.getFriendRequestStatus(message.id)
|
||||
if (!message.isOutgoing) {
|
||||
visibility = if (friendRequestStatus == LokiMessageFriendRequestStatus.NONE) View.GONE else View.VISIBLE
|
||||
buttonLinearLayout.visibility = if (friendRequestStatus != LokiMessageFriendRequestStatus.REQUEST_PENDING) View.GONE else View.VISIBLE
|
||||
@ -147,15 +147,15 @@ class FriendRequestView(context: Context, attrs: AttributeSet?, defStyleAttr: In
|
||||
|
||||
// region Interaction
|
||||
private fun accept() {
|
||||
val database = DatabaseFactory.getLokiMessageFriendRequestDatabase(context)
|
||||
database.setFriendRequestStatus(message!!.id, LokiMessageFriendRequestStatus.REQUEST_SENDING)
|
||||
val lokiMessageDatabase = DatabaseFactory.getLokiMessageDatabase(context)
|
||||
lokiMessageDatabase.setFriendRequestStatus(message!!.id, LokiMessageFriendRequestStatus.REQUEST_SENDING)
|
||||
updateUI()
|
||||
delegate?.acceptFriendRequest(message!!)
|
||||
}
|
||||
|
||||
private fun reject() {
|
||||
val database = DatabaseFactory.getLokiMessageFriendRequestDatabase(context)
|
||||
database.setFriendRequestStatus(message!!.id, LokiMessageFriendRequestStatus.REQUEST_REJECTED)
|
||||
val lokiMessageDatabase = DatabaseFactory.getLokiMessageDatabase(context)
|
||||
lokiMessageDatabase.setFriendRequestStatus(message!!.id, LokiMessageFriendRequestStatus.REQUEST_REJECTED)
|
||||
updateUI()
|
||||
delegate?.rejectFriendRequest(message!!)
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package org.thoughtcrime.securesms.loki
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import org.thoughtcrime.securesms.database.Database
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||
import org.whispersystems.signalservice.loki.api.LokiAPIDatabaseProtocol
|
||||
@ -78,15 +77,6 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
|
||||
val row = wrap(mapOf( userID to userPublicKey, receivedMessageHashValues to receivedMessageHashValuesAsString ))
|
||||
database.insertOrUpdate(receivedMessageHashValuesCache, row, "$userID = ?", wrap(userPublicKey))
|
||||
}
|
||||
|
||||
override fun getUserDisplayName(): String? {
|
||||
return TextSecurePreferences.getProfileName(context)
|
||||
}
|
||||
|
||||
override fun updateMessageIDIfNeeded(signalID: Long, lokiID: Long) {
|
||||
if (signalID == lokiID) return
|
||||
DatabaseFactory.getMmsDatabase(context).updateMessageID(signalID, lokiID)
|
||||
}
|
||||
}
|
||||
|
||||
// region Convenience
|
||||
|
@ -41,10 +41,10 @@ class LokiGroupChatPoller(private val context: Context, private val groupID: Lon
|
||||
|
||||
private fun poll() {
|
||||
val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context)
|
||||
val database = DatabaseFactory.getLokiAPIDatabase(context)
|
||||
LokiGroupChatAPI(userHexEncodedPublicKey, database).getMessages(groupID).success { messages ->
|
||||
val lokiUserDatabase = DatabaseFactory.getLokiUserDatabase(context)
|
||||
LokiGroupChatAPI(userHexEncodedPublicKey, lokiUserDatabase).getMessages(groupID).success { messages ->
|
||||
messages.map { message ->
|
||||
val id = "loki-group-chat-$groupID".toByteArray()
|
||||
val id = "${LokiGroupChatAPI.serverURL}.$groupID".toByteArray()
|
||||
val x1 = SignalServiceGroup(SignalServiceGroup.Type.UPDATE, id, null, null, null)
|
||||
val x2 = SignalServiceDataMessage(message.timestamp, x1, null, message.body)
|
||||
val senderDisplayName = "${message.displayName} (...${message.hexEncodedPublicKey.takeLast(8)})"
|
||||
|
@ -8,13 +8,22 @@ import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiMessageDatabaseProtocol
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiMessageFriendRequestStatus
|
||||
|
||||
class LokiMessageFriendRequestDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper), LokiMessageDatabaseProtocol {
|
||||
class LokiMessageDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper), LokiMessageDatabaseProtocol {
|
||||
|
||||
companion object {
|
||||
private val tableName = "loki_message_friend_request_database"
|
||||
private val messageID = "message_id"
|
||||
private val serverID = "server_id"
|
||||
private val friendRequestStatus = "friend_request_status"
|
||||
@JvmStatic val createTableCommand = "CREATE TABLE $tableName ($messageID INTEGER PRIMARY KEY, $friendRequestStatus INTEGER DEFAULT 0);"
|
||||
@JvmStatic val createTableCommand = "CREATE TABLE $tableName ($messageID INTEGER PRIMARY KEY, $serverID INTEGER DEFAULT 0, $friendRequestStatus INTEGER DEFAULT 0);"
|
||||
}
|
||||
|
||||
override fun setServerID(messageID: Long, serverID: Long) {
|
||||
val database = databaseHelper.writableDatabase
|
||||
val contentValues = ContentValues(2)
|
||||
contentValues.put(Companion.messageID, messageID)
|
||||
contentValues.put(Companion.serverID, serverID)
|
||||
database.insertOrUpdate(tableName, contentValues, "${Companion.messageID} = ?", arrayOf( messageID.toString() ))
|
||||
}
|
||||
|
||||
override fun getFriendRequestStatus(messageID: Long): LokiMessageFriendRequestStatus {
|
@ -6,8 +6,10 @@ import org.thoughtcrime.securesms.database.Address
|
||||
import org.thoughtcrime.securesms.database.Database
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiUserDatabaseProtocol
|
||||
|
||||
class LokiUserDisplayNameDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) {
|
||||
class LokiUserDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper), LokiUserDatabaseProtocol {
|
||||
|
||||
companion object {
|
||||
private val tableName = "loki_user_display_name_database"
|
||||
@ -16,10 +18,14 @@ class LokiUserDisplayNameDatabase(context: Context, helper: SQLCipherOpenHelper)
|
||||
@JvmStatic val createTableCommand = "CREATE TABLE $tableName ($hexEncodedPublicKey TEXT PRIMARY KEY, $displayName TEXT);"
|
||||
}
|
||||
|
||||
fun getDisplayName(hexEncodedPublicKey: String): String? {
|
||||
val database = databaseHelper.readableDatabase
|
||||
return database.get(tableName, "${Companion.hexEncodedPublicKey} = ?", arrayOf( hexEncodedPublicKey )) { cursor ->
|
||||
cursor.getString(cursor.getColumnIndexOrThrow(displayName))
|
||||
override fun getDisplayName(hexEncodedPublicKey: String): String? {
|
||||
if (hexEncodedPublicKey == TextSecurePreferences.getLocalNumber(context)) {
|
||||
return TextSecurePreferences.getProfileName(context)
|
||||
} else {
|
||||
val database = databaseHelper.readableDatabase
|
||||
return database.get(tableName, "${Companion.hexEncodedPublicKey} = ?", arrayOf(hexEncodedPublicKey)) { cursor ->
|
||||
cursor.getString(cursor.getColumnIndexOrThrow(displayName))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -86,9 +86,9 @@ public class MarkReadReceiver extends BroadcastReceiver {
|
||||
.collect(Collectors.groupingBy(SyncMessageId::getAddress));
|
||||
|
||||
for (Address address : addressMap.keySet()) {
|
||||
LokiThreadDatabase threadDatabase = DatabaseFactory.getLokiThreadDatabase(context);
|
||||
long threadID = threadDatabase.getThreadID(address.serialize());
|
||||
LokiThreadFriendRequestStatus friendRequestStatus = threadDatabase.getFriendRequestStatus(threadID);
|
||||
LokiThreadDatabase lokiThreadDatabase = DatabaseFactory.getLokiThreadDatabase(context);
|
||||
long threadID = lokiThreadDatabase.getThreadID(address.serialize());
|
||||
LokiThreadFriendRequestStatus friendRequestStatus = lokiThreadDatabase.getFriendRequestStatus(threadID);
|
||||
if (friendRequestStatus != LokiThreadFriendRequestStatus.FRIENDS) { return; }
|
||||
|
||||
List<Long> timestamps = Stream.of(addressMap.get(address)).map(SyncMessageId::getTimetamp).toList();
|
||||
|
@ -26,7 +26,6 @@ import android.text.TextUtils;
|
||||
|
||||
import com.annimon.stream.function.Consumer;
|
||||
|
||||
import network.loki.messenger.R;
|
||||
import org.thoughtcrime.securesms.color.MaterialColor;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.ContactColors;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.ContactPhoto;
|
||||
@ -60,6 +59,8 @@ import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import network.loki.messenger.R;
|
||||
|
||||
public class Recipient implements RecipientModifiedListener {
|
||||
|
||||
private static final String TAG = Recipient.class.getSimpleName();
|
||||
@ -292,7 +293,7 @@ public class Recipient implements RecipientModifiedListener {
|
||||
}
|
||||
|
||||
public synchronized @Nullable String getName() {
|
||||
String displayName = DatabaseFactory.getLokiUserDisplayNameDatabase(context).getDisplayName(this.address.toString());
|
||||
String displayName = DatabaseFactory.getLokiUserDatabase(context).getDisplayName(this.address.toString());
|
||||
if (displayName != null) { return displayName; }
|
||||
|
||||
if (this.name == null && isMmsGroupRecipient()) {
|
||||
|
@ -79,7 +79,7 @@ public class MessageSender {
|
||||
|
||||
// Loki - Set the message's friend request status as soon as it has hit the database
|
||||
if (message.isFriendRequest) {
|
||||
DatabaseFactory.getLokiMessageFriendRequestDatabase(context).setFriendRequestStatus(messageId, LokiMessageFriendRequestStatus.REQUEST_SENDING);
|
||||
DatabaseFactory.getLokiMessageDatabase(context).setFriendRequestStatus(messageId, LokiMessageFriendRequestStatus.REQUEST_SENDING);
|
||||
}
|
||||
|
||||
sendTextMessage(context, recipient, forceSms, keyExchange, messageId);
|
||||
|
Loading…
x
Reference in New Issue
Block a user