Search in sources :

Example 1 with ApiBotCommand

use of im.actor.core.api.ApiBotCommand in project actor-platform by actorapp.

the class User method applyWrapped.

@Override
protected void applyWrapped(@NotNull ApiUser wrapped, @Nullable ApiFullUser ext) {
    this.uid = wrapped.getId();
    this.accessHash = wrapped.getAccessHash();
    this.name = wrapped.getName();
    this.localName = wrapped.getLocalName();
    if (wrapped.getNick() != null && wrapped.getNick().length() > 0) {
        this.username = wrapped.getNick();
    } else {
        this.username = null;
    }
    if (wrapped.getAvatar() != null) {
        this.avatar = new Avatar(wrapped.getAvatar());
    }
    this.isBot = false;
    if (wrapped.isBot() != null) {
        this.isBot = wrapped.isBot();
    }
    this.sex = Sex.UNKNOWN;
    if (wrapped.getSex() != null) {
        switch(wrapped.getSex()) {
            case FEMALE:
                this.sex = Sex.FEMALE;
                break;
            case MALE:
                this.sex = Sex.MALE;
                break;
        }
    }
    if (wrapped.getExt() != null) {
        this.isVerified = true;
        for (ApiMapValueItem i : wrapped.getExt().getItems()) {
            if ("is_verified".equals(i.getKey())) {
                if (i.getValue() instanceof ApiInt32Value) {
                    this.isVerified = ((ApiInt32Value) i.getValue()).getValue() > 0;
                }
            }
        }
    }
    if (ext != null) {
        this.haveExtension = true;
        this.records = new ArrayList<>();
        this.commands = new ArrayList<BotCommand>();
        if (ext.isBlocked() != null) {
            this.isBlocked = ext.isBlocked();
        } else {
            this.isBlocked = false;
        }
        this.timeZone = ext.getTimeZone();
        for (ApiContactRecord record : ext.getContactInfo()) {
            if (record.getType() == ApiContactType.PHONE) {
                this.records.add(new ContactRecord(ContactRecordType.PHONE, record.getTypeSpec(), "" + record.getLongValue(), record.getTitle(), record.getSubtitle()));
            } else if (record.getType() == ApiContactType.EMAIL) {
                this.records.add(new ContactRecord(ContactRecordType.EMAIL, record.getTypeSpec(), record.getStringValue(), record.getTitle(), record.getSubtitle()));
            } else if (record.getType() == ApiContactType.WEB) {
                this.records.add(new ContactRecord(ContactRecordType.WEB, record.getTypeSpec(), record.getStringValue(), record.getTitle(), record.getSubtitle()));
            } else if (record.getType() == ApiContactType.SOCIAL) {
                this.records.add(new ContactRecord(ContactRecordType.SOCIAL, record.getTypeSpec(), record.getStringValue(), record.getTitle(), record.getSubtitle()));
            }
        }
        //Bot commands
        for (ApiBotCommand command : ext.getBotCommands()) {
            commands.add(new BotCommand(command.getSlashCommand(), command.getDescription(), command.getLocKey()));
        }
        this.about = ext.getAbout();
    } else {
        this.isBlocked = false;
        this.haveExtension = false;
        this.records = new ArrayList<>();
        this.commands = new ArrayList<BotCommand>();
        this.about = null;
        this.timeZone = null;
    }
}
Also used : ApiBotCommand(im.actor.core.api.ApiBotCommand) ApiBotCommand(im.actor.core.api.ApiBotCommand) ApiInt32Value(im.actor.core.api.ApiInt32Value) ApiContactRecord(im.actor.core.api.ApiContactRecord) ApiAvatar(im.actor.core.api.ApiAvatar) ApiMapValueItem(im.actor.core.api.ApiMapValueItem) ApiContactRecord(im.actor.core.api.ApiContactRecord)

Aggregations

ApiAvatar (im.actor.core.api.ApiAvatar)1 ApiBotCommand (im.actor.core.api.ApiBotCommand)1 ApiContactRecord (im.actor.core.api.ApiContactRecord)1 ApiInt32Value (im.actor.core.api.ApiInt32Value)1 ApiMapValueItem (im.actor.core.api.ApiMapValueItem)1