All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hn.im.easemob.comm.body.TextMessageBody Maven / Gradle / Ivy

There is a newer version: 1.0.18
Show newest version
package com.hn.im.easemob.comm.body;

import com.fasterxml.jackson.databind.node.ContainerNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.hn.im.easemob.comm.constant.MsgType;
import cn.hutool.core.util.StrUtil;

import java.util.Map;

public class TextMessageBody extends MessageBody {
	private String msg;

	public TextMessageBody(String targetType, String[] targets, String from, Map ext, String msg) {
		super(targetType, targets, from, ext);
		this.msg = msg;
	}

	public String getMsg() {
		return msg;
	}

    public ContainerNode getBody() {
        if(!isInit()){
        	ObjectNode objectNode=getMsgBody();
        	ObjectNode msgNode= JsonNodeFactory.instance.objectNode();
        	msgNode.put("type", MsgType.TEXT);
        	msgNode.put("msg", msg);
        	objectNode.put("msg", msgNode);
            this.setInit(true);
        }

        return this.getMsgBody();
    }

    public Boolean validate() {
		return super.validate() && StrUtil.isNotBlank(msg);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy