liyong
51 分钟以前 8f5be003e52fdbf034d1955216143bd184ebbdb4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
package cn.iocoder.yudao.module.im.service.message.dto;
 
import cn.iocoder.yudao.module.im.dal.dataobject.message.ImGroupMessageDO;
import cn.iocoder.yudao.module.im.enums.ImContentTypeEnum;
import cn.iocoder.yudao.module.im.service.websocket.notification.group.*;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
 
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
 
/**
 * IM 群聊消息发送 DTO
 *
 * @author 芋道源码
 */
@Data
public class ImGroupMessageSendDTO {
 
    /**
     * 群编号
     */
    @NotNull(message = "群编号不能为空")
    private Long groupId;
    /**
     * 消息类型
     * <p>
     * 枚举 {@link ImContentTypeEnum}
     */
    @NotNull(message = "消息类型不能为空")
    private Integer type;
    /**
     * 消息内容
     * <p>
     * 支持 String / POJO;非 String 时由 service 序列化为 JSON
     */
    private Object content;
    /**
     * @ 目标用户编号列表
     */
    private List<Long> atUserIds;
    /**
     * 定向接收用户编号列表
     * <p>
     * 为空表示全员可见
     */
    private List<Long> receiverUserIds;
    /**
     * 是否需要回执
     * <p>
     * 缺省视为无需回执(false)
     */
    private Boolean receipt;
 
    // ========== 群广播事件静态工厂(对应 ImContentTypeEnum 群事件) ==========
 
    public static ImGroupMessageSendDTO ofGroupCreate(Long groupId, Long operatorUserId, Collection<Long> memberUserIds) {
        GroupCreateNotification notification = new GroupCreateNotification();
        notification.setOperatorUserId(operatorUserId);
        notification.setMemberUserIds(new ArrayList<>(memberUserIds));
        return new ImGroupMessageSendDTO().setGroupId(groupId)
                .setType(ImContentTypeEnum.GROUP_CREATE.getType()).setContent(notification);
    }
 
    public static ImGroupMessageSendDTO ofGroupInfoUpdate(Long groupId, Long operatorUserId,
                                                          String oldAvatar, String newAvatar,
                                                          Boolean oldJoinApproval, Boolean newJoinApproval) {
        GroupInfoUpdateNotification notification = new GroupInfoUpdateNotification();
        notification.setOperatorUserId(operatorUserId);
        notification.setOldAvatar(oldAvatar);
        notification.setNewAvatar(newAvatar);
        notification.setOldJoinApproval(oldJoinApproval);
        notification.setNewJoinApproval(newJoinApproval);
        return new ImGroupMessageSendDTO().setGroupId(groupId)
                .setType(ImContentTypeEnum.GROUP_INFO_UPDATE.getType()).setContent(notification);
    }
 
    public static ImGroupMessageSendDTO ofGroupMemberQuit(Long groupId, Long operatorUserId) {
        GroupMemberQuitNotification notification = new GroupMemberQuitNotification();
        notification.setOperatorUserId(operatorUserId);
        return new ImGroupMessageSendDTO().setGroupId(groupId)
                .setType(ImContentTypeEnum.GROUP_MEMBER_QUIT.getType()).setContent(notification);
    }
 
    public static ImGroupMessageSendDTO ofGroupOwnerTransfer(Long groupId, Long operatorUserId, Long newOwnerUserId) {
        GroupOwnerTransferNotification notification = new GroupOwnerTransferNotification();
        notification.setOperatorUserId(operatorUserId);
        notification.setNewOwnerUserId(newOwnerUserId);
        return new ImGroupMessageSendDTO().setGroupId(groupId)
                .setType(ImContentTypeEnum.GROUP_OWNER_TRANSFER.getType()).setContent(notification);
    }
 
    public static ImGroupMessageSendDTO ofGroupMemberKick(Long groupId, Long operatorUserId, Collection<Long> memberUserIds) {
        GroupMemberKickNotification notification = new GroupMemberKickNotification();
        notification.setOperatorUserId(operatorUserId);
        notification.setMemberUserIds(new ArrayList<>(memberUserIds));
        return new ImGroupMessageSendDTO().setGroupId(groupId)
                .setType(ImContentTypeEnum.GROUP_MEMBER_KICK.getType()).setContent(notification);
    }
 
