Changed mechanism of chosing sex of profile and removed unneded console.logs
This commit is contained in:
13
src/db.js
13
src/db.js
@@ -50,18 +50,20 @@ const eraseUserMedia = async (roomId) => {
|
||||
}
|
||||
|
||||
const selectProfilesForUser = async (roomId) => {
|
||||
let interest = (await db.query("SELECT interest FROM users WHERE room_id = $1", [roomId])).rows[0].interest
|
||||
let myInterest = (await db.query("SELECT interest FROM users WHERE room_id = $1", [roomId])).rows[0].interest
|
||||
let mySex = (await db.query("SELECT sex FROM users WHERE room_id = $1", [roomId])).rows[0].sex
|
||||
let userAge = (await db.query("SELECT age FROM users WHERE room_id = $1", [roomId])).rows[0].age
|
||||
//Selecting profiles other than user's and with difference in age +-2.
|
||||
let user
|
||||
if (interest === 'b') // both, no matter what sex
|
||||
if (myInterest === 'b') // both, no matter what sex
|
||||
user = (await db.query(`SELECT
|
||||
room_id, name, age, sex, description, country, city FROM users
|
||||
WHERE
|
||||
age::numeric <@ ANY(ARRAY[numrange($1 - 2, $1 + 2)])
|
||||
AND room_id != $2
|
||||
AND room_id != $2
|
||||
AND (interest = $3 OR interest = 'b')
|
||||
ORDER BY RANDOM()
|
||||
LIMIT 1`, [userAge, roomId])
|
||||
LIMIT 1`, [userAge, roomId, mySex])
|
||||
).rows[0]
|
||||
else {
|
||||
user = (await db.query(`SELECT
|
||||
@@ -70,8 +72,9 @@ const selectProfilesForUser = async (roomId) => {
|
||||
age::numeric <@ ANY(ARRAY[numrange($1 - 2, $1 + 2)])
|
||||
AND room_id != $2
|
||||
AND sex = $3
|
||||
AND (interest = $4 OR interest = 'b')
|
||||
ORDER BY RANDOM()
|
||||
LIMIT 1`, [userAge, roomId, interest])
|
||||
LIMIT 1`, [userAge, roomId, myInterest, mySex])
|
||||
).rows[0]
|
||||
}
|
||||
if (!user) return null
|
||||
|
||||
18
src/index.js
18
src/index.js
@@ -54,6 +54,12 @@ client.on("room.message", async (roomId, event) => {
|
||||
let answer = event.content.body;
|
||||
|
||||
switch (current_action) {
|
||||
case "wait_start":
|
||||
if (answer !== "!start") return;
|
||||
await setUserState(roomId, "country");
|
||||
await client.sendText(roomId, messages.setup.country);
|
||||
|
||||
break;
|
||||
case "country":
|
||||
await processRequest(client, roomId, current_action, answer, 'city');
|
||||
break;
|
||||
@@ -111,8 +117,6 @@ client.on("room.message", async (roomId, event) => {
|
||||
} else {
|
||||
const message = new MessageEvent(event);
|
||||
const fileEvent = new MessageEvent(message.raw);
|
||||
console.log(event)
|
||||
console.log(fileEvent)
|
||||
const decrypted = await client.crypto.decryptMedia(fileEvent.content.file);
|
||||
const mxc = await client.uploadContent(decrypted);
|
||||
let type;
|
||||
@@ -135,18 +139,17 @@ client.on("room.message", async (roomId, event) => {
|
||||
}
|
||||
break;
|
||||
case "view_profiles":
|
||||
if (answer == '👍️' || answer == '❤️') {
|
||||
if (answer == '👍️' || answer == '❤️' || answer == '1') {
|
||||
let currently_viewing = await getUserCurrentlyViewingProfile(roomId)
|
||||
await appendUserLikes(roomId, currently_viewing);
|
||||
let value = await checkForMutualLike(roomId, currently_viewing);
|
||||
console.log(value)
|
||||
if (value) {
|
||||
await client.sendText(roomId, messages.general.newlikes);
|
||||
await client.sendText(currently_viewing, messages.general.newlikes);
|
||||
}
|
||||
} else if (answer == '💌') {
|
||||
} else if (answer == '💌' || answer == '3') {
|
||||
await client.sendText(roomId, messages.errors.notimplemented);
|
||||
} else if (answer == '🏠️') {
|
||||
} else if (answer == '🏠️' || answer == '4') {
|
||||
await client.sendText(roomId, messages.general.menu);
|
||||
await setUserState(roomId, 'menu')
|
||||
return
|
||||
@@ -204,10 +207,9 @@ client.on("room.invite", async (roomId, event) => {
|
||||
let is_profile_exists = (await db.query("SELECT * FROM users WHERE room_id = $1", [roomId])).rowCount > 0;
|
||||
|
||||
if (!is_profile_exists) {
|
||||
await db.query("INSERT INTO users(mx_id, room_id, current_action) VALUES ($1, $2, $3)", [mx_id, roomId, "country"])
|
||||
await db.query("INSERT INTO users(mx_id, room_id, current_action) VALUES ($1, $2, $3)", [mx_id, roomId, "wait_start"])
|
||||
|
||||
await client.sendText(roomId, messages.general.welcome);
|
||||
await client.sendText(roomId, messages.setup.country);
|
||||
} else {
|
||||
setUserState(roomId, 'view_profiles')
|
||||
}
|
||||
|
||||
@@ -52,7 +52,6 @@ ${chosenProfile.description}`
|
||||
|
||||
if (chosenProfile.media) {
|
||||
for (let media of chosenProfile.media) {
|
||||
console.log(media)
|
||||
let msgtype
|
||||
if (media.type == 'p') {
|
||||
msgtype = "m.image"
|
||||
@@ -73,7 +72,6 @@ ${chosenProfile.description}`
|
||||
|
||||
const showProfileToUser = async (client, roomId, profileId) => {
|
||||
let profileInfo = await getProfileInfo(profileId);
|
||||
console.log(profileInfo)
|
||||
let message =
|
||||
`${profileInfo.country}, ${profileInfo.city}.
|
||||
${profileInfo.name}, ${profileInfo.sex == 'm' ? 'male' : 'female'}, ${profileInfo.age}.
|
||||
@@ -84,7 +82,6 @@ ${profileInfo.description}`
|
||||
|
||||
if (profileInfo.media) {
|
||||
for (let media of profileInfo.media) {
|
||||
console.log(media)
|
||||
let msgtype
|
||||
if (media.type == 'p') {
|
||||
msgtype = "m.image"
|
||||
@@ -105,7 +102,6 @@ ${profileInfo.description}`
|
||||
const showNewLikes = async (client, roomId) => {
|
||||
let likes = (await getAllLikesForUser(roomId));
|
||||
for (let liked of likes) {
|
||||
console.log(await checkForMutualLike(liked.sender, roomId))
|
||||
if (await checkForMutualLike(liked.sender, roomId)) {
|
||||
await showProfileToUser(client, roomId, liked.sender);
|
||||
await markLikeAsRead(liked.sender, roomId);
|
||||
|
||||
Reference in New Issue
Block a user