Skip to content

Commit

Permalink
feat: 创建群组逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
showurl committed Jun 22, 2023
1 parent 2b4b466 commit d4b68c3
Show file tree
Hide file tree
Showing 50 changed files with 3,455 additions and 742 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions app/conversation/client/friendservice/friendService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions app/conversation/client/groupservice/groupService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions app/conversation/conversationmodel/conversationmember.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package conversationmodel

import (
"github.com/cherish-chat/xxim-server/common/pb"
"github.com/qiniu/qmgo"
opts "github.com/qiniu/qmgo/options"
"github.com/zeromicro/go-zero/core/stores/redis"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo/options"
)

type ValueType int8
type ConversationType int8
type ConversationType = pb.ConversationType

const (
// ValueTypeString 字符串
Expand Down Expand Up @@ -48,11 +51,11 @@ type ConversationMember struct {
// ConversationType 会话类型
ConversationType ConversationType `json:"conversationType"`
// MemberUserId 群成员ID
MemberUserId int `bson:"memberUserId"`
MemberUserId string `bson:"memberUserId"`
// JoinTime 加入时间
JoinTime int `bson:"joinTime"`
JoinTime primitive.DateTime `bson:"joinTime"`
// JoinSource 加入来源
JoinSource string `bson:"joinSource"`
JoinSource bson.M `bson:"joinSource,omitempty"`
// Settings 群成员设置
Settings []*ConversationSetting ` bson:"settings"`
}
Expand Down
22 changes: 12 additions & 10 deletions app/conversation/groupmodel/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/core/stores/redis"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"gorm.io/gorm"
"os"
)

Expand All @@ -24,24 +24,21 @@ type Group struct {
GroupAvatar string `json:"groupAvatar" gorm:"column:groupAvatar;type:varchar(255);not null" bson:"groupAvatar"`
//GroupInfo 自定义群信息
//如果没有查询需要,不要SELECT这个字段
GroupInfo bson.M `json:"groupInfo" gorm:"column:groupInfo;type:text;not null;" bson:"groupInfo"`
GroupInfo bson.M `json:"groupInfo" gorm:"column:groupInfo;type:text;not null;" bson:"groupInfo,omitempty"`

//OwnerUserId 群主id
OwnerUserId string `json:"ownerUserId" gorm:"column:ownerUserId;type:char(32);not null" bson:"ownerUserId"`
//ManagerUserIds 管理员id列表 逗号分隔
//如果没有查询需要,不要SELECT这个字段,因为这个字段可能会很大,群管理员上限是1900人,因为65535/33=1985.90
ManagerUserIds []string `json:"managerUserIds" gorm:"column:managerUserIds;type:text;not null" bson:"managerUserIds"`
//CreatedAt 创建时间 13位时间戳
CreateTime int64 `json:"createTime" gorm:"column:createTime;type:bigint;not null;index;" bson:"createTime"`
CreateTime primitive.DateTime `json:"createTime" gorm:"column:createTime;type:bigint;not null;index;" bson:"createTime"`
//UpdatedAt 更新时间 13位时间戳
UpdateTime int64 `json:"updateTime" gorm:"column:updateTime;type:bigint;not null" bson:"updateTime"`
UpdateTime primitive.DateTime `json:"updateTime" gorm:"column:updateTime;type:bigint;not null" bson:"updateTime"`
//DismissTime 解散时间 13位时间戳
DismissTime int64 `json:"dismissTime" gorm:"column:dismissTime;type:bigint;not null;default:0;index;" bson:"dismissTime"`
DismissTime primitive.DateTime `json:"dismissTime" gorm:"column:dismissTime;type:bigint;not null;default:0;index;" bson:"dismissTime"`
//MemberCount 成员数量
MemberCount int `json:"memberCount" gorm:"column:memberCount;type:int;not null;default:0;" bson:"memberCount"`

//RemarkForAdmin 管理员设置的备注
RemarkForAdmin string `json:"remarkForAdmin" gorm:"column:remarkForAdmin;type:varchar(32);not null;default:'';" bson:"remarkForAdmin"`
}

// TableName 表名
Expand All @@ -60,6 +57,10 @@ func (m *Group) GetIndexes() []opts.IndexModel {
}}
}

func (m *Group) GroupIdString() string {
return utils.AnyString(m.GroupId)
}

