package chat.module.entity; import java.nio.charset.StandardCharsets; import cn.wildfirechat.proto.WFCMessage.Message; import frame.object.data.DataObject; import frame.object.data.Entity; import frame.object.data.ID; public class MessageRelation { private String id; private String spaceid; private String spacecode; private String parentid; private String targetid; private int type; private int line; private String statuscode; private MessageRecord messageRecord; public MessageRelation() {} public static MessageRelation getInstance(int line, String targetId, MessageRecord record, Message message) { MessageRelation result = new MessageRelation(); result.id = ID.newValue(); result.parentid = record.getId(); if (message == null) { result.targetid = targetId; } else if (message.getConversation().getType() == 1) {//群组 result.targetid = message.getConversation().getTarget(); } else if (message.getConversation().getType() == 0) {//私聊 result.targetid = targetId; } result.type = message.getConversation().getType(); //result.targetid = targetId; result.line = line; result.statuscode = "unreceived"; result.messageRecord = record; result.spaceid = record.getSpaceid(); result.spacecode = record.getSpacecode(); return result; } public static MessageRelation getImageInstance(String content) { // TODO Auto-generated method stub return null; } public int insertToDataBase(MessageRelation relation) throws Exception { DataObject dataObject = DataObject.getInstance("messagerelation"); Entity entity = dataObject.newEntity(); relation.pushTo(entity); return dataObject.insertToDataBase(entity); } public int updateStatusToDataBase(MessageRelation relation, String status) throws Exception { DataObject dataObject = DataObject.getInstance("messagerelation"); Entity entity = dataObject.newEntity(); relation.pushTo(entity); entity.set("statuscode", status); return dataObject.updateToDataBase(entity); } public void load(Entity entity) throws Exception { id = entity.getString("id"); spaceid = entity.getString("spaceid"); spacecode = entity.getString("spacecode"); parentid = entity.getString("parentid"); targetid = entity.getString("targetid"); type = entity.getInteger("type"); line = entity.getInteger("line"); statuscode = entity.getString("statuscode"); messageRecord = MessageContainer.getLoadedMessage(parentid); } public void pushTo(Entity entity) throws Exception { entity.set("id", id); entity.set("spaceid", spaceid); entity.set("spacecode", spacecode); entity.set("parentid", parentid); entity.set("targetid", targetid); entity.set("type", type); entity.set("line", line); entity.set("statuscode", statuscode); } public MessageRecord getMessageRecord() { return messageRecord; } public void setMessageRecord(MessageRecord messageRecord) { this.messageRecord = messageRecord; } public String getId() { return id; } public String getTargetid() { return targetid; } public void setTargetid(String targetid) { this.targetid = targetid; } public String getStatuscode() { return statuscode; } public void setStatuscode(String statuscode) { this.statuscode = statuscode; } public int getType() { return type; } public void setType(int type) { this.type = type; } public int getLine() { return line; } public void setLine(int line) { this.line = line; } public String getSpaceid() { return spaceid; } public void setSpaceid(String spaceid) { this.spaceid = spaceid; } public String getSpacecode() { return spacecode; } public void setSpacecode(String spacecode) { this.spacecode = spacecode; } }