    public static ImGroupMessageSendDTO ofGroupMemberInvite(Long groupId, Long operatorUserId, Collection<Long> memberUserIds) {
        GroupMemberInviteNotification notification = new GroupMemberInviteNotification();
        notification.setOperatorUserId(operatorUserId);
        notification.setMemberUserIds(new ArrayList<>(memberUserIds));
        return new ImGroupMessageSendDTO().setGroupId(groupId)
                .setType(ImContentTypeEnum.GROUP_MEMBER_INVITE.getType()).setContent(notification);
    }
 
    public static ImGroupMessageSendDTO ofGroupMemberEnter(Long groupId, Long entrantUserId, Integer addSource) {
        GroupMemberEnterNotification notification = new GroupMemberEnterNotification();
        notification.setOperatorUserId(entrantUserId);
        notification.setEntrantUserId(entrantUserId);
        notification.setAddSource(addSource);
        return new ImGroupMessageSendDTO().setGroupId(groupId)
                .setType(ImContentTypeEnum.GROUP_MEMBER_ENTER.getType()).setContent(notification);
    }
 
    public static ImGroupMessageSendDTO ofGroupDissolve(Long groupId, Long operatorUserId) {
        GroupDissolveNotification notification = new GroupDissolveNotification();
        notification.setOperatorUserId(operatorUserId);
        return new ImGroupMessageSendDTO().setGroupId(groupId)
                .setType(ImContentTypeEnum.GROUP_DISSOLVE.getType()).setContent(notification);
    }
 
    public static ImGroupMessageSendDTO ofGroupMemberNicknameUpdate(Long groupId, Long operatorUserId, String displayUserName) {
        GroupMemberNicknameUpdateNotification notification = new GroupMemberNicknameUpdateNotification();
        notification.setOperatorUserId(operatorUserId);
        notification.setDisplayUserName(displayUserName);
        return new ImGroupMessageSendDTO().setGroupId(groupId)
                .setType(ImContentTypeEnum.GROUP_MEMBER_NICKNAME_UPDATE.getType()).setContent(notification);
    }
 
    public static ImGroupMessageSendDTO ofGroupAdminAdd(Long groupId, Long operatorUserId, Collection<Long> memberUserIds) {
        GroupAdminAddNotification notification = new GroupAdminAddNotification();
        notification.setOperatorUserId(operatorUserId);
        notification.setMemberUserIds(new ArrayList<>(memberUserIds));
        return new ImGroupMessageSendDTO().setGroupId(groupId)
                .setType(ImContentTypeEnum.GROUP_ADMIN_ADD.getType()).setContent(notification);
    }
 
    public static ImGroupMessageSendDTO ofGroupAdminRemove(Long groupId, Long operatorUserId, Collection<Long> memberUserIds) {
        GroupAdminRemoveNotification notification = new GroupAdminRemoveNotification();
        notification.setOperatorUserId(operatorUserId);
        notification.setMemberUserIds(new ArrayList<>(memberUserIds));
        return new ImGroupMessageSendDTO().setGroupId(groupId)
                .setType(ImContentTypeEnum.GROUP_ADMIN_REMOVE.getType()).setContent(notification);
    }
 
    public static ImGroupMessageSendDTO ofGroupNoticeUpdate(Long groupId, Long operatorUserId, String oldNotice, String newNotice) {
        GroupNoticeUpdateNotification notification = new GroupNoticeUpdateNotification();
        notification.setOperatorUserId(operatorUserId);
        notification.setOldNotice(oldNotice).setNewNotice(newNotice);
        return new ImGroupMessageSendDTO().setGroupId(groupId)
                .setType(ImContentTypeEnum.GROUP_NOTICE_UPDATE.getType()).setContent(notification);
    }
 
    public static ImGroupMessageSendDTO ofGroupNameUpdate(Long groupId, Long operatorUserId, String oldName, String newName) {
        GroupNameUpdateNotification notification = new GroupNameUpdateNotification();
        notification.setOperatorUserId(operatorUserId);
        notification.setOldName(oldName).setNewName(newName);
        return new ImGroupMessageSendDTO().setGroupId(groupId)
                .setType(ImContentTypeEnum.GROUP_NAME_UPDATE.getType()).setContent(notification);
    }
 
