Browse Source

Merge branch 'master' into dev

pull/981/head
jubb 3 months ago
parent
commit
2c3a949bb3
  1. 6
      app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt
  2. 6
      app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationReactionDelegate.kt
  3. 15
      app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationReactionOverlay.java
  4. 8
      app/src/main/java/org/thoughtcrime/securesms/conversation/v2/menus/ConversationMenuItemHelper.kt
  5. 14
      app/src/main/java/org/thoughtcrime/securesms/database/GroupMemberDatabase.kt
  6. 6
      app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt
  7. 3
      libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt
  8. 10
      libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPoller.kt
  9. 1
      libsession/src/main/java/org/session/libsession/utilities/recipients/Recipient.java

6
app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt

@ -1052,7 +1052,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
Log.e("Loki", "Failed to show emoji picker", e)
return
}
ViewUtil.hideKeyboard(this, visibleMessageView);
ViewUtil.hideKeyboard(this, visibleMessageView)
binding?.reactionsShade?.isVisible = true
showOrHidScrollToBottomButton(false)
binding?.conversationRecyclerView?.suppressLayout(true)
@ -1083,7 +1083,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
message.isOutgoing,
visibleMessageView.messageContentView
)
reactionDelegate.show(this, message, selectedConversationModel)
reactionDelegate.show(this, message, selectedConversationModel, viewModel.blindedPublicKey)
}
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
@ -1865,6 +1865,8 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
ConversationReactionOverlay.Action.VIEW_INFO -> showMessageDetail(selectedItems)
ConversationReactionOverlay.Action.SELECT -> selectMessages(selectedItems)
ConversationReactionOverlay.Action.DELETE -> deleteMessages(selectedItems)
ConversationReactionOverlay.Action.BAN_AND_DELETE_ALL -> banAndDeleteAll(selectedItems)
ConversationReactionOverlay.Action.BAN_USER -> banUser(selectedItems)
}
}
}

6
app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationReactionDelegate.kt

