mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 20:15:21 +00:00
Use alternative approach for group message sending
This commit is contained in:
parent
2c3e67e062
commit
04aa7db499
@ -224,8 +224,6 @@ import org.whispersystems.libsignal.util.guava.Optional;
|
||||
import org.whispersystems.signalservice.api.SignalServiceMessageSender;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
import org.whispersystems.signalservice.loki.api.LokiGroupChatAPI;
|
||||
import org.whispersystems.signalservice.loki.api.LokiGroupMessage;
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiMessageFriendRequestStatus;
|
||||
import org.whispersystems.signalservice.loki.messaging.LokiThreadFriendRequestStatus;
|
||||
|
||||
@ -240,7 +238,6 @@ import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import kotlin.Unit;
|
||||
import network.loki.messenger.R;
|
||||
|
||||
import static org.thoughtcrime.securesms.TransportOption.Type;
|
||||
@ -2216,15 +2213,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
final boolean initiating,
|
||||
final boolean clearComposeBox)
|
||||
{
|
||||
boolean isLokiPublicChat = isGroupConversation(); // TODO: Figure out a better way of determining this
|
||||
if (isLokiPublicChat) {
|
||||
try {
|
||||
return sendGroupMessage();
|
||||
} catch (Exception e) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
|
||||
if (!isDefaultSms && (!isSecureText || forceSms)) {
|
||||
showDefaultSmsPrompt();
|
||||
return new SettableFuture<>(null);
|
||||
@ -2292,9 +2280,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
private void sendTextMessage(final boolean forceSms, final long expiresIn, final int subscriptionId, final boolean initiatingConversation)
|
||||
throws InvalidMessageException
|
||||
{
|
||||
boolean isLokiPublicChat = isGroupConversation(); // TODO: Figure out a better way of determining this
|
||||
if (isLokiPublicChat) { sendGroupMessage(); return; }
|
||||
|
||||
if (!isDefaultSms && (!isSecureText || forceSms)) {
|
||||
showDefaultSmsPrompt();
|
||||
return;
|
||||
@ -2900,22 +2885,5 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
String contactID = DatabaseFactory.getThreadDatabase(this).getRecipientForThreadId(this.threadId).getAddress().toString();
|
||||
DatabaseFactory.getLokiPreKeyBundleDatabase(this).removePreKeyBundle(contactID);
|
||||
}
|
||||
|
||||
public ListenableFuture<Void> sendGroupMessage() throws InvalidMessageException {
|
||||
final SettableFuture<Void> future = new SettableFuture<>();
|
||||
String hexEncodedPublicKey = TextSecurePreferences.getLocalNumber(this);
|
||||
String displayName = DatabaseFactory.getLokiAPIDatabase(this).getUserDisplayName();
|
||||
if (displayName == null) displayName = "Anonymous";
|
||||
long timestamp = new Date().getTime();
|
||||
LokiGroupMessage message = new LokiGroupMessage(hexEncodedPublicKey, displayName, getMessage(), timestamp);
|
||||
LokiGroupChatAPI.sendMessage(message, LokiGroupChatAPI.getPublicChatID()).success(unit -> {
|
||||
future.set(null);
|
||||
return Unit.INSTANCE;
|
||||
}).fail(e -> {
|
||||
future.setException(e);
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
return future;
|
||||
}
|
||||
// endregion
|
||||
}
|
||||
|
@ -531,6 +531,11 @@ 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 + " = ?, " +
|
||||
|
@ -14,7 +14,6 @@ import org.thoughtcrime.securesms.attachments.DatabaseAttachment;
|
||||
import org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil;
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.GroupReceiptDatabase.GroupReceiptInfo;
|
||||
import org.thoughtcrime.securesms.database.MmsDatabase;
|
||||
import org.thoughtcrime.securesms.database.NoSuchMessageException;
|
||||
import org.thoughtcrime.securesms.database.documents.IdentityKeyMismatch;
|
||||
@ -47,6 +46,7 @@ import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
import org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@ -225,7 +225,7 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType {
|
||||
|
||||
private List<SendMessageResult> deliver(OutgoingMediaMessage message, @NonNull List<Address> destinations)
|
||||
throws IOException, UntrustedIdentityException, UndeliverableMessageException {
|
||||
rotateSenderCertificateIfNecessary();
|
||||
// rotateSenderCertificateIfNecessary();
|
||||
|
||||
String groupId = message.getRecipient().getAddress().toGroupString();
|
||||
Optional<byte[]> profileKey = getProfileKey(message.getRecipient());
|
||||
@ -279,11 +279,17 @@ 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"));
|
||||
return result;
|
||||
|
||||
/*
|
||||
List<GroupReceiptInfo> destinations = DatabaseFactory.getGroupReceiptDatabase(context).getGroupReceiptInfo(messageId);
|
||||
if (!destinations.isEmpty()) return Stream.of(destinations).map(GroupReceiptInfo::getAddress).toList();
|
||||
|
||||
List<Recipient> members = DatabaseFactory.getGroupDatabase(context).getGroupMembers(groupId, false);
|
||||
return Stream.of(members).map(Recipient::getAddress).toList();
|
||||
*/
|
||||
}
|
||||
|
||||
public static class Factory implements Job.Factory<PushGroupSendJob> {
|
||||
|
@ -3,6 +3,7 @@ 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
|
||||
@ -81,6 +82,10 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
|
||||
override fun getUserDisplayName(): String? {
|
||||
return TextSecurePreferences.getProfileName(context)
|
||||
}
|
||||
|
||||
override fun setMessageID(signalID: Long, lokiID: Long) {
|
||||
DatabaseFactory.getMmsDatabase(context).updateMessageID(signalID, lokiID)
|
||||
}
|
||||
}
|
||||
|
||||
// region Convenience
|
||||
|
@ -3,7 +3,9 @@ package org.thoughtcrime.securesms.loki
|
||||
import android.content.Context
|
||||
import android.os.Handler
|
||||
import android.util.Log
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||
import org.thoughtcrime.securesms.jobs.PushDecryptJob
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||
import org.whispersystems.libsignal.util.guava.Optional
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceContent
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage
|
||||
@ -38,7 +40,9 @@ class LokiGroupChatPoller(private val context: Context, private val groupID: Lon
|
||||
}
|
||||
|
||||
private fun poll() {
|
||||
LokiGroupChatAPI.getMessages(groupID).success { messages ->
|
||||
val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context)
|
||||
val database = DatabaseFactory.getLokiAPIDatabase(context)
|
||||
LokiGroupChatAPI(userHexEncodedPublicKey, database).getMessages(groupID).success { messages ->
|
||||
messages.map { message ->
|
||||
val id = "loki-group-chat-$groupID".toByteArray()
|
||||
val x1 = SignalServiceGroup(SignalServiceGroup.Type.UPDATE, id, null, null, null)
|
||||
|
Loading…
Reference in New Issue
Block a user