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
package chat.module.entity;
 
import chat.user.User;
import cn.wildfirechat.proto.WFCMessage;
import frame.object.data.DataObject;
import frame.object.data.Entity;
import frame.object.data.ID;
import frame.persist.NamedSQL;
import frame.persist.SQLRunner;
 
public class FriendShip {
 
    private String id;
    private String userid;
    private String friendid;
    private String statuscode;
    //private FriendshipStatus status;
    private String verifytext;
    private long timestamp;
    private FriendShip reverseInstance;
    private WFCMessage.FriendRequest friendRequest;
    
    public FriendShip() {}
    
    public FriendShip(User user, String friendId, String status) {
        this.id = ID.newValue();
        this.userid = user.getId();
        this.friendid = friendId;
        this.statuscode = status;
        this.verifytext = "我是" + user.getName();
        this.timestamp = System.currentTimeMillis();
    }
    
    public void load(Entity entity) {
        id = entity.getString("id");
        userid = entity.getString("userid");
        friendid = entity.getString("friendid");
        //status = FriendshipStatus.parse(entity.getString("statuscode"));
        statuscode = entity.getString("statuscode");
        verifytext = entity.getString("verifytext");
        timestamp = Long.parseLong(entity.getString("timestamp"));
    }
    
    public void pushTo(Entity entity) throws Exception {
        entity.set("id", id);
        entity.set("userid", userid);
        entity.set("friendid", friendid);
        entity.set("statuscode", statuscode);
        entity.set("verifytext", verifytext);
        entity.set("timestamp", timestamp);
    }
    
    public void addFriendShipToDataBase() {
        try {
             DataObject dataObject = DataObject.getInstance("friendship");
            
             Entity entity = dataObject.newEntity();
             pushTo(entity);
                
             dataObject.insertToDataBase(entity);            
        } catch(Exception e) {
             e.printStackTrace();
        }
    }
 
    public void updateFriendShipToDataBase(String status) {
        try {
             DataObject dataObject = DataObject.getInstance("friendship");
             
             Entity entity = dataObject.newEntity();
             pushTo(entity);
             entity.set("statuscode", status);
             
             dataObject.updateToDataBase(entity);        
        } catch(Exception e) {
             e.printStackTrace();
        }
    }
 
    public synchronized FriendShip getReverseInstance() {
        if (reverseInstance != null) {
            return reverseInstance;
        }
        
        reverseInstance = new FriendShip();
        
        reverseInstance.id = this.id;
        reverseInstance.userid = this.friendid;
        reverseInstance.friendid = this.userid;
        reverseInstance.statuscode = this.statuscode;
        reverseInstance.verifytext = this.verifytext;
        reverseInstance.timestamp = this.timestamp;
        
        return reverseInstance;
    }
 
    public String getId() {
        return id;
    }
 
    public String getUserid() {
        return userid;
    }
 
    public String getFriendid() {
        return friendid;
    }
 
    public String getVerifytext() {
        return verifytext;
    }
 
    public long getTimestamp() {
        return timestamp;
    }
 
    public WFCMessage.FriendRequest getFriendRequest() {
        return friendRequest;
    }
 
    public void setFriendRequest(WFCMessage.FriendRequest friendRequest) {
        this.friendRequest = friendRequest;
    }
 
}