|
6 | 6 |
|
7 | 7 | #import "base/strings/sys_string_conversions.h"
|
8 | 8 | #import "components/collaboration/public/messaging/messaging_backend_service.h"
|
| 9 | +#import "components/data_sharing/public/group_data.h" |
9 | 10 | #import "components/saved_tab_groups/public/saved_tab_group.h"
|
10 | 11 | #import "components/saved_tab_groups/public/tab_group_sync_service.h"
|
11 | 12 | #import "ios/chrome/browser/favicon/model/favicon_loader.h"
|
12 | 13 | #import "ios/chrome/browser/saved_tab_groups/model/ios_tab_group_sync_util.h"
|
| 14 | +#import "ios/chrome/browser/share_kit/model/share_kit_avatar_configuration.h" |
| 15 | +#import "ios/chrome/browser/share_kit/model/share_kit_service.h" |
13 | 16 | #import "ios/chrome/browser/shared/model/web_state_list/tab_group.h"
|
14 |
| -#import "ios/chrome/browser/shared/ui/symbols/symbols.h" |
15 | 17 | #import "ios/chrome/browser/ui/tab_switcher/tab_grid/tab_groups/recent_activity_consumer.h"
|
16 | 18 | #import "ios/chrome/browser/ui/tab_switcher/tab_grid/tab_groups/recent_activity_log_item.h"
|
17 | 19 | #import "ios/chrome/common/ui/favicon/favicon_attributes.h"
|
18 | 20 |
|
19 | 21 | namespace {
|
20 | 22 |
|
21 |
| -// The size of image of a user's icon and a favicon. |
22 |
| -const CGFloat kImageSize = 22; |
| 23 | +// The size of a favicon image. |
| 24 | +const CGFloat kFaviconSize = 20; |
| 25 | +// The size of an avatar image. |
| 26 | +const CGFloat kAvatarSize = 30; |
23 | 27 |
|
24 | 28 | ActivityLogType ConvertCollaborationEvent(
|
25 | 29 | collaboration::messaging::CollaborationEvent collaboration_event) {
|
@@ -53,21 +57,26 @@ @implementation RecentActivityMediator {
|
53 | 57 | raw_ptr<FaviconLoader> _faviconLoader;
|
54 | 58 | // A service to get the information of a tab group.
|
55 | 59 | raw_ptr<tab_groups::TabGroupSyncService> _syncService;
|
| 60 | + // A service to get the information of a shared tab group. |
| 61 | + raw_ptr<ShareKitService> _shareKitService; |
56 | 62 | }
|
57 | 63 |
|
58 | 64 | - (instancetype)initWithtabGroup:(base::WeakPtr<const TabGroup>)tabGroup
|
59 | 65 | messagingService:
|
60 | 66 | (collaboration::messaging::MessagingBackendService*)
|
61 | 67 | messagingService
|
62 | 68 | faviconLoader:(FaviconLoader*)faviconLoader
|
63 |
| - syncService:(tab_groups::TabGroupSyncService*)syncService { |
| 69 | + syncService:(tab_groups::TabGroupSyncService*)syncService |
| 70 | + shareKitService:(ShareKitService*)shareKitService { |
64 | 71 | CHECK(messagingService);
|
65 | 72 | CHECK(faviconLoader);
|
66 | 73 | CHECK(syncService);
|
| 74 | + CHECK(shareKitService); |
67 | 75 | if ((self = [super init])) {
|
68 | 76 | _messagingService = messagingService;
|
69 | 77 | _faviconLoader = faviconLoader;
|
70 | 78 | _syncService = syncService;
|
| 79 | + _shareKitService = shareKitService; |
71 | 80 | }
|
72 | 81 | return self;
|
73 | 82 | }
|
@@ -103,14 +112,28 @@ - (void)populateItemsFromService {
|
103 | 112 | _faviconLoader->FaviconForPageUrlOrHost(
|
104 | 113 | GURL(log.activity_metadata.tab_metadata.value()
|
105 | 114 | .last_known_url.value()),
|
106 |
| - kImageSize, ^(FaviconAttributes* attributes) { |
| 115 | + kFaviconSize, ^(FaviconAttributes* attributes) { |
107 | 116 | item.favicon = attributes.faviconImage;
|
108 | 117 | });
|
109 | 118 | }
|
110 | 119 |
|
111 |
| - // TODO(crbug.com/370897655): Get a correct user icon. |
112 |
| - item.userIcon = |
113 |
| - DefaultSymbolTemplateWithPointSize(kXMarkCircleFillSymbol, 20); |
| 120 | + // Get a user's icon from the avatar URL and set it to `item`. |
| 121 | + // The image is asynchronously loaded. |
| 122 | + if (_shareKitService->IsSupported() && |
| 123 | + log.activity_metadata.triggering_user.has_value()) { |
| 124 | + ShareKitAvatarConfiguration* config = |
| 125 | + [[ShareKitAvatarConfiguration alloc] init]; |
| 126 | + data_sharing::GroupMember user = |
| 127 | + log.activity_metadata.triggering_user.value(); |
| 128 | + config.avatarUrl = |
| 129 | + [NSURL URLWithString:base::SysUTF8ToNSString(user.avatar_url.spec())]; |
| 130 | + // Use email intead when the display name is empty. |
| 131 | + config.displayName = user.display_name.empty() |
| 132 | + ? base::SysUTF8ToNSString(user.email) |
| 133 | + : base::SysUTF8ToNSString(user.display_name); |
| 134 | + config.avatarSize = CGSizeMake(kAvatarSize, kAvatarSize); |
| 135 | + item.avatarPrimitive = _shareKitService->AvatarImage(config); |
| 136 | + } |
114 | 137 |
|
115 | 138 | [items addObject:item];
|
116 | 139 | }
|
|
0 commit comments