Skip to content

Commit

Permalink
Fixes the following
Browse files Browse the repository at this point in the history
- Show "Load messages to translate" button
- Create getTgMsgOptions function to reduce redundancy

Fixes amire80#7
  • Loading branch information
mdew192837 committed Jul 3, 2017
1 parent b7c2168 commit 8005a78
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions MediaWikiTelegramBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ function inlineKeyboardButton(text, action, params) {
return [{ text, callback_data: callbackString(action, params) }];
}

function getTgMsgOptions(inlineKeyboard) {
return {
reply_markup: JSON.stringify({
inline_keyboard: inlineKeyboard
})
};
}

let config;

try {
Expand Down Expand Up @@ -123,6 +131,19 @@ function setLanguageCode(userID, newLanguageCode) {
user.languageCode = newLanguageCode;
user.currentMwMessageIndex = 0;
user.loadedMwMessages = [];

// Since Issue #7
const inlineKeyboard = [
createGetUntranslatedMessagesButton(userID)
];

const tgMsgOptions = getTgMsgOptions(inlineKeyboard);

tgBot.sendMessage(
userID,
i18n(getLanguageCode(userID), "tgbot-load-messages"),
tgMsgOptions
);
}

// TODO: Replace with something like jquery.i18n
Expand Down Expand Up @@ -265,11 +286,7 @@ function showCurrentMwMessage(userID) {
callbackPrefixes.SKIP
));

const tgMsgOptions = {
reply_markup: JSON.stringify({
inline_keyboard: inlineKeyboard
})
};
const tgMsgOptions = getTgMsgOptions(inlineKeyboard);

tgBot.sendMessage(
userID,
Expand Down Expand Up @@ -309,11 +326,7 @@ function advanceMwMessage(userID) {
createGetUntranslatedMessagesButton(userID)
];

const tgMsgOptions = {
reply_markup: JSON.stringify({
inline_keyboard: inlineKeyboard
})
};
const tgMsgOptions = getTgMsgOptions(inlineKeyboard);

tgBot.sendMessage(
userID,
Expand Down Expand Up @@ -591,11 +604,7 @@ tgBot.onText(/^([^\/].*)/, (tgMsg, match) => {
createGetUntranslatedMessagesButton(userID)
];

const tgMsgOptions = {
reply_markup: JSON.stringify({
inline_keyboard: inlineKeyboard
})
};
const tgMsgOptions = getTgMsgOptions(inlineKeyboard);

tgBot.sendMessage(
userID,
Expand Down

0 comments on commit 8005a78

Please sign in to comment.