2022-09-08 00:30:04 -06:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const { TemplateView, AvatarView } = require('hydrogen-view-sdk');
|
|
|
|
const AvatarViewModel = require('../viewmodels/AvatarViewModel');
|
|
|
|
|
|
|
|
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,
|
|
|
|
},
|
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',
|
|
|
|
href: vm.archiveRoomUrl,
|
|
|
|
// Since this is the same button as the "View" link, just tab to
|
|
|
|
// that instead
|
|
|
|
tabindex: -1,
|
|
|
|
},
|
|
|
|
[
|
|
|
|
t.view(new AvatarView(avatarViewModel, 24)),
|
|
|
|
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
|
|
|
|
title: displayName,
|
|
|
|
},
|
|
|
|
displayName
|
|
|
|
)
|
|
|
|
),
|
|
|
|
]
|
|
|
|
),
|
|
|
|
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]
|
|
|
|
),
|
2022-10-18 17:38:00 -06:00
|
|
|
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' }, [
|
|
|
|
t.div({}, [memberDisplay]),
|
|
|
|
t.a(
|
|
|
|
{
|
|
|
|
className: 'RoomCardView_viewButtonWrapperLink',
|
|
|
|
href: vm.archiveRoomUrl,
|
|
|
|
title: `View the ${displayName} room`,
|
|
|
|
},
|
|
|
|
t.span(
|
|
|
|
{
|
|
|
|
className: 'RoomCardView_viewButton',
|
|
|
|
},
|
|
|
|
['View']
|
|
|
|
)
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
]),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = RoomCardView;
|