Skip to content

Commit ea816d2

Browse files
authored
Merge pull request #417 from Seluj78/399-filter-blocked-from-messages
399 filter blocked from messages
2 parents f02d8c7 + a4b3739 commit ea816d2

File tree

3 files changed

+84
-5
lines changed

3 files changed

+84
-5
lines changed

frontend/src/components/app/matches/Message.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export default {
6363
computed: {
6464
getMessage() {
6565
if (this.message.last_message_content.length > 20) {
66-
return `${this.message.last_message_content.substring(1, 20)}...`;
66+
return `${this.message.last_message_content.substring(0, 20)}...`;
6767
}
6868
return this.message.last_message_content;
6969
},

frontend/src/components/app/matches/MessageBubble.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<img v-if="message.to_id === loggedInUserId && message.is_liked"
2323
src="../../../assets/heartGreen.png" class="w-6 ml-2 inline-block absolute heart"
2424
v-on:dblclick="likeMessage(message.id, message.is_liked)">
25-
<h1 v-if="last" class="text-gray-600">{{getSeenMessage(message.is_seen, message.dt_seen_ago)}}</h1>
25+
<h1 v-if="last && message.to_id !== loggedInUserId" class="text-gray-600">{{getSeenMessage(message.is_seen, message.dt_seen_ago)}}</h1>
2626
</div>
2727
</template>
2828

frontend/src/views/app/Matches.vue

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<img class="h-36" src="../../assets/loading.svg">
66
</div>
77
<section v-if="fetchingDone" class="mx-auto relative md:flex md:items-start md:justify-center">
8-
<div class="md:w-full md:max-w-xs md:shadow-md md:rounded-md md:p-8 md:flex md:flex-col md:justify-start">
8+
<div v-if="(isSmallScreen && !chatWithUserId) || !isSmallScreen" class="sideBar md:w-full md:max-w-xs md:shadow-md md:rounded-md md:p-8 md:flex md:flex-col md:justify-start">
99
<div class="mt-8 sm:mt-0">
1010
<div v-if="matches.length">
1111
<h1 class="text-xl md:text-base text-gray-matcha font-bold">Matches</h1>
@@ -26,7 +26,7 @@
2626
<div class="mt-8">
2727
<div v-if="messages.length">
2828
<h1 class="text-xl md:text-base text-gray-matcha text-left font-bold">Messages</h1>
29-
<div class="overflow-scroll md:h-64 mt-4">
29+
<div class="overflow-scroll messageBox mt-4">
3030
<Message v-on:chat="chat" v-for="message in messages" :key="message.with_user.id" v-bind:message="message"></Message>
3131
</div>
3232
</div>
@@ -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';
@@ -83,7 +84,25 @@ export default {
8384
messages: [],
8485
chatWithUserId: null,
8586
fetchingDone: false,
87+
isSmallScreen: false,
8688
}),
89+
watch: {
90+
messages: {
91+
handler() {
92+
const len = this.messages.length;
93+
const messagedIds = [];
94+
for (let i = 0; i < len; i += 1) {
95+
messagedIds.push(this.messages[i].with_user.id);
96+
}
97+
let i = this.matches.length;
98+
while (i--) {
99+
if (messagedIds.indexOf(this.matches[i].id) !== -1) {
100+
this.matches.splice(i, 1);
101+
}
102+
}
103+
},
104+
},
105+
},
87106
methods: {
88107
async fetchMatch(user1, user2) {
89108
if (this.$store.getters.getLoggedInUser.id === user1) {
@@ -116,9 +135,49 @@ export default {
116135
}
117136
}
118137
},
138+
async filterOutUnlikedPeople() {
139+
let i = this.messages.length;
140+
const { sent } = this.$store.getters.getLoggedInUser.likes;
141+
const likedIds = [];
142+
for (let j = 0; j < sent.length; j += 1) {
143+
likedIds.push(sent[j].liked_id);
144+
}
145+
while (i--) {
146+
if (likedIds.indexOf(this.messages[i].with_user.id) === -1) {
147+
this.messages.splice(i, 1);
148+
}
149+
}
150+
i = this.matches.length;
151+
while (i--) {
152+
if (likedIds.indexOf(this.matches[i].id) === -1) {
153+
this.matches.splice(i, 1);
154+
}
155+
}
156+
},
157+
filterOutBlockedPeople() {
158+
const { blocks } = this.$store.getters.getLoggedInUser;
159+
const blockedIds = [];
160+
for (let j = 0; j < blocks.length; j += 1) {
161+
blockedIds.push(blocks[j].blocked_id);
162+
}
163+
let i = this.messages.length;
164+
while (i--) {
165+
if (blockedIds.indexOf(this.messages[i].with_user.id) !== -1) {
166+
this.messages.splice(i, 1);
167+
}
168+
}
169+
i = this.matches.length;
170+
while (i--) {
171+
if (blockedIds.indexOf(this.matches[i].id) !== -1) {
172+
this.matches.splice(i, 1);
173+
}
174+
}
175+
},
119176
async fetchMessages() {
120177
const messagesRequest = await this.$http.get('/conversations');
121-
this.messages = messagesRequest.data.conversations;
178+
let messages = messagesRequest.data.conversations;
179+
messages = messages.reverse();
180+
this.messages = messages;
122181
},
123182
async chat(...args) {
124183
const [id] = args;
@@ -135,14 +194,20 @@ export default {
135194
this.chatWithUserId = this.messages[0].with_user.id;
136195
}
137196
}
197+
this.isSmallScreen = window.innerWidth < 768;
138198
},
139199
async fetchData() {
140200
window.addEventListener('resize', this.openMessageOnMd);
141201
await this.fetchMessages();
142202
await this.fetchMatches();
203+
await this.filterOutUnlikedPeople();
204+
await this.filterOutBlockedPeople();
143205
if (window.innerWidth >= 768 && this.messages.length) {
144206
this.chatWithUserId = this.messages[0].with_user.id;
145207
}
208+
if (window.innerWidth < 768) {
209+
this.isSmallScreen = true;
210+
}
146211
this.fetchingDone = true;
147212
},
148213
},
@@ -161,3 +226,17 @@ export default {
161226
},
162227
};
163228
</script>
229+
230+
<style scoped>
231+
@screen md {
232+
.sideBar {
233+
max-height: 85vh;
234+
}
235+
}
236+
237+
@screen md {
238+
.messageBox {
239+
max-height: 32rem;
240+
}
241+
}
242+
</style>

0 commit comments

Comments
 (0)