Use window.log in browser context, turn on console eslint rule

This commit is contained in:
Scott Nonnenberg 2018-07-21 12:00:08 -07:00
parent 4320b125dd
commit 5933a34a18
71 changed files with 816 additions and 559 deletions

View file

@ -15,7 +15,7 @@
return;
}
console.log('adding', number, 'to blocked list');
window.log.info('adding', number, 'to blocked list');
storage.put('blocked', numbers.concat(number));
};
storage.removeBlockedNumber = number => {
@ -24,7 +24,7 @@
return;
}
console.log('removing', number, 'from blocked list');
window.log.info('removing', number, 'from blocked list');
storage.put('blocked', _.without(numbers, number));
};
})();

View file

@ -156,7 +156,7 @@
async onExpiredCollection(message) {
const removeMessage = () => {
console.log('Remove expired message from collection', {
window.log.info('Remove expired message from collection', {
sentAt: message.get('sent_at'),
});
this.messageCollection.remove(message.id);
@ -347,7 +347,7 @@
return lookup;
})
.catch(error => {
console.log(
window.log.error(
'getIdentityKeys error for conversation',
this.idForLogging(),
error && error.stack ? error.stack : error
@ -361,7 +361,7 @@
lookup[contact.id] = key;
},
error => {
console.log(
window.log.error(
'getIdentityKeys error for group member',
contact.idForLogging(),
error && error.stack ? error.stack : error
@ -375,7 +375,7 @@
replay(error, message) {
const replayable = new textsecure.ReplayableError(error);
return replayable.replay(message.attributes).catch(e => {
console.log('replay error:', e && e.stack ? e.stack : e);
window.log.error('replay error:', e && e.stack ? e.stack : e);
});
},
decryptOldIncomingKeyErrors() {
@ -383,7 +383,10 @@
if (this.get('decryptedOldIncomingKeyErrors')) {
return Promise.resolve();
}
console.log('decryptOldIncomingKeyErrors start for', this.idForLogging());
window.log.info(
'decryptOldIncomingKeyErrors start for',
this.idForLogging()
);
const messages = this.messageCollection.filter(message => {
const errors = message.get('errors');
@ -399,7 +402,7 @@
});
const markComplete = () => {
console.log(
window.log.info(
'decryptOldIncomingKeyErrors complete for',
this.idForLogging()
);
@ -412,7 +415,7 @@
return markComplete();
}
console.log(
window.log.info(
'decryptOldIncomingKeyErrors found',
messages.length,
'messages to process'
@ -449,7 +452,7 @@
)
)
.catch(error => {
console.log(
window.log.error(
'decryptOldIncomingKeyErrors error:',
error && error.stack ? error.stack : error
);
@ -583,7 +586,7 @@
},
addKeyChange(id) {
console.log(
window.log.info(
'adding key change advisory for',
this.idForLogging(),
id,
@ -606,7 +609,7 @@
_.defaults(options, { local: true });
if (this.isMe()) {
console.log(
window.log.info(
'refusing to add verified change advisory for our own number'
);
return;
@ -614,7 +617,7 @@
const lastMessage = this.get('timestamp') || Date.now();
console.log(
window.log.info(
'adding verified change advisory for',
this.idForLogging(),
id,
@ -823,7 +826,7 @@
this.queueJob(async () => {
const now = Date.now();
console.log(
window.log.info(
'Sending message to conversation',
this.idForLogging(),
'with timestamp',
@ -933,7 +936,7 @@
return Promise.resolve();
}
console.log("Update conversation 'expireTimer'", {
window.log.info("Update conversation 'expireTimer'", {
id: this.idForLogging(),
expireTimer,
source,
@ -1085,7 +1088,7 @@
if (this.messageCollection.get(m.id)) {
m = this.messageCollection.get(m.id);
} else {
console.log(
window.log.warn(
'Marked a message as read in the database, but ' +
'it was not in messageCollection.'
);
@ -1117,7 +1120,7 @@
read = read.filter(item => !item.hasErrors);
if (read.length && options.sendReadReceipts) {
console.log('Sending', read.length, 'read receipts');
window.log.info('Sending', read.length, 'read receipts');
promises.push(textsecure.messaging.syncReadMessages(read));
if (storage.get('read-receipt-setting')) {
@ -1173,7 +1176,7 @@
// save identity will close all sessions except for .1, so we
// must close that one manually.
const address = new libsignal.SignalProtocolAddress(id, 1);
console.log('closing session for', address.toString());
window.log.info('closing session for', address.toString());
const sessionCipher = new libsignal.SessionCipher(
textsecure.storage.protocol,
address
@ -1197,7 +1200,7 @@
e => {
if (e.name === 'ProfileDecryptError') {
// probably the profile key has changed.
console.log(
window.log.error(
'decryptProfile error:',
id,
profile,
@ -1209,7 +1212,7 @@
});
})
.catch(error => {
console.log(
window.log.error(
'getProfile error:',
error && error.stack ? error.stack : error
);
@ -1365,7 +1368,7 @@
await wrapDeferred(message.save());
}
} catch (error) {
console.log(
window.log.error(
'Problem upgrading message quoted message from database',
Errors.toLogFormat(error)
);
@ -1532,7 +1535,7 @@
throw new Error('This conversation has no id!');
}
if (this.inProgressFetch) {
console.log('Attempting to start a parallel fetchMessages() call');
window.log.warn('Attempting to start a parallel fetchMessages() call');
return;
}
@ -1550,7 +1553,7 @@
// one-time hit. We do this so we have guarantees about message structure.
await this.upgradeMessages(this.messageCollection);
} catch (error) {
console.log(
window.log.error(
'fetchMessages: failed to upgrade messages',
Errors.toLogFormat(error)
);
@ -1758,7 +1761,7 @@
const messageId = message.id;
const isExpiringMessage = Message.hasExpiration(messageJSON);
console.log('Add notification', {
window.log.info('Add notification', {
conversationId: this.idForLogging(),
isExpiringMessage,
messageSentAt,

View file

@ -59,7 +59,12 @@
storeName: 'messages',
initialize(attributes) {
if (_.isObject(attributes)) {
this.set(TypedMessage.initializeSchemaVersion(attributes));
this.set(
TypedMessage.initializeSchemaVersion({
message: attributes,
logger: window.log,
})
);
}
this.OUR_NUMBER = textsecure.storage.user.getNumber();
@ -86,7 +91,7 @@
const required = ['conversationId', 'received_at', 'sent_at'];
const missing = _.filter(required, attr => !attributes[attr]);
if (missing.length) {
console.log(`Message missing attributes: ${missing}`);
window.log.warn(`Message missing attributes: ${missing}`);
}
},
isEndSession() {
@ -860,7 +865,7 @@
errors = [errors];
}
errors.forEach(e => {
console.log(
window.log.error(
'Message.saveErrors:',
e && e.reason ? e.reason : null,
e && e.stack ? e.stack : e
@ -972,7 +977,7 @@
groupUpdate.joined = difference;
}
if (conversation.get('left')) {
console.log('re-added to a left group');
window.log.warn('re-added to a left group');
attributes.left = false;
}
} else if (dataMessage.group.type === GROUP_TYPES.QUIT) {
@ -1038,7 +1043,7 @@
const shouldLogExpireTimerChange =
message.isExpirationTimerUpdate() || expireTimer;
if (shouldLogExpireTimerChange) {
console.log("Update conversation 'expireTimer'", {
window.log.info("Update conversation 'expireTimer'", {
id: conversation.idForLogging(),
expireTimer,
source: 'handleDataMessage',
@ -1142,7 +1147,7 @@
const handleError = error => {
const errorForLog = error && error.stack ? error.stack : error;
console.log(
window.log.error(
'handleDataMessage',
message.idForLogging(),
'error:',
@ -1167,7 +1172,7 @@
() => {
try {
if (previousUnread !== message.get('unread')) {
console.log(
window.log.warn(
'Caught race condition on new message read state! ' +
'Manually starting timers.'
);
@ -1192,7 +1197,7 @@
},
() => {
try {
console.log(
window.log.warn(
'handleDataMessage: Message',
message.idForLogging(),
'was deleted'
@ -1257,7 +1262,7 @@
}
Whisper.ExpiringMessagesListener.update();
console.log('Set message expiration', {
window.log.info('Set message expiration', {
expiresAt,
sentAt: this.get('sent_at'),
});
@ -1364,7 +1369,9 @@
return Promise.resolve();
}
console.log('fetchConversation: doing another fetch to get all unread');
window.log.info(
'fetchConversation: doing another fetch to get all unread'
);
return this.fetchConversation(conversationId, limit, unreadCount);
});
},
@ -1374,7 +1381,7 @@
},
fetchExpired() {
console.log('Load expired messages');
window.log.info('Load expired messages');
this.fetch({
conditions: { expires_at: { $lte: Date.now() } },
addIndividually: true,