twister-react/jsx/other/Conversation.js

112 lines
3.0 KiB
JavaScript
Raw Normal View History

2015-04-30 09:22:58 +00:00
var React = require('react');
var Postboard = require("../common/Postboard.js");
var SetIntervalMixin = require("../common/SetIntervalMixin.js");
var StreamMixin = require("../common/StreamMixin.js");
var SafeStateChangeMixin = require('../common/SafeStateChangeMixin.js');
var EventListenerMixin = require('../common/EventListenerMixin.js');
2015-04-30 09:42:10 +00:00
var AppSettingsMixin = require('../common/AppSettingsMixin.js');
2015-04-30 09:22:58 +00:00
var ReactBootstrap = require('react-bootstrap')
, NavItem = ReactBootstrap.NavItem
, Nav = ReactBootstrap.Nav
, ListGroup = ReactBootstrap.ListGroup
, ListGroupItem = ReactBootstrap.ListGroupItem
, Panel = ReactBootstrap.Panel
, Glyphicon = ReactBootstrap.Glyphicon
, Button = ReactBootstrap.Button
2015-08-16 11:30:33 +00:00
module.exports = Conversation = React.createClass({
2015-04-30 09:22:58 +00:00
mixins:[
2015-04-30 09:42:10 +00:00
AppSettingsMixin,
2015-04-30 09:22:58 +00:00
StreamMixin,
SetIntervalMixin,
SafeStateChangeMixin,
EventListenerMixin('newpostbyuser')
],
contextTypes: {
router: React.PropTypes.func
},
getInitialState: function() {
return {
username: this.context.router.getCurrentParams().username,
postid: parseInt(this.context.router.getCurrentParams().postid),
data: [],
postIdentifiers: {},
loading: true
};
},
updatePosts: function(outdatedLimit) {
//console.log(this.state.username+":post"+this.state.postid)
2015-04-30 09:42:10 +00:00
if (!outdatedLimit) {outdatedLimit=this.state.appSettings.pollInterval/2;}
2015-04-30 09:22:58 +00:00
var thisComponent = this;
var thisUsername = this.state.username;
var goUpConversation = function (post) {
2016-01-22 20:01:50 +00:00
if(!post) return;
2015-04-30 09:22:58 +00:00
if (post.isReply()) {
2016-01-22 20:01:50 +00:00
post.doPostRepliedTo(function(otherpost){
if(otherpost){
goUpConversation(otherpost);
}else{
thisComponent.addPost(post);
thisComponent.setStateSafe({loading: false});
post.doReplies(doRepliesRecursive);
}
});
2015-04-30 09:22:58 +00:00
} else {
thisComponent.addPost(post);
thisComponent.setStateSafe({loading: false});
2015-04-30 09:22:58 +00:00
post.doReplies(doRepliesRecursive);
}
}
var doRepliesRecursive = function (replies) {
for (var i in replies) {
replies[i].doReplies(doRepliesRecursive);
thisComponent.addPost(replies[i]);
//console.log(replies[i].getContent())
2015-04-30 09:22:58 +00:00
}
};
Twister.getUser(this.state.username).doPost(this.state.postid,goUpConversation,{outdatedLimit: outdatedLimit, logfunc: function(log){console.log(log)}});
},
componentDidMount: function() {
2015-04-30 09:42:10 +00:00
this.updatePosts(2*this.state.appSettings.pollInterval);
this.setInterval(this.updatePosts, this.state.appSettings.pollInterval*1000);
2015-04-30 09:22:58 +00:00
},
onnewpostbyuser: function (event) {
//alert("got event")
2016-01-05 08:14:23 +00:00
this.updatePosts();
2015-04-30 09:22:58 +00:00
},
render: function() {
return (
<Postboard header={
<ListGroupItem>
Conversation
</ListGroupItem>
} data={this.state.data} loading={this.state.loading} activeAccount={this.props.activeAccount}/>
2015-04-30 09:22:58 +00:00
);
}
});