Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add command to change display name repeatedly or not #233

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions lib/interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ function getDisplayName(author) {
return colorList[colorPosition](displayName);
}

function renderMessage(author, message) {
let msg = `${getDisplayName(author)}: `;

function renderMessage(author, message, showAuthor = true) {
let msg = showAuthor ? `${getDisplayName(author)}: ` : ``;
if (Settings.properties.showTimestamps) {

const timeDifference = Date.now() - message.timestamp;
Expand Down Expand Up @@ -212,15 +211,35 @@ InteractiveCli.prototype.initializeConversationViewFromFbid = function(id) {
refreshConsole();
attsNo = 0;
atts = [];
// for store previous author name
let previousAuthorString = "";
const msgLength = messages.length;
const linesToShow = Settings.properties.threadLineLimit > 0
? Math.min(msgLength, Settings.properties.threadLineLimit)
: msgLength;
// display author name repeatedly or not
const showPreAuthor = Settings.properties.showPreAuthor;
// calculate which line is first line
const firstShowMsgLine = msgLength - linesToShow;
for (const i in messages) {
const message = messages[i];
let authorString = message.author;

if (authorString.indexOf('fbid:') === 0)
authorString = authorString.substr('fbid:'.length);

// Determine whether to display author name
let showAuthor = true;
if (previousAuthorString == authorString && !showPreAuthor) {
showAuthor = false;
}
if (!showPreAuthor) {
previousAuthorString = authorString;
}
// first line have to show author name
if (i == firstShowMsgLine && !showPreAuthor) {
showAuthor = true;
}
const author = messenger.users[authorString];
const msg = renderMessage(author, message);
const msg = renderMessage(author, message, showAuthor);

interactive.threadHistory.push(msg);
}
Expand Down Expand Up @@ -429,6 +448,7 @@ InteractiveCli.prototype.handleCommands = function(command) {
console.log('/timestamp ........ Toggle timestamp for messages'.cyan);
console.log('/linelimit [#] .... Set max number of messages to display in a conversation'.cyan);
console.log('/nolimit .......... Unset a line limit, display all available messages'.cyan);
console.log('/repeat............ Display name repeatedly or not(default repeatedly)'.cyan);
console.log('/help ............. Print this message'.cyan);
rlInterface.prompt(true);
break;
Expand Down Expand Up @@ -485,7 +505,13 @@ InteractiveCli.prototype.handleCommands = function(command) {
interactive.handleCommands("/refresh");
}
break;
case '/repeat':
Settings.properties.showPreAuthor = !Settings.properties.showPreAuthor;
Settings.save();
console.log(`Changed display author name settings!`.cyan);

interactive.handleCommands("/refresh");
break;
default:
console.log('Unknown command. Type /help for commands.'.cyan);
rlInterface.prompt(true);
Expand Down
3 changes: 2 additions & 1 deletion lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class Settings {
twoFactorAuth: false,
headlessLogin: true,
noSandbox: true,
logonTimeout: 86400000 // 24hrs in ms
logonTimeout: 86400000, // 24hrs in ms
showPreAuthor: true
};
}

Expand Down