blob: 6e5e233e4619cc1d1778db25c29cb50cdea1d0a6 [file] [log] [blame]
idillon-sfl9d956ab2022-10-20 16:33:24 -04001/*
2 * Copyright (C) 2022 Savoir-faire Linux Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation; either version 3 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
13 *
14 * You should have received a copy of the GNU Affero General Public
15 * License along with this program. If not, see
16 * <https://www.gnu.org/licenses/>.
17 */
18import { Stack } from '@mui/system';
idillon-sfl9d956ab2022-10-20 16:33:24 -040019import { Account, ConversationMember, Message } from 'jami-web-common';
idillon-sfl9d956ab2022-10-20 16:33:24 -040020
idillon-sfl118ae442022-10-25 10:42:54 -040021import { MessageRow } from './Message';
idillon-sfl9d956ab2022-10-20 16:33:24 -040022
23interface MessageListProps {
24 account: Account;
25 members: ConversationMember[];
26 messages: Message[];
27}
28
29export default function MessageList({ account, members, messages }: MessageListProps) {
idillon-sfl118ae442022-10-25 10:42:54 -040030 return (
31 <Stack direction="column-reverse">
32 {
33 // most recent messages first
34 messages.map((message, index) => {
35 const isAccountMessage = message.author === account.getUri();
36 let author;
37 if (isAccountMessage) {
38 author = account;
39 } else {
40 const member = members.find((member) => message.author === member.contact.getUri());
41 author = member?.contact;
42 }
43 if (!author) {
44 return null;
45 }
46 const props = {
47 messageIndex: index,
48 messages,
49 isAccountMessage,
50 author,
51 };
52 return <MessageRow key={message.id} {...props} />;
53 })
idillon-sfl9d956ab2022-10-20 16:33:24 -040054 }
idillon-sfl118ae442022-10-25 10:42:54 -040055 </Stack>
56 );
57}