Minor refactoring

This commit is contained in:
Niels Andriesse 2021-05-17 15:18:41 +10:00
parent cf3f0fbe57
commit 6b3aa86324
13 changed files with 106 additions and 138 deletions

View File

@ -454,8 +454,8 @@ public class MessageDetailsActivity extends PassphraseRequiredActionBarActivity
UpdateMessageData updateMessageData = UpdateMessageData.Companion.fromJSON(messageRecord.getBody()); UpdateMessageData updateMessageData = UpdateMessageData.Companion.fromJSON(messageRecord.getBody());
if (updateMessageData.getKind() instanceof UpdateMessageData.Kind.OpenGroupInvitation) { if (updateMessageData.getKind() instanceof UpdateMessageData.Kind.OpenGroupInvitation) {
UpdateMessageData.Kind.OpenGroupInvitation data = (UpdateMessageData.Kind.OpenGroupInvitation)updateMessageData.getKind(); UpdateMessageData.Kind.OpenGroupInvitation data = (UpdateMessageData.Kind.OpenGroupInvitation)updateMessageData.getKind();
openGroupInvitation.setGroupName(data.getGroupName()); openGroupInvitation.setName(data.getGroupName());
openGroupInvitation.setGroupUrl(data.getGroupUrl()); openGroupInvitation.setUrl(data.getGroupUrl());
} }
message.setOpenGroupInvitation(openGroupInvitation); message.setOpenGroupInvitation(openGroupInvitation);
} else { } else {

View File

@ -1859,19 +1859,18 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
sendComplete(allocatedThreadId); sendComplete(allocatedThreadId);
} }
private void sendOpenGroupInvitations(String[] contactsID) { private void sendOpenGroupInvitations(String[] contactIDs) {
final Context context = getApplicationContext(); final Context context = getApplicationContext();
OpenGroupV2 openGroup = DatabaseFactory.getLokiThreadDatabase(context).getOpenGroupChat(threadId); OpenGroupV2 openGroup = DatabaseFactory.getLokiThreadDatabase(context).getOpenGroupChat(threadId);
for (String contactId: contactsID) { for (String contactID : contactIDs) {
Recipient recipient = Recipient.from(context, Address.fromSerialized(contactId), true); Recipient recipient = Recipient.from(context, Address.fromSerialized(contactID), true);
VisibleMessage message = new VisibleMessage(); VisibleMessage message = new VisibleMessage();
message.setSentTimestamp(System.currentTimeMillis()); message.setSentTimestamp(System.currentTimeMillis());
OpenGroupInvitation openGroupInvitationMessage = new OpenGroupInvitation(); OpenGroupInvitation openGroupInvitationMessage = new OpenGroupInvitation();
openGroupInvitationMessage.setGroupName(openGroup.getName()); openGroupInvitationMessage.setName(openGroup.getName());
openGroupInvitationMessage.setGroupUrl(openGroup.getJoinURL()); openGroupInvitationMessage.setUrl(openGroup.getJoinURL());
message.setOpenGroupInvitation(openGroupInvitationMessage); message.setOpenGroupInvitation(openGroupInvitationMessage);
OutgoingTextMessage outgoingTextMessage = OutgoingTextMessage.fromOpenGroupInvitation(openGroupInvitationMessage, recipient, message.getSentTimestamp()); OutgoingTextMessage outgoingTextMessage = OutgoingTextMessage.fromOpenGroupInvitation(openGroupInvitationMessage, recipient, message.getSentTimestamp());
DatabaseFactory.getSmsDatabase(context).insertMessageOutbox(-1, outgoingTextMessage, message.getSentTimestamp()); DatabaseFactory.getSmsDatabase(context).insertMessageOutbox(-1, outgoingTextMessage, message.getSentTimestamp());
MessageSender.send(message, recipient.getAddress()); MessageSender.send(message, recipient.getAddress());
} }

View File

@ -48,7 +48,8 @@ public interface MmsSmsColumns {
OUTGOING_CALL_TYPE}; OUTGOING_CALL_TYPE};
//TODO clean unused keys // TODO: Clean unused keys
// Message attributes // Message attributes
protected static final long MESSAGE_FORCE_SMS_BIT = 0x40; protected static final long MESSAGE_FORCE_SMS_BIT = 0x40;
@ -74,9 +75,10 @@ public interface MmsSmsColumns {
protected static final long EXPIRATION_TIMER_UPDATE_BIT = 0x40000; protected static final long EXPIRATION_TIMER_UPDATE_BIT = 0x40000;
protected static final long GROUP_UPDATE_MESSAGE_BIT = 0x80000; protected static final long GROUP_UPDATE_MESSAGE_BIT = 0x80000;
// Data Extraction Information // Data Extraction Notification
protected static final long MEDIA_SAVED_EXTRACTION_BIT = 0x01000; protected static final long MEDIA_SAVED_EXTRACTION_BIT = 0x01000;
protected static final long SCREENSHOT_EXTRACTION_BIT = 0x02000; protected static final long SCREENSHOT_EXTRACTION_BIT = 0x02000;
// Open Group Invitation // Open Group Invitation
protected static final long OPEN_GROUP_INVITATION_BIT = 0x04000; protected static final long OPEN_GROUP_INVITATION_BIT = 0x04000;

View File

@ -165,7 +165,7 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
mmsDatabase.endTransaction() mmsDatabase.endTransaction()
} else { } else {
val smsDatabase = DatabaseFactory.getSmsDatabase(context) val smsDatabase = DatabaseFactory.getSmsDatabase(context)
val isOpenGroupInvitation = message.openGroupInvitation != null val isOpenGroupInvitation = (message.openGroupInvitation != null)
val insertResult = if (message.sender == getUserPublicKey()) { val insertResult = if (message.sender == getUserPublicKey()) {
val textMessage = if (isOpenGroupInvitation) OutgoingTextMessage.fromOpenGroupInvitation(message.openGroupInvitation, targetRecipient, message.sentTimestamp) val textMessage = if (isOpenGroupInvitation) OutgoingTextMessage.fromOpenGroupInvitation(message.openGroupInvitation, targetRecipient, message.sentTimestamp)

View File

@ -145,8 +145,6 @@ public abstract class DisplayRecord {
return isMediaSavedExtraction() || isScreenshotExtraction(); return isMediaSavedExtraction() || isScreenshotExtraction();
} }
// Open Group Invitation
public boolean isOpenGroupInvitation() { public boolean isOpenGroupInvitation() {
return MmsSmsColumns.Types.isOpenGroupInvitation(type); return MmsSmsColumns.Types.isOpenGroupInvitation(type);
} }

View File

@ -1,12 +1,11 @@
package org.thoughtcrime.securesms.loki.views package org.thoughtcrime.securesms.loki.views
import android.content.Context import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color
import android.util.AttributeSet import android.util.AttributeSet
import android.view.View import android.view.View
import android.widget.FrameLayout import android.widget.*
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
@ -20,17 +19,12 @@ import org.thoughtcrime.securesms.loki.protocol.MultiDeviceProtocol
import org.thoughtcrime.securesms.loki.utilities.OpenGroupUtilities import org.thoughtcrime.securesms.loki.utilities.OpenGroupUtilities
class OpenGroupInvitationView : FrameLayout { class OpenGroupInvitationView : FrameLayout {
companion object {
private const val TAG = "OpenGroupInvitationView"
}
private val joinButton: ImageView private val joinButton: ImageView
private val openGroupIcon: ImageView private val openGroupIconContainer: RelativeLayout
private val groupName: TextView private val openGroupIconImageView: ImageView
private val displayedUrl: TextView private val nameTextView: TextView
private val urlTextView: TextView
private var groupUrl: String = "" private var url: String = ""
constructor(context: Context): this(context, null) constructor(context: Context): this(context, null)
@ -38,40 +32,31 @@ class OpenGroupInvitationView : FrameLayout {
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int): super(context, attrs, defStyleAttr) { constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int): super(context, attrs, defStyleAttr) {
View.inflate(context, R.layout.open_group_invitation_view, this) View.inflate(context, R.layout.open_group_invitation_view, this)
joinButton = findViewById(R.id.join_open_group) joinButton = findViewById(R.id.join_open_group_button)
openGroupIcon = findViewById(R.id.open_group_icon) openGroupIconContainer = findViewById(R.id.open_group_icon_image_view_container)
groupName = findViewById(R.id.group_name) openGroupIconImageView = findViewById(R.id.open_group_icon_image_view)
displayedUrl = findViewById(R.id.group_url) nameTextView = findViewById(R.id.name_text_view)
urlTextView = findViewById(R.id.url_text_view)
joinButton.setOnClickListener { joinPublicGroup(groupUrl) } joinButton.setOnClickListener { joinOpenGroup(url) }
} }
fun setOpenGroup(name: String, url: String, isOutgoing: Boolean = false) { fun setOpenGroup(name: String, url: String, isOutgoing: Boolean = false) {
groupName.text = name nameTextView.text = name
displayedUrl.text = OpenGroupUrlParser.trimQueryParameter(url) urlTextView.text = OpenGroupUrlParser.trimQueryParameter(url)
groupUrl = url this.url = url
joinButton.visibility = if (isOutgoing) View.GONE else View.VISIBLE
if(isOutgoing) { openGroupIconContainer.visibility = if (isOutgoing) View.VISIBLE else View.GONE
joinButton.visibility = View.GONE
openGroupIcon.visibility = View.VISIBLE
} else {
joinButton.visibility = View.VISIBLE
openGroupIcon.visibility = View.GONE
}
} }
private fun joinPublicGroup(url: String) { private fun joinOpenGroup(url: String) {
val openGroup = OpenGroupUrlParser.parseUrl(url) val openGroup = OpenGroupUrlParser.parseUrl(url)
val builder = AlertDialog.Builder(context) val builder = AlertDialog.Builder(context)
builder.setTitle(context.getString(R.string.ConversationActivity_join_open_group, groupName.text.toString())) builder.setTitle(context.getString(R.string.ConversationActivity_join_open_group, nameTextView.text.toString()))
builder.setIconAttribute(R.attr.dialog_info_icon)
builder.setCancelable(true) builder.setCancelable(true)
val message: String =
var message: String = context.getString(R.string.ConversationActivity_join_open_group_confirmation_message, nameTextView.text.toString())
context.getString(R.string.ConversationActivity_join_open_group_confirmation_message, groupName.text.toString())
builder.setMessage(message) builder.setMessage(message)
builder.setPositiveButton(R.string.yes) { dialog, which -> builder.setPositiveButton(R.string.yes) { dialog, _ ->
GlobalScope.launch(Dispatchers.IO) { GlobalScope.launch(Dispatchers.IO) {
try { try {
dialog.dismiss() dialog.dismiss()
@ -81,23 +66,14 @@ class OpenGroupInvitationView : FrameLayout {
openGroup.room, openGroup.room,
openGroup.serverPublicKey openGroup.serverPublicKey
) )
val threadID = GroupManager.getOpenGroupThreadID(group.id, context)
val groupID = GroupUtil.getEncodedOpenGroupID(group.id.toByteArray())
MultiDeviceProtocol.forceSyncConfigurationNowIfNeeded(context) MultiDeviceProtocol.forceSyncConfigurationNowIfNeeded(context)
} catch (e: Exception) { } catch (e: Exception) {
Log.e("JoinPublicChatActivity", "Failed to join open group.", e) Log.e("Loki", "Failed to join open group.", e)
Toast.makeText( Toast.makeText(context, R.string.activity_join_public_chat_error, Toast.LENGTH_SHORT).show()
context,
R.string.activity_join_public_chat_error,
Toast.LENGTH_SHORT
).show()
} }
} }
} }
builder.setNegativeButton(R.string.no, null) builder.setNegativeButton(R.string.no, null)
builder.show() builder.show()
} }
} }

View File

@ -1,73 +1,74 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" <merge
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
tools:context="org.thoughtcrime.securesms.loki.views.OpenGroupInvitationView"> tools:context="org.thoughtcrime.securesms.loki.views.OpenGroupInvitationView">
<LinearLayout <LinearLayout
android:id="@+id/audio_widget_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="horizontal" android:paddingHorizontal="@dimen/medium_spacing"
android:padding="8dp" android:orientation="horizontal">
tools:ignore="MissingConstraints" >
<com.google.android.material.floatingactionbutton.FloatingActionButton <ImageButton
android:id="@+id/join_open_group" android:id="@+id/join_open_group_button"
android:layout_width="wrap_content" android:layout_width="48dp"
android:layout_height="wrap_content" android:layout_height="48dp"
android:clickable="true" android:background="@drawable/circle_tintable"
android:focusable="true" android:backgroundTint="#00E076"
android:layout_margin="4dp"
android:contentDescription="@string/open_group_invitation_view__join_accessibility_description" android:contentDescription="@string/open_group_invitation_view__join_accessibility_description"
app:srcCompat="@drawable/ic_add_white_original_24dp" /> app:srcCompat="@drawable/ic_add_white_original_24dp" />
<ImageView <RelativeLayout
android:id="@+id/open_group_icon" android:id="@+id/open_group_icon_image_view_container"
android:layout_width="48dp" android:layout_width="48dp"
android:layout_height="48dp" android:layout_height="48dp"
android:clickable="false" android:background="@drawable/circle_tintable"
android:visibility="gone" android:backgroundTint="#00E076">
android:layout_margin="4dp"
android:contentDescription="@string/open_group_invitation_view__join_accessibility_description" <ImageView
android:src="@drawable/ic_globe" /> android:id="@+id/open_group_icon_image_view"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_centerInParent="true"
android:contentDescription="@string/open_group_invitation_view__join_accessibility_description"
android:src="@drawable/ic_globe" />
</RelativeLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="6dp" android:layout_marginStart="@dimen/small_spacing"
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
android:id="@+id/group_name" android:id="@+id/name_text_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
style="@style/Signal.Text.Caption" android:textStyle="bold"
android:fontFamily="sans-serif-medium"
android:textSize="@dimen/large_font_size" android:textSize="@dimen/large_font_size"
android:maxLines="1" android:maxLines="1"
tools:text="Open group" /> tools:text="Open group" />
<TextView <TextView
android:id="@+id/open_group_invitation_text"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
style="@style/Signal.Text.Body" android:textSize="@dimen/small_font_size"
android:maxLines="1" android:maxLines="1"
android:text="@string/open_group_invitation_view__open_group_invitation" /> android:text="@string/open_group_invitation_view__open_group_invitation" />
<TextView <TextView
android:id="@+id/group_url" android:id="@+id/url_text_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
style="@style/Signal.Text.Caption" android:textSize="@dimen/small_font_size"
android:maxLines="1" android:maxLines="1"
tools:text="http://1.1.1.1" /> tools:text="http://1.1.1.1" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</merge> </merge>

View File

@ -12,7 +12,6 @@ import org.session.libsession.messaging.utilities.UpdateMessageData;
import org.session.libsession.utilities.GroupUtil; import org.session.libsession.utilities.GroupUtil;
import org.session.libsignal.libsignal.util.guava.Optional; import org.session.libsignal.libsignal.util.guava.Optional;
import org.session.libsignal.service.api.messages.SignalServiceGroup; import org.session.libsignal.service.api.messages.SignalServiceGroup;
import org.session.libsignal.utilities.logging.Log;
public class IncomingTextMessage implements Parcelable { public class IncomingTextMessage implements Parcelable {
@ -112,7 +111,11 @@ public class IncomingTextMessage implements Parcelable {
public static IncomingTextMessage fromOpenGroupInvitation(OpenGroupInvitation openGroupInvitation, Address sender, Long sentTimestamp) public static IncomingTextMessage fromOpenGroupInvitation(OpenGroupInvitation openGroupInvitation, Address sender, Long sentTimestamp)
{ {
String body = UpdateMessageData.Companion.buildOpenGroupInvitation(openGroupInvitation.getGroupUrl(), openGroupInvitation.getGroupName()).toJSON(); String url = openGroupInvitation.getUrl();
String name = openGroupInvitation.getName();
if (url == null || name == null) { return null; }
// FIXME: Doing toJSON() to get the body here is weird
String body = UpdateMessageData.Companion.buildOpenGroupInvitation(url, name).toJSON();
IncomingTextMessage incomingTextMessage = new IncomingTextMessage(sender, 1, sentTimestamp, body, Optional.absent(), 0, false); IncomingTextMessage incomingTextMessage = new IncomingTextMessage(sender, 1, sentTimestamp, body, Optional.absent(), 0, false);
incomingTextMessage.isOpenGroupInvitation = true; incomingTextMessage.isOpenGroupInvitation = true;
return incomingTextMessage; return incomingTextMessage;

View File

@ -6,14 +6,12 @@ import org.session.libsession.messaging.threads.recipients.Recipient;
import org.session.libsession.messaging.utilities.UpdateMessageData; import org.session.libsession.messaging.utilities.UpdateMessageData;
public class OutgoingTextMessage { public class OutgoingTextMessage {
private final Recipient recipient; private final Recipient recipient;
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 final long sentTimestampMillis; private final long sentTimestampMillis;
private boolean isOpenGroupInvitation = false;
private boolean isOpenGroupInvitation = false;
public OutgoingTextMessage(Recipient recipient, String message, long expiresIn, int subscriptionId, long sentTimestampMillis) { public OutgoingTextMessage(Recipient recipient, String message, long expiresIn, int subscriptionId, long sentTimestampMillis) {
this.recipient = recipient; this.recipient = recipient;
@ -28,7 +26,11 @@ public class OutgoingTextMessage {
} }
public static OutgoingTextMessage fromOpenGroupInvitation(OpenGroupInvitation openGroupInvitation, Recipient recipient, Long sentTimestamp) { public static OutgoingTextMessage fromOpenGroupInvitation(OpenGroupInvitation openGroupInvitation, Recipient recipient, Long sentTimestamp) {
String body = UpdateMessageData.Companion.buildOpenGroupInvitation(openGroupInvitation.getGroupUrl(), openGroupInvitation.getGroupName()).toJSON(); String url = openGroupInvitation.getUrl();
String name = openGroupInvitation.getName();
if (url == null || name == null) { return null; }
// FIXME: Doing toJSON() to get the body here is weird
String body = UpdateMessageData.Companion.buildOpenGroupInvitation(url, name).toJSON();
OutgoingTextMessage outgoingTextMessage = new OutgoingTextMessage(recipient, body, 0, -1, sentTimestamp); OutgoingTextMessage outgoingTextMessage = new OutgoingTextMessage(recipient, body, 0, -1, sentTimestamp);
outgoingTextMessage.isOpenGroupInvitation = true; outgoingTextMessage.isOpenGroupInvitation = true;
return outgoingTextMessage; return outgoingTextMessage;

View File

@ -1,42 +1,37 @@
package org.session.libsession.messaging.messages.visible package org.session.libsession.messaging.messages.visible
import org.session.libsession.messaging.messages.control.ControlMessage
import org.session.libsignal.service.internal.push.SignalServiceProtos import org.session.libsignal.service.internal.push.SignalServiceProtos
import org.session.libsignal.utilities.logging.Log import org.session.libsignal.utilities.logging.Log
class OpenGroupInvitation() { class OpenGroupInvitation() {
var url: String? = null
var name: String? = null
var groupUrl: String? = null; fun isValid(): Boolean {
var groupName: String? = null; return (url != null && name != null)
}
companion object { companion object {
const val TAG = "OpenGroupInvitation" const val TAG = "OpenGroupInvitation"
fun fromProto(proto: SignalServiceProtos.DataMessage.OpenGroupInvitation): OpenGroupInvitation? { fun fromProto(proto: SignalServiceProtos.DataMessage.OpenGroupInvitation): OpenGroupInvitation {
val groupUrl = proto.url return OpenGroupInvitation(proto.url, proto.name)
val groupName = proto.name
return OpenGroupInvitation(groupUrl, groupName)
} }
} }
constructor(url: String?, serverName: String?): this() { constructor(url: String?, serverName: String?): this() {
this.groupUrl = url this.url = url
this.groupName = serverName this.name = serverName
}
fun isValid(): Boolean {
return (groupUrl != null && groupName != null)
} }
fun toProto(): SignalServiceProtos.DataMessage.OpenGroupInvitation? { fun toProto(): SignalServiceProtos.DataMessage.OpenGroupInvitation? {
val openGroupInvitationProto = SignalServiceProtos.DataMessage.OpenGroupInvitation.newBuilder() val openGroupInvitationProto = SignalServiceProtos.DataMessage.OpenGroupInvitation.newBuilder()
openGroupInvitationProto.url = groupUrl openGroupInvitationProto.url = url
openGroupInvitationProto.name = groupName openGroupInvitationProto.name = name
return try { return try {
openGroupInvitationProto.build() openGroupInvitationProto.build()
} catch (e: Exception) { } catch (e: Exception) {
Log.w(TAG, "Couldn't construct open group invitation proto from: $this") Log.w(TAG, "Couldn't construct open group invitation proto from: $this.")
null null
} }
} }

View File

@ -58,9 +58,9 @@ class VisibleMessage : Message() {
result.linkPreview = linkPreview result.linkPreview = linkPreview
} }
val openGroupInvitationProto = if (dataMessage.hasOpenGroupInvitation()) dataMessage.openGroupInvitation else null val openGroupInvitationProto = if (dataMessage.hasOpenGroupInvitation()) dataMessage.openGroupInvitation else null
openGroupInvitationProto?.let { if (openGroupInvitationProto != null) {
val openGroupInvitation = OpenGroupInvitation.fromProto(openGroupInvitationProto) val openGroupInvitation = OpenGroupInvitation.fromProto(openGroupInvitationProto)
openGroupInvitation?.let { result.openGroupInvitation = openGroupInvitation} result.openGroupInvitation = openGroupInvitation
} }
// TODO Contact // TODO Contact
val profile = Profile.fromProto(dataMessage) val profile = Profile.fromProto(dataMessage)
@ -73,7 +73,7 @@ class VisibleMessage : Message() {
val proto = SignalServiceProtos.Content.newBuilder() val proto = SignalServiceProtos.Content.newBuilder()
val dataMessage: SignalServiceProtos.DataMessage.Builder val dataMessage: SignalServiceProtos.DataMessage.Builder
// Profile // Profile
val profileProto = profile?.let { it.toProto() } val profileProto = profile?.toProto()
if (profileProto != null) { if (profileProto != null) {
dataMessage = profileProto.toBuilder() dataMessage = profileProto.toBuilder()
} else { } else {
@ -82,19 +82,19 @@ class VisibleMessage : Message() {
// Text // Text
if (text != null) { dataMessage.body = text } if (text != null) { dataMessage.body = text }
// Quote // Quote
val quoteProto = quote?.let { it.toProto() } val quoteProto = quote?.toProto()
if (quoteProto != null) { if (quoteProto != null) {
dataMessage.quote = quoteProto dataMessage.quote = quoteProto
} }
// Link preview // Link preview
val linkPreviewProto = linkPreview?.let { it.toProto() } val linkPreviewProto = linkPreview?.toProto()
if (linkPreviewProto != null) { if (linkPreviewProto != null) {
dataMessage.addAllPreview(listOf(linkPreviewProto)) dataMessage.addAllPreview(listOf(linkPreviewProto))
} }
//Open group invitation // Open group invitation
openGroupInvitation?.let { val openGroupInvitationProto = openGroupInvitation?.toProto()
val openGroupInvitationProto = it.toProto() if (openGroupInvitationProto != null) {
if (openGroupInvitationProto != null) dataMessage.openGroupInvitation = openGroupInvitationProto dataMessage.openGroupInvitation = openGroupInvitationProto
} }
// Attachments // Attachments
val database = MessagingModuleConfiguration.shared.messageDataProvider val database = MessagingModuleConfiguration.shared.messageDataProvider

View File

@ -53,8 +53,7 @@ fun MessageReceiver.handle(message: Message, proto: SignalServiceProtos.Content,
} }
} }
//region ControlMessage // region Control Messages
private fun MessageReceiver.handleReadReceipt(message: ReadReceipt) { private fun MessageReceiver.handleReadReceipt(message: ReadReceipt) {
val context = MessagingModuleConfiguration.shared.context val context = MessagingModuleConfiguration.shared.context
SSKEnvironment.shared.readReceiptManager.processReadReceipts(context, message.sender!!, message.timestamps!!, message.receivedTimestamp!!) SSKEnvironment.shared.readReceiptManager.processReadReceipts(context, message.sender!!, message.timestamps!!, message.receivedTimestamp!!)
@ -143,13 +142,9 @@ private fun handleConfigurationMessage(message: ConfigurationMessage) {
} }
storage.addContacts(message.contacts) storage.addContacts(message.contacts)
} }
//endregion //endregion
//region VisibleMessage // region Visible Messages
// Visible message handling
fun MessageReceiver.handleVisibleMessage(message: VisibleMessage, proto: SignalServiceProtos.Content, openGroupID: String?) { fun MessageReceiver.handleVisibleMessage(message: VisibleMessage, proto: SignalServiceProtos.Content, openGroupID: String?) {
val storage = MessagingModuleConfiguration.shared.storage val storage = MessagingModuleConfiguration.shared.storage
val context = MessagingModuleConfiguration.shared.context val context = MessagingModuleConfiguration.shared.context
@ -242,11 +237,9 @@ fun MessageReceiver.handleVisibleMessage(message: VisibleMessage, proto: SignalS
//Notify the user if needed //Notify the user if needed
SSKEnvironment.shared.notificationManager.updateNotification(context, threadID) SSKEnvironment.shared.notificationManager.updateNotification(context, threadID)
} }
//endregion //endregion
//region ClosedGroupControlMessage // region Closed Groups
private fun MessageReceiver.handleClosedGroupControlMessage(message: ClosedGroupControlMessage) { private fun MessageReceiver.handleClosedGroupControlMessage(message: ClosedGroupControlMessage) {
when (message.kind!!) { when (message.kind!!) {
is ClosedGroupControlMessage.Kind.New -> handleNewClosedGroup(message) is ClosedGroupControlMessage.Kind.New -> handleNewClosedGroup(message)
@ -571,5 +564,4 @@ fun MessageReceiver.disableLocalGroupAndUnsubscribe(groupPublicKey: String, grou
// Notify the PN server // Notify the PN server
PushNotificationAPI.performOperation(PushNotificationAPI.ClosedGroupOperation.Unsubscribe, groupPublicKey, userPublicKey) PushNotificationAPI.performOperation(PushNotificationAPI.ClosedGroupOperation.Unsubscribe, groupPublicKey, userPublicKey)
} }
// endregion
//endregion

View File

@ -33,4 +33,4 @@ object OpenGroupUrlParser {
} }
} }
class V2OpenGroupInfo(val server: String, val room: String, val serverPublicKey: String) {} class V2OpenGroupInfo(val server: String, val room: String, val serverPublicKey: String)