This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { GiftedChat } from 'react-native-gifted-chat'; | |
import { connect } from 'react-redux'; | |
import { openChat, sendMessage } from '../store'; | |
class Chat extends React.Component { | |
constructor(props) { | |
super(props); | |
this.send = this.send.bind(this); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { View, Text, TouchableOpacity, StyleSheet } from 'react-native'; | |
import { connect } from 'react-redux'; | |
class Users extends React.Component { | |
constructor() { | |
super(); | |
this.openChat = this.openChat.bind(this); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { View, Text, TextInput, StyleSheet, TouchableOpacity } from 'react-native'; | |
import { login } from '../store'; | |
export default class Login extends React.Component { | |
constructor() { | |
super(); | |
this.state = { | |
name: '', | |
password: '' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const server = require('http').createServer().listen(3000); | |
const conn = require('./db').conn; | |
const io = require('socket.io')(server); | |
const { User, Conversation, Message } = require('./db').models; | |
conn.sync({ logging: false, force: true }); | |
const mobileSockets = {}; | |
io.on('connection', socket => { | |
socket.on('newUser', credentials => { | |
const { name, password } = credentials; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const conn = require('./conn'); | |
const Conversation = require('./models/Conversation'); | |
const Message = require('./models/Message'); | |
const User = require('./models/User'); | |
User.hasMany(Conversation); | |
Conversation.belongsTo(User, { as: 'user1' }); | |
Conversation.belongsTo(User, { as: 'user2' }); | |
Message.belongsTo(Conversation); | |
Conversation.hasMany(Message); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Message.createMessage = (text, sender, receiver) => { | |
return Promise.all([ | |
Message.create({ | |
text, | |
user: { | |
_id: sender.id, | |
name: sender.name | |
} | |
}), | |
conn.models.conversation.findOrCreateConversation(sender.id, receiver.id) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const conn = require('../conn'); | |
const { Sequelize } = conn; | |
const Message = conn.define('message', { | |
text: Sequelize.STRING, | |
user: Sequelize.JSON, | |
_id: { | |
type: Sequelize.UUID, | |
defaultValue: Sequelize.UUIDV4, | |
primaryKey: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Conversation.findOrCreateConversation = function(user1Id, user2Id) { | |
return Conversation.find({ | |
where: { | |
user1Id: { | |
[Op.or]: [user1Id, user2Id] | |
}, | |
user2Id: { | |
[Op.or]: [user1Id, user2Id] | |
} | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const conn = require('../conn'); | |
const { Sequelize } = conn; | |
const { Op } = Sequelize; | |
const Conversation = conn.define('conversation', { | |
}); | |
module.exports = Conversation; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const conn = require('../conn'); | |
const { Sequelize } = conn; | |
const User = conn.define('user', { | |
name: Sequelize.STRING, | |
password: Sequelize.STRING | |
}); | |
module.exports = User; |
NewerOlder