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
package chat.handler;
 
import java.util.Date;
import java.util.List;
 
import chat.module.PrivateFriendBucket;
import chat.module.entity.PrivateFriend;
import chat.module.entity.PublishOperator;
import chat.module.entity.MessageRecord;
import chat.server.call.CallObject;
 
public class FriendshipHandler extends CallObject {
 
    private static PrivateFriendBucket friendshipBucket;
    
    static {
        friendshipBucket = PrivateFriendBucket.getInstance();
    }
    
    @Override
    protected void publishMethod() {
        addOneMethod("add");
        addOneMethod("delete");
        addOneMethod("pull");
        addOneMethod("publish");
        addOneMethod("setFriendAlias");
    }
    
    protected void add() {
        String friendId = dataPool.getString("target");
        
        //1. add friend ship
        PrivateFriend friendShip = friendshipBucket.createOne(friendId, user);
        
        //2. notify friend
        friendShip.notify(PublishOperator.Create, user);
    }
    
    protected void delete() {
        String friendshipId = dataPool.getString("target");
        
        PrivateFriend friendship = friendshipBucket.getOne(friendshipId);
        
        if (friendship == null) {
            return;
        }
        
        //1. notify friend
        friendship.notify(PublishOperator.Destroy, user);
        
        //2. destroy
        friendshipBucket.deleteOne(friendshipId);
    }
    
    protected void pull() {
        String friendshipId = dataPool.getString("friendshipId");
        long timeStamp = Long.parseLong(dataPool.getString("timePoint"));
        
        PrivateFriend friendship = friendshipBucket.getOne(friendshipId);
        
        if (friendship == null) {
            return;
        }
        
        //1. get message list
        List<MessageRecord> messageList = friendship.getMessageList(timeStamp);
        
        //2. result
        resultPool.add(messageList);
    }
    
    protected void publish() {
        String friendshipId = dataPool.getString("friendshipId");
        MessageRecord record = dataPool.getMessageRecord();
        
        PrivateFriend friendship = friendshipBucket.getOne(friendshipId);
        
        if (friendship == null) {
            return;
        }
        
        //1. add to list
        //friendship.publishOneMessage(record, user, true, null);
        
        //2. notify
        friendship.notify(PublishOperator.PublishMessage, record, user);
    }
    
    protected void setFriendAlias() {
        String friendshipId = dataPool.getString("friendshipId");
        String alias = dataPool.getString("alias");
        
        PrivateFriend friendship = friendshipBucket.getOne(friendshipId);
        
        if (friendship == null) {
            return;
        }
        
        //1. set alias
        friendship.setMemberAlias(friendshipId, alias);
    }
 
}