    public static ImGroupMessageSendDTO ofGroupMemberSettingUpdate(Long groupId, Long operatorUserId, Boolean silent, String groupRemark) {
        GroupMemberSettingUpdateNotification notification = new GroupMemberSettingUpdateNotification();
        notification.setOperatorUserId(operatorUserId);
        notification.setSilent(silent).setGroupRemark(groupRemark);
        return new ImGroupMessageSendDTO().setGroupId(groupId)
                .setType(ImContentTypeEnum.GROUP_MEMBER_SETTING_UPDATE.getType()).setContent(notification);
    }
 
    public static ImGroupMessageSendDTO ofGroupMessagePin(Long groupId, Long operatorUserId, ImGroupMessageDO message) {
        GroupMessagePinNotification notification = new GroupMessagePinNotification();
        GroupMessagePinNotification.PinnedMessage pinnedMessage = new GroupMessagePinNotification.PinnedMessage()
                .setId(message.getId()).setSenderId(message.getSenderId()).setGroupId(message.getGroupId())
                .setType(message.getType()).setContent(message.getContent()).setSendTime(message.getSendTime())
                .setAtUserIds(message.getAtUserIds()).setReceiverUserIds(message.getReceiverUserIds());
        notification.setOperatorUserId(operatorUserId);
        notification.setMessageId(message.getId()).setMessage(pinnedMessage);
        return new ImGroupMessageSendDTO().setGroupId(groupId)
                .setType(ImContentTypeEnum.GROUP_MESSAGE_PIN.getType()).setContent(notification);
    }
 
    public static ImGroupMessageSendDTO ofGroupMessageUnpin(Long groupId, Long operatorUserId, Long messageId) {
        GroupMessageUnpinNotification notification = new GroupMessageUnpinNotification();
        notification.setOperatorUserId(operatorUserId);
        notification.setMessageId(messageId);
        return new ImGroupMessageSendDTO().setGroupId(groupId)
                .setType(ImContentTypeEnum.GROUP_MESSAGE_UNPIN.getType()).setContent(notification);
    }
 
    public static ImGroupMessageSendDTO ofGroupMemberMuted(Long groupId, Long operatorUserId,
                                                            Long mutedUserId,
                                                            java.time.LocalDateTime muteEndTime) {
        GroupMemberMutedNotification notification = new GroupMemberMutedNotification();
        notification.setOperatorUserId(operatorUserId);
        notification.setMutedUserId(mutedUserId);
        notification.setMuteEndTime(muteEndTime);
        return new ImGroupMessageSendDTO().setGroupId(groupId)
                .setType(ImContentTypeEnum.GROUP_MEMBER_MUTED.getType()).setContent(notification);
    }
 
    public static ImGroupMessageSendDTO ofGroupMemberCancelMuted(Long groupId, Long operatorUserId, Long mutedUserId) {
        GroupMemberCancelMutedNotification notification = new GroupMemberCancelMutedNotification();
        notification.setOperatorUserId(operatorUserId);
        notification.setMutedUserId(mutedUserId);
        return new ImGroupMessageSendDTO().setGroupId(groupId)
                .setType(ImContentTypeEnum.GROUP_MEMBER_CANCEL_MUTED.getType()).setContent(notification);
    }
 
    public static ImGroupMessageSendDTO ofGroupMuted(Long groupId, Long operatorUserId) {
        GroupMutedNotification notification = new GroupMutedNotification();
        notification.setOperatorUserId(operatorUserId);
        return new ImGroupMessageSendDTO().setGroupId(groupId)
                .setType(ImContentTypeEnum.GROUP_MUTED.getType()).setContent(notification);
    }
 
    public static ImGroupMessageSendDTO ofGroupCancelMuted(Long groupId, Long operatorUserId) {
        GroupCancelMutedNotification notification = new GroupCancelMutedNotification();
        notification.setOperatorUserId(operatorUserId);
        return new ImGroupMessageSendDTO().setGroupId(groupId)
                .setType(ImContentTypeEnum.GROUP_CANCEL_MUTED.getType()).setContent(notification);
    }
 
    public static ImGroupMessageSendDTO ofGroupBanned(Long groupId, Long operatorUserId, boolean banned) {
        GroupBannedNotification notification = new GroupBannedNotification();
        notification.setOperatorUserId(operatorUserId);
        notification.setBanned(banned);
        return new ImGroupMessageSendDTO().setGroupId(groupId)
                .setType(ImContentTypeEnum.GROUP_BANNED.getType()).setContent(notification);
    }
 
}