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: //邀请加群,直接加入