Files
IM-server-new/broker/src/main/java/io/moquette/imhandler/GroupHandler.java
T

64 lines
2.3 KiB
Java
Raw Normal View History

2019-03-16 17:04:23 +08:00
/*
* 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.ProtoConstants;
import cn.wildfirechat.proto.WFCMessage;
import win.liyufan.im.MessageShardingUtil;
import java.util.ArrayList;
2020-12-10 18:03:41 +08:00
import java.util.Collection;
2019-03-16 17:04:23 +08:00
import java.util.List;
abstract public class GroupHandler<T> extends IMHandler<T> {
protected void sendGroupNotification(String fromUser, String targetId, List<Integer> lines, WFCMessage.MessageContent content) {
2020-12-10 18:03:41 +08:00
sendGroupNotification(fromUser, targetId, lines, content, null);
}
protected void sendGroupNotification(String fromUser, String targetId, List<Integer> lines, WFCMessage.MessageContent content, Collection<String> toUsers) {
2020-06-08 19:10:13 +08:00
if (lines == null) {
2019-03-16 17:04:23 +08:00
lines = new ArrayList<>();
} else {
lines = new ArrayList<>(lines);
2019-03-16 17:04:23 +08:00
}
if (lines.isEmpty()) {
lines.add(0);
}
for (int line : lines) {
long timestamp = System.currentTimeMillis();
WFCMessage.Message.Builder builder = WFCMessage.Message.newBuilder().setContent(content).setServerTimestamp(timestamp);
builder.setConversation(builder.getConversationBuilder().setType(ProtoConstants.ConversationType.ConversationType_Group).setTarget(targetId).setLine(line));
2019-03-16 17:04:23 +08:00
builder.setFromUser(fromUser);
2020-12-10 18:03:41 +08:00
if(toUsers != null && !toUsers.isEmpty()) {
builder.addAllTo(toUsers);
}
2020-08-24 09:30:59 +08:00
try {
long messageId = MessageShardingUtil.generateId();
builder.setMessageId(messageId);
saveAndPublish(fromUser, null, builder.build(), ProtoConstants.RequestSourceType.Request_From_User);
2020-08-24 09:30:59 +08:00
} catch (Exception e) {
e.printStackTrace();
}
2019-03-16 17:04:23 +08:00
}
}
protected List<String> getMemberIdList(List<WFCMessage.GroupMember> groupMembers) {
List<String> out = new ArrayList<>();
if (groupMembers != null) {
for (WFCMessage.GroupMember gm : groupMembers
) {
out.add(gm.getMemberId());
}
}
return out;
}
}