删除旧的好友欢迎语的多语言处理方式
This commit is contained in:
@@ -1,3 +0,0 @@
|
|||||||
#native2ascii -encoding UTF-8 messages.properties temp_messages.properties
|
|
||||||
Above_Greeting_Message=\u4ee5\u4e0a\u662f\u6253\u62db\u547c\u4fe1\u606f
|
|
||||||
Friend_Can_Start_Chat=\u4f60\u4eec\u5df2\u7ecf\u6210\u4e3a\u597d\u53cb\u4e86\uff0c\u73b0\u5728\u53ef\u4ee5\u5f00\u59cb\u804a\u5929\u4e86
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
Above_Greeting_Message=This's the greeting
|
|
||||||
Friend_Can_Start_Chat=You're already friend, start chat now.
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
Above_Greeting_Message=This's the greeting
|
|
||||||
Friend_Can_Start_Chat=You're already friend, start chat now.
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
Above_Greeting_Message=\u4ee5\u4e0a\u662f\u6253\u62db\u547c\u4fe1\u606f
|
|
||||||
Friend_Can_Start_Chat=\u4f60\u4eec\u5df2\u7ecf\u6210\u4e3a\u597d\u53cb\u4e86\uff0c\u73b0\u5728\u53ef\u4ee5\u5f00\u59cb\u804a\u5929\u4e86
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
Above_Greeting_Message=\u4ee5\u4e0a\u662f\u6253\u62db\u547c\u4fe1\u606f
|
|
||||||
Friend_Can_Start_Chat=\u4f60\u4eec\u5df2\u7ecf\u6210\u4e3a\u597d\u53cb\u4e86\uff0c\u73b0\u5728\u53ef\u4ee5\u5f00\u59cb\u804a\u5929\u4e86
|
|
||||||
@@ -142,12 +142,6 @@ friend.reject_request_duration 2592000000
|
|||||||
##好友请求过期时间,单位是毫秒,默认是7天,0为无限长期限。
|
##好友请求过期时间,单位是毫秒,默认是7天,0为无限长期限。
|
||||||
friend.request_expiration_duration 604800000
|
friend.request_expiration_duration 604800000
|
||||||
|
|
||||||
##添加好友后会发送欢迎消息,比如"你们已经是好友了,可以聊天了"。这个开关控制是用旧的方式还是用新的方式。
|
|
||||||
##旧的方式会发送notification消息(contenttype是80),内容会根据好友接收者的语言选择对应的语言,如果双方语言不一致会导致另外一方看到的不是本地语言。
|
|
||||||
##新的方式会发送添加好友消息(contenttype是93)和欢迎消息(contenttype是92),需要客户端实现这两种消息。
|
|
||||||
##如果客户端已经实现这两种消息可以打开这个开关(客户端2020.6.30添加了此消息类型)。
|
|
||||||
friend.new_welcome_message true
|
|
||||||
|
|
||||||
## 聊天室观众空闲退出时间,单位为毫秒,默认为15分钟,0为永远不退出
|
## 聊天室观众空闲退出时间,单位为毫秒,默认为15分钟,0为永远不退出
|
||||||
chatroom.participant_idle_time 900000
|
chatroom.participant_idle_time 900000
|
||||||
|
|
||||||
|
|||||||
@@ -156,7 +156,6 @@ public final class BrokerConstants {
|
|||||||
public static final String FRIEND_Repeat_Request_Duration = "friend.repeat_request_duration";
|
public static final String FRIEND_Repeat_Request_Duration = "friend.repeat_request_duration";
|
||||||
public static final String FRIEND_Reject_Request_Duration = "friend.reject_request_duration";
|
public static final String FRIEND_Reject_Request_Duration = "friend.reject_request_duration";
|
||||||
public static final String FRIEND_Request_Expiration_Duration = "friend.request_expiration_duration";
|
public static final String FRIEND_Request_Expiration_Duration = "friend.request_expiration_duration";
|
||||||
public static final String FRIEND_New_Welcome_Message = "friend.new_welcome_message";
|
|
||||||
|
|
||||||
public static final String CHATROOM_Participant_Idle_Time = "chatroom.participant_idle_time";
|
public static final String CHATROOM_Participant_Idle_Time = "chatroom.participant_idle_time";
|
||||||
public static final String CHATROOM_Rejoin_When_Active = "chatroom.rejoin_when_active";
|
public static final String CHATROOM_Rejoin_When_Active = "chatroom.rejoin_when_active";
|
||||||
|
|||||||
@@ -10,12 +10,10 @@ package io.moquette.imhandler;
|
|||||||
|
|
||||||
import cn.wildfirechat.proto.ProtoConstants;
|
import cn.wildfirechat.proto.ProtoConstants;
|
||||||
import cn.wildfirechat.proto.WFCMessage;
|
import cn.wildfirechat.proto.WFCMessage;
|
||||||
import io.moquette.persistence.MemorySessionStore;
|
|
||||||
import io.moquette.spi.impl.Qos1PublishHandler;
|
import io.moquette.spi.impl.Qos1PublishHandler;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import cn.wildfirechat.common.ErrorCode;
|
import cn.wildfirechat.common.ErrorCode;
|
||||||
import io.netty.util.internal.StringUtil;
|
import io.netty.util.internal.StringUtil;
|
||||||
import win.liyufan.im.I18n;
|
|
||||||
import win.liyufan.im.IMTopic;
|
import win.liyufan.im.IMTopic;
|
||||||
import win.liyufan.im.MessageShardingUtil;
|
import win.liyufan.im.MessageShardingUtil;
|
||||||
|
|
||||||
@@ -43,17 +41,8 @@ public class HandleFriendRequestHandler extends IMHandler<WFCMessage.HandleFrien
|
|||||||
saveAndPublish(request.getTargetUid(), null, builder.build(), requestSourceType);
|
saveAndPublish(request.getTargetUid(), null, builder.build(), requestSourceType);
|
||||||
}
|
}
|
||||||
|
|
||||||
MemorySessionStore.Session session = m_sessionsStore.getSession(clientID);
|
|
||||||
String language = "zh_CN";
|
|
||||||
if (session != null && !StringUtil.isNullOrEmpty(session.getLanguage())) {
|
|
||||||
language = session.getLanguage();
|
|
||||||
}
|
|
||||||
WFCMessage.MessageContent.Builder contentBuilder = WFCMessage.MessageContent.newBuilder();
|
WFCMessage.MessageContent.Builder contentBuilder = WFCMessage.MessageContent.newBuilder();
|
||||||
if (m_messagesStore.isNewFriendWelcomeMessage()) {
|
contentBuilder.setType(92);
|
||||||
contentBuilder.setType(92);
|
|
||||||
} else {
|
|
||||||
contentBuilder.setType(90).setContent(I18n.getString(language, "Above_Greeting_Message"));
|
|
||||||
}
|
|
||||||
|
|
||||||
builder = WFCMessage.Message.newBuilder();
|
builder = WFCMessage.Message.newBuilder();
|
||||||
builder.setFromUser(request.getTargetUid());
|
builder.setFromUser(request.getTargetUid());
|
||||||
@@ -64,13 +53,7 @@ public class HandleFriendRequestHandler extends IMHandler<WFCMessage.HandleFrien
|
|||||||
messageId = MessageShardingUtil.generateId();
|
messageId = MessageShardingUtil.generateId();
|
||||||
builder.setMessageId(messageId);
|
builder.setMessageId(messageId);
|
||||||
saveAndPublish(request.getTargetUid(), null, builder.build(), requestSourceType);
|
saveAndPublish(request.getTargetUid(), null, builder.build(), requestSourceType);
|
||||||
|
contentBuilder.setType(93);
|
||||||
if (m_messagesStore.isNewFriendWelcomeMessage()) {
|
|
||||||
contentBuilder.setType(93);
|
|
||||||
} else {
|
|
||||||
contentBuilder.setContent(I18n.getString(language, "Friend_Can_Start_Chat"));
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.setContent(contentBuilder);
|
builder.setContent(contentBuilder);
|
||||||
messageId = MessageShardingUtil.generateId();
|
messageId = MessageShardingUtil.generateId();
|
||||||
builder.setMessageId(messageId);
|
builder.setMessageId(messageId);
|
||||||
|
|||||||
@@ -138,7 +138,6 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
private long mFriendRequestDuration = 7 * 24 * 60 * 60 * 1000;
|
private long mFriendRequestDuration = 7 * 24 * 60 * 60 * 1000;
|
||||||
private long mFriendRejectDuration = 30 * 24 * 60 * 60 * 1000;
|
private long mFriendRejectDuration = 30 * 24 * 60 * 60 * 1000;
|
||||||
private long mFriendRequestExpiration = 7 * 24 * 60 * 60 * 1000;
|
private long mFriendRequestExpiration = 7 * 24 * 60 * 60 * 1000;
|
||||||
private boolean mFriendNewWelcomeMessage = true;
|
|
||||||
|
|
||||||
private boolean mMultiPlatformNotification = false;
|
private boolean mMultiPlatformNotification = false;
|
||||||
private boolean mMobileDefaultSilentWhenPCOnline = true;
|
private boolean mMobileDefaultSilentWhenPCOnline = true;
|
||||||
@@ -256,15 +255,6 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
printMissConfigLog(FRIEND_Request_Expiration_Duration, mFriendRequestExpiration + "");
|
printMissConfigLog(FRIEND_Request_Expiration_Duration, mFriendRequestExpiration + "");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
mFriendNewWelcomeMessage = Boolean.parseBoolean(m_Server.getConfig().getProperty(FRIEND_New_Welcome_Message));
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
Utility.printExecption(LOG, e);
|
|
||||||
printMissConfigLog(FRIEND_New_Welcome_Message, mFriendNewWelcomeMessage + "");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mChatroomRejoinWhenActive = Boolean.parseBoolean(m_Server.getConfig().getProperty(BrokerConstants.CHATROOM_Rejoin_When_Active));
|
mChatroomRejoinWhenActive = Boolean.parseBoolean(m_Server.getConfig().getProperty(BrokerConstants.CHATROOM_Rejoin_When_Active));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -3509,11 +3499,6 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
return ErrorCode.ERROR_CODE_AUTH_FAILURE;
|
return ErrorCode.ERROR_CODE_AUTH_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isNewFriendWelcomeMessage() {
|
|
||||||
return mFriendNewWelcomeMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ErrorCode deleteFriend(String userId, String friendUid, long[] head) {
|
public ErrorCode deleteFriend(String userId, String friendUid, long[] head) {
|
||||||
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
HazelcastInstance hzInstance = m_Server.getHazelcastInstance();
|
||||||
|
|||||||
@@ -179,7 +179,6 @@ public interface IMessagesStore {
|
|||||||
|
|
||||||
ErrorCode saveAddFriendRequest(String userId, WFCMessage.AddFriendRequest request, long[] head, boolean isAdmin);
|
ErrorCode saveAddFriendRequest(String userId, WFCMessage.AddFriendRequest request, long[] head, boolean isAdmin);
|
||||||
ErrorCode handleFriendRequest(String userId, WFCMessage.HandleFriendRequest request, WFCMessage.Message.Builder msgBuilder, long[] heads, boolean isAdmin);
|
ErrorCode handleFriendRequest(String userId, WFCMessage.HandleFriendRequest request, WFCMessage.Message.Builder msgBuilder, long[] heads, boolean isAdmin);
|
||||||
boolean isNewFriendWelcomeMessage();
|
|
||||||
ErrorCode deleteFriend(String userId, String friendUid, long[] head);
|
ErrorCode deleteFriend(String userId, String friendUid, long[] head);
|
||||||
ErrorCode blackUserRequest(String fromUser, String targetUserId, int status, long[] head);
|
ErrorCode blackUserRequest(String fromUser, String targetUserId, int status, long[] head);
|
||||||
FriendData getFriendData(String fromUser, String targetUserId);
|
FriendData getFriendData(String fromUser, String targetUserId);
|
||||||
|
|||||||
@@ -1,68 +0,0 @@
|
|||||||
package win.liyufan.im;
|
|
||||||
|
|
||||||
import io.netty.util.internal.StringUtil;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLClassLoader;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
public class I18n {
|
|
||||||
private static ClassLoader Loader = null;
|
|
||||||
static {
|
|
||||||
String configPath = System.getProperty("wildfirechat.path", null);
|
|
||||||
String resBundlePaht = "config/i18n";
|
|
||||||
|
|
||||||
File file = new File(configPath, resBundlePaht);
|
|
||||||
URL[] urls = new URL[0];
|
|
||||||
try {
|
|
||||||
urls = new URL[]{file.toURI().toURL()};
|
|
||||||
Loader = new URLClassLoader(urls);
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Map<String, ResourceBundle> bundleMap = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
public static String getString(String language, String key) {
|
|
||||||
ResourceBundle bundle = bundleMap.get(language);
|
|
||||||
|
|
||||||
if (StringUtil.isNullOrEmpty(language)) language = "zh_CN";
|
|
||||||
|
|
||||||
if (bundle == null) {
|
|
||||||
bundle = ResourceBundle.getBundle("messages", new Locale(language), Loader);
|
|
||||||
bundleMap.put(language, bundle);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
return bundle.getString(key);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return "糟糕,字符串 " + key + " 没有找到";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void test() throws MalformedURLException {
|
|
||||||
|
|
||||||
// 设置定制的语言国家代码
|
|
||||||
Locale locale1 = new Locale("zh");
|
|
||||||
Locale locale2 = new Locale("en");
|
|
||||||
ResourceBundle rb = ResourceBundle.getBundle("messages", locale1, Loader);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 获得相应的key值
|
|
||||||
String greeting = rb.getString("Above_Greeting_Message");
|
|
||||||
String userInfo = rb.getString("Friend_Can_Start_Chat");
|
|
||||||
|
|
||||||
System.out.println(greeting);
|
|
||||||
System.out.println(userInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
test();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -20,11 +20,6 @@
|
|||||||
<outputDirectory>/migrate/h2</outputDirectory>
|
<outputDirectory>/migrate/h2</outputDirectory>
|
||||||
</fileSet>
|
</fileSet>
|
||||||
|
|
||||||
<fileSet>
|
|
||||||
<directory>../broker/config/i18n/</directory>
|
|
||||||
<outputDirectory>/config/i18n</outputDirectory>
|
|
||||||
</fileSet>
|
|
||||||
|
|
||||||
<fileSet>
|
<fileSet>
|
||||||
<directory>src/main/resources/</directory>
|
<directory>src/main/resources/</directory>
|
||||||
<outputDirectory>config/</outputDirectory>
|
<outputDirectory>config/</outputDirectory>
|
||||||
|
|||||||
@@ -139,12 +139,6 @@ friend.reject_request_duration 2592000000
|
|||||||
##好友请求过期时间,单位是毫秒,默认是7天,0为无限长期限。
|
##好友请求过期时间,单位是毫秒,默认是7天,0为无限长期限。
|
||||||
friend.request_expiration_duration 604800000
|
friend.request_expiration_duration 604800000
|
||||||
|
|
||||||
##添加好友后会发送欢迎消息,比如"你们已经是好友了,可以聊天了"。这个开关控制是用旧的方式还是用新的方式。
|
|
||||||
##旧的方式会发送notification消息(contenttype是80),内容会根据好友接收者的语言选择对应的语言,如果双方语言不一致会导致另外一方看到的不是本地语言。
|
|
||||||
##新的方式会发送添加好友消息(contenttype是93)和欢迎消息(contenttype是92),需要客户端实现这两种消息。
|
|
||||||
##如果客户端已经实现这两种消息可以打开这个开关(客户端2020.6.30添加了此消息类型)。
|
|
||||||
friend.new_welcome_message true
|
|
||||||
|
|
||||||
## 聊天室观众空闲退出时间,单位为毫秒,默认为15分钟,0为永远不退出
|
## 聊天室观众空闲退出时间,单位为毫秒,默认为15分钟,0为永远不退出
|
||||||
chatroom.participant_idle_time 900000
|
chatroom.participant_idle_time 900000
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user