From eee2db628a3fcfe1eb700f8f3f0ce6a30d1b9adb Mon Sep 17 00:00:00 2001 From: Gene S Date: Tue, 12 Jan 2016 18:57:34 -0800 Subject: [PATCH] fetching messages from the server --- index.html | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index d874213a..9d8eae23 100644 --- a/index.html +++ b/index.html @@ -329,7 +329,7 @@ /* A single topic */ var Contact = React.createClass({ handleClick: function() { - this.props.onSelected(this.props.public); + this.props.onSelected(this.props.topic); }, render: function() { return ( @@ -391,7 +391,7 @@ var c = this.props.data[key]; return ( + onSelected={this.onSelectionChange} topic={c.topic} key={c.topic} /> ); }, this); } @@ -591,9 +591,16 @@ dignissim a diam a hendrerit. Nulla vel est ut quam rhoncus pulvinar. In hac hab instance.setState({loginDisabled: false, errorText: err.message}); }); }, + handleInfoChange: function(info) { + console.log(info); + this.setState({selectedTopicName: info.public}); + }, handleMeInfoChange: function(info) { this.setState({sideTitle: info.public}); }, + handleSubsUpdated: function(uids) { + console.log(uids); + }, handleMeSubsChange: function(sub) { var subs = this.state.subscriptions; subs[sub.topic] = sub; @@ -602,8 +609,19 @@ dignissim a diam a hendrerit. Nulla vel est ut quam rhoncus pulvinar. In hac hab handleNewAccount: function(login_, password_, public_, private_) { }, - handleTopicSelected: function(topic) { - this.setState({selectedTopicName: topic}); + handleNewMessage: function(msg) { + console.log(msg); + }, + handleTopicSelected: function(topicName) { + var topic = Tinode.getTopic(topicName); + if (topic.isSubscribed()) { + this.handleInfoChange(topic); + } else { + topic.onData = this.handleNewMessage; + topic.onInfoChange = this.handleInfoChange; + topic.onSubsUpdated = this.handleSubsUpdated; + topic.subscribe({get: "info sub data"}); + } }, handleSignUp: function() { this.setState({sidePanel: 'register'});