update bus.subscribe

This commit is contained in:
undefined committed 2020-07-30 17:04:46 +08:00
1 parent 875bf696e2
commit d077019e0d
15 files changed
+85 -162

No files matched your search

+21 -8
View File
@@ -206,18 +206,30 @@ class HomeSettingsHandler extends Handler {
this.response.body.settings = setting.PREFERENCE_SETTINGS;
} else if (category === 'account') {
this.response.body.settings = setting.ACCOUNT_SETTINGS;
} else if (category === 'domain') {
this.response.body.settings = setting.DOMAIN_USER_SETTINGS;
} else throw new NotFoundError();
}
async post(args: any) {
const $set = {};
for (const key in args) {
if (setting.SETTINGS_BY_KEY[key]
&& !(setting.SETTINGS_BY_KEY[key].flag & setting.FLAG_DISABLED)) {
$set[key] = args[key];
if (args.category === 'domain') {
for (const key in args) {
if (setting.DOMAIN_USER_SETTINGS_BY_KEY[key]
&& !(setting.DOMAIN_USER_SETTINGS_BY_KEY[key].flag & setting.FLAG_DISABLED)) {
$set[key] = args[key];
}
}
await domain.setUserInDomain(args.domainId, this.user._id, $set);
} else {
for (const key in args) {
if (setting.SETTINGS_BY_KEY[key]
&& !(setting.SETTINGS_BY_KEY[key].flag & setting.FLAG_DISABLED)) {
$set[key] = args[key];
}
}
await user.setById(this.user._id, $set);
}
await user.setById(this.user._id, $set);
this.back();
}
}
@@ -322,7 +334,6 @@ class HomeMessagesHandler extends Handler {
if (!udoc) throw new UserNotFoundError(uid);
if (udoc.gravatar) udoc.gravatar = misc.gravatar(udoc.gravatar);
const mdoc = await message.send(this.user._id, uid, content, message.FLAG_UNREAD);
// TODO(twd2): improve here: projection\
this.back({ mdoc, udoc });
}
@@ -345,8 +356,10 @@ class HomeMessagesHandler extends Handler {
}
class HomeMessagesConnectionHandler extends ConnectionHandler {
id: string;
async prepare() {
bus.subscribe([`user_message-${this.user._id}`], this, 'onMessageReceived');
bus.subscribe([`user_message-${this.user._id}`], this.onMessageReceived.bind(this));
}
async onMessageReceived(e: any) {
@@ -354,7 +367,7 @@ class HomeMessagesConnectionHandler extends ConnectionHandler {
}
async cleanup() {
bus.unsubscribe([`user_message-${this.user._id}`], this, 'onMessageReceived');
bus.unsubscribe([`user_message-${this.user._id}`], this.id);
}
}
+1 -3
View File
@@ -8,9 +8,7 @@ class NotFoundHandler extends Handler {
throw new NotFoundError();
}
async get() { }
async post() { }
all() { }
}
export async function apply() {
+4 -2
View File
@@ -284,6 +284,8 @@ class ProblemPretestConnectionHandler extends ConnectionHandler {
domainId: string;
id: string;
@param('pid', Types.String)
async prepare(domainId: string, pid: string) {
const pdoc = await problem.get(domainId, pid);
@@ -291,7 +293,7 @@ class ProblemPretestConnectionHandler extends ConnectionHandler {
if (!pdoc) throw new ProblemNotFoundError(domainId, pid);
this.pid = pdoc.docId.toString();
this.domainId = domainId;
bus.subscribe(['record_change'], this, 'onRecordChange');
this.id = bus.subscribe(['record_change'], this.onRecordChange.bind(this));
}
async onRecordChange(data) {
@@ -313,7 +315,7 @@ class ProblemPretestConnectionHandler extends ConnectionHandler {
}
async cleanup() {
bus.unsubscribe(['record_change'], this, 'onRecordChange');
bus.unsubscribe(['record_change'], this.id);
}
}
+4 -4
View File
@@ -113,7 +113,7 @@ class RecordMainConnectionHandler extends RecordConnectionHandler {
return;
}
}
bus.subscribe(['record_change'], this, 'onRecordChange');
this.id = bus.subscribe(['record_change'], this.onRecordChange.bind(this));
}
async message(msg) {
@@ -129,7 +129,7 @@ class RecordMainConnectionHandler extends RecordConnectionHandler {
}
async cleanup() {
bus.unsubscribe(['record_change'], this, 'onRecordChange');
bus.unsubscribe(['record_change'], this.id);
}
async onRecordChange(data) {
@@ -157,7 +157,7 @@ class RecordDetailConnectionHandler extends contest.ContestHandlerMixin(Connecti
}
}
this.rid = rid.toString();
bus.subscribe(['record_change'], this, 'onRecordChange');
this.id = bus.subscribe(['record_change'], this.onRecordChange.bind(this));
this.onRecordChange({ value: { rdoc } });
}
@@ -175,7 +175,7 @@ class RecordDetailConnectionHandler extends contest.ContestHandlerMixin(Connecti
}
async cleanup() {
bus.unsubscribe(['record_change'], this, 'onRecordChange');
bus.unsubscribe(['record_change'], this.id);
}
}