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

Allow users to select a preferen language #116

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
8 changes: 8 additions & 0 deletions src/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@
</select>
</div>
</div>
<div class="row">
<div class="col-xl-12">
<label>Language</label>
<select name="userLanguage" id="userLanguage">
<option value="any">Any / All</option>
</select>
</div>
</div>
<div class="row">
<div class="col-xl-12">
<div class="btn-group partner-actions" role="group">
Expand Down
3 changes: 3 additions & 0 deletions src/client/js/partner.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ const connected = (data) => {
const partnerKinks = data.kinks.split(', ').map(chat.safe_tags_replace);
const formattedPartnerKinks = partnerKinks.map((kink) => userKinks.includes(kink) ? `<span class="common_kink">${kink}</span>` : kink);


chat.addChatMessage(`Your partner's language is ${data.language}`, { class: 'message-system'});

chat.addChatMessage(`Your partner is a ${chat.safe_tags_replace(data.role)}, ${chat.safe_tags_replace(data.gender)}, ${chat.safe_tags_replace(data.species)} interested in: ${formattedPartnerKinks.join(', ')}.`,
{ class: 'message-system', alreadyStripped: true });

Expand Down
32 changes: 28 additions & 4 deletions src/client/js/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const SlimSelect = require('./../../../node_modules/slim-select/dist/slimselect'
const genderRepo = require('./../../models/gender'),
kinksRepo = require('./../../models/kinks'),
roleRepo = require('./../../models/role'),
speciesRepo = require('./../../models/species');
speciesRepo = require('./../../models/species'),
languageRepo = require('./../../models/language');

const toast = require('./toast');

Expand Down Expand Up @@ -106,6 +107,19 @@ const initPreferences = () => {
}
});

new SlimSelect({
select: '#userLanguage',
showSearch: false,
data: [{ value: 'any', text: 'Any / All'}, ...languageRepo.getAll().map(item => {
return { text: item };
})],
placeholder: true,
onChange: (userLanguage) => {
localStorage['language'] = userLanguage.value;
}
});


loadPreferences();
loadSettings();
loadTheme();
Expand All @@ -118,7 +132,8 @@ const initPreferences = () => {
const loadPreferences = () => {
const gendersSelect = document.getElementById('partnerGender'),
kinksSelect = document.getElementById('userKinks'),
speciesSelect = document.getElementById('partnerSpecies');
speciesSelect = document.getElementById('partnerSpecies'),
languageSelect = document.getElementById('userLanguage');

if (localStorage['gender']) {
document.getElementById('userGender').value = localStorage['gender'];
Expand Down Expand Up @@ -177,6 +192,12 @@ const loadPreferences = () => {
} else {
kinksSelect.options[0].selected = 'selected';
}

if (localStorage['language']) {
document.getElementById('userLanguage').value = localStorage['language'];
} else {
languageSelect.options[0].selected = 'selected';
}
}

/**
Expand Down Expand Up @@ -242,7 +263,8 @@ const validatePreferences = () => {
kinks = document.getElementById('userKinks'),
matchGender = document.getElementById('partnerGender'),
matchSpecies = document.getElementById('partnerSpecies'),
matchRole = document.getElementById('partnerRole').value;
matchRole = document.getElementById('partnerRole').value,
language = document.getElementById('userLanguage').value;

const selectedKinks = [];
const selectedGenders = [];
Expand All @@ -265,6 +287,7 @@ const validatePreferences = () => {
validPreferences = validPreferences && assertToastMessage(matchSpecies !== '', 'Please select the species you\'re seeking.');
validPreferences = validPreferences && assertToastMessage(matchRole !== '', 'Please select the role you\'re seeking.');
validPreferences = validPreferences && assertToastMessage(kinks !== '', 'Please select the kinks you\'re interested in.');
validPreferences = validPreferences && assertToastMessage(language !== '', 'Please select a prefered language.');

if (!validPreferences) {
return false;
Expand Down Expand Up @@ -292,7 +315,8 @@ const validatePreferences = () => {
'user': {
'gender': gender,
'species': species,
'role': role
'role': role,
'language': language
},
'partner': {
'gender': selectedGenders,
Expand Down
12 changes: 12 additions & 0 deletions src/models/language.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const languages = [
'English',
'Spanish',
'French',
'Deutsch',
'Portuguese'
];

module.exports = {
getAll: () => languages,
find: (value) => languages.includes(value)
}
17 changes: 15 additions & 2 deletions src/server/find-partner.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ const matchedDesires = (userKinks, partnerKinks) => {
return (userKinks.includes('any') || partnerKinks.includes('any')) || similiarKinks(userKinks, partnerKinks, 1);
}

/**
* Match users language.
*
* @param String userLanguage User's Language
* @param String partnerLanguage Possible partner's kinks
* @return Boolean
*/
const matchedLanguage = (userLanguage, partnerLanguage) => {
return userLanguage.includes('any') || partnerLanguage.includes('any') || userLanguage === partnerLanguage
}


/**
* Checks if the user and partner share a number of similar kinks.
* @param Object userKinks The user's kink preferences.
Expand Down Expand Up @@ -153,7 +165,7 @@ module.exports = (users, token, preferences) => {
// Make sure not on blocked list for user.
if (!users.checkBlocks(currentUser.id, client.id) && !users.checkBlocks(client.id, currentUser.id)) {
// Match based off preferences.
if (matchedDesires(preferences.kinks, client.preferences.kinks) && matchedPreferences(preferences, client.preferences)) {
if (matchedDesires(preferences.kinks, client.preferences.kinks) && matchedPreferences(preferences, client.preferences) && matchedLanguage(preferences.user.language, client.preferences.user.language)) {
partner = client;
users.pairPartners(currentUser.id, client.id);

Expand All @@ -164,7 +176,8 @@ module.exports = (users, token, preferences) => {
gender: partner.preferences.user.gender,
species: partner.preferences.user.species,
kinks: partner.preferences.kinks.join(', '),
role: partner.preferences.user.role
role: partner.preferences.user.role,
language: partner.preferences.user.language
}
}));

Expand Down