diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/MulticastMessageAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/MulticastMessageAction.java new file mode 100755 index 00000000..9f1b2dd0 --- /dev/null +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/MulticastMessageAction.java @@ -0,0 +1,90 @@ +/* + * This file is part of the Wildfire Chat package. + * (c) Heavyrain2012 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +package com.xiaoleilu.loServer.action.admin; + + +import cn.wildfirechat.common.APIPath; +import cn.wildfirechat.common.ErrorCode; +import cn.wildfirechat.pojos.BroadMessageData; +import cn.wildfirechat.pojos.BroadMessageResult; +import cn.wildfirechat.pojos.MultiMessageResult; +import cn.wildfirechat.pojos.MulticastMessageData; +import com.google.gson.Gson; +import com.hazelcast.util.StringUtil; +import com.xiaoleilu.loServer.RestResult; +import com.xiaoleilu.loServer.annotation.HttpMethod; +import com.xiaoleilu.loServer.annotation.Route; +import com.xiaoleilu.loServer.handler.Request; +import com.xiaoleilu.loServer.handler.Response; +import io.moquette.persistence.RPCCenter; +import io.moquette.persistence.TargetEntry; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.handler.codec.http.FullHttpRequest; +import io.netty.handler.codec.http.HttpResponseStatus; +import win.liyufan.im.IMTopic; + +import java.util.concurrent.Executor; + +@Route(APIPath.Msg_Multicast) +@HttpMethod("POST") +public class MulticastMessageAction extends AdminAction { + + @Override + public boolean isTransactionAction() { + return true; + } + + @Override + public boolean action(Request request, Response response) { + if (request.getNettyRequest() instanceof FullHttpRequest) { + MulticastMessageData sendMessageData = getRequestBody(request.getNettyRequest(), MulticastMessageData.class); + if (MulticastMessageData.isValide(sendMessageData)) { + RPCCenter.getInstance().sendRequest(sendMessageData.getSender(), null, IMTopic.MultiCastMessageTopic, sendMessageData.toProtoMessage().toByteArray(), sendMessageData.getSender(), TargetEntry.Type.TARGET_TYPE_USER, new RPCCenter.Callback() { + @Override + public void onSuccess(byte[] result) { + ByteBuf byteBuf = Unpooled.buffer(); + byteBuf.writeBytes(result); + ErrorCode errorCode = ErrorCode.fromCode(byteBuf.readByte()); + if (errorCode == ErrorCode.ERROR_CODE_SUCCESS) { + long messageId = byteBuf.readLong(); + long timestamp = byteBuf.readLong(); + sendResponse(response, null, new MultiMessageResult(messageId, timestamp)); + } else { + sendResponse(response, errorCode, null); + } + } + + @Override + public void onError(ErrorCode errorCode) { + sendResponse(response, errorCode, null); + } + + @Override + public void onTimeout() { + sendResponse(response, ErrorCode.ERROR_CODE_TIMEOUT, null); + } + + @Override + public Executor getResponseExecutor() { + return command -> { + ctx.executor().execute(command); + }; + } + }, true); + return false; + } else { + response.setStatus(HttpResponseStatus.OK); + RestResult result = RestResult.resultOf(ErrorCode.INVALID_PARAMETER); + response.setContent(new Gson().toJson(result)); + } + } + return true; + } +} diff --git a/broker/src/main/java/io/moquette/imhandler/IMHandler.java b/broker/src/main/java/io/moquette/imhandler/IMHandler.java index 13175190..0b2f7b06 100755 --- a/broker/src/main/java/io/moquette/imhandler/IMHandler.java +++ b/broker/src/main/java/io/moquette/imhandler/IMHandler.java @@ -32,6 +32,8 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.Collection; +import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Set; @@ -250,4 +252,12 @@ abstract public class IMHandler { mServer.getImBusinessScheduler().execute(() -> publisher.publish2Receivers(updatedMessage, notifyReceivers, clientID, ProtoConstants.PullType.Pull_Normal)); return notifyReceivers.size(); } + + protected long saveAndMulticast(String username, String clientID, WFCMessage.Message message, Collection targets) { + Set notifyReceivers = new HashSet<>(); + notifyReceivers.addAll(targets); + WFCMessage.Message updatedMessage = m_messagesStore.storeMessage(username, clientID, message); + mServer.getImBusinessScheduler().execute(() -> publisher.publish2Receivers(updatedMessage, notifyReceivers, clientID, ProtoConstants.PullType.Pull_Normal)); + return notifyReceivers.size(); + } } diff --git a/broker/src/main/java/io/moquette/imhandler/MultiCastMessageHandler.java b/broker/src/main/java/io/moquette/imhandler/MultiCastMessageHandler.java new file mode 100644 index 00000000..2b33bcae --- /dev/null +++ b/broker/src/main/java/io/moquette/imhandler/MultiCastMessageHandler.java @@ -0,0 +1,57 @@ +/* + * This file is part of the Wildfire Chat package. + * (c) Heavyrain2012 + * + * 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.common.ErrorCode; +import cn.wildfirechat.proto.ProtoConstants; +import cn.wildfirechat.proto.WFCMessage; +import com.hazelcast.util.StringUtil; +import io.moquette.BrokerConstants; +import io.moquette.server.Server; +import io.moquette.spi.impl.Qos1PublishHandler; +import io.netty.buffer.ByteBuf; +import win.liyufan.im.IMTopic; +import win.liyufan.im.MessageShardingUtil; + +import java.util.Set; + +import static cn.wildfirechat.proto.ProtoConstants.ContentType.Text; +import static cn.wildfirechat.proto.ProtoConstants.ConversationType.ConversationType_Private; + +@Handler(value = IMTopic.MultiCastMessageTopic) +public class MultiCastMessageHandler extends IMHandler { + + + @Override + public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, boolean isAdmin, WFCMessage.MultiCastMessage multiCastMessage, Qos1PublishHandler.IMCallback callback) { + ErrorCode errorCode = ErrorCode.ERROR_CODE_SUCCESS; + if (!isAdmin) { + return ErrorCode.ERROR_CODE_NOT_RIGHT; + } + + long timestamp = System.currentTimeMillis(); + long messageId = MessageShardingUtil.generateId(); + WFCMessage.Message message = WFCMessage.Message.newBuilder() + .setContent(multiCastMessage.getContent()) + .setConversation(WFCMessage.Conversation.newBuilder().setTarget(fromUser).setType(ConversationType_Private).setLine(multiCastMessage.getLine()).build()) + .setFromUser(fromUser) + .setMessageId(messageId) + .setServerTimestamp(timestamp) + .build(); + + saveAndMulticast(fromUser, clientID, message, multiCastMessage.getToList()); + + ackPayload = ackPayload.capacity(20); + ackPayload.writeLong(messageId); + ackPayload.writeLong(timestamp); + + return errorCode; + } + +} diff --git a/broker/src/main/java/win/liyufan/im/IMTopic.java b/broker/src/main/java/win/liyufan/im/IMTopic.java index c89f7ad1..c4ea00de 100755 --- a/broker/src/main/java/win/liyufan/im/IMTopic.java +++ b/broker/src/main/java/win/liyufan/im/IMTopic.java @@ -10,6 +10,7 @@ package win.liyufan.im; public interface IMTopic { String SendMessageTopic = "MS"; + String MultiCastMessageTopic = "MMC"; String RecallMessageTopic = "MR"; String PullMessageTopic = "MP"; String NotifyMessageTopic = "MN"; diff --git a/common/src/main/java/cn.wildfirechat.pojos/MultiMessageResult.java b/common/src/main/java/cn.wildfirechat.pojos/MultiMessageResult.java new file mode 100644 index 00000000..71a097c0 --- /dev/null +++ b/common/src/main/java/cn.wildfirechat.pojos/MultiMessageResult.java @@ -0,0 +1,38 @@ +/* + * This file is part of the Wildfire Chat package. + * (c) Heavyrain2012 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +package cn.wildfirechat.pojos; + +public class MultiMessageResult { + private long messageUid; + private long timestamp; + + public MultiMessageResult() { + } + + public MultiMessageResult(long messageUid, long timestamp) { + this.messageUid = messageUid; + this.timestamp = timestamp; + } + + public long getMessageUid() { + return messageUid; + } + + public void setMessageUid(long messageUid) { + this.messageUid = messageUid; + } + + public long getTimestamp() { + return timestamp; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } +} diff --git a/common/src/main/java/cn.wildfirechat.pojos/MulticastMessageData.java b/common/src/main/java/cn.wildfirechat.pojos/MulticastMessageData.java new file mode 100644 index 00000000..6a843521 --- /dev/null +++ b/common/src/main/java/cn.wildfirechat.pojos/MulticastMessageData.java @@ -0,0 +1,71 @@ +/* + * This file is part of the Wildfire Chat package. + * (c) Heavyrain2012 + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +package cn.wildfirechat.pojos; + +import cn.wildfirechat.proto.ProtoConstants; +import cn.wildfirechat.proto.WFCMessage; +import io.netty.util.internal.StringUtil; + +import java.util.List; + +public class MulticastMessageData { + private String sender; + private int line; + private MessagePayload payload; + private List targets; + + public String getSender() { + return sender; + } + + public void setSender(String sender) { + this.sender = sender; + } + + public int getLine() { + return line; + } + + public void setLine(int line) { + this.line = line; + } + + public MessagePayload getPayload() { + return payload; + } + + public void setPayload(MessagePayload payload) { + this.payload = payload; + } + + public static boolean isValide(MulticastMessageData sendMessageData) { + if(sendMessageData == null || + StringUtil.isNullOrEmpty(sendMessageData.getSender()) || + sendMessageData.getPayload() == null) { + return false; + } + return true; + } + + public WFCMessage.MultiCastMessage toProtoMessage() { + return WFCMessage.MultiCastMessage.newBuilder().setFromUser(sender) + .setLine(line) + .setContent(payload.toProtoMessageContent()) + .addAllTo(targets) + .build(); + } + + public List getTargets() { + return targets; + } + + public void setTargets(List targets) { + this.targets = targets; + } +} diff --git a/common/src/main/java/cn/wildfirechat/common/APIPath.java b/common/src/main/java/cn/wildfirechat/common/APIPath.java index 8563c194..86098f67 100644 --- a/common/src/main/java/cn/wildfirechat/common/APIPath.java +++ b/common/src/main/java/cn/wildfirechat/common/APIPath.java @@ -26,6 +26,7 @@ public interface APIPath { String Msg_Send = "/admin/message/send"; String Msg_Recall = "/admin/message/recall"; String Msg_Broadcast = "/admin/message/broadcast"; + String Msg_Multicast = "/admin/message/multicast"; String Create_Group = "/admin/group/create"; String Group_Dismiss = "/admin/group/del"; diff --git a/common/src/main/java/cn/wildfirechat/proto/WFCMessage.java b/common/src/main/java/cn/wildfirechat/proto/WFCMessage.java index eb02b06b..15ea1d08 100644 --- a/common/src/main/java/cn/wildfirechat/proto/WFCMessage.java +++ b/common/src/main/java/cn/wildfirechat/proto/WFCMessage.java @@ -58078,6 +58078,967 @@ public final class WFCMessage { // @@protoc_insertion_point(class_scope:LoadRemoteMessages) } + public interface MultiCastMessageOrBuilder + extends com.google.protobuf.MessageOrBuilder { + + // required string from_user = 1; + /** + * required string from_user = 1; + */ + boolean hasFromUser(); + /** + * required string from_user = 1; + */ + java.lang.String getFromUser(); + /** + * required string from_user = 1; + */ + com.google.protobuf.ByteString + getFromUserBytes(); + + // required .MessageContent content = 2; + /** + * required .MessageContent content = 2; + */ + boolean hasContent(); + /** + * required .MessageContent content = 2; + */ + cn.wildfirechat.proto.WFCMessage.MessageContent getContent(); + /** + * required .MessageContent content = 2; + */ + cn.wildfirechat.proto.WFCMessage.MessageContentOrBuilder getContentOrBuilder(); + + // repeated string to = 3; + /** + * repeated string to = 3; + */ + java.util.List + getToList(); + /** + * repeated string to = 3; + */ + int getToCount(); + /** + * repeated string to = 3; + */ + java.lang.String getTo(int index); + /** + * repeated string to = 3; + */ + com.google.protobuf.ByteString + getToBytes(int index); + + // required int32 line = 4; + /** + * required int32 line = 4; + */ + boolean hasLine(); + /** + * required int32 line = 4; + */ + int getLine(); + } + /** + * Protobuf type {@code MultiCastMessage} + */ + public static final class MultiCastMessage extends + com.google.protobuf.GeneratedMessage + implements MultiCastMessageOrBuilder { + // Use MultiCastMessage.newBuilder() to construct. + private MultiCastMessage(com.google.protobuf.GeneratedMessage.Builder builder) { + super(builder); + this.unknownFields = builder.getUnknownFields(); + } + private MultiCastMessage(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } + + private static final MultiCastMessage defaultInstance; + public static MultiCastMessage getDefaultInstance() { + return defaultInstance; + } + + public MultiCastMessage getDefaultInstanceForType() { + return defaultInstance; + } + + private final com.google.protobuf.UnknownFieldSet unknownFields; + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return this.unknownFields; + } + private MultiCastMessage( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + initFields(); + int mutable_bitField0_ = 0; + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder(); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!parseUnknownField(input, unknownFields, + extensionRegistry, tag)) { + done = true; + } + break; + } + case 10: { + bitField0_ |= 0x00000001; + fromUser_ = input.readBytes(); + break; + } + case 18: { + cn.wildfirechat.proto.WFCMessage.MessageContent.Builder subBuilder = null; + if (((bitField0_ & 0x00000002) == 0x00000002)) { + subBuilder = content_.toBuilder(); + } + content_ = input.readMessage(cn.wildfirechat.proto.WFCMessage.MessageContent.PARSER, extensionRegistry); + if (subBuilder != null) { + subBuilder.mergeFrom(content_); + content_ = subBuilder.buildPartial(); + } + bitField0_ |= 0x00000002; + break; + } + case 26: { + if (!((mutable_bitField0_ & 0x00000004) == 0x00000004)) { + to_ = new com.google.protobuf.LazyStringArrayList(); + mutable_bitField0_ |= 0x00000004; + } + to_.add(input.readBytes()); + break; + } + case 32: { + bitField0_ |= 0x00000004; + line_ = input.readInt32(); + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException( + e.getMessage()).setUnfinishedMessage(this); + } finally { + if (((mutable_bitField0_ & 0x00000004) == 0x00000004)) { + to_ = new com.google.protobuf.UnmodifiableLazyStringList(to_); + } + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return cn.wildfirechat.proto.WFCMessage.internal_static_MultiCastMessage_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return cn.wildfirechat.proto.WFCMessage.internal_static_MultiCastMessage_fieldAccessorTable + .ensureFieldAccessorsInitialized( + cn.wildfirechat.proto.WFCMessage.MultiCastMessage.class, cn.wildfirechat.proto.WFCMessage.MultiCastMessage.Builder.class); + } + + public static com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + public MultiCastMessage parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new MultiCastMessage(input, extensionRegistry); + } + }; + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + private int bitField0_; + // required string from_user = 1; + public static final int FROM_USER_FIELD_NUMBER = 1; + private java.lang.Object fromUser_; + /** + * required string from_user = 1; + */ + public boolean hasFromUser() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + /** + * required string from_user = 1; + */ + public java.lang.String getFromUser() { + java.lang.Object ref = fromUser_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + fromUser_ = s; + } + return s; + } + } + /** + * required string from_user = 1; + */ + public com.google.protobuf.ByteString + getFromUserBytes() { + java.lang.Object ref = fromUser_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + fromUser_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + // required .MessageContent content = 2; + public static final int CONTENT_FIELD_NUMBER = 2; + private cn.wildfirechat.proto.WFCMessage.MessageContent content_; + /** + * required .MessageContent content = 2; + */ + public boolean hasContent() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + /** + * required .MessageContent content = 2; + */ + public cn.wildfirechat.proto.WFCMessage.MessageContent getContent() { + return content_; + } + /** + * required .MessageContent content = 2; + */ + public cn.wildfirechat.proto.WFCMessage.MessageContentOrBuilder getContentOrBuilder() { + return content_; + } + + // repeated string to = 3; + public static final int TO_FIELD_NUMBER = 3; + private com.google.protobuf.LazyStringList to_; + /** + * repeated string to = 3; + */ + public java.util.List + getToList() { + return to_; + } + /** + * repeated string to = 3; + */ + public int getToCount() { + return to_.size(); + } + /** + * repeated string to = 3; + */ + public java.lang.String getTo(int index) { + return to_.get(index); + } + /** + * repeated string to = 3; + */ + public com.google.protobuf.ByteString + getToBytes(int index) { + return to_.getByteString(index); + } + + // required int32 line = 4; + public static final int LINE_FIELD_NUMBER = 4; + private int line_; + /** + * required int32 line = 4; + */ + public boolean hasLine() { + return ((bitField0_ & 0x00000004) == 0x00000004); + } + /** + * required int32 line = 4; + */ + public int getLine() { + return line_; + } + + private void initFields() { + fromUser_ = ""; + content_ = cn.wildfirechat.proto.WFCMessage.MessageContent.getDefaultInstance(); + to_ = com.google.protobuf.LazyStringArrayList.EMPTY; + line_ = 0; + } + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized != -1) return isInitialized == 1; + + if (!hasFromUser()) { + memoizedIsInitialized = 0; + return false; + } + if (!hasContent()) { + memoizedIsInitialized = 0; + return false; + } + if (!hasLine()) { + memoizedIsInitialized = 0; + return false; + } + if (!getContent().isInitialized()) { + memoizedIsInitialized = 0; + return false; + } + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + getSerializedSize(); + if (((bitField0_ & 0x00000001) == 0x00000001)) { + output.writeBytes(1, getFromUserBytes()); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + output.writeMessage(2, content_); + } + for (int i = 0; i < to_.size(); i++) { + output.writeBytes(3, to_.getByteString(i)); + } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + output.writeInt32(4, line_); + } + getUnknownFields().writeTo(output); + } + + private int memoizedSerializedSize = -1; + public int getSerializedSize() { + int size = memoizedSerializedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) == 0x00000001)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(1, getFromUserBytes()); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + size += com.google.protobuf.CodedOutputStream + .computeMessageSize(2, content_); + } + { + int dataSize = 0; + for (int i = 0; i < to_.size(); i++) { + dataSize += com.google.protobuf.CodedOutputStream + .computeBytesSizeNoTag(to_.getByteString(i)); + } + size += dataSize; + size += 1 * getToList().size(); + } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(4, line_); + } + size += getUnknownFields().getSerializedSize(); + memoizedSerializedSize = size; + return size; + } + + private static final long serialVersionUID = 0L; + @java.lang.Override + protected java.lang.Object writeReplace() + throws java.io.ObjectStreamException { + return super.writeReplace(); + } + + public static cn.wildfirechat.proto.WFCMessage.MultiCastMessage parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static cn.wildfirechat.proto.WFCMessage.MultiCastMessage parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static cn.wildfirechat.proto.WFCMessage.MultiCastMessage parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static cn.wildfirechat.proto.WFCMessage.MultiCastMessage parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static cn.wildfirechat.proto.WFCMessage.MultiCastMessage parseFrom(java.io.InputStream input) + throws java.io.IOException { + return PARSER.parseFrom(input); + } + public static cn.wildfirechat.proto.WFCMessage.MultiCastMessage parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseFrom(input, extensionRegistry); + } + public static cn.wildfirechat.proto.WFCMessage.MultiCastMessage parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return PARSER.parseDelimitedFrom(input); + } + public static cn.wildfirechat.proto.WFCMessage.MultiCastMessage parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseDelimitedFrom(input, extensionRegistry); + } + public static cn.wildfirechat.proto.WFCMessage.MultiCastMessage parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return PARSER.parseFrom(input); + } + public static cn.wildfirechat.proto.WFCMessage.MultiCastMessage parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseFrom(input, extensionRegistry); + } + + public static Builder newBuilder() { return Builder.create(); } + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder(cn.wildfirechat.proto.WFCMessage.MultiCastMessage prototype) { + return newBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { return newBuilder(this); } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code MultiCastMessage} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder + implements cn.wildfirechat.proto.WFCMessage.MultiCastMessageOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return cn.wildfirechat.proto.WFCMessage.internal_static_MultiCastMessage_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return cn.wildfirechat.proto.WFCMessage.internal_static_MultiCastMessage_fieldAccessorTable + .ensureFieldAccessorsInitialized( + cn.wildfirechat.proto.WFCMessage.MultiCastMessage.class, cn.wildfirechat.proto.WFCMessage.MultiCastMessage.Builder.class); + } + + // Construct using cn.wildfirechat.proto.WFCMessage.MultiCastMessage.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + getContentFieldBuilder(); + } + } + private static Builder create() { + return new Builder(); + } + + public Builder clear() { + super.clear(); + fromUser_ = ""; + bitField0_ = (bitField0_ & ~0x00000001); + if (contentBuilder_ == null) { + content_ = cn.wildfirechat.proto.WFCMessage.MessageContent.getDefaultInstance(); + } else { + contentBuilder_.clear(); + } + bitField0_ = (bitField0_ & ~0x00000002); + to_ = com.google.protobuf.LazyStringArrayList.EMPTY; + bitField0_ = (bitField0_ & ~0x00000004); + line_ = 0; + bitField0_ = (bitField0_ & ~0x00000008); + return this; + } + + public Builder clone() { + return create().mergeFrom(buildPartial()); + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return cn.wildfirechat.proto.WFCMessage.internal_static_MultiCastMessage_descriptor; + } + + public cn.wildfirechat.proto.WFCMessage.MultiCastMessage getDefaultInstanceForType() { + return cn.wildfirechat.proto.WFCMessage.MultiCastMessage.getDefaultInstance(); + } + + public cn.wildfirechat.proto.WFCMessage.MultiCastMessage build() { + cn.wildfirechat.proto.WFCMessage.MultiCastMessage result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public cn.wildfirechat.proto.WFCMessage.MultiCastMessage buildPartial() { + cn.wildfirechat.proto.WFCMessage.MultiCastMessage result = new cn.wildfirechat.proto.WFCMessage.MultiCastMessage(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) == 0x00000001)) { + to_bitField0_ |= 0x00000001; + } + result.fromUser_ = fromUser_; + if (((from_bitField0_ & 0x00000002) == 0x00000002)) { + to_bitField0_ |= 0x00000002; + } + if (contentBuilder_ == null) { + result.content_ = content_; + } else { + result.content_ = contentBuilder_.build(); + } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + to_ = new com.google.protobuf.UnmodifiableLazyStringList( + to_); + bitField0_ = (bitField0_ & ~0x00000004); + } + result.to_ = to_; + if (((from_bitField0_ & 0x00000008) == 0x00000008)) { + to_bitField0_ |= 0x00000004; + } + result.line_ = line_; + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof cn.wildfirechat.proto.WFCMessage.MultiCastMessage) { + return mergeFrom((cn.wildfirechat.proto.WFCMessage.MultiCastMessage)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(cn.wildfirechat.proto.WFCMessage.MultiCastMessage other) { + if (other == cn.wildfirechat.proto.WFCMessage.MultiCastMessage.getDefaultInstance()) return this; + if (other.hasFromUser()) { + bitField0_ |= 0x00000001; + fromUser_ = other.fromUser_; + onChanged(); + } + if (other.hasContent()) { + mergeContent(other.getContent()); + } + if (!other.to_.isEmpty()) { + if (to_.isEmpty()) { + to_ = other.to_; + bitField0_ = (bitField0_ & ~0x00000004); + } else { + ensureToIsMutable(); + to_.addAll(other.to_); + } + onChanged(); + } + if (other.hasLine()) { + setLine(other.getLine()); + } + this.mergeUnknownFields(other.getUnknownFields()); + return this; + } + + public final boolean isInitialized() { + if (!hasFromUser()) { + + return false; + } + if (!hasContent()) { + + return false; + } + if (!hasLine()) { + + return false; + } + if (!getContent().isInitialized()) { + + return false; + } + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + cn.wildfirechat.proto.WFCMessage.MultiCastMessage parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (cn.wildfirechat.proto.WFCMessage.MultiCastMessage) e.getUnfinishedMessage(); + throw e; + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + private int bitField0_; + + // required string from_user = 1; + private java.lang.Object fromUser_ = ""; + /** + * required string from_user = 1; + */ + public boolean hasFromUser() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + /** + * required string from_user = 1; + */ + public java.lang.String getFromUser() { + java.lang.Object ref = fromUser_; + if (!(ref instanceof java.lang.String)) { + java.lang.String s = ((com.google.protobuf.ByteString) ref) + .toStringUtf8(); + fromUser_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * required string from_user = 1; + */ + public com.google.protobuf.ByteString + getFromUserBytes() { + java.lang.Object ref = fromUser_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + fromUser_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * required string from_user = 1; + */ + public Builder setFromUser( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000001; + fromUser_ = value; + onChanged(); + return this; + } + /** + * required string from_user = 1; + */ + public Builder clearFromUser() { + bitField0_ = (bitField0_ & ~0x00000001); + fromUser_ = getDefaultInstance().getFromUser(); + onChanged(); + return this; + } + /** + * required string from_user = 1; + */ + public Builder setFromUserBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000001; + fromUser_ = value; + onChanged(); + return this; + } + + // required .MessageContent content = 2; + private cn.wildfirechat.proto.WFCMessage.MessageContent content_ = cn.wildfirechat.proto.WFCMessage.MessageContent.getDefaultInstance(); + private com.google.protobuf.SingleFieldBuilder< + cn.wildfirechat.proto.WFCMessage.MessageContent, cn.wildfirechat.proto.WFCMessage.MessageContent.Builder, cn.wildfirechat.proto.WFCMessage.MessageContentOrBuilder> contentBuilder_; + /** + * required .MessageContent content = 2; + */ + public boolean hasContent() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + /** + * required .MessageContent content = 2; + */ + public cn.wildfirechat.proto.WFCMessage.MessageContent getContent() { + if (contentBuilder_ == null) { + return content_; + } else { + return contentBuilder_.getMessage(); + } + } + /** + * required .MessageContent content = 2; + */ + public Builder setContent(cn.wildfirechat.proto.WFCMessage.MessageContent value) { + if (contentBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + content_ = value; + onChanged(); + } else { + contentBuilder_.setMessage(value); + } + bitField0_ |= 0x00000002; + return this; + } + /** + * required .MessageContent content = 2; + */ + public Builder setContent( + cn.wildfirechat.proto.WFCMessage.MessageContent.Builder builderForValue) { + if (contentBuilder_ == null) { + content_ = builderForValue.build(); + onChanged(); + } else { + contentBuilder_.setMessage(builderForValue.build()); + } + bitField0_ |= 0x00000002; + return this; + } + /** + * required .MessageContent content = 2; + */ + public Builder mergeContent(cn.wildfirechat.proto.WFCMessage.MessageContent value) { + if (contentBuilder_ == null) { + if (((bitField0_ & 0x00000002) == 0x00000002) && + content_ != cn.wildfirechat.proto.WFCMessage.MessageContent.getDefaultInstance()) { + content_ = + cn.wildfirechat.proto.WFCMessage.MessageContent.newBuilder(content_).mergeFrom(value).buildPartial(); + } else { + content_ = value; + } + onChanged(); + } else { + contentBuilder_.mergeFrom(value); + } + bitField0_ |= 0x00000002; + return this; + } + /** + * required .MessageContent content = 2; + */ + public Builder clearContent() { + if (contentBuilder_ == null) { + content_ = cn.wildfirechat.proto.WFCMessage.MessageContent.getDefaultInstance(); + onChanged(); + } else { + contentBuilder_.clear(); + } + bitField0_ = (bitField0_ & ~0x00000002); + return this; + } + /** + * required .MessageContent content = 2; + */ + public cn.wildfirechat.proto.WFCMessage.MessageContent.Builder getContentBuilder() { + bitField0_ |= 0x00000002; + onChanged(); + return getContentFieldBuilder().getBuilder(); + } + /** + * required .MessageContent content = 2; + */ + public cn.wildfirechat.proto.WFCMessage.MessageContentOrBuilder getContentOrBuilder() { + if (contentBuilder_ != null) { + return contentBuilder_.getMessageOrBuilder(); + } else { + return content_; + } + } + /** + * required .MessageContent content = 2; + */ + private com.google.protobuf.SingleFieldBuilder< + cn.wildfirechat.proto.WFCMessage.MessageContent, cn.wildfirechat.proto.WFCMessage.MessageContent.Builder, cn.wildfirechat.proto.WFCMessage.MessageContentOrBuilder> + getContentFieldBuilder() { + if (contentBuilder_ == null) { + contentBuilder_ = new com.google.protobuf.SingleFieldBuilder< + cn.wildfirechat.proto.WFCMessage.MessageContent, cn.wildfirechat.proto.WFCMessage.MessageContent.Builder, cn.wildfirechat.proto.WFCMessage.MessageContentOrBuilder>( + content_, + getParentForChildren(), + isClean()); + content_ = null; + } + return contentBuilder_; + } + + // repeated string to = 3; + private com.google.protobuf.LazyStringList to_ = com.google.protobuf.LazyStringArrayList.EMPTY; + private void ensureToIsMutable() { + if (!((bitField0_ & 0x00000004) == 0x00000004)) { + to_ = new com.google.protobuf.LazyStringArrayList(to_); + bitField0_ |= 0x00000004; + } + } + /** + * repeated string to = 3; + */ + public java.util.List + getToList() { + return java.util.Collections.unmodifiableList(to_); + } + /** + * repeated string to = 3; + */ + public int getToCount() { + return to_.size(); + } + /** + * repeated string to = 3; + */ + public java.lang.String getTo(int index) { + return to_.get(index); + } + /** + * repeated string to = 3; + */ + public com.google.protobuf.ByteString + getToBytes(int index) { + return to_.getByteString(index); + } + /** + * repeated string to = 3; + */ + public Builder setTo( + int index, java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + ensureToIsMutable(); + to_.set(index, value); + onChanged(); + return this; + } + /** + * repeated string to = 3; + */ + public Builder addTo( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + ensureToIsMutable(); + to_.add(value); + onChanged(); + return this; + } + /** + * repeated string to = 3; + */ + public Builder addAllTo( + java.lang.Iterable values) { + ensureToIsMutable(); + super.addAll(values, to_); + onChanged(); + return this; + } + /** + * repeated string to = 3; + */ + public Builder clearTo() { + to_ = com.google.protobuf.LazyStringArrayList.EMPTY; + bitField0_ = (bitField0_ & ~0x00000004); + onChanged(); + return this; + } + /** + * repeated string to = 3; + */ + public Builder addToBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + ensureToIsMutable(); + to_.add(value); + onChanged(); + return this; + } + + // required int32 line = 4; + private int line_ ; + /** + * required int32 line = 4; + */ + public boolean hasLine() { + return ((bitField0_ & 0x00000008) == 0x00000008); + } + /** + * required int32 line = 4; + */ + public int getLine() { + return line_; + } + /** + * required int32 line = 4; + */ + public Builder setLine(int value) { + bitField0_ |= 0x00000008; + line_ = value; + onChanged(); + return this; + } + /** + * required int32 line = 4; + */ + public Builder clearLine() { + bitField0_ = (bitField0_ & ~0x00000008); + line_ = 0; + onChanged(); + return this; + } + + // @@protoc_insertion_point(builder_scope:MultiCastMessage) + } + + static { + defaultInstance = new MultiCastMessage(true); + defaultInstance.initFields(); + } + + // @@protoc_insertion_point(class_scope:MultiCastMessage) + } + private static com.google.protobuf.Descriptors.Descriptor internal_static_AddFriendRequest_descriptor; private static @@ -58428,6 +59389,11 @@ public final class WFCMessage { private static com.google.protobuf.GeneratedMessage.FieldAccessorTable internal_static_LoadRemoteMessages_fieldAccessorTable; + private static com.google.protobuf.Descriptors.Descriptor + internal_static_MultiCastMessage_descriptor; + private static + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_MultiCastMessage_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { @@ -58586,8 +59552,11 @@ public final class WFCMessage { "rt\030\003 \002(\005\"5\n\017GetTokenRequest\022\017\n\007user_id\030\001" + " \002(\t\022\021\n\tclient_id\030\002 \002(\t\"\\\n\022LoadRemoteMes" + "sages\022#\n\014conversation\030\001 \002(\0132\r.Conversati" + - "on\022\022\n\nbefore_uid\030\002 \002(\003\022\r\n\005count\030\003 \002(\005B#\n", - "\025cn.wildfirechat.protoB\nWFCMessage" + "on\022\022\n\nbefore_uid\030\002 \002(\003\022\r\n\005count\030\003 \002(\005\"a\n", + "\020MultiCastMessage\022\021\n\tfrom_user\030\001 \002(\t\022 \n\007" + + "content\030\002 \002(\0132\017.MessageContent\022\n\n\002to\030\003 \003" + + "(\t\022\014\n\004line\030\004 \002(\005B#\n\025cn.wildfirechat.prot" + + "oB\nWFCMessage" }; com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { @@ -59014,6 +59983,12 @@ public final class WFCMessage { com.google.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_LoadRemoteMessages_descriptor, new java.lang.String[] { "Conversation", "BeforeUid", "Count", }); + internal_static_MultiCastMessage_descriptor = + getDescriptor().getMessageTypes().get(70); + internal_static_MultiCastMessage_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_MultiCastMessage_descriptor, + new java.lang.String[] { "FromUser", "Content", "To", "Line", }); return null; } }; diff --git a/sdk/src/main/java/cn/wildfirechat/sdk/Main.java b/sdk/src/main/java/cn/wildfirechat/sdk/Main.java index 425b096c..32a86ade 100644 --- a/sdk/src/main/java/cn/wildfirechat/sdk/Main.java +++ b/sdk/src/main/java/cn/wildfirechat/sdk/Main.java @@ -7,6 +7,7 @@ import cn.wildfirechat.sdk.model.IMResult; import cn.wildfirechat.sdk.utilities.AdminHttpUtils; import cn.wildfirechat.sdk.utilities.RobotHttpUtils; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -27,7 +28,7 @@ public class Main { userInfo.setMobile("13900000000"); userInfo.setDisplayName("user 1"); - IMResult resultCreateUser = UserAdmin.createUser(userInfo); + IMResult resultCreateUser = UserAdmin.createUser(userInfo); if (resultCreateUser != null && resultCreateUser.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) { System.out.println("Create user " + resultCreateUser.getResult().getName() + " success"); } else {