<commit_before>import React, { Component } from 'react';
import {socket, NAME} from '../../main';

export class InterfaceBody extends Component {
	constructor(props) {
	    super(props);
	}
	componentDidMount() {
		//初始化头像点击事件
		const ul =  this.refs.ul;
		this.createNewRoom = this.createNewRoom.bind(this);
		ul.addEventListener('dblclick',this.createNewRoom,false);
		//初始化滚动事件
		const ulwrap = this.refs.ulwrap;
		this.handleMouseWheel = this.handleMouseWheel.bind(this);
		ulwrap.addEventListener('mousewheel', this.handleMouseWheel,false);
		//初始化添加好友事件
		const addFri = this.refs.addFri;
		this.handleAddFriend = this.handleAddFriend.bind(this);
		addFri.addEventListener('click', this.handleAddFriend, false);
	}
	handleAddFriend() {
		const {addFriend, users:{friends, friendList, current, chatList}} = this.props;
		if(!friends[current]) {//好友不存在该用户才添加好友
			const friend = {
				username:current,
				photo: chatList[current].photo
			};
			addFriend(friend);
			const xhr = new XMLHttpRequest();
			xhr.onreadystatechange = function() {
				if (xhr.readyState == 4) {
					if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304) {
						let data = JSON.parse(xhr.responseText);
						console.log(data.message);
					} else {
						console.log("init failed!");
					}
				}
			}
			xhr.open("post", "/addFriend", true);
			xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
			let data = "username="+NAME+"&friend="+friend.username;
			xhr.send(data);
		}
	}
	handleMouseWheel(e) {
		const ul =  this.refs.ul;
		const ulwrap = this.refs.ulwrap;
		if(!ul.style.bottom)
			ul.style.bottom = "0px";
		var bottom = parseInt(ul.style.bottom);
		var height = ul.clientHeight;
		var distance = 50;
		var wrapHeight = ulwrap.clientHeight;
		if(e.wheelDelta < 0 && bottom >= -height && bottom <= -10) { //向下滚动
			console.log(ul.style.bottom = bottom+10+"px")
		} else if(e.wheelDelta > 0 && bottom > wrapHeight-height && bottom <= distance) { //向上滚动
			console.log(ul.style.bottom = bottom-10+"px")
		}
	}
	createNewRoom(e) {
		e = e || window.event;//这一行及下一行是为兼容IE8及以下版本
		var target = e.target || e.srcElement;
		if(e.target && e.target.nodeName == 'IMG') {
			const username = e.target.getAttribute('data-username');
			const imgsrc = e.target.src;
			if(username != NAME) {
				const {changeRoom, addUser, users} = this.props;
				let flag = true;
				users.userlist.forEach(function(_username){
					if(_username == username)
						flag = false;
				})
				if(flag) {
					addUser({
						username: username,
						photo: imgsrc
					});
					changeRoom(username);
				}
			}
	    }
	}
	render() {
		const {users:{current, chatList, friends}} = this.props;
		let addFri_className = "add-friend";
		if(chatList[current].type == 'PUBLIC' || friends[current])
			addFri_className += " d-hidden";
		return (<div id='interface-body' ref="ulwrap">
					<div className={addFri_className} ref="addFri">加为好友</div>
					<ul id='chatUl' ref="ul">
						{chatList[current]?chatList[current].DOM:[]}
					</ul>
				</div>)
	}
}<commit_msg>UI持续完善中<commit_after>import React, { Component } from 'react';
import {socket, NAME} from '../../main';

export class InterfaceBody extends Component {
	constructor(props) {
	    super(props);
	}
	componentDidMount() {
		//初始化头像点击事件
		const ul =  this.refs.ul;
		this.createNewRoom = this.createNewRoom.bind(this);
		ul.addEventListener('dblclick',this.createNewRoom,false);
		//初始化滚动事件
		const ulwrap = this.refs.ulwrap;
		this.handleMouseWheel = this.handleMouseWheel.bind(this);
		ulwrap.addEventListener('mousewheel', this.handleMouseWheel,false);
		//初始化添加好友事件
		const addFri = this.refs.addFri;
		this.handleAddFriend = this.handleAddFriend.bind(this);
		addFri.addEventListener('click', this.handleAddFriend, false);
	}
	handleAddFriend() {
		const {addFriend, users:{friends, friendList, current, chatList}} = this.props;
		if(!friends[current]) {//好友不存在该用户才添加好友
			const friend = {
				username:current,
				photo: chatList[current].photo
			};
			addFriend(friend);
			const xhr = new XMLHttpRequest();
			xhr.onreadystatechange = function() {
				if (xhr.readyState == 4) {
					if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304) {
						let data = JSON.parse(xhr.responseText);
						console.log(data.message);
					} else {
						console.log("init failed!");
					}
				}
			}
			xhr.open("post", "/addFriend", true);
			xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
			let data = "username="+NAME+"&friend="+friend.username;
			xhr.send(data);
		}
	}
	handleMouseWheel(e) {
		const ul =  this.refs.ul;
		const ulwrap = this.refs.ulwrap;
		if(!ul.style.bottom)
			ul.style.bottom = "0px";
		var bottom = parseInt(ul.style.bottom);
		var height = ul.clientHeight;
		var distance = 50;
		var wrapHeight = ulwrap.clientHeight;
		if(e.wheelDelta < 0 && bottom >= -height && bottom <= -10) { //向下滚动
			console.log(ul.style.bottom = bottom+10+"px")
		} else if(e.wheelDelta > 0 && bottom > wrapHeight-height && bottom <= distance) { //向上滚动
			console.log(ul.style.bottom = bottom-10+"px")
		}
	}
	createNewRoom(e) {
		e = e || window.event;//这一行及下一行是为兼容IE8及以下版本
		var target = e.target || e.srcElement;
		if(e.target && e.target.nodeName == 'IMG') {
			const username = e.target.getAttribute('data-username');
			const imgsrc = e.target.src;
			if(username != NAME) {
				const {changeRoom, addUser, users} = this.props;
				let flag = true;
				users.userlist.forEach(function(_username){
					if(_username == username)
						flag = false;
				})
				if(flag) {
					addUser({
						username: username,
						photo: imgsrc
					});
					changeRoom(username);
				}
			}
	    }
	}
	render() {
		const {users:{current, chatList, friends}} = this.props;
		let addFri_className = "add-friend";
		if(chatList[current].type == 'PUBLIC' || friends[current])
			addFri_className += " d-hidden";
		let agreeAddFri_className = "agree-add-friend";

		return (<div id='interface-body' ref="ulwrap">
					<div className={addFri_className} ref="addFri">加为好友</div>
					<div className={agreeAddFri_className} ref="agreeAddFri">同意</div>
					<ul id='chatUl' ref="ul">
						{chatList[current]?chatList[current].DOM:[]}
					</ul>
				</div>)
	}
}
{'fraction_non_alphanumeric': 0.16218379763048352, 'fraction_numerical': 0.007044508485430675, 'mean_word_length': 3.536673928830792, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '818860', 'n_tokens_mistral': 2641, 'n_tokens_neox': 2243, 'n_words': 398}