2016-06-12 14:32:46 +03:00
|
|
|
import AutocompleteProvider from './AutocompleteProvider';
|
|
|
|
import Q from 'q';
|
|
|
|
import MatrixClientPeg from '../MatrixClientPeg';
|
|
|
|
|
|
|
|
const ROOM_REGEX = /@[^\s]*/g;
|
|
|
|
|
2016-06-20 11:22:55 +03:00
|
|
|
let instance = null;
|
|
|
|
|
2016-06-12 14:32:46 +03:00
|
|
|
export default class UserProvider extends AutocompleteProvider {
|
|
|
|
constructor() {
|
|
|
|
super();
|
2016-06-20 11:22:55 +03:00
|
|
|
this.users = [];
|
2016-06-12 14:32:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
getCompletions(query: String) {
|
|
|
|
let completions = [];
|
|
|
|
const matches = query.match(ROOM_REGEX);
|
|
|
|
if(!!matches) {
|
|
|
|
const command = matches[0];
|
2016-06-20 11:22:55 +03:00
|
|
|
completions = this.users.map(user => {
|
2016-06-12 14:32:46 +03:00
|
|
|
return {
|
2016-06-20 11:22:55 +03:00
|
|
|
title: user.displayName || user.userId,
|
2016-06-12 14:32:46 +03:00
|
|
|
description: user.userId
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return Q.when(completions);
|
|
|
|
}
|
|
|
|
|
|
|
|
getName() {
|
|
|
|
return 'Users';
|
|
|
|
}
|
2016-06-20 11:22:55 +03:00
|
|
|
|
|
|
|
setUserList(users) {
|
|
|
|
console.log('setUserList');
|
|
|
|
this.users = users;
|
|
|
|
}
|
|
|
|
|
|
|
|
static getInstance(): UserProvider {
|
|
|
|
if(instance == null)
|
|
|
|
instance = new UserProvider();
|
|
|
|
return instance;
|
|
|
|
}
|
2016-06-12 14:32:46 +03:00
|
|
|
}
|