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