1
0
forked from notnull/ircz

Compare commits

..

No commits in common. "5bf5c2b9837a3e9b4e6070b280d69be1afbe8955" and "774fe6e2629da7cb60cc957a3d47707c2141d85e" have entirely different histories.

View File

@ -58,14 +58,26 @@ class App extends React.Component {
this.state.chats.map(c => {
if (c === socketId) {
const messages = this.state.messages.concat(
this.addNotification(`${oldNick} disconnected`, c)
this.formatMessage(
`${oldNick} disconnected`,
socketId,
'[server]',
c,
c === this.state.namespace ? true : false
)
)
this.setState({ messages })
}
this.state.allNamespaces.map(n => {
if (n.namespace === c && n.sockets.find(s => s === socketId)) {
const messages = this.state.messages.concat(
this.addNotification(`${oldNick} disconnected`, c)
this.formatMessage(
`${oldNick} disconnected`,
socketId,
'[server]',
c,
c === this.state.namespace ? true : false
)
)
this.setState({ messages })
}
@ -80,7 +92,13 @@ class App extends React.Component {
const user = this.state.allUsers.find(u => u.socketId === socketId)
console.log(`${user.nick} joined ${namespace}`)
const messages = this.state.messages.concat(
this.addNotification(`${user.nick} joined ${namespace}`, namespace)
this.formatMessage(
`${user.nick} joined ${namespace}`,
socketId,
'[server]',
namespace,
namespace === this.state.namespace ? true : false
)
)
this.setState({ messages })
})
@ -90,7 +108,13 @@ class App extends React.Component {
const user = this.state.allUsers.find(u => u.socketId === socketId)
console.log(`${user.nick} left ${namespace}`)
const messages = this.state.messages.concat(
this.addNotification(`${user.nick} left ${namespace}`, namespace)
this.formatMessage(
`${user.nick} left ${namespace}`,
socketId,
'[server]',
namespace,
namespace === this.state.namespace ? true : false
)
)
this.setState({ messages })
})
@ -104,14 +128,26 @@ class App extends React.Component {
this.state.chats.map(c => {
if (c === user.socketId) {
const messages = this.state.messages.concat(
this.addNotification(`${oldNick} is now known as ${user.nick}`, c)
this.formatMessage(
`${oldNick} is now known as ${user.nick}`,
user.socketId,
'[server]',
c,
c === this.state.namespace ? true : false
)
)
this.setState({ messages })
}
this.state.allNamespaces.map(n => {
if (n.namespace === c && n.sockets.find(s => s === user.socketId)) {
const messages = this.state.messages.concat(
this.addNotification(`${oldNick} is now known as ${user.nick}`, c)
this.formatMessage(
`${oldNick} is now known as ${user.nick}`,
user.socketId,
'[server]',
c,
c === this.state.namespace ? true : false
)
)
this.setState({ messages })
}
@ -186,16 +222,6 @@ class App extends React.Component {
}
this.setState({ message: '' })
}
addNotification(text, namespace) {
return this.formatMessage(
text,
'server',
'server',
namespace,
namespace === this.state.namespace ? true : false
)
}
formatMessage(text, from, nick, to, read) {
if (!text || !from || !to || !nick) {
console.log(
@ -431,18 +457,13 @@ class App extends React.Component {
(m.from === this.state.user.socketId &&
m.to === this.state.namespace)
)
.map(m => {
const rowColor = m.from === 'server' ? 'text-secondary' : ''
return (
<div className={`d-flex ${rowColor}`} key={m.id}>
<div className="pr-3 text-nowrap">{m.date}</div>
{m.from === 'server' ? null : (
<div className="pr-3 text-nowrap">{m.nick}:</div>
)}
<div className="pr-3 flex-grow-1">{m.text}</div>
</div>
)
})}
.map(m => (
<div className="d-flex" key={m.id}>
<div className="p-2 text-nowrap">{m.date}</div>
<div className="p-2">{m.nick}</div>
<div className="p-2 flex-grow-1">{m.text}</div>
</div>
))}
</div>
<form onSubmit={this.submitMessage}>
<input