remove duplicates from room lists
This commit is contained in:
parent
245dfbf957
commit
441036ff93
2 changed files with 34 additions and 9 deletions
29
src/ArrayUtils.js
Normal file
29
src/ArrayUtils.js
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
Copyright 2018 New Vector
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* creates a new array with only the unique values of the given array
|
||||||
|
* @return {array} the deduplicated array
|
||||||
|
*/
|
||||||
|
export function unique(arr) {
|
||||||
|
const cpy = [];
|
||||||
|
arr.forEach((el) => {
|
||||||
|
if (!cpy.includes(el)) {
|
||||||
|
cpy.push(el);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return cpy;
|
||||||
|
};
|
|
@ -15,6 +15,7 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import MatrixClientPeg from '../MatrixClientPeg';
|
import MatrixClientPeg from '../MatrixClientPeg';
|
||||||
|
import {unique} from '../ArrayUtils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that takes a Matrix Client and flips the m.direct map
|
* Class that takes a Matrix Client and flips the m.direct map
|
||||||
|
@ -120,19 +121,14 @@ export default class DMRoomMap {
|
||||||
return !guessedUserIdsThatChanged
|
return !guessedUserIdsThatChanged
|
||||||
.some((ids) => ids.roomId === roomId);
|
.some((ids) => ids.roomId === roomId);
|
||||||
});
|
});
|
||||||
|
|
||||||
guessedUserIdsThatChanged.forEach(({userId, roomId}) => {
|
guessedUserIdsThatChanged.forEach(({userId, roomId}) => {
|
||||||
if (!userId) {
|
|
||||||
// if not able to guess the other user (unlikely)
|
|
||||||
// still put it in the map so the room stays marked
|
|
||||||
// as a DM, we just wont be able to show an avatar.
|
|
||||||
userId = "";
|
|
||||||
}
|
|
||||||
let roomIds = userToRooms[userId];
|
let roomIds = userToRooms[userId];
|
||||||
if (!roomIds) {
|
if (!roomIds) {
|
||||||
roomIds = userToRooms[userId] = [];
|
userToRooms[userId] = [roomId];
|
||||||
}
|
} else {
|
||||||
roomIds.push(roomId);
|
roomIds.push(roomId);
|
||||||
|
userToRooms[userId] = unique(roomIds);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue