Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (props.isBot !== true) {
const nationIdX = props.groupDefault
? props.groupNationId
: props.nationId; // hardcode for bitnation chat group
const selectedNation = resolveNation(props.nations || [], nationIdX);
if (!selectedNation) {
if (Platform.OS === "ios") {
props.navigator.pop();
} else {
props.navigator.dismissModal();
}
return;
}
this.nationId = selectedNation.idInSmartContract;
// Creating the socket-client instance will automatically connect to the server.
this.connection = SocketIOClient(config.CHAT_URL, {
transports: ["websocket"],
upgrade: false,
query: `token=${config.AUTH_TOKEN}`
});
this.connection.on("connect", () => {
this.connection.emit("room:join", {
nation_id: this.nationId,
});
});
this.state = {
messages: [],
joined: false
};
} else {
// add initial bot message
constructor(props: Props) {
super(props);
if (props.isBot !== true) {
const selectedNation = resolveNation(props.nations || [], props.nationId);
if (selectedNation === null) {
props.navigator.pop();
return;
}
this.nationId = selectedNation.idInSmartContract;
// Creating the socket-client instance will automatically connect to the server.
this.connection = SocketIOClient(config.CHAT_URL, {
transports: ['websocket'],
upgrade: false,
query: `token=${config.AUTH_TOKEN}`,
});
this.connection.on('connect', () => {
this.connection.emit('room:join', {
nation_id: this.nationId,
});
});
this.state = {
messages: [],
joined: false,
};
} else {
// add initial bot message
constructor(props: Props) {
super(props);
if (props.isBot !== true) {
const selectedNation = resolveNation(props.nations || [], props.nationId);
if (selectedNation === null) {
props.navigator.pop();
return;
}
this.nationId = selectedNation.idInSmartContract;
// Creating the socket-client instance will automatically connect to the server.
this.connection = SocketIOClient(config.CHAT_URL, {
transports: ['websocket'],
upgrade: false,
query: `token=${config.AUTH_TOKEN}`,
});
this.connection.on('connect', () => {
this.connection.emit('room:join', {
nation_id: this.nationId,
});
});
this.state = {
messages: [],
joined: false,
};
} else {
// add initial bot message
componentDidMount() {
if (this.props.isBot !== true && this.connection) {
this.props.showSpinner();
// load initial messages
const URL = `${config.CHAT_URL}/messages/${this.nationId}?auth_token=${
config.AUTH_TOKEN
}`;
fetch(URL)
.then(response => response.json())
.then(
json => {
const messages = deprecatedCreateGiftedChatMessageObject(
json.reverse()
);
this.props.hideSpinner();
this.setState(previousState => ({
messages: GiftedChat.append(previousState.messages, messages)
}));
},
() => {
this.props.hideSpinner();