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);
|
}
|
|
}
|