do parts creation only in PartCreator to not scatter dependencies
This commit is contained in:
parent
4ce72fdffa
commit
eb4ff50c3c
4 changed files with 89 additions and 84 deletions
|
@ -15,22 +15,19 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import {UserPillPart, RoomPillPart, PlainPart} from "./parts";
|
||||
|
||||
export default class AutocompleteWrapperModel {
|
||||
constructor(updateCallback, getAutocompleterComponent, updateQuery, room, client) {
|
||||
constructor(updateCallback, getAutocompleterComponent, updateQuery, partCreator) {
|
||||
this._updateCallback = updateCallback;
|
||||
this._getAutocompleterComponent = getAutocompleterComponent;
|
||||
this._updateQuery = updateQuery;
|
||||
this._partCreator = partCreator;
|
||||
this._query = null;
|
||||
this._room = room;
|
||||
this._client = client;
|
||||
}
|
||||
|
||||
onEscape(e) {
|
||||
this._getAutocompleterComponent().onEscape(e);
|
||||
this._updateCallback({
|
||||
replacePart: new PlainPart(this._queryPart.text),
|
||||
replacePart: this._partCreator.plain(this._queryPart.text),
|
||||
caretOffset: this._queryOffset,
|
||||
close: true,
|
||||
});
|
||||
|
@ -93,21 +90,18 @@ export default class AutocompleteWrapperModel {
|
|||
}
|
||||
|
||||
_partForCompletion(completion) {
|
||||
const firstChr = completion.completionId && completion.completionId[0];
|
||||
const {completionId} = completion;
|
||||
const text = completion.completion;
|
||||
const firstChr = completionId && completionId[0];
|
||||
switch (firstChr) {
|
||||
case "@": {
|
||||
const displayName = completion.completion;
|
||||
const userId = completion.completionId;
|
||||
const member = this._room.getMember(userId);
|
||||
return new UserPillPart(userId, displayName, member);
|
||||
}
|
||||
case "#": {
|
||||
const displayAlias = completion.completionId;
|
||||
return new RoomPillPart(displayAlias, this._client);
|
||||
return this._partCreator.userPill(text, completionId);
|
||||
}
|
||||
case "#":
|
||||
return this._partCreator.roomPill(completionId);
|
||||
// also used for emoji completion
|
||||
default:
|
||||
return new PlainPart(completion.completion);
|
||||
return this._partCreator.plain(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue