FEATURE: Live updates for user's messages page.

https://meta.discourse.org/t/group-inbox-messages-not-updated-for-new-posts/38189
This commit is contained in:
Guo Xiang Tan
2018-03-06 14:38:43 +08:00
parent 13764b31ec
commit 1365bab0d7
24 changed files with 296 additions and 41 deletions

View File

@@ -61,5 +61,11 @@ export default Ember.Component.extend({
}
return false;
}
}
},
actions: {
showInserted() {
this.sendAction('showInserted');
},
},
});

View File

@@ -42,7 +42,7 @@ const controllerOpts = {
const tracker = this.topicTrackingState;
// Move inserted into topics
this.get('content').loadBefore(tracker.get('newIncoming'));
this.get('content').loadBefore(tracker.get('newIncoming'), true);
tracker.resetTracking();
return false;
},

View File

@@ -33,7 +33,6 @@ export default Ember.Controller.extend({
return hasSelection && pmView !== "archive" && !archive;
},
bulkOperation(operation) {
const selected = this.get('selected');
var params = {type: operation};

View File

@@ -1,18 +1,58 @@
import computed from 'ember-addons/ember-computed-decorators';
// Lists of topics on a user's page.
export default Ember.Controller.extend({
application: Ember.inject.controller(),
hideCategory: false,
showPosters: false,
newIncoming: [],
incomingCount: 0,
channel: null,
_showFooter: function() {
this.set("application.showFooter", !this.get("model.canLoadMore"));
}.observes("model.canLoadMore"),
@computed('incomingCount')
hasIncoming(incomingCount) {
return incomingCount > 0;
},
subscribe(channel) {
this.set('channel', channel);
this.messageBus.subscribe(channel, data => {
if (this.get('newIncoming').indexOf(data.topic_id) === -1) {
this.get('newIncoming').push(data.topic_id);
this.incrementProperty('incomingCount');
}
});
},
unsubscribe() {
this.messageBus.unsubscribe(this.get('channel'));
this._resetTracking();
},
_resetTracking() {
this.setProperties({
"newIncoming": [],
"incomingCount": 0,
"channel": null,
});
},
actions: {
loadMore: function() {
this.get('model').loadMore();
}
},
showInserted() {
this.get('model').loadBefore(this.get('newIncoming'));
this._resetTracking();
return false;
},
},
});

View File

@@ -70,14 +70,14 @@ const TopicList = RestModel.extend({
// loads topics with these ids "before" the current topics
loadBefore(topic_ids) {
loadBefore(topic_ids, storeInSession) {
const topicList = this,
topics = this.get('topics');
// refresh dupes
topics.removeObjects(topics.filter(topic => topic_ids.indexOf(topic.get('id')) >= 0));
const url = `${Discourse.getURL("/")}${this.get('filter')}?topic_ids=${topic_ids.join(",")}`;
const url = `${Discourse.getURL("/")}${this.get('filter')}.json?topic_ids=${topic_ids.join(",")}`;
const store = this.store;
return ajax({ url }).then(result => {
@@ -88,7 +88,7 @@ const TopicList = RestModel.extend({
topics.insertAt(i,t);
i++;
});
Discourse.Session.currentProp('topicList', topicList);
if (storeInSession) Discourse.Session.currentProp('topicList', topicList);
});
}
});

View File

@@ -1,7 +1,7 @@
import UserTopicListRoute from "discourse/routes/user-topic-list";
// A helper to build a user topic list route
export default (viewName, path) => {
export default (viewName, path, channel) => {
return UserTopicListRoute.extend({
userActionType: Discourse.UserAction.TYPES.messages_received,
@@ -19,6 +19,10 @@ export default (viewName, path) => {
setupController() {
this._super.apply(this, arguments);
if (channel) {
this.controllerFor("user-topics-list").subscribe(`/private-messages/${channel}`);
}
this.controllerFor("user-topics-list").setProperties({
hideCategory: true,
showPosters: true,
@@ -32,6 +36,8 @@ export default (viewName, path) => {
},
deactivate() {
this.controllerFor('user-topics-list').unsubscribe();
this.searchService.set(
'searchContext',
this.controllerFor("user").get("model.searchContext")

View File

@@ -1,3 +1,3 @@
import createPMRoute from "discourse/routes/build-private-messages-route";
export default createPMRoute('archive', 'private-messages-archive');
export default createPMRoute('archive', 'private-messages-archive', 'archive');

View File

@@ -22,5 +22,6 @@ export default createPMRoute('groups', 'private-messages-groups').extend({
const group = split[split.length-2];
this.controllerFor("user-private-messages").set("groupFilter", group);
this.controllerFor("user-private-messages").set("archive", true);
this.controllerFor("user-topics-list").subscribe(`/private-messages/group/${group}/archive`);
}
});

View File

@@ -20,5 +20,6 @@ export default createPMRoute('groups', 'private-messages-groups').extend({
const group = _.last(model.get("filter").split('/'));
this.controllerFor("user-private-messages").set("groupFilter", group);
this.controllerFor("user-private-messages").set("archive", false);
this.controllerFor("user-topics-list").subscribe(`/private-messages/group/${group}`);
}
});

View File

@@ -1,3 +1,3 @@
import createPMRoute from "discourse/routes/build-private-messages-route";
export default createPMRoute('index', 'private-messages');
export default createPMRoute('index', 'private-messages', 'inbox');

View File

@@ -1,3 +1,3 @@
import createPMRoute from "discourse/routes/build-private-messages-route";
export default createPMRoute('sent', 'private-messages-sent');
export default createPMRoute('sent', 'private-messages-sent', 'sent');

View File

@@ -1,4 +1,13 @@
{{#conditional-loading-spinner condition=loading}}
{{#if hasIncoming}}
<div class="show-mores">
<div class='alert alert-info clickable' {{action "showInserted"}}>
{{count-i18n key="topic_count_" suffix="latest" count=incomingCount}}
{{i18n 'click_to_show'}}
</div>
</div>
{{/if}}
{{#if topics}}
{{topic-list showParticipants=showParticipants
showPosters=showPosters

View File

@@ -4,7 +4,10 @@
showParticipants=showParticipants
showPosters=showPosters
bulkSelectEnabled=bulkSelectEnabled
selected=selected}}
selected=selected
hasIncoming=hasIncoming
incomingCount=incomingCount
showInserted="showInserted"}}
{{conditional-loading-spinner condition=model.loadingMore}}
{{/load-more}}

View File

@@ -7,6 +7,15 @@
margin-right: 10px;
}
}
.paginated-topics-list {
position: relative;
}
.show-mores {
position: absolute;
width: 100%;
}
}
.user-main {