hefeixia
2021-02-18 5b8c95c760840f09910730943b21391e47187315
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
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;
    }
    
}