Skip to content

Commit

Permalink
Enhance chat message metadata logging for verbose debug mode (#797)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgrahl committed May 8, 2019
1 parent d356d5b commit 124225a
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/services/webclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2654,9 +2654,6 @@ export class WebClientService {
this.$log.warn('Invalid messages response, data or arguments missing');
return future.reject('invalidResponse');
}
if (this.config.MSG_DEBUGGING) {
this.logChatMessages(message.type, message.subType, data);
}

// Unpack required argument fields
const type: string = args[WebClientService.ARGUMENT_RECEIVER_TYPE];
Expand All @@ -2670,6 +2667,9 @@ export class WebClientService {
this.$log.warn('Invalid messages response, unknown receiver type (' + type + ')');
return future.reject('invalidResponse');
}
if (this.config.MSG_DEBUGGING) {
this.logChatMessages(message.type, message.subType, type, id, 'new', data);
}
const receiver: threema.BaseReceiver = {type: type, id: id};

// If there's no data returned, override `more` field.
Expand Down Expand Up @@ -2851,9 +2851,6 @@ export class WebClientService {
this.$log.warn('Invalid message update, data or arguments missing');
return future.reject('invalidResponse');
}
if (this.config.MSG_DEBUGGING) {
this.logChatMessages(message.type, message.subType, data);
}

// Unpack required argument fields
const type: string = args[WebClientService.ARGUMENT_RECEIVER_TYPE];
Expand All @@ -2867,6 +2864,9 @@ export class WebClientService {
this.$log.warn(this.logTag, 'Invalid messages update, unknown receiver type (' + type + ')');
return future.reject('invalidResponse');
}
if (this.config.MSG_DEBUGGING) {
this.logChatMessages(message.type, message.subType, type, id, mode, data);
}
const receiver: threema.BaseReceiver = {type: type, id: id};

// React depending on mode
Expand Down Expand Up @@ -4219,17 +4219,21 @@ export class WebClientService {
/**
* Log chat message's metadata for debugging purposes.
*/
private logChatMessages(type: string, subType: string, messages: threema.Message[]) {
private logChatMessages(
type: string, subType: string, receiverType: string, receiver: string, mode: string,
messages: threema.Message[],
) {
for (const message of messages) {
let id: string = message.id;
if (this.clientInfo.os === threema.OperatingSystem.Ios) {
try {
id = u8aToHex(base64ToU8a(message.id));
} catch { /* ignored */ }
}
this.$log.debug('[MessageInspector]', `${type}/${subType}: direction=${message.isOutbox ? 'out' : 'in'}, ` +
`id=${id}, type=${message.type}, state=${message.state !== undefined ? message.state : '?'}, ` +
`is-status=${message.isStatus}, date=${message.date}`);
this.$log.debug('[MessageInspector]', `${type}/${subType}: receiver=${receiverType}/${receiver}, ` +
`mode=${mode}, direction=${message.isOutbox ? 'out' : 'in'}, id=${id}, type=${message.type}, ` +
`state=${message.state !== undefined ? message.state : '?'}, is-status=${message.isStatus}, ` +
`date=${message.date}`);
}
}
}

0 comments on commit 124225a

Please sign in to comment.