friend alias
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user