mobile: refine allowed group actions; inactive group indicator (#852)

This commit is contained in:
JRoberts
2022-07-30 16:49:34 +04:00
committed by GitHub
parent de0f231c60
commit 1dd7520bbd
13 changed files with 110 additions and 76 deletions
@@ -48,8 +48,8 @@ struct GroupMemberInfoView: View {
}
}
Section {
if member.canRemove(userRole: groupInfo.membership.memberRole) && member.memberStatus != .memRemoved {
if member.canBeRemoved(membership: groupInfo.membership) {
Section {
removeMemberButton()
}
}
@@ -35,19 +35,21 @@ struct GroupChatInfoView: View {
groupInfoHeader()
.listRowBackground(Color.clear)
Section {
Button {
showGroupProfile = true
} label: {
Label("Edit group profile", systemImage: "pencil")
if groupInfo.canEdit {
Section {
Button {
showGroupProfile = true
} label: {
Label("Edit group profile", systemImage: "pencil")
}
}
.sheet(isPresented: $showGroupProfile) {
GroupProfileView(groupId: groupInfo.apiId, groupProfile: groupInfo.groupProfile)
}
}
.sheet(isPresented: $showGroupProfile) {
GroupProfileView(groupId: groupInfo.apiId, groupProfile: groupInfo.groupProfile)
}
Section("\(members.count + 1) members") {
if (groupInfo.canAddMembers) {
if groupInfo.canAddMembers {
addMembersButton()
}
memberView(groupInfo.membership, user: true)
@@ -67,7 +69,7 @@ struct GroupChatInfoView: View {
if groupInfo.canDelete {
deleteGroupButton()
}
if (groupInfo.membership.memberStatus != .memLeft) {
if groupInfo.membership.memberCurrent {
leaveGroupButton()
}
}
@@ -113,7 +113,7 @@ struct ChatListNavLink: View {
clearChatButton()
}
.swipeActions(edge: .trailing) {
if (groupInfo.membership.memberStatus != .memLeft) {
if (groupInfo.membership.memberCurrent) {
Button {
AlertManager.shared.showAlert(leaveGroupAlert(groupInfo))
} label: {
@@ -18,9 +18,14 @@ struct ChatPreviewView: View {
let cItem = chat.chatItems.last
let unread = chat.chatStats.unreadCount
return HStack(spacing: 8) {
ChatInfoImage(chat: chat)
.frame(width: 63, height: 63)
.padding(.leading, 4)
ZStack(alignment: .bottomTrailing) {
ChatInfoImage(chat: chat)
.frame(width: 63, height: 63)
chatPreviewImageOverlayIcon()
.padding([.bottom, .trailing], 1)
}
.padding(.leading, 4)
VStack(spacing: 0) {
HStack(alignment: .top) {
@@ -51,6 +56,28 @@ struct ChatPreviewView: View {
}
}
@ViewBuilder private func chatPreviewImageOverlayIcon() -> some View {
if case let .group(groupInfo) = chat.chatInfo {
switch (groupInfo.membership.memberStatus) {
case .memLeft:
groupInactiveIcon()
case .memRemoved:
groupInactiveIcon()
case .memGroupDeleted:
groupInactiveIcon()
default: EmptyView()
}
} else {
EmptyView()
}
}
@ViewBuilder private func groupInactiveIcon() -> some View {
Image(systemName: "minus.circle.fill")
.foregroundColor(.red)
.background(Circle().foregroundColor(Color(uiColor: .systemBackground)))
}
@ViewBuilder private func chatPreviewTitle() -> some View {
let v = Text(chat.chatInfo.chatViewName)
.font(.title3)
@@ -66,18 +93,6 @@ struct ChatPreviewView: View {
v.foregroundColor(.accentColor)
case .memAccepted:
v.foregroundColor(.secondary)
case .memLeft:
HStack {
Text(NSLocalizedString("[left]", comment: "group left description"))
.font(.title3)
.fontWeight(.bold)
.foregroundColor(.secondary)
Text(chat.chatInfo.chatViewName)
.font(.title3)
.fontWeight(.bold)
.lineLimit(1)
}
.frame(maxHeight: .infinity, alignment: .topLeading)
default: v
}
default: v
@@ -106,12 +121,12 @@ struct ChatPreviewView: View {
switch (chat.chatInfo) {
case let .direct(contact):
if !contact.ready {
chatPreviewInfoText("Connecting...")
chatPreviewInfoText("connecting...")
}
case let .group(groupInfo):
switch (groupInfo.membership.memberStatus) {
case .memInvited: chatPreviewInfoText("You are invited to group")
case .memAccepted: chatPreviewInfoText("Connecting...")
case .memInvited: chatPreviewInfoText("you are invited to group")
case .memAccepted: chatPreviewInfoText("connecting...")
default: EmptyView()
}
default: EmptyView()