From 61eb0db82be7d440a9b74028a604ea5e367b2eba Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Tue, 20 Aug 2024 10:50:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AF=B7=E6=B1=82=E5=8A=A0?= =?UTF-8?q?=E5=85=A5=E7=BE=A4=E8=81=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/im.go | 2 +- service/imService.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/dao/im.go b/dao/im.go index b976795..b0c980c 100644 --- a/dao/im.go +++ b/dao/im.go @@ -274,6 +274,6 @@ func FindGroupUsers(group_id int) []GroupUser { func FindGroupByNameLike(groupName string) []Group { var groups []Group - DB.Debug().Where("group_name like ?", "%"+groupName+"%").Find(&groups) + DB.Debug().Where("group_name like ?", "%"+groupName+"%").Limit(20).Find(&groups) return groups } diff --git a/service/imService.go b/service/imService.go index 3eb2f7b..0e5ab18 100644 --- a/service/imService.go +++ b/service/imService.go @@ -66,6 +66,12 @@ func CreateGeneralMessageService(from_id, to_id, msg_type, group_id int, content err, id = dao.CreateGeneralMessage(from_id, to_id, msg_type, 0, group_id, content) case proto.MSG_TYPE_GROUP_ADD: //加入群聊请求 + //判断是否在群里 + groupUser := dao.FindGroupUser(from_id, group_id) + if len(groupUser) > 0 { + return errors.New("已在群里"), 0 + } + err, id = dao.CreateGeneralMessage(from_id, to_id, msg_type, 0, group_id, content) case proto.MSG_TYPE_GROUP_INVI: //邀请加群,直接加入