better use of local cache

This commit is contained in:
or-else
2017-09-13 12:17:24 -07:00
parent 9adff7572e
commit 7870fb06a2
2 changed files with 31 additions and 20 deletions
+1 -1
View File
@@ -17,9 +17,9 @@ Background pattern from http://subtlepatterns.com/, commercial and non-commercia
## Missing functionality ## Missing functionality
* Cannot send images or other media. * Cannot send images or other media.
* Cannot delete messages.
* No typing indicators. * No typing indicators.
* No indication of chat status (muted, blocked, etc.). * No indication of chat status (muted, blocked, etc.).
* Long polling as a wire transport does not work.
* Browser push notifications are missing. * Browser push notifications are missing.
* No encryption. * No encryption.
* Editing chat permissions is incomplete. * Editing chat permissions is incomplete.
+30 -19
View File
@@ -2342,6 +2342,9 @@
componentWillMount: function() { componentWillMount: function() {
this.propsChange(this.props); this.propsChange(this.props);
if (this.messagesScroller) {
this.messagesScroller.addEventListener('scroll', this.fetchMoreMessages);
}
}, },
componentWillUnmount: function() { componentWillUnmount: function() {
@@ -2368,20 +2371,28 @@
// Unbind the previous topic from this component. // Unbind the previous topic from this component.
this.leave(); this.leave();
if (topic.isSubscribed()) { this.handleDescChange(topic);
this.handleDescChange(topic); topic.messages(function(msg) {
topic.messages(function(msg) { msgs = msgs.concat(msg);
msgs = msgs.concat(msg); });
});
} else { if (!topic.isSubscribed()) {
topic.subscribe({get: {desc: {}, sub: {}, data: {limit: MESSAGES_PAGE}}}); topic.subscribe(topic.startMetaQuery()
.withLaterDesc()
.withLaterSub()
.withLaterData(MESSAGES_PAGE)
.build());
} }
// The user switched to the new topic before the timer for // The user switched to the new topic before the timer for
// the previous topic has triggered, kill it. // the previous topic has triggered, kill it.
clearTimeout(this.readTimer); clearTimeout(this.readTimer);
this.setState({messages: msgs, topic: props.topic, scrollPosition: 0}); this.setState({
messages: msgs,
topic: props.topic,
scrollPosition: 0
});
} }
}, },
@@ -2417,10 +2428,8 @@
var topic = Tinode.getTopic(instance.state.topic); var topic = Tinode.getTopic(instance.state.topic);
if (topic && topic.msgHasMore()) { if (topic && topic.msgHasMore()) {
newState.fetchingMessages = true; newState.fetchingMessages = true;
console.log("START fetching messages from " + topic._minSeq);
topic.getMessagesPage(MESSAGES_PAGE).then(function() { topic.getMessagesPage(MESSAGES_PAGE).then(function() {
instance.setState({fetchingMessages: false}); instance.setState({fetchingMessages: false});
console.log("DONE fetching messages");
}); });
} }
} }
@@ -2437,6 +2446,7 @@
}); });
} }
}, },
handleSubsUpdated: function(uids) { handleSubsUpdated: function(uids) {
// console.log("topic subscriptions updated"); // console.log("topic subscriptions updated");
}, },
@@ -2816,8 +2826,8 @@
var me = Tinode.getMeTopic(); var me = Tinode.getMeTopic();
me.onMetaDesc = instance.tnMeMetaDesc; me.onMetaDesc = instance.tnMeMetaDesc;
instance.setState({sidePanelSelected: "contacts", myUserId: Tinode.getCurrentUserID()}); instance.setState({sidePanelSelected: "contacts", myUserId: Tinode.getCurrentUserID()});
// Subscribe, fetch topic desc, the list of subscriptions, and messages (invites). // Subscribe, fetch topic desc, the list of subscriptions. Messages are not fetched.
me.subscribe({get: {desc: {}, sub: {}, data: {}}}); me.subscribe(me.startMetaQuery().withLaterSub().withLaterDesc().build());
}, },
handleDisconnect: function(err) { handleDisconnect: function(err) {
@@ -2866,7 +2876,7 @@
this.setState({contactsSearchQuery: fnd.private ? fnd.private.toString() : ''}); this.setState({contactsSearchQuery: fnd.private ? fnd.private.toString() : ''});
this.tnFndSubsUpdated(); this.tnFndSubsUpdated();
} else { } else {
fnd.subscribe({get: {sub: {}, desc: {}}}); fnd.subscribe(fnd.startMetaQuery().withSub().withLaterDesc().build());
} }
}, },
@@ -2888,9 +2898,9 @@
@param query {Array} is an array of contacts to search for @param query {Array} is an array of contacts to search for
*/ */
handleSearchContacts: function(query) { handleSearchContacts: function(query) {
var find = Tinode.getFndTopic(); var fnd = Tinode.getFndTopic();
find.setMeta({desc: {private: query}}).then(function(ctrl) { fnd.setMeta({desc: {private: query}}).then(function(ctrl) {
find.getMeta({sub: {}, desc: {}}); fnd.getMeta(fnd.startMetaQuery().withSub().withLaterDesc().build());
}); });
}, },
@@ -2990,12 +3000,13 @@
var instance = this; var instance = this;
var topic = peerName ? Tinode.newTopicWith(peerName) : Tinode.newTopic(); var topic = peerName ? Tinode.newTopicWith(peerName) : Tinode.newTopic();
var params = {get: {desc: {}, data: {}, sub: {}}}; var query = topic.startMetaQuery().withDesc().withSub().withData();
var setParams;
if (!peerName) { if (!peerName) {
params.set = {desc: {public: pub}}; setParams = {desc: {public: pub}};
} }
topic.subscribe(params).then(function() { topic.subscribe(query.build(), setParams).then(function() {
instance.setState({ instance.setState({
errorText: '', errorText: '',
topicSelected: topic.name, topicSelected: topic.name,