friend alias
This commit is contained in:
@@ -13,13 +13,15 @@ import java.io.Serializable;
|
||||
public class FriendData implements Serializable {
|
||||
private String userId;
|
||||
private String friendUid;
|
||||
private String alias;
|
||||
private int state;
|
||||
private long timestamp;
|
||||
|
||||
|
||||
public FriendData(String userId, String friendUid, int state, long timestamp) {
|
||||
public FriendData(String userId, String friendUid, String alias, int state, long timestamp) {
|
||||
this.userId = userId;
|
||||
this.friendUid = friendUid;
|
||||
this.alias = alias;
|
||||
this.state = state;
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
@@ -43,6 +45,14 @@ public class FriendData implements Serializable {
|
||||
this.friendUid = friendUid;
|
||||
}
|
||||
|
||||
public String getAlias() {
|
||||
return alias;
|
||||
}
|
||||
|
||||
public void setAlias(String alias) {
|
||||
this.alias = alias;
|
||||
}
|
||||
|
||||
public int getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* This file is part of the Wildfire Chat package.
|
||||
* (c) Heavyrain2012 <[email protected]>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
package io.moquette.imhandler;
|
||||
|
||||
import cn.wildfirechat.proto.WFCMessage;
|
||||
import io.moquette.spi.impl.Qos1PublishHandler;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import win.liyufan.im.ErrorCode;
|
||||
import win.liyufan.im.IMTopic;
|
||||
|
||||
import static win.liyufan.im.ErrorCode.ERROR_CODE_SUCCESS;
|
||||
|
||||
@Handler(IMTopic.SetFriendAliasTopic)
|
||||
public class SetFriendAliasRequestHandler extends GroupHandler<WFCMessage.AddFriendRequest> {
|
||||
@Override
|
||||
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.AddGroupMemberRequest request, Qos1PublishHandler.IMCallback callback) {
|
||||
long[] head = new long[1];
|
||||
ErrorCode errorCode = m_messagesStore.blackUserRequest(fromUser, request.getUid(), request.getStatus(), head);
|
||||
if (errorCode == ERROR_CODE_SUCCESS) {
|
||||
publisher.publishNotification(IMTopic.NotifyFriendTopic, fromUser, head[0]);
|
||||
}
|
||||
return errorCode;
|
||||
}
|
||||
}
|
||||
@@ -272,7 +272,7 @@ public class DatabaseStore {
|
||||
|
||||
try {
|
||||
connection = DBUtil.getConnection();
|
||||
String sql = "select `_uid`, `_friend_uid`, `_state`, `_dt` from t_friend";
|
||||
String sql = "select `_uid`, `_friend_uid`, `_alias`, `_state`, `_dt` from t_friend";
|
||||
statement = connection.prepareStatement(sql);
|
||||
|
||||
int index;
|
||||
@@ -290,6 +290,9 @@ public class DatabaseStore {
|
||||
value = (value == null ? "" : value);
|
||||
builder.setFriendUid(value);
|
||||
|
||||
value = rs.getString(index++);
|
||||
value = (value == null ? "" : value);
|
||||
builder.setAlias(value);
|
||||
|
||||
int intvalue = rs.getInt(index++);
|
||||
builder.setState(intvalue);
|
||||
@@ -1777,7 +1780,7 @@ public class DatabaseStore {
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
connection = DBUtil.getConnection();
|
||||
String sql = "select `_friend_uid`, `_state`, `_dt` from t_friend where `_uid` = ?";
|
||||
String sql = "select `_friend_uid`, `_alias`, `_state`, `_dt` from t_friend where `_uid` = ?";
|
||||
statement = connection.prepareStatement(sql);
|
||||
|
||||
|
||||
@@ -1789,10 +1792,11 @@ public class DatabaseStore {
|
||||
List<FriendData> out = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
String uid = rs.getString(1);
|
||||
int state = rs.getInt(2);
|
||||
long timestamp = rs.getLong(3);
|
||||
String alias = rs.getString(2);
|
||||
int state = rs.getInt(3);
|
||||
long timestamp = rs.getLong(4);
|
||||
|
||||
FriendData data = new FriendData(userId, uid, state, timestamp);
|
||||
FriendData data = new FriendData(userId, uid, alias, state, timestamp);
|
||||
out.add(data);
|
||||
}
|
||||
return out;
|
||||
@@ -1947,8 +1951,9 @@ public class DatabaseStore {
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
connection = DBUtil.getConnection();
|
||||
String sql = "insert into t_friend (`_uid`, `_friend_uid`, `_state`, `_dt`) values(?, ?, ?, ?)" +
|
||||
String sql = "insert into t_friend (`_uid`, `_friend_uid`, `_alias`, `_state`, `_dt`) values(?, ?, ?, ?, ?)" +
|
||||
" ON DUPLICATE KEY UPDATE " +
|
||||
"`_alias` = ?," +
|
||||
"`_state` = ?," +
|
||||
"`_dt` = ?";
|
||||
|
||||
@@ -1957,8 +1962,10 @@ public class DatabaseStore {
|
||||
int index = 1;
|
||||
statement.setString(index++, request.getUserId());
|
||||
statement.setString(index++, request.getFriendUid());
|
||||
statement.setString(index++, request.getAlias());
|
||||
statement.setInt(index++, request.getState());
|
||||
statement.setLong(index++, request.getTimestamp());
|
||||
statement.setString(index++, request.getAlias());
|
||||
statement.setInt(index++, request.getState());
|
||||
statement.setLong(index++, request.getTimestamp());
|
||||
int count = statement.executeUpdate();
|
||||
|
||||
@@ -1567,11 +1567,11 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
|
||||
MultiMap<String, FriendData> friendsMap = hzInstance.getMultiMap(USER_FRIENDS);
|
||||
|
||||
FriendData friendData1 = new FriendData(userId, request.getTargetUid(), 0, System.currentTimeMillis());
|
||||
FriendData friendData1 = new FriendData(userId, request.getTargetUid(), "", 0, System.currentTimeMillis());
|
||||
friendsMap.put(userId, friendData1);
|
||||
databaseStore.persistOrUpdateFriendData(friendData1);
|
||||
|
||||
FriendData friendData2 = new FriendData(request.getTargetUid(), userId, 0, friendData1.getTimestamp());
|
||||
FriendData friendData2 = new FriendData(request.getTargetUid(), userId, "", 0, friendData1.getTimestamp());
|
||||
friendsMap.put(request.getTargetUid(), friendData2);
|
||||
databaseStore.persistOrUpdateFriendData(friendData2);
|
||||
|
||||
@@ -1588,15 +1588,58 @@ public class MemoryMessagesStore implements IMessagesStore {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorCode blackUserRequest(String fromUser, String targetUserId, int status, long[] heads) {
|
||||
public ErrorCode blackUserRequest(String fromUser, String targetUserId, int state, long[] heads) {
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
MultiMap<String, FriendData> friendsMap = hzInstance.getMultiMap(USER_FRIENDS);
|
||||
|
||||
FriendData friendData1 = new FriendData(fromUser, targetUserId, status, System.currentTimeMillis());
|
||||
friendsMap.put(fromUser, friendData1);
|
||||
databaseStore.persistOrUpdateFriendData(friendData1);
|
||||
FriendData friendData = null;
|
||||
Collection<FriendData> friends = friendsMap.get(fromUser);
|
||||
for (FriendData fd:friends) {
|
||||
if (fd.getFriendUid().equals(targetUserId)) {
|
||||
friendData = fd;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
heads[0] = friendData1.getTimestamp();
|
||||
if (friendData == null) {
|
||||
friendData = new FriendData(fromUser, targetUserId, "", state, System.currentTimeMillis());
|
||||
}
|
||||
friendData.setState(state);
|
||||
friendData.setTimestamp(System.currentTimeMillis());
|
||||
|
||||
friendsMap.put(fromUser, friendData);
|
||||
databaseStore.persistOrUpdateFriendData(friendData);
|
||||
|
||||
heads[0] = friendData.getTimestamp();
|
||||
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorCode setFriendAliasRequest(String fromUser, String targetUserId, String alias, long[] heads){
|
||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||
MultiMap<String, FriendData> friendsMap = hzInstance.getMultiMap(USER_FRIENDS);
|
||||
|
||||
FriendData friendData = null;
|
||||
Collection<FriendData> friends = friendsMap.get(fromUser);
|
||||
for (FriendData fd:friends) {
|
||||
if (fd.getFriendUid().equals(targetUserId)) {
|
||||
friendData = fd;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (friendData == null) {
|
||||
return ErrorCode.ERROR_CODE_NOT_EXIST;
|
||||
}
|
||||
|
||||
friendData.setAlias(alias);
|
||||
friendData.setTimestamp(System.currentTimeMillis());
|
||||
|
||||
friendsMap.put(fromUser, friendData);
|
||||
databaseStore.persistOrUpdateFriendData(friendData);
|
||||
|
||||
heads[0] = friendData.getTimestamp();
|
||||
|
||||
return ErrorCode.ERROR_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -157,6 +157,7 @@ public interface IMessagesStore {
|
||||
ErrorCode blackUserRequest(String fromUser, String targetUserId, int status, long[] head);
|
||||
ErrorCode SyncFriendRequestUnread(String userId, long unreadDt, long[] head);
|
||||
boolean isBlacked(String fromUser, String userId);
|
||||
ErrorCode setFriendAliasRequest(String fromUser, String targetUserId, String alias, long[] head);
|
||||
|
||||
ErrorCode handleJoinChatroom(String userId, String clientId, String chatroomId);
|
||||
ErrorCode handleQuitChatroom(String userId, String clientId, String chatroomId);
|
||||
|
||||
@@ -46,6 +46,8 @@ public interface IMTopic {
|
||||
String FriendPullTopic = "FP";
|
||||
String NotifyFriendTopic = "FN";
|
||||
String BlackListUserTopic = "BLU";
|
||||
String SetFriendAliasTopic = "FALS";
|
||||
|
||||
|
||||
String UploadDeviceTokenTopic = "UDT";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user