Review changes

pull/48/head
Beaudan 6 years ago
parent 4b16ff755b
commit ff3cc7a315

@ -1137,7 +1137,6 @@ async function saveMessage(data, { forceSave } = {}) {
// eslint-disable-next-line camelcase // eslint-disable-next-line camelcase
received_at, received_at,
schemaVersion, schemaVersion,
// eslint-disable-next-line camelcase
sent, sent,
// eslint-disable-next-line camelcase // eslint-disable-next-line camelcase
sent_at, sent_at,

@ -743,7 +743,7 @@
const requests = await this.getPendingFriendRequests('incoming'); const requests = await this.getPendingFriendRequests('incoming');
// Delete the old message if it's pending // Delete the old message if it's pending
await Promise.all(requests.map(async request => this._removeMessage(request.id))); await Promise.all(requests.map(request => this._removeMessage(request.id)));
// Trigger an update if we removed messages // Trigger an update if we removed messages
if (requests.length > 0) if (requests.length > 0)
this.trigger('change'); this.trigger('change');
@ -1038,7 +1038,7 @@
// and send the new request if possible // and send the new request if possible
let friendRequestSent = false; let friendRequestSent = false;
const promises = []; const promises = [];
outgoingRequests.forEach(async outgoing => { outgoingRequests.forEach(outgoing => {
if (outgoing.hasErrors()) { if (outgoing.hasErrors()) {
promises.push(this._removeMessage(outgoing.id)); promises.push(this._removeMessage(outgoing.id));
} else { } else {
@ -2110,9 +2110,10 @@
// Notification for friend request received // Notification for friend request received
async notifyFriendRequest(source, type) { async notifyFriendRequest(source, type) {
// Data validation // Data validation
if (!source) return Promise.reject(new Error('Invalid source')); if (!source)
throw new Error('Invalid source');
if (!['accepted', 'requested'].includes(type)) if (!['accepted', 'requested'].includes(type))
return Promise.reject(new Error('Type must be accepted or requested.')); throw new Error('Type must be accepted or requested.');
// Call the notification on the right conversation // Call the notification on the right conversation
let conversation = this; let conversation = this;
@ -2125,7 +2126,7 @@
window.log.info(`Notify called on a different conversation. window.log.info(`Notify called on a different conversation.
Expected: ${this.id}. Actual: ${conversation.id}`); Expected: ${this.id}. Actual: ${conversation.id}`);
} catch (e) { } catch (e) {
return Promise.reject(new Error('Failed to fetch conversation')); throw new Error('Failed to fetch conversation.');
} }
} }
@ -2149,7 +2150,6 @@
messageSentAt: Date.now(), messageSentAt: Date.now(),
title: i18n(title), title: i18n(title),
}); });
return Promise.resolve();
}, },
}); });

@ -254,27 +254,26 @@ MessageReceiver.prototype.extend({
this.calledClose this.calledClose
); );
// TODO: handle properly // TODO: handle properly
return Promise.resolve(); // this.shutdown();
this.shutdown();
// if (this.calledClose) {
if (this.calledClose) { // return Promise.resolve();
return Promise.resolve(); // }
} // if (ev.code === 3000) {
if (ev.code === 3000) { // return Promise.resolve();
return Promise.resolve(); // }
} // if (ev.code === 3001) {
if (ev.code === 3001) { // this.onEmpty();
this.onEmpty(); // }
} // // possible 403 or network issue. Make an request to confirm
// possible 403 or network issue. Make an request to confirm // return this.server
return this.server // .getDevices(this.number)
.getDevices(this.number) // .then(this.connect.bind(this)) // No HTTP error? Reconnect
.then(this.connect.bind(this)) // No HTTP error? Reconnect // .catch(e => {
.catch(e => { // const event = new Event('error');
const event = new Event('error'); // event.error = e;
event.error = e; // return this.dispatchAndWait(event);
return this.dispatchAndWait(event); // });
});
}, },
handleRequest(request) { handleRequest(request) {
this.incoming = this.incoming || []; this.incoming = this.incoming || [];
@ -1047,7 +1046,7 @@ MessageReceiver.prototype.extend({
} }
// Exit early since the friend request reply will be a regular empty message // Exit early since the friend request reply will be a regular empty message
return Promise.resolve(); return null;
} }
if (content.syncMessage) { if (content.syncMessage) {

Loading…
Cancel
Save