Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
im-microservice
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Li Feifei
im-microservice
Commits
11320ac5
Commit
11320ac5
authored
Jul 07, 2020
by
李洪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改chat
parent
79dee922
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
117 deletions
+83
-117
im_chat_room_user.db.go
sevice/im_chat_room_user/im_chat_room_user.db.go
+11
-12
im_chat_room_user.go
sevice/im_chat_room_user/im_chat_room_user.go
+39
-77
im_user.go
sevice/im_user/im_user.go
+33
-28
No files found.
sevice/im_chat_room_user/im_chat_room_user.db.go
View file @
11320ac5
...
@@ -14,10 +14,10 @@ const (
...
@@ -14,10 +14,10 @@ const (
cr_table_name
=
"im_chat_room_user"
cr_table_name
=
"im_chat_room_user"
)
)
//查询房间
管理员
//查询房间
创建者
func
GetChatRoomUserOper
(
room_id
int64
,
operator
string
)
(
db
.
ImChatRoomUser
,
error
)
{
func
GetChatRoomUserOper
(
room_id
int64
)
(
db
.
ImChatRoomUser
,
error
)
{
var
r_user
db
.
ImChatRoomUser
var
r_user
db
.
ImChatRoomUser
err
:=
db
.
MysqlClient
.
QueryTable
(
cr_table_name
)
.
Filter
(
"room_id"
,
room_id
)
.
Filter
(
"
operator"
,
operator
)
.
One
(
&
r_user
)
err
:=
db
.
MysqlClient
.
QueryTable
(
cr_table_name
)
.
Filter
(
"room_id"
,
room_id
)
.
Filter
(
"
role"
,
0
)
.
One
(
&
r_user
)
if
err
!=
nil
{
if
err
!=
nil
{
return
r_user
,
err
return
r_user
,
err
}
}
...
@@ -43,7 +43,7 @@ func AddChatRoomUser(room_id int64, accid string, oper bool) (db.ImChatRoomUser,
...
@@ -43,7 +43,7 @@ func AddChatRoomUser(room_id int64, accid string, oper bool) (db.ImChatRoomUser,
r_user
.
Createtime
=
helper
.
GetNowTime
()
r_user
.
Createtime
=
helper
.
GetNowTime
()
if
oper
==
true
{
if
oper
==
true
{
r_user
.
Operator
=
accid
r_user
.
Operator
=
accid
r_user
.
Role
=
1
r_user
.
Role
=
0
}
}
_
,
err
:=
db
.
MysqlClient
.
Insert
(
&
r_user
)
_
,
err
:=
db
.
MysqlClient
.
Insert
(
&
r_user
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -53,18 +53,17 @@ func AddChatRoomUser(room_id int64, accid string, oper bool) (db.ImChatRoomUser,
...
@@ -53,18 +53,17 @@ func AddChatRoomUser(room_id int64, accid string, oper bool) (db.ImChatRoomUser,
}
}
//设置用户
//设置用户
func
SetChatRoomUser
(
room_id
int64
,
accid
string
,
role
int64
)
(
db
.
ImChatRoomUser
,
error
)
{
func
SetChatRoomUser
(
in
*
pb
.
RoomUserSetRoleRequest
)
error
{
var
r_user
db
.
ImChatRoomUser
orm_params
:=
make
(
orm
.
Params
)
orm_params
:=
make
(
orm
.
Params
)
orm_params
[
"role"
]
=
role
orm_params
[
"role"
]
=
in
.
GetRole
()
orm_params
[
"operator"
]
=
in
.
GetOperator
()
orm_params
[
"updatetime"
]
=
helper
.
GetNowTime
()
orm_params
[
"updatetime"
]
=
helper
.
GetNowTime
()
res
,
err
:=
db
.
MysqlClient
.
QueryTable
(
cr_table_name
)
.
Filter
(
"room_id"
,
room_id
)
.
Filter
(
"accid"
,
accid
)
.
Update
(
orm_params
)
res
,
err
:=
db
.
MysqlClient
.
QueryTable
(
cr_table_name
)
.
Filter
(
"room_id"
,
in
.
GetRoomId
())
.
Filter
(
"accid"
,
in
.
GetAccid
()
)
.
Update
(
orm_params
)
if
res
!=
1
{
if
res
!=
1
{
err
=
errors
.
New
(
"
没有查询到任何数据
"
)
err
=
errors
.
New
(
"
修改数据失败
"
)
return
r_user
,
err
return
err
}
}
r_user
,
_
=
GetChatRoomUser
(
room_id
,
accid
)
return
nil
return
r_user
,
nil
}
}
//获取房间用户列表
//获取房间用户列表
...
...
sevice/im_chat_room_user/im_chat_room_user.go
View file @
11320ac5
...
@@ -3,7 +3,8 @@ package im_chat_room_user
...
@@ -3,7 +3,8 @@ package im_chat_room_user
import
(
import
(
"context"
"context"
"im-microservice/db"
"im-microservice/db"
"im-microservice/helper"
//"im-microservice/helper"
"im-microservice/pb"
"im-microservice/pb"
"google.golang.org/grpc/status"
"google.golang.org/grpc/status"
...
@@ -13,43 +14,18 @@ type ChatRoomUserServer struct {
...
@@ -13,43 +14,18 @@ type ChatRoomUserServer struct {
pb
.
UnimplementedChatRoomUserServer
pb
.
UnimplementedChatRoomUserServer
}
}
type
RoomUserOperator
struct
{
//添加创建者
RoomId
int64
`validate:"required"`
Operator
string
`validate:"required"`
}
type
ChatRoomUser
struct
{
RoomId
int64
`validate:"required"`
Accid
string
`validate:"required"`
}
type
ChatRoomUserRole
struct
{
RoomId
int64
`validate:"required"`
Operator
string
`validate:"required"`
Accid
string
`validate:"required"`
Role
int64
`validate:"required,numeric"`
}
//添加管理员
func
(
c
*
ChatRoomUserServer
)
AddOperator
(
ctx
context
.
Context
,
in
*
pb
.
RoomUserAddOpeRequest
)
(
reply
*
pb
.
RoomUserReply
,
err
error
)
{
func
(
c
*
ChatRoomUserServer
)
AddOperator
(
ctx
context
.
Context
,
in
*
pb
.
RoomUserAddOpeRequest
)
(
reply
*
pb
.
RoomUserReply
,
err
error
)
{
roomUserOperator
:=
&
RoomUserOperator
{
RoomId
:
in
.
GetRoomId
(),
Operator
:
in
.
GetOperator
(),
}
//验证参数
if
err
=
helper
.
Valiator
(
roomUserOperator
);
err
!=
nil
{
return
}
//查询房间是否已经添加过了
//查询房间是否已经添加过了
if
r_user
,
_
:=
GetChatRoomUserOper
(
roomUserOperator
.
RoomId
,
roomUserOperator
.
Operator
);
r_user
.
Operator
!=
""
{
if
r_user
,
_
:=
GetChatRoomUserOper
(
in
.
GetRoomId
());
r_user
.
Accid
!=
""
{
err
=
status
.
Error
(
20438
,
"该聊天室已存在管理员"
)
err
=
status
.
Error
(
20438
,
"该聊天室已存在管理员"
)
return
return
}
}
//添加
管理员
//添加
创建者
r_user
,
err
:=
AddChatRoomUser
(
roomUserOperator
.
RoomId
,
roomUserOperator
.
Operator
,
true
)
r_user
,
err
:=
AddChatRoomUser
(
in
.
GetRoomId
(),
in
.
GetOperator
()
,
true
)
if
err
!=
nil
{
if
err
!=
nil
{
err
=
status
.
Error
(
500
,
"添加
管理员
失败"
)
err
=
status
.
Error
(
500
,
"添加
创建者
失败"
)
return
return
}
}
reply
=
&
pb
.
RoomUserReply
{}
reply
=
&
pb
.
RoomUserReply
{}
...
@@ -62,22 +38,14 @@ func (c *ChatRoomUserServer) AddOperator(ctx context.Context, in *pb.RoomUserAdd
...
@@ -62,22 +38,14 @@ func (c *ChatRoomUserServer) AddOperator(ctx context.Context, in *pb.RoomUserAdd
//添加普通用户
//添加普通用户
func
(
c
*
ChatRoomUserServer
)
ChatRoomUserAdd
(
ctx
context
.
Context
,
in
*
pb
.
RoomUserAddRequest
)
(
reply
*
pb
.
RoomUserReply
,
err
error
)
{
func
(
c
*
ChatRoomUserServer
)
ChatRoomUserAdd
(
ctx
context
.
Context
,
in
*
pb
.
RoomUserAddRequest
)
(
reply
*
pb
.
RoomUserReply
,
err
error
)
{
chatRoomUser
:=
&
ChatRoomUser
{
RoomId
:
in
.
GetRoomId
(),
Accid
:
in
.
GetAccid
(),
}
//验证参数
if
err
=
helper
.
Valiator
(
chatRoomUser
);
err
!=
nil
{
return
}
//查询是否已经有了
//查询是否已经有了
if
r_user
,
_
:=
GetChatRoomUser
(
chatRoomUser
.
RoomId
,
chatRoomUser
.
Accid
);
r_user
.
Accid
!=
""
{
if
r_user
,
_
:=
GetChatRoomUser
(
in
.
GetRoomId
(),
in
.
GetAccid
()
);
r_user
.
Accid
!=
""
{
err
=
status
.
Error
(
20438
,
"聊天室已存在该用户"
)
err
=
status
.
Error
(
20438
,
"聊天室已存在该用户"
)
return
return
}
}
//添加用户
//添加用户
r_user
,
err
:=
AddChatRoomUser
(
chatRoomUser
.
RoomId
,
chatRoomUser
.
Accid
,
false
)
r_user
,
err
:=
AddChatRoomUser
(
in
.
GetRoomId
(),
in
.
GetAccid
()
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
err
=
status
.
Error
(
500
,
"聊天室添加用户失败"
)
err
=
status
.
Error
(
500
,
"聊天室添加用户失败"
)
return
return
...
@@ -91,57 +59,55 @@ func (c *ChatRoomUserServer) ChatRoomUserAdd(ctx context.Context, in *pb.RoomUse
...
@@ -91,57 +59,55 @@ func (c *ChatRoomUserServer) ChatRoomUserAdd(ctx context.Context, in *pb.RoomUse
//设置用户角色
//设置用户角色
func
(
c
*
ChatRoomUserServer
)
ChatRoomUserSetRole
(
ctx
context
.
Context
,
in
*
pb
.
RoomUserSetRoleRequest
)
(
reply
*
pb
.
RoomUserReply
,
err
error
)
{
func
(
c
*
ChatRoomUserServer
)
ChatRoomUserSetRole
(
ctx
context
.
Context
,
in
*
pb
.
RoomUserSetRoleRequest
)
(
reply
*
pb
.
RoomUserReply
,
err
error
)
{
setRole
:=
&
ChatRoomUserRole
{
//获取操作者信息
RoomId
:
in
.
GetRoomId
(),
o_user
,
err
:=
GetChatRoomUser
(
in
.
GetRoomId
(),
in
.
GetOperator
())
Operator
:
in
.
GetOperator
(),
Accid
:
in
.
GetAccid
(),
Role
:
in
.
GetRole
(),
}
if
err
=
helper
.
Valiator
(
setRole
);
err
!=
nil
{
return
}
if
setRole
.
Role
>
4
||
setRole
.
Role
<
1
{
err
=
status
.
Error
(
401
,
"聊天权限超出异常"
)
return
}
//查看是否该房间操作者
_
,
err
=
GetChatRoomUserOper
(
setRole
.
RoomId
,
setRole
.
Operator
)
if
err
!=
nil
{
if
err
!=
nil
{
err
=
status
.
Error
(
40
3
,
"不是该聊天室操作者
"
)
err
=
status
.
Error
(
40
4
,
"该操作者不存在
"
)
return
return
}
}
switch
in
.
GetRole
()
{
//设为管理员
case
1
:
if
o_user
.
Role
!=
0
{
err
=
status
.
Error
(
403
,
"不是创建者不能设置管理员"
)
return
}
default
:
if
o_user
.
Role
>
1
{
err
=
status
.
Error
(
403
,
"没有操作权限"
)
return
}
}
//查询该用户是否存在
//查询该用户是否存在
_
,
err
=
GetChatRoomUser
(
setRole
.
RoomId
,
setRole
.
Accid
)
check_u
,
err
:=
GetChatRoomUser
(
in
.
GetRoomId
(),
in
.
GetAccid
()
)
if
err
!=
nil
{
if
err
!=
nil
{
err
=
status
.
Error
(
404
,
"不是该聊天室用户"
)
err
=
status
.
Error
(
404
,
"不是该聊天室用户"
)
return
return
}
}
if
check_u
.
Role
==
in
.
GetRole
()
{
err
=
status
.
Error
(
417
,
"已经是该种角色了,不用重复设置"
)
return
}
//设置权限
//设置权限
r_user
,
err
:=
SetChatRoomUser
(
setRole
.
RoomId
,
setRole
.
Accid
,
setRole
.
Role
)
err
=
SetChatRoomUser
(
in
)
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
reply
=
&
pb
.
RoomUserReply
{}
reply
=
&
pb
.
RoomUserReply
{}
reply
.
RoomId
=
r_user
.
RoomId
reply
.
RoomId
=
check_u
.
RoomId
reply
.
Operator
=
r_user
.
Operator
reply
.
Operator
=
in
.
GetOperator
()
reply
.
Accid
=
r_user
.
Accid
reply
.
Accid
=
check_u
.
Accid
reply
.
Role
=
r_user
.
Role
reply
.
Role
=
in
.
GetRole
()
return
return
}
}
//获取单个用户
//获取单个用户
func
(
c
*
ChatRoomUserServer
)
ChatRoomUserOne
(
ctx
context
.
Context
,
in
*
pb
.
RoomUserOneRequest
)
(
reply
*
pb
.
RoomUserOneReply
,
err
error
)
{
func
(
c
*
ChatRoomUserServer
)
ChatRoomUserOne
(
ctx
context
.
Context
,
in
*
pb
.
RoomUserOneRequest
)
(
reply
*
pb
.
RoomUserOneReply
,
err
error
)
{
chatRoomUser
:=
&
ChatRoomUser
{
c_user
,
err
:=
GetChatRoomUser
(
in
.
GetRoomId
(),
in
.
GetAccid
())
RoomId
:
in
.
GetRoomId
(),
Accid
:
in
.
GetAccid
(),
}
//验证参数
if
err
=
helper
.
Valiator
(
chatRoomUser
);
err
!=
nil
{
return
}
c_user
,
err
:=
GetChatRoomUser
(
chatRoomUser
.
RoomId
,
chatRoomUser
.
Accid
)
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
...
@@ -185,11 +151,7 @@ func (c *ChatRoomUserServer) ChatRoomUserList(ctx context.Context, in *pb.RoomUs
...
@@ -185,11 +151,7 @@ func (c *ChatRoomUserServer) ChatRoomUserList(ctx context.Context, in *pb.RoomUs
//删除
//删除
func
(
c
*
ChatRoomUserServer
)
ChatRoomUserDel
(
ctx
context
.
Context
,
in
*
pb
.
RoomUserOneRequest
)
(
reply
*
pb
.
RoomUserDelReply
,
err
error
)
{
func
(
c
*
ChatRoomUserServer
)
ChatRoomUserDel
(
ctx
context
.
Context
,
in
*
pb
.
RoomUserOneRequest
)
(
reply
*
pb
.
RoomUserDelReply
,
err
error
)
{
delRoomUser
:=
&
ChatRoomUser
{
if
err
=
DelChatRoomUser
(
in
.
GetRoomId
(),
in
.
GetAccid
());
err
!=
nil
{
RoomId
:
in
.
GetRoomId
(),
Accid
:
in
.
GetAccid
(),
}
if
err
=
DelChatRoomUser
(
delRoomUser
.
RoomId
,
delRoomUser
.
Accid
);
err
!=
nil
{
return
return
}
}
reply
=
&
pb
.
RoomUserDelReply
{}
reply
=
&
pb
.
RoomUserDelReply
{}
...
...
sevice/im_user/im_user.go
View file @
11320ac5
...
@@ -38,11 +38,6 @@ func (u *ImUserServer) ImUserRegister(ctx context.Context, in *pb.ImUserRequest)
...
@@ -38,11 +38,6 @@ func (u *ImUserServer) ImUserRegister(ctx context.Context, in *pb.ImUserRequest)
Code
:
in
.
GetCode
(),
Code
:
in
.
GetCode
(),
}
}
// 参数验证是否合法
if
err
=
helper
.
Valiator
(
imUser
);
err
!=
nil
{
return
}
// 从redis获取短信验证码
// 从redis获取短信验证码
cache_code
,
err
:=
helper
.
GetCode
(
imUser
.
Mobile
)
cache_code
,
err
:=
helper
.
GetCode
(
imUser
.
Mobile
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -78,22 +73,17 @@ func (u *ImUserServer) ImUserLogin(ctx context.Context, in *pb.ImUserRequest) (r
...
@@ -78,22 +73,17 @@ func (u *ImUserServer) ImUserLogin(ctx context.Context, in *pb.ImUserRequest) (r
Platform
:
in
.
GetPlatform
(),
Platform
:
in
.
GetPlatform
(),
}
}
// // 参数验证是否合法
// 从redis获取短信验证码
// if err = helper.Valiator(imUser); err != nil {
cache_code
,
err
:=
helper
.
GetCode
(
imUser
.
Mobile
)
// return
if
err
!=
nil
{
// }
return
}
// // 从redis获取短信验证码
// cache_code, err := helper.GetCode(imUser.Mobile)
// if err != nil {
// return
// }
//
//
对比验证码
//对比验证码
//
if cache_code != imUser.Code {
if
cache_code
!=
imUser
.
Code
{
//
err = status.Error(302, "验证码不匹配")
err
=
status
.
Error
(
302
,
"验证码不匹配"
)
//
return
return
//
}
}
reply
=
&
pb
.
ImUserReply
{}
reply
=
&
pb
.
ImUserReply
{}
c_user
,
_
:=
GetImUserByMobile
(
imUser
.
Mobile
)
c_user
,
_
:=
GetImUserByMobile
(
imUser
.
Mobile
)
if
c_user
.
Accid
==
""
{
if
c_user
.
Accid
==
""
{
...
@@ -117,10 +107,6 @@ func (u *ImUserServer) ImUserLoginOut(ctx context.Context, in *pb.ImUserOutReque
...
@@ -117,10 +107,6 @@ func (u *ImUserServer) ImUserLoginOut(ctx context.Context, in *pb.ImUserOutReque
Accid
:
in
.
GetAccid
(),
Accid
:
in
.
GetAccid
(),
Platform
:
in
.
GetPlatform
(),
Platform
:
in
.
GetPlatform
(),
}
}
// 参数验证是否合法
if
err
=
helper
.
Valiator
(
imUserOut
);
err
!=
nil
{
return
}
reply
=
&
pb
.
ImUserSetReply
{}
reply
=
&
pb
.
ImUserSetReply
{}
c_user
,
_
:=
GetImUserByAccid
(
imUserOut
.
Accid
)
c_user
,
_
:=
GetImUserByAccid
(
imUserOut
.
Accid
)
...
@@ -141,6 +127,17 @@ func (u *ImUserServer) ImUserForbiddenWords(ctx context.Context, in *pb.ImUserSe
...
@@ -141,6 +127,17 @@ func (u *ImUserServer) ImUserForbiddenWords(ctx context.Context, in *pb.ImUserSe
if
in
.
GetMute
()
==
true
{
if
in
.
GetMute
()
==
true
{
mute
=
1
mute
=
1
}
}
//检测该用户
c_user
,
err
:=
GetImUserByAccid
(
in
.
GetAccid
())
if
err
!=
nil
{
err
=
status
.
Error
(
404
,
"该用户不存在"
)
return
}
if
c_user
.
MuteEstoppel
==
mute
{
err
=
status
.
Error
(
417
,
"请勿重复操作"
)
return
}
m
:=
make
(
map
[
string
]
interface
{})
m
:=
make
(
map
[
string
]
interface
{})
m
[
"mute_estoppel"
]
=
mute
m
[
"mute_estoppel"
]
=
mute
if
res
,
_
:=
UpdateImUser
(
in
.
GetAccid
(),
m
);
res
!=
1
{
if
res
,
_
:=
UpdateImUser
(
in
.
GetAccid
(),
m
);
res
!=
1
{
...
@@ -157,6 +154,17 @@ func (u *ImUserServer) ImUserForbiddenAV(ctx context.Context, in *pb.ImUserSetRe
...
@@ -157,6 +154,17 @@ func (u *ImUserServer) ImUserForbiddenAV(ctx context.Context, in *pb.ImUserSetRe
if
in
.
GetMute
()
==
true
{
if
in
.
GetMute
()
==
true
{
mute
=
1
mute
=
1
}
}
//检测该用户
c_user
,
err
:=
GetImUserByAccid
(
in
.
GetAccid
())
if
err
!=
nil
{
err
=
status
.
Error
(
404
,
"该用户不存在"
)
return
}
if
c_user
.
MuteAudioVideo
==
mute
{
err
=
status
.
Error
(
417
,
"请勿重复操作"
)
return
}
m
:=
make
(
map
[
string
]
interface
{})
m
:=
make
(
map
[
string
]
interface
{})
m
[
"mute_audio_video"
]
=
mute
m
[
"mute_audio_video"
]
=
mute
if
res
,
_
:=
UpdateImUser
(
in
.
GetAccid
(),
m
);
res
!=
1
{
if
res
,
_
:=
UpdateImUser
(
in
.
GetAccid
(),
m
);
res
!=
1
{
...
@@ -173,10 +181,7 @@ func (u *ImUserServer) ImUserOne(ctx context.Context, in *pb.ImUserOneRequest) (
...
@@ -173,10 +181,7 @@ func (u *ImUserServer) ImUserOne(ctx context.Context, in *pb.ImUserOneRequest) (
imUserId
:=
&
ImUserQ
{
imUserId
:=
&
ImUserQ
{
Accid
:
in
.
GetAccid
(),
Accid
:
in
.
GetAccid
(),
}
}
// 参数验证是否合法
if
err
=
helper
.
Valiator
(
imUserId
);
err
!=
nil
{
return
}
reply
=
&
pb
.
ImUserOneReply
{}
reply
=
&
pb
.
ImUserOneReply
{}
c_user
,
err
:=
GetImUserByAccid
(
imUserId
.
Accid
)
c_user
,
err
:=
GetImUserByAccid
(
imUserId
.
Accid
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment