File indexing completed on 2025-01-26 05:27:59
0001 import React, { Component } from 'react'; 0002 0003 class ChatContainer extends Component { 0004 0005 constructor(props){ 0006 super(props); 0007 this.chatUrl = '/json/chat'; 0008 this.avatarUrl= 'https://chat.opendesktop.org/_matrix/media/v1/thumbnail'; 0009 this.state = {items:[]}; 0010 } 0011 0012 componentDidMount() { 0013 fetch(this.chatUrl) 0014 .then(response => response.json()) 0015 .then(data => { 0016 this.setState({items:data}); 0017 }); 0018 } 0019 0020 render(){ 0021 let container, members; 0022 if (this.state.items){ 0023 const feedItems = this.state.items.map((fi,index) => { 0024 if(fi.members){ 0025 let mb=Object.values(fi.members); 0026 if(mb.length>0){ 0027 members = mb.slice(0,4).map((m,index) => { 0028 let imgAvatar; 0029 if(m.avatar_url){ 0030 imgAvatar = <img src={this.avatarUrl+m.avatar_url.substring(5)+'?width=39&height=39&method=crop'}></img> 0031 } 0032 return ( 0033 <div className="chatUser"> 0034 {imgAvatar} 0035 <div className="name"> 0036 {m.display_name} 0037 </div> 0038 </div> 0039 ) 0040 } 0041 ); 0042 } 0043 if(fi.guest_can_join==false) 0044 { 0045 return ( 0046 <li key={index} className="chatMember"> 0047 <a href={this.roomUrl+fi.room_id} > 0048 join our chat {(fi.canonical_alias)?fi.canonical_alias.substring(0,fi.canonical_alias.indexOf(':'))+' ('+fi.num_joined_members+')':''} 0049 </a> 0050 {members} 0051 </li> 0052 ) 0053 } 0054 } 0055 0056 }); 0057 container = <ul>{feedItems}</ul>; 0058 } 0059 return ( 0060 <div id="chat-container" className="panelContainer"> 0061 <div className="title"><a href="https://chat.opendesktop.org">Riot Chat</a> </div> 0062 {container} 0063 </div> 0064 ) 0065 } 0066 } 0067 0068 export default ChatContainer;