Skip to content

Commit c50249c

Browse files
authored
Merge pull request #661 from GetStream/og-video
feat: display scraped video metadata
2 parents 25e0c3b + 7a9b55e commit c50249c

File tree

5 files changed

+86
-21
lines changed

5 files changed

+86
-21
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
"@ctrl/ngx-emoji-mart": "^8.2.0",
115115
"@floating-ui/dom": "^1.6.3",
116116
"@ngx-translate/core": "^14.0.0",
117-
"@stream-io/stream-chat-css": "5.1.0",
117+
"@stream-io/stream-chat-css": "5.3.0",
118118
"@stream-io/transliterate": "^1.5.2",
119119
"angular-mentions": "1.4.0",
120120
"dayjs": "^1.11.10",

projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.html

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -334,17 +334,34 @@
334334
*ngIf="attachmentConfiguration.url"
335335
class="str-chat__message-attachment-card--header"
336336
>
337-
<img
338-
fetchpriority="low"
339-
loading="lazy"
340-
data-testclass="card-img"
341-
alt="{{ attachmentConfiguration.url }}"
342-
src="{{ attachmentConfiguration.url }}"
343-
[ngStyle]="{
344-
height: attachmentConfiguration.height,
345-
width: attachmentConfiguration.width
346-
}"
347-
/>
337+
<a
338+
*ngIf="attachmentContext.type === 'video'; else cardImage"
339+
[href]="
340+
attachmentContext.title_link ||
341+
attachmentContext.og_scrape_url
342+
"
343+
target="_blank"
344+
data-testclass="scraped-video"
345+
>
346+
<ng-content *ngTemplateOutlet="cardImage"></ng-content>
347+
<div
348+
class="str-chat__message-attachment-card--video-play"
349+
></div>
350+
<stream-icon-placeholder icon="play"></stream-icon-placeholder>
351+
</a>
352+
<ng-template #cardImage>
353+
<img
354+
fetchpriority="low"
355+
loading="lazy"
356+
data-testclass="card-img"
357+
alt="{{ attachmentConfiguration.url }}"
358+
src="{{ attachmentConfiguration.url }}"
359+
[ngStyle]="{
360+
height: attachmentConfiguration.height,
361+
width: attachmentConfiguration.width
362+
}"
363+
/>
364+
</ng-template>
348365
</div>
349366
<div class="str-chat__message-attachment-card--content">
350367
<div class="str-chat__message-attachment-card--flex">

projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.spec.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ describe('AttachmentListComponent', () => {
4747
let queryGallery: () => HTMLElement | null;
4848
let queryVideos: () => HTMLVideoElement[];
4949
let queryVideoContainers: () => HTMLElement[];
50+
let queryScrapedVideos: () => HTMLLinkElement[];
5051
let sendAction: jasmine.Spy;
5152

5253
beforeEach(async () => {
@@ -130,6 +131,10 @@ describe('AttachmentListComponent', () => {
130131
'[data-testclass="video-attachment-parent"]'
131132
)
132133
);
134+
queryScrapedVideos = () =>
135+
Array.from(
136+
nativeElement.querySelectorAll('[data-testclass=scraped-video]')
137+
);
133138
}));
134139

135140
it('should display received #attachments ordered', () => {
@@ -205,6 +210,48 @@ describe('AttachmentListComponent', () => {
205210
expect(component.orderedAttachments.length).toBe(1);
206211
});
207212

213+
it('should display scraped videos', () => {
214+
const scrapedVideoAttachments = [
215+
{
216+
type: 'video',
217+
author_name: 'YouTube',
218+
title: 'Rachmaninoff - Prelude in C Sharp Minor (Op. 3 No. 2)',
219+
title_link: 'https://www.youtube.com/watch?v=sCtixpIWBto',
220+
text: 'Rachmaninoff - Prelude in C Sharp Minor (Op. 3 No. 2) Click the 🔔bell to always be notified on new uploads! ♫ Listen on Spotify: http://spoti.fi/2LdpqK7 ♫ MI...',
221+
image_url: 'https://i.ytimg.com/vi/sCtixpIWBto/maxresdefault.jpg',
222+
thumb_url: 'https://i.ytimg.com/vi/sCtixpIWBto/maxresdefault.jpg',
223+
asset_url: 'https://www.youtube.com/embed/sCtixpIWBto',
224+
og_scrape_url: 'https://www.youtube.com/watch?v=sCtixpIWBto',
225+
},
226+
{
227+
type: 'video',
228+
author_name: 'Twitch',
229+
title: 'ledo_drito - Twitch',
230+
title_link: 'https://www.twitch.tv/ledo_drito',
231+
text: 'GG',
232+
image_url:
233+
'https://static-cdn.jtvnw.net/jtv_user_pictures/ae659572-9c29-4f91-867f-d7de167b982f-profile_image-300x300.png',
234+
thumb_url:
235+
'https://static-cdn.jtvnw.net/jtv_user_pictures/ae659572-9c29-4f91-867f-d7de167b982f-profile_image-300x300.png',
236+
asset_url:
237+
'https://player.twitch.tv/?channel=ledo_drito&player=facebook&autoplay=true&parent=meta.tag',
238+
og_scrape_url: 'https://www.twitch.tv/ledo_drito',
239+
},
240+
];
241+
242+
component.attachments = scrapedVideoAttachments;
243+
component.ngOnChanges({ attachments: {} as SimpleChange });
244+
fixture.detectChanges();
245+
246+
const scrapedVideos = queryScrapedVideos();
247+
248+
expect(scrapedVideos.length).toBe(2);
249+
250+
scrapedVideos.forEach((video, index) => {
251+
expect(video.href).toBe(scrapedVideoAttachments[index].og_scrape_url);
252+
});
253+
});
254+
208255
it('should display voice recording', () => {
209256
component.attachments = [mockVoiceRecording];
210257
component.ngOnChanges({ attachments: {} as SimpleChange });

projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,16 @@ export class AttachmentListComponent implements OnChanges, OnInit, OnDestroy {
152152
return (
153153
attachment.type === 'video' &&
154154
attachment.asset_url &&
155-
!attachment.og_scrape_url // links from video share services (such as YouTube or Facebook) are can't be played
155+
!attachment.og_scrape_url
156156
);
157157
}
158158

159159
isCard(attachment: Attachment) {
160160
return (
161161
!attachment.type ||
162162
(attachment.type === 'image' && !this.isImage(attachment)) ||
163-
attachment.type === 'giphy'
163+
attachment.type === 'giphy' ||
164+
(attachment.type === 'video' && attachment.og_scrape_url)
164165
);
165166
}
166167

0 commit comments

Comments
 (0)