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 >
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 >
6767<script >
6868/* eslint-disable max-len */
6969/* eslint-disable no-await-in-loop */
70+ /* eslint-disable no-plusplus */
7071
7172import Match from ' @/components/app/matches/Match.vue' ;
7273import 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