Skip to content

Commit 98611d7

Browse files
committed
filter blocked and unliked people matches and messages
1 parent f02d8c7 commit 98611d7

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

frontend/src/views/app/Matches.vue

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
<script>
6868
/* eslint-disable max-len */
6969
/* eslint-disable no-await-in-loop */
70+
/* eslint-disable no-plusplus */
7071
7172
import Match from '@/components/app/matches/Match.vue';
7273
import Chat from '@/components/app/matches/Chat.vue';
@@ -116,6 +117,44 @@ export default {
116117
}
117118
}
118119
},
120+
async filterOutUnlikedPeople() {
121+
let i = this.messages.length;
122+
const { sent } = this.$store.getters.getLoggedInUser.likes;
123+
const likedIds = [];
124+
for (let j = 0; j < sent.length; j += 1) {
125+
likedIds.push(sent[j].liked_id);
126+
}
127+
while (i--) {
128+
if (likedIds.indexOf(this.messages[i].with_user.id) === -1) {
129+
this.messages.splice(i, 1);
130+
}
131+
}
132+
i = this.matches.length;
133+
while (i--) {
134+
if (likedIds.indexOf(this.matches[i].id) === -1) {
135+
this.matches.splice(i, 1);
136+
}
137+
}
138+
},
139+
filterOutBlockedPeople() {
140+
const { blocks } = this.$store.getters.getLoggedInUser;
141+
const blockedIds = [];
142+
for (let j = 0; j < blocks.length; j += 1) {
143+
blockedIds.push(blocks[j].blocked_id);
144+
}
145+
let i = this.messages.length;
146+
while (i--) {
147+
if (blockedIds.indexOf(this.messages[i].with_user.id) !== -1) {
148+
this.messages.splice(i, 1);
149+
}
150+
}
151+
i = this.matches.length;
152+
while (i--) {
153+
if (blockedIds.indexOf(this.matches[i].id) !== -1) {
154+
this.matches.splice(i, 1);
155+
}
156+
}
157+
},
119158
async fetchMessages() {
120159
const messagesRequest = await this.$http.get('/conversations');
121160
this.messages = messagesRequest.data.conversations;
@@ -140,6 +179,8 @@ export default {
140179
window.addEventListener('resize', this.openMessageOnMd);
141180
await this.fetchMessages();
142181
await this.fetchMatches();
182+
await this.filterOutUnlikedPeople();
183+
await this.filterOutBlockedPeople();
143184
if (window.innerWidth >= 768 && this.messages.length) {
144185
this.chatWithUserId = this.messages[0].with_user.id;
145186
}

0 commit comments

Comments
 (0)