Unverified Commit b06cbce1 authored by Yang Libin's avatar Yang Libin Committed by GitHub

fix: msg element type (#48)

parent 394f71f2
......@@ -22,7 +22,7 @@ Add the Maven dependency:
<dependency>
<groupId>io.github.doocs</groupId>
<artifactId>im-server-sdk-java</artifactId>
<version>0.2.3</version>
<version>0.2.4</version>
</dependency>
```
......
......@@ -6,7 +6,7 @@
<groupId>io.github.doocs</groupId>
<artifactId>im-server-sdk-java</artifactId>
<version>0.2.3</version>
<version>0.2.4</version>
<packaging>jar</packaging>
<name>qcloud-im-server-sdk-java</name>
......
......@@ -2,6 +2,9 @@ package io.github.doocs.im.model.message;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import io.github.doocs.im.constant.MsgType;
/**
* 抽象消息元素
......@@ -10,6 +13,17 @@ import com.fasterxml.jackson.annotation.JsonProperty;
* @since 2021/10/29 16:24
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "MsgType", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = TIMTextMsgElement.class, name = MsgType.TIM_TEXT_ELEM),
@JsonSubTypes.Type(value = TIMVideoFileMsgElement.class, name = MsgType.TIM_VIDEO_FILE_ELEM),
@JsonSubTypes.Type(value = TIMCustomMsgElement.class, name = MsgType.TIM_CUSTOM_ELEM),
@JsonSubTypes.Type(value = TIMSoundMsgElement.class, name = MsgType.TIM_SOUND_ELEM),
@JsonSubTypes.Type(value = TIMImageMsgElement.class, name = MsgType.TIM_IMAGE_ELEM),
@JsonSubTypes.Type(value = TIMLocationMsgElement.class, name = MsgType.TIM_LOCATION_ELEM),
@JsonSubTypes.Type(value = TIMFileMsgElement.class, name = MsgType.TIM_FILE_ELEM),
@JsonSubTypes.Type(value = TIMFaceMsgElement.class, name = MsgType.TIM_FACE_ELEM)
})
public abstract class TIMMsgElement {
@JsonProperty("MsgType")
private String msgType;
......
package io.github.doocs.im;
import io.github.doocs.im.constant.MsgType;
import io.github.doocs.im.constant.SyncOtherMachine;
import io.github.doocs.im.model.message.TIMCustomMsgElement;
import io.github.doocs.im.model.message.TIMMsgElement;
import io.github.doocs.im.model.message.TIMTextMsgElement;
import io.github.doocs.im.model.request.*;
......@@ -10,10 +12,7 @@ import org.junit.Test;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.*;
/**
* @author bingo
......@@ -38,7 +37,7 @@ public class MessageTest {
@Test
public void testSendMsg() throws IOException {
TIMTextMsgElement msg = new TIMTextMsgElement("hello world");
TIMMsgElement msg = new TIMTextMsgElement("hello world");
SendMsgRequest request = new SendMsgRequest("test2", 123, Collections.singletonList(msg));
request.setFromAccount("test1");
request.setSyncOtherMachine(SyncOtherMachine.YES);
......@@ -73,9 +72,17 @@ public class MessageTest {
@Test
public void testAdminGetRoamMsg() throws IOException {
AdminGetRoamMsgRequest request = new AdminGetRoamMsgRequest("test1", "test2", 123, 1631934000, 1631934060);
AdminGetRoamMsgRequest request = new AdminGetRoamMsgRequest("200942", "151", 200, 1603954915, 1643954915);
AdminRoamMsgResult result = client.message.getRoamMsg(request);
System.out.println(result);
List<TIMMsgElement> msgBody = result.getMsgList().get(0).getMsgBody();
System.out.println(msgBody.get(0).getMsgType());
for (TIMMsgElement ee : msgBody) {
if (Objects.equals(ee.getMsgType(), MsgType.TIM_CUSTOM_ELEM)) {
TIMCustomMsgElement t = (TIMCustomMsgElement) ee;
System.out.println(t.getMsgContent().getData());
}
}
Assert.assertEquals("OK", result.getActionStatus());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment