Skip to content

Commit 22ae62b

Browse files
yanglbmegitee-org
authored andcommitted
feat: support group message with GroupAtInfo
2 parents 3e92877 + 77278b0 commit 22ae62b

File tree

4 files changed

+155
-0
lines changed

4 files changed

+155
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.github.doocs.im.constant;
2+
3+
/**
4+
* 群组@全体成员标识
5+
*
6+
* @author Vensin
7+
* @since 2025/1/25 13:52
8+
*/
9+
public final class GroupAtAllFlag {
10+
11+
/**
12+
* 群组消息 @all
13+
*/
14+
public static final int AT_ALL = 1;
15+
16+
/**
17+
* 群组消息 @指定成员
18+
*/
19+
public static final int AT_MEMBER = 0;
20+
21+
private GroupAtAllFlag() {
22+
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package io.github.doocs.im.model.request;
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
6+
import java.io.Serializable;
7+
8+
/**
9+
* 群@消息
10+
*
11+
* @author Vensin
12+
* @since 2025/1/25 13:43
13+
*/
14+
@JsonInclude(JsonInclude.Include.NON_NULL)
15+
public class GroupAtInfo implements Serializable {
16+
17+
private static final long serialVersionUID = -11238790123456789L;
18+
19+
/**
20+
* 为1表示 @all,为0表示 @某个群成员 <br>
21+
* {@link io.github.doocs.im.constant.GroupAtAllFlag}
22+
*/
23+
@JsonProperty("GroupAtAllFlag")
24+
private Integer groupAtAllFlag;
25+
26+
/**
27+
* 表示 @的具体的群成员,如果为 @all,则无需填写该字段 <br>
28+
* 消息体里面@的用户按顺序逐一对应,该字段上送的是用户的userId,消息体里的'@'后面内容任意,一般为用户的昵称
29+
*/
30+
@JsonProperty("GroupAt_Account")
31+
private String groupAtAccount;
32+
33+
public static GroupAtInfo.Builder builder() {
34+
return new GroupAtInfo.Builder();
35+
}
36+
37+
38+
public Integer getGroupAtAllFlag() {
39+
return groupAtAllFlag;
40+
}
41+
42+
public void setGroupAtAllFlag(Integer groupAtAllFlag) {
43+
this.groupAtAllFlag = groupAtAllFlag;
44+
}
45+
46+
public String getGroupAtAccount() {
47+
return groupAtAccount;
48+
}
49+
50+
public void setGroupAtAccount(String groupAtAccount) {
51+
this.groupAtAccount = groupAtAccount;
52+
}
53+
54+
55+
public static class Builder {
56+
private Integer groupAtAllFlag;
57+
private String groupAtAccount;
58+
59+
private Builder() {
60+
}
61+
62+
public Builder groupAtAllFlag(Integer groupAtAllFlag) {
63+
this.groupAtAllFlag = groupAtAllFlag;
64+
return this;
65+
}
66+
67+
public Builder groupAtAccount(String groupAtAccount) {
68+
this.groupAtAccount = groupAtAccount;
69+
return this;
70+
}
71+
72+
public GroupAtInfo build() {
73+
GroupAtInfo groupAtInfo = new GroupAtInfo();
74+
groupAtInfo.groupAtAllFlag = this.groupAtAllFlag;
75+
groupAtInfo.groupAtAccount = this.groupAtAccount;
76+
return groupAtInfo;
77+
}
78+
79+
public static Builder builder() {
80+
return new Builder();
81+
}
82+
}
83+
84+
}

src/main/java/io/github/doocs/im/model/request/SendGroupMsgRequest.java

+28
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ public class SendGroupMsgRequest extends GenericRequest implements Serializable
4848
@JsonProperty("From_Account")
4949
private String fromAccount;
5050

51+
/**
52+
* 群组消息设置@的用户,跟消息体里面@的用户按顺序逐一对应。
53+
*/
54+
@JsonProperty("GroupAtInfo")
55+
private List<GroupAtInfo> groupAtInfos;
56+
5157
/**
5258
* 线推送信息配置,详细可参阅 消息格式描述
5359
*/
@@ -129,6 +135,14 @@ public SendGroupMsgRequest(String groupId, Long random, String msgPriority, List
129135
this.topicId = topicId;
130136
}
131137

138+
public SendGroupMsgRequest(String groupId, Long random, String msgPriority, List<TIMMsgElement> msgBody,
139+
String fromAccount, OfflinePushInfo offlinePushInfo, List<String> forbidCallbackControl,
140+
Integer onlineOnlyFlag, List<String> sendMsgControl, String cloudCustomData,
141+
Integer supportMessageExtension, String toAccount, String topicId, List<GroupAtInfo> groupAtInfos) {
142+
this(groupId, random, msgPriority, msgBody, fromAccount, offlinePushInfo, forbidCallbackControl, onlineOnlyFlag, sendMsgControl, cloudCustomData, supportMessageExtension, toAccount, topicId);
143+
this.groupAtInfos = groupAtInfos;
144+
}
145+
132146
private SendGroupMsgRequest(Builder builder) {
133147
this.groupId = builder.groupId;
134148
this.random = builder.random;
@@ -143,6 +157,7 @@ private SendGroupMsgRequest(Builder builder) {
143157
this.supportMessageExtension = builder.supportMessageExtension;
144158
this.toAccount = builder.toAccount;
145159
this.topicId = builder.topicId;
160+
this.groupAtInfos = builder.groupAtInfos;
146161
}
147162

148163
public static Builder builder() {
@@ -253,12 +268,20 @@ public void setTopicId(String topicId) {
253268
this.topicId = topicId;
254269
}
255270

271+
public List<GroupAtInfo> getGroupAtInfos() {
272+
return groupAtInfos;
273+
}
274+
275+
public void setGroupAtInfos(List<GroupAtInfo> groupAtInfos) {
276+
this.groupAtInfos = groupAtInfos;
277+
}
256278

257279
public static final class Builder {
258280
private String groupId;
259281
private Long random;
260282
private String msgPriority;
261283
private List<TIMMsgElement> msgBody;
284+
private List<GroupAtInfo> groupAtInfos;
262285
private String fromAccount;
263286
private OfflinePushInfo offlinePushInfo;
264287
private List<String> forbidCallbackControl;
@@ -296,6 +319,11 @@ public Builder msgBody(List<TIMMsgElement> msgBody) {
296319
return this;
297320
}
298321

322+
public Builder groupAtInfos(List<GroupAtInfo> groupAtInfos) {
323+
this.groupAtInfos = groupAtInfos;
324+
return this;
325+
}
326+
299327
public Builder fromAccount(String fromAccount) {
300328
this.fromAccount = fromAccount;
301329
return this;

src/test/java/io/github/doocs/im/core/GroupTest.java

+19
Original file line numberDiff line numberDiff line change
@@ -702,4 +702,23 @@ void testCheckMembers() throws IOException {
702702
System.out.println(result);
703703
Assertions.assertEquals(ErrorCode.SUCCESS.getCode(), result.getErrorCode());
704704
}
705+
706+
@Test
707+
void testGroupMessageWithAtInfo() throws IOException {
708+
TIMTextMsgElement msgEle = new TIMTextMsgElement();
709+
msgEle.setMsgContent(new TIMTextMsgElement.TextMsgContent("Hello @小鬼 欢迎加入小组"));
710+
711+
SendGroupMsgRequest request = SendGroupMsgRequest.builder()
712+
.groupId("shg_90")
713+
.fromAccount("260")
714+
.msgBody(Collections.singletonList(msgEle))
715+
.groupAtInfos(Collections.singletonList(GroupAtInfo.builder()
716+
.groupAtAllFlag(GroupAtAllFlag.AT_MEMBER)
717+
.groupAtAccount("276").build()))
718+
.build();
719+
720+
SendGroupMsgResult result = client.group.sendGroupMsg(request);
721+
System.out.println(result);
722+
Assertions.assertEquals(ErrorCode.SUCCESS.getCode(), result.getErrorCode());
723+
}
705724
}

0 commit comments

Comments
 (0)