Skip to content

Commit 40cc625

Browse files
committed
feat: Can add group and teams avatar
1 parent 71d3926 commit 40cc625

File tree

9 files changed

+99
-11
lines changed

9 files changed

+99
-11
lines changed

Mail/Views/New Message/AutocompletionCell.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ struct AutocompletionCell: View {
2929
let alreadyAppend: Bool
3030
let unknownRecipient: Bool
3131

32+
var contactConfiguration: ContactConfiguration {
33+
if let groupContact = autocompletion as? GroupContact {
34+
return .groupContact(group: groupContact)
35+
} else if let addressBook = autocompletion as? AddressBook {
36+
return .addressBook(addressbook: addressBook)
37+
} else {
38+
return .emptyContact
39+
}
40+
}
41+
3242
var body: some View {
3343
HStack(spacing: IKPadding.intermediate) {
3444
Button {
@@ -37,7 +47,7 @@ struct AutocompletionCell: View {
3747
if unknownRecipient {
3848
UnknownRecipientCell(email: autocompletion.autocompletableName)
3949
} else {
40-
RecipientCell(contact: autocompletion, highlight: highlight)
50+
RecipientCell(contact: autocompletion, contactConfiguration: contactConfiguration, highlight: highlight)
4151
}
4252
}
4353
.allowsHitTesting(!alreadyAppend || unknownRecipient)

MailCore/Cache/ContactManager/ContactManager+DB.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ public extension ContactManager {
149149

150150
func getContacts(with groupContactId: Int) -> [MergedContact] {
151151
let frozenContacts = fetchResults(ofType: MergedContact.self) { partial in
152-
partial
153-
.where { $0.groupContactId == [groupContactId] }
152+
partial.filter("ANY remoteGroupContactId == %@", groupContactId)
154153
}
155154
return Array(frozenContacts.freezeIfNeeded())
156155
}
@@ -160,7 +159,6 @@ public extension ContactManager {
160159
partial
161160
.where { $0.remoteAddressBookId == addressbookId }
162161
}
163-
164162
return Array(contacts.freezeIfNeeded())
165163
}
166164

MailCore/Models/Contact/Contact.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public struct InfomaniakContact: Codable, Identifiable {
3434
public var favorite: Bool?
3535
public var nickname: String?
3636
public var organization: String?
37-
public var groupContactId: RealmSwift.List<Int>?
37+
public var groupContactId: List<Int>?
3838

3939
enum CodingKeys: String, CodingKey {
4040
case id
@@ -73,6 +73,6 @@ public struct InfomaniakContact: Codable, Identifiable {
7373
favorite = try values.decodeIfPresent(Bool.self, forKey: .favorite)
7474
nickname = try values.decodeIfPresent(String.self, forKey: .nickname)
7575
organization = try values.decodeIfPresent(String.self, forKey: .organization)
76-
groupContactId = try values.decodeIfPresent(RealmSwift.List<Int>.self, forKey: .groupContactId)
76+
groupContactId = try values.decodeIfPresent(List<Int>.self, forKey: .groupContactId)
7777
}
7878
}

MailCore/Models/Contact/ContactConfiguration.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ public enum ContactConfiguration: CustomDebugStringConvertible {
2828
return ".user:\(user.displayName) \(user.email)"
2929
case .contact(let contact):
3030
return ".contact:\(contact.fullName) \(contact.email)"
31-
case .groupContact(let groupContactId):
31+
case .groupContact:
3232
return ".groupContact"
33-
case .addressBook(let addressBookId):
33+
case .addressBook:
3434
return ".addressBook"
3535
case .emptyContact:
3636
return ".emptyContact"
@@ -46,7 +46,7 @@ public enum ContactConfiguration: CustomDebugStringConvertible {
4646
case user(user: UserProfile)
4747
case contact(contact: CommonContact)
4848
case groupContact(group: GroupContact)
49-
case addressBook(adressbook: AddressBook)
49+
case addressBook(addressbook: AddressBook)
5050
case emptyContact
5151

5252
public func freezeIfNeeded() -> Self {

MailCore/Models/MergedContact.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public final class MergedContact: Object, Identifiable {
5353
@Persisted public var remoteAvatarURL: String?
5454
@Persisted public var remoteIdentifier: String?
5555
@Persisted public var remoteAddressBookId: Int?
56-
public var groupContactId: [Int]?
56+
@Persisted public var remoteGroupContactId: List<Int>
5757

5858
/// Local
5959
@Persisted public var localIdentifier: String?
@@ -129,7 +129,7 @@ public final class MergedContact: Object, Identifiable {
129129
remoteAvatarURL = contact.avatar
130130
remoteIdentifier = contact.id
131131
remoteAddressBookId = contact.addressbookId
132-
// remoteGroupContactId = contact.groupContactId
132+
remoteGroupContactId = contact.groupContactId ?? List<Int>()
133133
}
134134

135135
static func computeId(email: String, name: String?) -> String {

MailCoreUI/Components/AvatarView.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ public struct AvatarView: View {
6161
Group {
6262
if case .emptyContact = contactConfiguration {
6363
UnknownRecipientView(size: size)
64+
} else if case .addressBook = contactConfiguration {
65+
GroupRecipientsView(size: size)
66+
} else if case .groupContact = contactConfiguration {
67+
GroupRecipientsView(size: size)
6468
} else if let avatarImageRequest = getAvatarImageRequest() {
6569
LazyImage(request: avatarImageRequest) { state in
6670
if let image = state.image {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Infomaniak Mail - iOS App
3+
Copyright (C) 2024 Infomaniak Network SA
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
import InfomaniakCoreSwiftUI
20+
import MailCore
21+
import MailResources
22+
import SwiftUI
23+
24+
struct GroupRecipientsView: View {
25+
let size: CGFloat
26+
27+
private var iconSize: CGFloat {
28+
return size - 2 * IKPadding.small
29+
}
30+
31+
public init(size: CGFloat) {
32+
self.size = size
33+
}
34+
35+
public var body: some View {
36+
Circle()
37+
.fill(Color.accentColor)
38+
.frame(width: size, height: size)
39+
.overlay {
40+
MailResourcesAsset.teamsUser.swiftUIImage
41+
.resizable()
42+
.foregroundStyle(MailResourcesAsset.backgroundColor)
43+
.frame(width: iconSize, height: iconSize)
44+
}
45+
}
46+
}
47+
48+
#Preview {
49+
GroupRecipientsView(size: 40)
50+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "teams-user.svg",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
},
12+
"properties" : {
13+
"preserves-vector-representation" : true
14+
}
15+
}
Lines changed: 11 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)