2022-09-08 00:30:04 -06:00
|
|
|
'use strict';
|
|
|
|
|
2023-05-03 03:45:33 -06:00
|
|
|
const { TemplateView, AvatarView, text } = require('hydrogen-view-sdk');
|
2022-09-08 00:30:04 -06:00
|
|
|
const AvatarViewModel = require('../viewmodels/AvatarViewModel');
|
|
|
|
|
2023-05-03 03:45:33 -06:00
|
|
|
const safeSearchBlockedRoomTitle = 'Blocked by safe search';
|
|
|
|
const safeSearchBlockedRoomDescription =
|
|
|
|
'This room was blocked because safe search is turned on and may contain explicit content. Turn off safe search to view this room.';
|
|
|
|
|
|
|
|
const blockedBySafeSearchAvatarViewModel = new AvatarViewModel({
|
|
|
|
avatarTitle: 'x',
|
|
|
|
avatarLetterString: 'x',
|
|
|
|
entityId: 'x',
|
|
|
|
});
|
|
|
|
|
2022-09-08 00:30:04 -06:00
|
|
|
class RoomCardView extends TemplateView {
|
|
|
|
render(t, vm) {
|
|
|
|
const avatarViewModel = new AvatarViewModel({
|
|
|
|
homeserverUrlToPullMediaFrom: vm.homeserverUrlToPullMediaFrom,
|
2022-11-09 23:29:44 -07:00
|
|
|
avatarUrl: vm.mxcAvatarUrl,
|
2022-10-20 01:06:43 -06:00
|
|
|
avatarTitle: vm.name || vm.canonicalAlias || vm.roomId,
|
2022-09-08 00:30:04 -06:00
|
|
|
avatarLetterString:
|
|
|
|
vm.name ||
|
2022-11-09 23:29:44 -07:00
|
|
|
// Skip to the first letter after the `#` sigil from the alias
|
2022-09-08 00:30:04 -06:00
|
|
|
vm.canonicalAlias?.[1] ||
|
2022-11-09 23:29:44 -07:00
|
|
|
// Skip to the first letter after the `!` sigil from the room ID
|
2022-09-08 00:30:04 -06:00
|
|
|
vm.roomId?.[1],
|
|
|
|
entityId: vm.roomId,
|
|
|
|
});
|
|
|
|
|
|
|
|
// Pluralize based on number of members in the room
|
|
|
|
let memberDisplay = `${vm.numJoinedMembers} member`;
|
|
|
|
if (vm.numJoinedMembers > 1) {
|
|
|
|
memberDisplay = `${vm.numJoinedMembers} members`;
|
|
|
|
}
|
|
|
|
|
|
|
|
const aliasOrRoomId = vm.canonicalAlias || vm.roomId;
|
|
|
|
const displayName = vm.name || aliasOrRoomId;
|
|
|
|
|
|
|
|
return t.li(
|
|
|
|
{
|
|
|
|
className: {
|
|
|
|
RoomCardView: true,
|
2023-05-03 03:45:33 -06:00
|
|
|
blockedBySafeSearch: (vm) => vm.blockedBySafeSearch,
|
2022-09-08 00:30:04 -06:00
|
|
|
},
|
2022-09-15 19:41:55 -06:00
|
|
|
'data-room-id': vm.roomId,
|
|
|
|
'data-testid': 'room-card',
|
2022-09-08 00:30:04 -06:00
|
|
|
},
|
|
|
|
[
|
|
|
|
t.a(
|
|
|
|
{
|
|
|
|
className: 'RoomCardView_header',
|
2023-05-03 03:45:33 -06:00
|
|
|
href: (vm) => {
|
|
|
|
if (vm.blockedBySafeSearch) {
|
|
|
|
// Omit the href so the link is not clickable when it's blocked by
|
|
|
|
// safe search
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return vm.archiveRoomUrl;
|
|
|
|
},
|
2022-09-08 00:30:04 -06:00
|
|
|
// Since this is the same button as the "View" link, just tab to
|
|
|
|
// that instead
|
|
|
|
tabindex: -1,
|
|
|
|
},
|
|
|
|
[
|
2023-05-03 03:45:33 -06:00
|
|
|
t.mapView(
|
|
|
|
(vm) => vm.blockedBySafeSearch,
|
|
|
|
(blockedBySafeSearch) => {
|
|
|
|
if (blockedBySafeSearch) {
|
|
|
|
return new AvatarView(blockedBySafeSearchAvatarViewModel, 24);
|
|
|
|
}
|
|
|
|
return new AvatarView(avatarViewModel, 24);
|
|
|
|
}
|
|
|
|
),
|
2022-09-08 00:30:04 -06:00
|
|
|
t.if(
|
|
|
|
(vm) => vm.name,
|
2022-09-27 21:21:00 -06:00
|
|
|
(t /*, vm*/) =>
|
2022-09-08 00:30:04 -06:00
|
|
|
t.h4(
|
|
|
|
{
|
|
|
|
className: 'RoomCardView_headerTitle',
|
|
|
|
// We add a title so a tooltip shows the full name on hover
|
2023-05-03 03:45:33 -06:00
|
|
|
title: (vm) => {
|
|
|
|
if (vm.blockedBySafeSearch) {
|
|
|
|
return safeSearchBlockedRoomTitle;
|
|
|
|
}
|
|
|
|
|
|
|
|
return displayName;
|
|
|
|
},
|
2022-09-08 00:30:04 -06:00
|
|
|
},
|
2023-05-03 03:45:33 -06:00
|
|
|
[
|
|
|
|
(vm) => {
|
|
|
|
if (vm.blockedBySafeSearch) {
|
|
|
|
return safeSearchBlockedRoomTitle;
|
|
|
|
}
|
|
|
|
|
|
|
|
return displayName;
|
|
|
|
},
|
|
|
|
]
|
2022-09-08 00:30:04 -06:00
|
|
|
)
|
|
|
|
),
|
|
|
|
]
|
|
|
|
),
|
2023-05-03 03:45:33 -06:00
|
|
|
t.if(
|
|
|
|
(vm) => !vm.blockedBySafeSearch,
|
|
|
|
(t /*, vm*/) =>
|
|
|
|
t.a(
|
|
|
|
{
|
|
|
|
className: 'RoomCardView_alias',
|
|
|
|
href: vm.archiveRoomUrl,
|
|
|
|
// Since this is the same button as the "View" link, just tab to
|
|
|
|
// that instead
|
|
|
|
tabindex: -1,
|
|
|
|
},
|
|
|
|
[aliasOrRoomId]
|
|
|
|
)
|
|
|
|
),
|
|
|
|
t.if(
|
|
|
|
(vm) => vm.blockedBySafeSearch,
|
|
|
|
(t /*, vm*/) =>
|
|
|
|
t.p({ className: 'RoomCardView_blockedBySafeSearchTopic' }, [
|
|
|
|
safeSearchBlockedRoomDescription,
|
|
|
|
])
|
|
|
|
),
|
|
|
|
t.if(
|
|
|
|
(vm) => !vm.blockedBySafeSearch,
|
|
|
|
(t /*, vm*/) =>
|
|
|
|
t.p({ className: 'RoomCardView_topic', title: vm.topic || null }, [vm.topic || ''])
|
2022-09-08 00:30:04 -06:00
|
|
|
),
|
|
|
|
t.div({ className: 'RoomCardView_footer' }, [
|
|
|
|
t.div({ className: 'RoomCardView_footerInner' }, [
|
2023-05-03 03:45:33 -06:00
|
|
|
t.div({}, [
|
|
|
|
t.if(
|
|
|
|
(vm) => !vm.blockedBySafeSearch,
|
|
|
|
(/*t , vm*/) => text(memberDisplay)
|
|
|
|
),
|
|
|
|
]),
|
2022-09-08 00:30:04 -06:00
|
|
|
t.a(
|
|
|
|
{
|
|
|
|
className: 'RoomCardView_viewButtonWrapperLink',
|
2023-05-03 03:45:33 -06:00
|
|
|
href: (vm) => {
|
|
|
|
if (vm.blockedBySafeSearch) {
|
|
|
|
// Omit the href so the link is not clickable when it's blocked by
|
|
|
|
// safe search
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return vm.archiveRoomUrl;
|
|
|
|
},
|
|
|
|
title: (vm) => {
|
|
|
|
if (vm.blockedBySafeSearch) {
|
|
|
|
return `Turn off safe search to view this room`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return `View the ${displayName} room`;
|
|
|
|
},
|
2022-09-08 00:30:04 -06:00
|
|
|
},
|
|
|
|
t.span(
|
|
|
|
{
|
|
|
|
className: 'RoomCardView_viewButton',
|
2023-05-03 03:45:33 -06:00
|
|
|
disabled: (vm) => vm.blockedBySafeSearch,
|
2022-09-08 00:30:04 -06:00
|
|
|
},
|
|
|
|
['View']
|
|
|
|
)
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
]),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = RoomCardView;
|