accept all direct messages

This commit is contained in:
Barry Gitarts 2018-11-11 15:43:54 -05:00
parent eebba31eb3
commit 9a73564d9c
2 changed files with 26 additions and 23 deletions

View File

@ -40,7 +40,7 @@ const ChatBox = ({ username, message, pubkey }) => (
<Avatar> <Avatar>
<ListItemAvatar> <ListItemAvatar>
<Avatar> <Avatar>
<Jazzicon diameter={40} seed={jsNumberForAddress(pubkey)} /> {pubkey && <Jazzicon diameter={40} seed={jsNumberForAddress(pubkey)} />}
</Avatar> </Avatar>
</ListItemAvatar> </ListItemAvatar>
</Avatar> </Avatar>

View File

@ -36,11 +36,10 @@ export default class Home extends Component<Props> {
componentDidMount() { componentDidMount() {
const { currentChannel } = this.state; const { currentChannel } = this.state;
this.joinChannel(currentChannel); this.joinChannel(currentChannel);
setTimeout(() => { this.createOnUserMessageHandler(); }, 2000);
setInterval(() => { setInterval(() => {
console.dir("setInterval!");
const { currentChannel, users } = this.state; const { currentChannel, users } = this.state;
console.dir("channel: " + currentChannel);
status.sendJsonMessage(currentChannel, {type: "ping"}); status.sendJsonMessage(currentChannel, {type: "ping"});
let currentTime = (new Date().getTime()); let currentTime = (new Date().getTime());
@ -75,14 +74,13 @@ export default class Home extends Component<Props> {
addDirectMessage = contactCode => { addDirectMessage = contactCode => {
status.addContact(contactCode, () => { status.addContact(contactCode, () => {
this.addConversationEntry(contactCode); this.addConversationEntry(contactCode);
this.createOnUserMessageHandler(contactCode);
}) })
} }
addConversationEntry = code => { addConversationEntry = (code, changeChannel = true) => {
const { channels } = this.state; const { channels, currentChannel } = this.state;
this.setState({ this.setState({
currentChannel: code, currentChannel: changeChannel ? code : currentChannel,
channels: { channels: {
...channels, ...channels,
[code]: { users: {} } [code]: { users: {} }
@ -114,22 +112,27 @@ export default class Home extends Component<Props> {
}); });
} }
createOnUserMessageHandler = contactCode => { createOnUserMessageHandler = () => {
status.onUserMessage((err, data) => { status.onUserMessage((err, res) => {
const payload = JSON.parse(data.payload); if (res) {
const msg = payload[1][0]; const payload = JSON.parse(res.payload);
//const sender = data.sig; const msg = payload[1][0];
const sender = res.data.sig;
const message = { username: data.username, message: msg, data }; const message = { username: res.username, message: msg, data: res };
this.setState((prevState) => { this.setState((prevState) => {
const existing = prevState.messages[contactCode]; const existing = prevState.messages[sender];
return { return {
messages: { messages: {
...prevState.messages, ...prevState.messages,
[contactCode]: existing ? [ ...existing, message ] : [ message ] [sender]: existing ? [ ...existing, message ] : [ message ]
},
channels: {
...prevState.channels,
[sender]: { users: {} }
}
} }
} })
}) }
}); });
} }
@ -238,7 +241,7 @@ export default class Home extends Component<Props> {
usersTyping={this.whoIsTyping()} usersTyping={this.whoIsTyping()}
typingEvent={this.typingEvent.bind(this)} typingEvent={this.typingEvent.bind(this)}
channelUsers={channelUsers} channelUsers={channelUsers}
allUsers={this.state.users} allUsers={users}
/> />
</Grid> </Grid>
</Grid> </Grid>