type xGroupModel struct {
coll *qmgo.QmgoClient
rc *redis.Redis
Expand Down Expand Up @@ -104,9 +105,10 @@ func (x *xGroupModel) GenerateGroupId() int {
return int(groupId)
}

func (x *xGroupModel) Insert(ctx context.Context, tx gorm.DB, group *Group) error {
func (x *xGroupModel) Insert(ctx context.Context, group *Group) error {
if group.GroupId == 0 {
group.GroupId = x.GenerateGroupId()
}
return tx.WithContext(ctx).Create(group).Error
_, err := x.coll.InsertOne(ctx, group)
return err
}
86 changes: 86 additions & 0 deletions app/conversation/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,90 @@ type Config struct {
}
Group struct {
MinGroupId int `json:",default=100000"`
//创建时必填名称
RequiredName bool `json:",default=true"`
//创建时必填头像
RequiredAvatar bool `json:",default=true"`
//默认名称规则
DefaultNameRule string `json:",options=byMember|fixed"` // byMember:根据成员名称拼接,fixed:固定名称
//FixedName 固定名称
FixedName string `json:",default=未命名群聊"` // 固定名称 只有DefaultNameRule=fixed时有效
//默认头像规则
DefaultAvatarRule string `json:",options=byName|fixed"` // byName:根据名称生成,fixed:固定头像
//FixedAvatar 固定头像
FixedAvatar string `json:",default=group_avatar.png"` // 固定头像 只有DefaultAvatarRule=fixed时有效
//ByNameAvatarBgColors 根据昵称生成头像的背景颜色 ex: ["#ffffff","#000000"]
ByNameAvatarBgColors []string
//ByNameAvatarFgColors 根据昵称生成头像的字体颜色 ex: ["#ffffff","#000000"]
ByNameAvatarFgColors []string
//一个人能加入的最大群组数量
JoinedMaxCount int `json:",default=500"`
//MaxMemberCount 最大成员数
MaxMemberCount int `json:",default=200000"` // 最大成员数 默认200000
Create struct {
//AllowPlatform 可以接受的platform创建
//const (
// Platform_IOS Platform = 0 // ios
// Platform_ANDROID Platform = 1 // android
// Platform_WEB Platform = 2 // web
// Platform_WINDOWS Platform = 3 // windows
// Platform_MAC Platform = 4 // mac
// Platform_LINUX Platform = 5 // linux
// Platform_Ipad Platform = 6 // ipad
// Platform_AndroidPad Platform = 7 // android pad
//)
AllowPlatform []pb.Platform `json:",optional"`
//AllowRole 允许什么角色创建
//const (
// AccountRoleUser = "user"
// AccountRoleRobot = "robot"
//)
AllowRole []string `json:",optional"`
}
Invite struct {
//AllowPlatform 可以接受的platform邀请
//const (
// Platform_IOS Platform = 0 // ios
// Platform_ANDROID Platform = 1 // android
// Platform_WEB Platform = 2 // web
// Platform_WINDOWS Platform = 3 // windows
// Platform_MAC Platform = 4 // mac
// Platform_LINUX Platform = 5 // linux
// Platform_Ipad Platform = 6 // ipad
// Platform_AndroidPad Platform = 7 // android pad
//)
AllowPlatform []pb.Platform `json:",optional"`
//AllowRole 允许什么角色邀请
//const (
// AccountRoleUser = "user"
// AccountRoleRobot = "robot"
//)
AllowRole []string `json:",optional"`

UserDefaultAllow bool `json:",default=true"` // 用户默认允许邀请
//DefaultWelcomeMessage 默认欢迎消息
DefaultWelcomeMessage string `json:",default=欢迎加入群聊"`
}
Apply struct {
//AllowPlatform 可以接受的platform邀请
//const (
// Platform_IOS Platform = 0 // ios
// Platform_ANDROID Platform = 1 // android
// Platform_WEB Platform = 2 // web
// Platform_WINDOWS Platform = 3 // windows
// Platform_MAC Platform = 4 // mac
// Platform_LINUX Platform = 5 // linux
// Platform_Ipad Platform = 6 // ipad
// Platform_AndroidPad Platform = 7 // android pad
//)
AllowPlatform []pb.Platform `json:",optional"`
//AllowRole 允许什么角色邀请
//const (
// AccountRoleUser = "user"
// AccountRoleRobot = "robot"
//)
AllowRole []string `json:",optional"`
}
}
RpcClientConf struct {
Dispatch zrpc.RpcClientConf
Expand Down Expand Up @@ -54,5 +138,7 @@ type Config struct {
AllowRoleBeApplied []string `json:",optional"`
//MaxFriendCount 最大好友数
MaxFriendCount int64 `json:",default=2000"`
//DefaultSayHello 默认打招呼内容
DefaultSayHello string `json:",default=我通过了你的好友验证请求,现在我们可以开始聊天了"`
}
}
37 changes: 37 additions & 0 deletions app/conversation/internal/logic/friendservice/countFriendLogic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package friendservicelogic

import (
"context"
"go.mongodb.org/mongo-driver/bson"

"github.com/cherish-chat/xxim-server/app/conversation/internal/svc"
"github.com/cherish-chat/xxim-server/common/pb"

"github.com/zeromicro/go-zero/core/logx"
)

type CountFriendLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}

func NewCountFriendLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CountFriendLogic {
return &CountFriendLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}

// CountFriend 统计好友数量
func (l *CountFriendLogic) CountFriend(in *pb.CountFriendReq) (*pb.CountFriendResp, error) {
count, err := l.svcCtx.FriendCollection.Find(l.ctx, bson.M{
"userId": in.Header.UserId,
}).Count()
if err != nil {
l.Errorf("find friend error: %v", err)
return &pb.CountFriendResp{}, err
}
return &pb.CountFriendResp{Count: count}, nil
}
Loading

0 comments on commit d4b68c3

Please sign in to comment.