Skip to content

Commit

Permalink
debug alerte messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ClemenceCartet committed Apr 20, 2023
1 parent 69e6d08 commit c9e18e3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
11 changes: 6 additions & 5 deletions front/react_project/src/components/ChatModule/ChatMessages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { SocketContext } from "../context";
import LogoOrdi from'../../assets/LogoOrdi.jpg';

class MessageDisplay extends React.Component<{message: IMessage, prevSender: string, last: boolean}, {
playload: JwtPayload, me: boolean, sameSender: boolean, avatar: string}> {
payload: JwtPayload, me: boolean, sameSender: boolean, avatar: string}> {
constructor(props: {message: IMessage, prevSender: string, last: boolean}) {
super(props);
this.state = { playload: accountService.readPayload()!,
this.state = { payload: accountService.readPayload()!,
me: false,
sameSender: false,
avatar: '' };
Expand All @@ -22,10 +22,11 @@ class MessageDisplay extends React.Component<{message: IMessage, prevSender: str
componentDidMount(): void {
if (this.props.prevSender === this.props.message.senderName)
this.setState({ sameSender: true });
if (this.state.playload.login === this.props.message.senderName)
this.setState({me: true});
if (this.props.prevSender !== this.props.message.senderName && this.state.playload.login !== this.props.message.senderName)
if (this.state.payload.sub === this.props.message.senderId)
this.setState({ me: true });
if (this.props.prevSender !== this.props.message.senderName && this.state.payload.sub !== this.props.message.senderId) {
this.getProfilePicture();
}
}

setTimeAgo() {
Expand Down
22 changes: 17 additions & 5 deletions front/react_project/src/components/ChatModule/ChatModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ class ChannelDMList extends React.Component<{}, {
this.initList = this.initList.bind(this);
this.checkOnline = this.checkOnline.bind(this);
this.checkOffline = this.checkOffline.bind(this);
this.checkNewMsg = this.checkNewMsg.bind(this);
}
static contextType = SocketContext;
declare context: ContextType<typeof SocketContext>;

changeLoc(channel: {loc: string, isChannel: boolean}) {
this.context.socket.emit('changeLoc', channel);
const index = this.state.dms.findIndex(dm => dm.userName === channel.loc);
const index = this.state.dms.findIndex(dm => dm.userId === channel.loc);
if (index != -1) {
const tmpDM = [...this.state.dms];
tmpDM[index].waitingMsg = false;
Expand All @@ -41,11 +42,14 @@ class ChannelDMList extends React.Component<{}, {
}

initList() {
console.log("initList");
this.context.socket.emit('myChannels');
this.context.socket.on('listMyChannels', (channels: {channel: IChannel, status: string}[]) => {
console.log("listMyChannels")
this.setState({ channels: channels }) });
this.context.socket.emit('myDM');
this.context.socket.on('listMyDM', (strs: {userName: string, userId: string, connected: boolean}[]) => {
console.log("listMyDM")
let listDM: {userName: string, userId: string, connected: boolean, waitingMsg: boolean}[] = [];
strs.forEach((elt) => {
listDM.push({userName: elt.userName, userId: elt.userId, connected: elt.connected, waitingMsg: false});
Expand All @@ -55,6 +59,7 @@ class ChannelDMList extends React.Component<{}, {

checkNewMsg() {
this.context.socket.on('pingedBy', (login: string) => {
console.log("pingedBy")
const index = this.state.dms.findIndex(dm => dm.userName === login);
if (index != -1) {
const tmpDM = [...this.state.dms];
Expand All @@ -66,6 +71,7 @@ class ChannelDMList extends React.Component<{}, {

checkOnline() {
this.context.socket.on("userConnected", (user: {userId: string, userLogin: string}) => {
console.log("userConnected")
let sorted = new Map<string, {userName: string, connected: boolean, waitingMsg: boolean}>();
for (let elt of this.state.dms) {
sorted.set(elt.userId, {userName: elt.userName, connected: elt.connected, waitingMsg: elt.waitingMsg});
Expand All @@ -83,6 +89,7 @@ class ChannelDMList extends React.Component<{}, {

checkOffline() {
this.context.socket.on("userDisconnected", (user: {userId: string, userLogin: string}) => {
console.log("userDisconnected")
let sorted = new Map<string, {userName: string, connected: boolean, waitingMsg: boolean}>();
for (let elt of this.state.dms) {
sorted.set(elt.userId, {userName: elt.userName, connected: elt.connected, waitingMsg: elt.waitingMsg});
Expand All @@ -102,8 +109,10 @@ class ChannelDMList extends React.Component<{}, {
this.initList();
this.checkOnline();
this.checkOffline();
this.checkNewMsg();

this.context.socket.on('checkNewDM', (room: {id: string, login: string}, connected: boolean) => {
console.log("checkNewDM")
let sorted = new Map<string, {userName: string, userId: string, connected: boolean, waitingMsg: boolean}>();
for (let elt of this.state.dms) {
sorted.set(elt.userName, {userName: elt.userName, userId: elt.userId, connected: elt.connected, waitingMsg: elt.waitingMsg});
Expand All @@ -115,6 +124,7 @@ class ChannelDMList extends React.Component<{}, {
});

this.context.socket.on('channelJoined', (chann: {channel: IChannel, status: string}) => {
console.log("channelJoined")
let nextState: {channel: IChannel, status: string}[] = [...this.state.channels, chann];
nextState.sort((a, b) => {
if (a.status == "god" && b.status != "god")
Expand All @@ -133,20 +143,22 @@ class ChannelDMList extends React.Component<{}, {
})

this.context.socket.on('channelLeaved', (chann: IChannel) => {
console.log("channelLeaved")
let nextState: {channel: IChannel, status: string}[] = this.state.channels.filter(
(elt: {channel: IChannel}) => {return (elt.channel.id != chann.id)}
);
this.setState({channels: nextState});
})

this.context.socket.on('channelDestroy', (channelId: string) => {
console.log("channelDestroy")
let nextState: {channel: IChannel, status: string}[] = this.state.channels.filter(
(elt: {channel: IChannel}) => {return (elt.channel.id != channelId)}
);
this.setState({channels: nextState});
})
}

componentWillUnmount(): void {
this.context.socket.off('listMyChannels');
this.context.socket.off('listMyDM');
Expand All @@ -160,10 +172,10 @@ class ChannelDMList extends React.Component<{}, {
}

render() {
console.log(this.state.dms);
let displayDM: boolean = false;
if (this.state.dms.length !== 0)
displayDM = true;

displayDM = true;
return (
<div id="channelListWrapper">
<h2>Channels</h2>
Expand All @@ -177,7 +189,7 @@ class ChannelDMList extends React.Component<{}, {
<h2>DMs</h2>
<ul className="channelList">
{this.state.dms.map((dm, id) => {
if (this.state.me.login !== dm.userName) {
if (this.state.me.sub !== dm.userId) {
return (
<li key={id}>
<button onClick={() => this.changeLoc({loc: dm.userId, isChannel: false})} className={dm.waitingMsg ? "waitingMsg" : ""}>
Expand Down
4 changes: 2 additions & 2 deletions front/react_project/src/components/ChatModule/ChatSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ class SearchChat extends React.Component<{handleHistory: any, changeLoc: any}, {
fetchUsers() { // récupération de tous les users, sauf moi-même, et les users que j'ai déjà DM
userService.getAllUsers()
.then(response => {
const playload: JwtPayload = accountService.readPayload()!;
const payload: JwtPayload = accountService.readPayload()!;
const users = new Map<string, string>();
response.data.forEach((user: {id: string, login: string}) => users.set(user.id, user.login)); // à revoir
let newUserList: ISearch[] = [];
users.forEach((login, id) => {
if (playload.login !== login)
if (payload.sub !== id)
newUserList.push({id: id, name: login, isChannel: false, password: false, isClickable: true});
});
newUserList.sort((a, b) => {return a.name.localeCompare(b.name);});
Expand Down
1 change: 1 addition & 0 deletions front/react_project/src/styles/ChatModule.scss
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
}
}
& ul {
color: black;
position: absolute;
z-index: 9999;
width: 10.2rem;
Expand Down

0 comments on commit c9e18e3

Please sign in to comment.