@ -27,13 +27,15 @@ internal class ConversationReactionDelegate(private val overlayStub: Stub<Conver
fun show(
activity: Activity,
messageRecord: MessageRecord,
selectedConversationModel: SelectedConversationModel
selectedConversationModel: SelectedConversationModel,
blindedPublicKey: String?
) {
resolveOverlay().show(
activity,
messageRecord,
lastSeenDownPoint,
selectedConversationModel
selectedConversationModel,
blindedPublicKey
)
}

15
app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationReactionOverlay.java

@ -68,6 +68,7 @@ public final class ConversationReactionOverlay extends FrameLayout {
private Activity activity;
private MessageRecord messageRecord;
private SelectedConversationModel selectedConversationModel;
private String blindedPublicKey;
private OverlayState overlayState = OverlayState.HIDDEN;
private RecentEmojiPageModel recentEmojiPageModel;
@ -142,7 +143,8 @@ public final class ConversationReactionOverlay extends FrameLayout {
public void show(@NonNull Activity activity,
@NonNull MessageRecord messageRecord,
@NonNull PointF lastSeenDownPoint,
@NonNull SelectedConversationModel selectedConversationModel)
@NonNull SelectedConversationModel selectedConversationModel,
@Nullable String blindedPublicKey)
{
if (overlayState != OverlayState.HIDDEN) {
return;
@ -150,6 +152,7 @@ public final class ConversationReactionOverlay extends FrameLayout {
this.messageRecord = messageRecord;
this.selectedConversationModel = selectedConversationModel;
this.blindedPublicKey = blindedPublicKey;
overlayState = OverlayState.UNINITAILIZED;
selected = -1;
recentEmojiPageModel = new RecentEmojiPageModel(activity);
@ -668,16 +671,16 @@ public final class ConversationReactionOverlay extends FrameLayout {
items.add(new ActionItem(R.attr.menu_copy_icon, getContext().getResources().getString(R.string.activity_conversation_menu_copy_session_id), () -> handleActionItemClicked(Action.COPY_SESSION_ID)));
}
// Delete message
if (ConversationMenuItemHelper.userCanDeleteSelectedItems(getContext(), message, openGroup, userPublicKey)) {
if (ConversationMenuItemHelper.userCanDeleteSelectedItems(getContext(), message, openGroup, userPublicKey, blindedPublicKey)) {
items.add(new ActionItem(R.attr.menu_trash_icon, getContext().getResources().getString(R.string.delete), () -> handleActionItemClicked(Action.DELETE)));
}
// Ban user
if (ConversationMenuItemHelper.userCanBanSelectedUsers(getContext(), message, openGroup, userPublicKey)) {
items.add(new ActionItem(0, getContext().getResources().getString(R.string.conversation_context__menu_ban_user), () -> handleActionItemClicked(Action.BAN_USER)));
if (ConversationMenuItemHelper.userCanBanSelectedUsers(getContext(), message, openGroup, userPublicKey, blindedPublicKey)) {
items.add(new ActionItem(R.attr.menu_block_icon, getContext().getResources().getString(R.string.conversation_context__menu_ban_user), () -> handleActionItemClicked(Action.BAN_USER)));
}
// Ban and delete all
if (ConversationMenuItemHelper.userCanBanSelectedUsers(getContext(), message, openGroup, userPublicKey)) {
items.add(new ActionItem(0, getContext().getResources().getString(R.string.conversation_context__menu_ban_and_delete_all), () -> handleActionItemClicked(Action.BAN_AND_DELETE_ALL)));
if (ConversationMenuItemHelper.userCanBanSelectedUsers(getContext(), message, openGroup, userPublicKey, blindedPublicKey)) {
items.add(new ActionItem(R.attr.menu_trash_icon, getContext().getResources().getString(R.string.conversation_context__menu_ban_and_delete_all), () -> handleActionItemClicked(Action.BAN_AND_DELETE_ALL)));
}
// Message detail
if (message.isFailed()) {

8
app/src/main/java/org/thoughtcrime/securesms/conversation/v2/menus/ConversationMenuItemHelper.kt

@ -8,17 +8,17 @@ import org.thoughtcrime.securesms.groups.OpenGroupManager
object ConversationMenuItemHelper {
@JvmStatic
fun userCanDeleteSelectedItems(context: Context, message: MessageRecord, openGroup: OpenGroup?, userPublicKey: String): Boolean {
fun userCanDeleteSelectedItems(context: Context, message: MessageRecord, openGroup: OpenGroup?, userPublicKey: String, blindedPublicKey: String?): Boolean {
if (openGroup == null) return message.isOutgoing || !message.isOutgoing
if (message.isOutgoing) return true
return OpenGroupManager.isUserModerator(context, openGroup.groupId, userPublicKey)
return OpenGroupManager.isUserModerator(context, openGroup.groupId, userPublicKey, blindedPublicKey)
}
@JvmStatic
fun userCanBanSelectedUsers(context: Context, message: MessageRecord, openGroup: OpenGroup?, userPublicKey: String): Boolean {
fun userCanBanSelectedUsers(context: Context, message: MessageRecord, openGroup: OpenGroup?, userPublicKey: String, blindedPublicKey: String?): Boolean {
if (openGroup == null) return false
if (message.isOutgoing) return false // Users can't ban themselves
return OpenGroupManager.isUserModerator(context, openGroup.groupId, userPublicKey)
return OpenGroupManager.isUserModerator(context, openGroup.groupId, userPublicKey, blindedPublicKey)
}
}

14
app/src/main/java/org/thoughtcrime/securesms/database/GroupMemberDatabase.kt

@ -3,9 +3,9 @@ package org.thoughtcrime.securesms.database
import android.content.ContentValues
import android.content.Context
import android.database.Cursor
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
import org.session.libsession.messaging.open_groups.GroupMember
import org.session.libsession.messaging.open_groups.GroupMemberRole
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
class GroupMemberDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) {
@ -69,4 +69,16 @@ class GroupMemberDatabase(context: Context, helper: SQLCipherOpenHelper) : Datab
}
}
fun clearGroupMemberRoles(groupId: String) {
writableDatabase.beginTransaction()
try {
val query = "$GROUP_ID = ?"
val args = arrayOf(groupId)
writableDatabase.delete(TABLE_NAME, query, args)
writableDatabase.setTransactionSuccessful()
} finally {
writableDatabase.endTransaction()
}
}
}

6
app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt

@ -319,7 +319,11 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
return getAllOpenGroups().values.firstOrNull { it.server == server && it.room == room }
}
override fun addGroupMember(member: GroupMember) {
override fun clearGroupMemberRoles(groupId: String) {
DatabaseComponent.get(context).groupMemberDatabase().clearGroupMemberRoles(groupId)
}
override fun addGroupMemberRole(member: GroupMember) {
DatabaseComponent.get(context).groupMemberDatabase().addGroupMember(member)
}

3
libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt

@ -71,7 +71,8 @@ interface StorageProtocol {
fun hasBackgroundGroupAddJob(groupJoinUrl: String): Boolean
fun setOpenGroupServerMessageID(messageID: Long, serverID: Long, threadID: Long, isSms: Boolean)
fun getOpenGroup(room: String, server: String): OpenGroup?
fun addGroupMember(member: GroupMember)
fun addGroupMemberRole(member: GroupMember)
fun clearGroupMemberRoles(groupId: String)
// Open Group Public Keys
fun getOpenGroupPublicKey(server: String): String?

10
libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupPoller.kt

@ -134,18 +134,20 @@ class OpenGroupPoller(private val server: String, private val executorService: S
storage.setUserCount(roomToken, server, pollInfo.activeUsers)
// - Moderators
storage.clearGroupMemberRoles(groupId)
pollInfo.details?.moderators?.forEach {
storage.addGroupMember(GroupMember(groupId, it, GroupMemberRole.MODERATOR))
storage.addGroupMemberRole(GroupMember(groupId, it, GroupMemberRole.MODERATOR))
}
pollInfo.details?.hiddenModerators?.forEach {
storage.addGroupMember(GroupMember(groupId, it, GroupMemberRole.HIDDEN_MODERATOR))
storage.addGroupMemberRole(GroupMember(groupId, it, GroupMemberRole.HIDDEN_MODERATOR))
}
// - Admins
pollInfo.details?.admins?.forEach {
storage.addGroupMember(GroupMember(groupId, it, GroupMemberRole.ADMIN))
storage.addGroupMemberRole(GroupMember(groupId, it, GroupMemberRole.ADMIN))
}
pollInfo.details?.hiddenAdmins?.forEach {
storage.addGroupMember(GroupMember(groupId, it, GroupMemberRole.HIDDEN_ADMIN))
storage.addGroupMemberRole(GroupMember(groupId, it, GroupMemberRole.HIDDEN_ADMIN))
}
}

1
libsession/src/main/java/org/session/libsession/utilities/recipients/Recipient.java

@ -224,6 +224,7 @@ public class Recipient implements RecipientModifiedListener {
Recipient.this.profileSharing = result.profileSharing;
Recipient.this.unidentifiedAccessMode = result.unidentifiedAccessMode;
Recipient.this.forceSmsSelection = result.forceSmsSelection;
Recipient.this.notifyType = result.notifyType;
Recipient.this.participants.clear();
Recipient.this.participants.addAll(result.participants);

Loading…
Cancel
Save