Fix bug where a received message would remove completions for users

`Array.prototype.splice` will return the array of removed items, not a new array. The array operated on is actually modified in-place.

This was causing a few weird things to happen: https://github.com/vector-im/riot-web/issues/4511 and https://github.com/vector-im/riot-web/issues/4533. This should fix both of them but it is concerning that doing the tab completion is required to reproduce. Let's just see how this goes before closing the issues.

Thanks @turt2live for reproducing both bugs, giving enough information for a fix :)
This commit is contained in:
Luke Barnard 2017-07-11 10:42:02 +01:00
parent 66525f6826
commit e18924c8fc

View file

@ -101,7 +101,8 @@ export default class UserProvider extends AutocompleteProvider {
onUserSpoke(user: RoomMember) {
if(user.userId === MatrixClientPeg.get().credentials.userId) return;
this.users = this.users.splice(
// Move the user that spoke to the front of the array
this.users.splice(
this.users.findIndex((user2) => user2.userId === user.userId), 1);
this.users = [user, ...this.users];