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
package chat.module.entity;
 
import chat.user.User;
import chat.user.UserStore;
import cn.wildfirechat.proto.WFCMessage;
import cn.wildfirechat.proto.WFCMessage.GroupMember;
import frame.object.data.Entity;
import frame.object.data.ID;
 
public class Member {
 
    private String id;
    private String spaceid;
    private String spacecode;
    private String userid;
    private String alias;
    private String statuscode;
    private int rolecode;
    private long timestamp;
    private String ismute;    
    private String isforbidden;
    
    private User user;
    private WFCMessage.GroupMember wfcMember;
    
    public Member(String containerId, String typecode) {
        this.id = ID.newValue();
        this.spaceid = containerId;
        this.spacecode = typecode;
        this.timestamp = System.currentTimeMillis();
    }
    
    public Member(String spaceId, User user) {
        this.id = ID.newValue();
        this.spaceid = spaceId;
        this.spacecode = "Private";
        this.userid = user.getId();
        this.alias = user.getName();
        this.statuscode = "Open";
        this.rolecode = 0;
        this.timestamp = System.currentTimeMillis();
        this.ismute = "F";
        this.isforbidden = "F";
    }
    
    public void load(Entity entity) throws Exception {
        id = entity.getString("id");
        spaceid = entity.getString("spaceid");
        spacecode = entity.getString("spacecode");
        userid = entity.getString("userid");
        alias = entity.getString("alias");
        statuscode = entity.getString("statuscode");
        rolecode = entity.getInteger("rolecode");
        timestamp = Long.parseLong(entity.getString("timestamp"));
        ismute = entity.getString("ismute");
        isforbidden = entity.getString("isforbidden");
    }    
 
    public void load(GroupMember groupMember) {
        alias = groupMember.getAlias();
        userid = groupMember.getMemberId();
        rolecode = groupMember.getType();
    }
 
    public void pushTo(Entity entity) throws Exception {
        entity.set("id", id);
        entity.set("spaceid", spaceid);
        entity.set("spacecode", spacecode);
        entity.set("userid", userid);
        entity.set("alias", alias);
        entity.set("statuscode", "Open");
        entity.set("rolecode", rolecode);
        entity.set("timestamp", timestamp);
        entity.set("ismute", ismute);
        entity.set("isforbidden", isforbidden);
    }
 
    public User getUser() {
        return UserStore.getById(userid);
    }
 
    public String getAlias() {
        return alias;
    }
 
    public WFCMessage.GroupMember toWFCMember() {
        if (wfcMember != null) {
            synchronized (this) {
                if (wfcMember != null) {
                    return wfcMember;
                }
            }
        }
        
        WFCMessage.GroupMember.Builder builder = WFCMessage.GroupMember.newBuilder();
        
        builder.setAlias(alias);
        builder.setMemberId(userid);
        builder.setType(rolecode);
        
        return wfcMember;
    }
    
    public String getId() {
        return id;
    }
 
    public String getUserId() {
        return userid;
    }
 
    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;
    }
 
    public int getRolecode() {
        return rolecode;
    }
 
    public void setRolecode(int rolecode) {
        this.rolecode = rolecode;
    }
 
}