2015-12-22 13:00:30 +03:00
|
|
|
/*
|
2016-01-07 07:06:39 +03:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2015-12-22 13:00:30 +03:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
var sdk = require("./index");
|
|
|
|
|
|
|
|
class Entry {
|
|
|
|
constructor(text) {
|
|
|
|
this.text = text;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {string} The text to display in this entry.
|
|
|
|
*/
|
|
|
|
getText() {
|
|
|
|
return this.text;
|
|
|
|
}
|
|
|
|
|
2016-01-14 17:39:58 +03:00
|
|
|
/**
|
|
|
|
* @return {string} The text to insert into the input box. Most of the time
|
|
|
|
* this is the same as getText().
|
|
|
|
*/
|
|
|
|
getFillText() {
|
|
|
|
return this.text;
|
|
|
|
}
|
|
|
|
|
2015-12-22 13:00:30 +03:00
|
|
|
/**
|
|
|
|
* @return {ReactClass} Raw JSX
|
|
|
|
*/
|
|
|
|
getImageJsx() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {?string} The unique key= prop for React dedupe
|
|
|
|
*/
|
|
|
|
getKey() {
|
|
|
|
return null;
|
|
|
|
}
|
2015-12-22 14:14:36 +03:00
|
|
|
|
2016-01-13 20:46:36 +03:00
|
|
|
/**
|
2016-01-14 14:39:24 +03:00
|
|
|
* @return {?string} The suffix to append to the tab-complete, or null to
|
2016-01-13 20:46:36 +03:00
|
|
|
* not do this.
|
|
|
|
*/
|
2016-01-14 14:39:24 +03:00
|
|
|
getSuffix(isFirstWord) {
|
2016-01-13 20:46:36 +03:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-12-22 14:14:36 +03:00
|
|
|
/**
|
|
|
|
* Called when this entry is clicked.
|
|
|
|
*/
|
|
|
|
onClick() {
|
|
|
|
// NOP
|
|
|
|
}
|
2015-12-22 13:00:30 +03:00
|
|
|
}
|
|
|
|
|
2016-01-13 20:46:36 +03:00
|
|
|
class CommandEntry extends Entry {
|
2016-01-14 17:39:58 +03:00
|
|
|
constructor(cmd, cmdWithArgs) {
|
|
|
|
super(cmdWithArgs);
|
2016-07-15 18:10:27 +03:00
|
|
|
this.kind = 'command';
|
2016-01-14 17:39:58 +03:00
|
|
|
this.cmd = cmd;
|
|
|
|
}
|
|
|
|
|
|
|
|
getFillText() {
|
|
|
|
return this.cmd;
|
2016-01-13 20:46:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
getKey() {
|
2016-01-14 17:39:58 +03:00
|
|
|
return this.getFillText();
|
2016-01-13 20:46:36 +03:00
|
|
|
}
|
|
|
|
|
2016-01-14 14:39:24 +03:00
|
|
|
getSuffix(isFirstWord) {
|
2016-01-13 20:46:36 +03:00
|
|
|
return " "; // force a space after the command.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-14 17:39:58 +03:00
|
|
|
CommandEntry.fromCommands = function(commandArray) {
|
2016-01-13 20:46:36 +03:00
|
|
|
return commandArray.map(function(cmd) {
|
2016-01-14 17:39:58 +03:00
|
|
|
return new CommandEntry(cmd.getCommand(), cmd.getCommandWithArgs());
|
2016-01-13 20:46:36 +03:00
|
|
|
});
|
2017-01-20 17:22:27 +03:00
|
|
|
};
|
2016-01-13 20:46:36 +03:00
|
|
|
|
2015-12-22 13:00:30 +03:00
|
|
|
class MemberEntry extends Entry {
|
|
|
|
constructor(member) {
|
2016-08-16 01:20:59 +03:00
|
|
|
super((member.name || member.userId).replace(' (IRC)', ''));
|
2015-12-22 13:00:30 +03:00
|
|
|
this.member = member;
|
2016-07-15 18:10:27 +03:00
|
|
|
this.kind = 'member';
|
2015-12-22 13:00:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
getImageJsx() {
|
|
|
|
var MemberAvatar = sdk.getComponent("views.avatars.MemberAvatar");
|
|
|
|
return (
|
|
|
|
<MemberAvatar member={this.member} width={24} height={24} />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
getKey() {
|
|
|
|
return this.member.userId;
|
|
|
|
}
|
2016-01-14 14:39:24 +03:00
|
|
|
|
|
|
|
getSuffix(isFirstWord) {
|
|
|
|
return isFirstWord ? ": " : " ";
|
|
|
|
}
|
2015-12-22 13:00:30 +03:00
|
|
|
}
|
|
|
|
|
2016-07-15 18:10:27 +03:00
|
|
|
MemberEntry.fromMemberList = function(members) {
|
|
|
|
return members.map(function(m) {
|
2015-12-22 18:38:23 +03:00
|
|
|
return new MemberEntry(m);
|
|
|
|
});
|
2017-01-20 17:22:27 +03:00
|
|
|
};
|
2015-12-22 18:38:23 +03:00
|
|
|
|
2015-12-22 13:00:30 +03:00
|
|
|
module.exports.Entry = Entry;
|
|
|
|
module.exports.MemberEntry = MemberEntry;
|
2016-01-13 20:46:36 +03:00
|
|
|
module.exports.CommandEntry = CommandEntry;
|