@@ -84,27 +84,28 @@ export default {
8484 fetchingDone: false ,
8585 }),
8686 methods: {
87+ async fetchMatch (user1 , user2 ) {
88+ if (this .$store .getters .getLoggedInUser .id === user1) {
89+ const userRequest = await this .$http .get (` /users/${ user2} ` );
90+ this .matches .push (userRequest .data );
91+ } else {
92+ const userRequest = await this .$http .get (` /users/${ user1} ` );
93+ this .matches .push (userRequest .data );
94+ }
95+ },
8796 async fetchMatches () {
8897 const matchesRequest = await this .$http .get (' /matches' );
8998 const { matches } = matchesRequest .data ;
99+ if (! this .messages .length ) {
100+ for (let i = 0 ; i < matches .length ; i += 1 ) {
101+ await this .fetchMatch (matches[i].user_1 , matches[i].user_2 );
102+ }
103+ return ;
104+ }
90105 for (let i = 0 ; i < matches .length ; i += 1 ) {
91- if (! this .messages .length ) {
92- if (this .$store .getters .getLoggedInUser .id === matches[i].user_1 ) {
93- const userRequest = await this .$http .get (` /users/${ matches[i].user_2 } ` );
94- this .matches .push (userRequest .data );
95- } else {
96- const userRequest = await this .$http .get (` /users/${ matches[i].user_1 } ` );
97- this .matches .push (userRequest .data );
98- }
99- } else {
100- for (let j = 0 ; j < this .messages .length ; j += 1 ) {
101- if (this .$store .getters .getLoggedInUser .id === matches[i].user_1 ) {
102- const userRequest = await this .$http .get (` /users/${ matches[i].user_2 } ` );
103- this .matches .push (userRequest .data );
104- } else {
105- const userRequest = await this .$http .get (` /users/${ matches[i].user_1 } ` );
106- this .matches .push (userRequest .data );
107- }
106+ for (let j = 0 ; j < this .messages .length ; j += 1 ) {
107+ if (this .messages [j].with_user .id !== matches[i].user_1 && this .messages [j].with_user .id !== matches[i].user_2 ) {
108+ await this .fetchMatch (matches[i].user_1 , matches[i].user_2 );
108109 }
109110 }
110111 }
0 commit comments