Commit 347fc415 by Li Feifei

add appkey field

parent 6a8be980
...@@ -40,6 +40,7 @@ type ImChatRoomUser struct { ...@@ -40,6 +40,7 @@ type ImChatRoomUser struct {
type ImUserRelationship struct { type ImUserRelationship struct {
Id int Id int
Accid string Accid string
Appkey string
Faccid string Faccid string
Type int Type int
Msg string Msg string
...@@ -67,6 +68,7 @@ type ImUser struct { ...@@ -67,6 +68,7 @@ type ImUser struct {
type ImFriendRequest struct { type ImFriendRequest struct {
Id int Id int
Accid string Accid string
Appkey string
Faccid string Faccid string
Status int64 Status int64
Createtime string Createtime string
......
...@@ -13,6 +13,7 @@ var ( ...@@ -13,6 +13,7 @@ var (
field_accid = "accid" field_accid = "accid"
field_faccid = "faccid" field_faccid = "faccid"
field_status = "status" field_status = "status"
field_key = "appkey"
field_updatetime = "updatetime" field_updatetime = "updatetime"
) )
...@@ -29,10 +30,11 @@ func All(accid string) ([]db.ImFriendRequest, error){ ...@@ -29,10 +30,11 @@ func All(accid string) ([]db.ImFriendRequest, error){
return list, err return list, err
} }
func FindExits(accid, faccid string) bool { func FindExits(accid, faccid, key string) bool {
return db.MysqlClient.QueryTable(table_name). return db.MysqlClient.QueryTable(table_name).
Filter(field_accid, accid). Filter(field_accid, accid).
Filter(field_faccid, faccid). Filter(field_faccid, faccid).
Filter(field_key, key).
Filter(field_status,field_status_wait).Exist() Filter(field_status,field_status_wait).Exist()
} }
...@@ -46,6 +48,7 @@ func AddRecord(in *pb.ImFriendAddReq) error { ...@@ -46,6 +48,7 @@ func AddRecord(in *pb.ImFriendAddReq) error {
db_friend.Status = field_status_wait db_friend.Status = field_status_wait
db_friend.Createtime = now db_friend.Createtime = now
db_friend.Updatetime = now db_friend.Updatetime = now
db_friend.Appkey = in.Common.Appkey
_, err := db.MysqlClient.Insert(&db_friend) _, err := db.MysqlClient.Insert(&db_friend)
return err return err
} }
......
...@@ -61,17 +61,17 @@ func (fs *ImFriendService) Add (ctx context.Context,in *pb.ImFriendAddReq) (repl ...@@ -61,17 +61,17 @@ func (fs *ImFriendService) Add (ctx context.Context,in *pb.ImFriendAddReq) (repl
return return
} }
//是否已经添加过好友 //是否已经添加过好友
if ok := im_user_relationship.IsUserRelationship(in.Accid, in.Faccid); ok { if ok := im_user_relationship.IsUserRelationship(in.Accid, in.Faccid, in.Common.Appkey); ok {
err = status.Error(codes.AlreadyExists, "已经添加过该好友") err = status.Error(codes.AlreadyExists, "已经添加过该好友")
return return
} }
//对方用户黑名单不能添加 //对方用户黑名单不能添加
if ok :=im_user_relationship.IsBlack(in.Accid, in.Faccid); ok { if ok :=im_user_relationship.IsBlack(in.Accid, in.Faccid, in.Common.Appkey); ok {
err = status.Error(codes.AlreadyExists, "已经添加过该好友") err = status.Error(codes.AlreadyExists, "已经添加过该好友")
return return
} }
// 已经提过添加好友申请 // 已经提过添加好友申请
if ok := FindExits(in.Accid, in.Faccid); ok { if ok := FindExits(in.Accid, in.Faccid, in.Common.Appkey); ok {
err = status.Error(codes.AlreadyExists, "已经提交过申请") err = status.Error(codes.AlreadyExists, "已经提交过申请")
return return
} }
......
...@@ -27,15 +27,15 @@ var ( ...@@ -27,15 +27,15 @@ var (
) )
// 是否是好友 // 是否是好友
func IsUserRelationship(accid, faccid string) bool { func IsUserRelationship(accid, faccid,key string) bool {
return db.MysqlClient.QueryTable(db_tabel).Filter(db_field_accid, accid). return db.MysqlClient.QueryTable(db_tabel).Filter(db_field_accid, accid).
Filter(db_field_faccid, faccid).Exist() Filter(db_field_faccid, faccid).Filter("appkey", key).Exist()
} }
//是否是对方黑名单 //是否是对方黑名单
func IsBlack(accid, faccid string) bool { func IsBlack(accid, faccid, key string) bool {
return db.MysqlClient.QueryTable(db_tabel).Filter(db_field_accid, faccid). return db.MysqlClient.QueryTable(db_tabel).Filter(db_field_accid, faccid).
Filter(db_field_faccid, accid).Filter(db_field_blacklist, db_close).Exist() Filter(db_field_faccid, accid).Filter(db_field_blacklist, db_close).Filter("appkey", key).Exist()
} }
...@@ -55,9 +55,10 @@ func AddUserRelationship(in *pb.UserRelationshipAddRequest) error { ...@@ -55,9 +55,10 @@ func AddUserRelationship(in *pb.UserRelationshipAddRequest) error {
us.Blacklist = open us.Blacklist = open
us.Mute = open us.Mute = open
us.Createtime = now us.Createtime = now
us.Appkey = in.Common.Appkey
_, err := db.MysqlClient.Insert(&us) _, err := db.MysqlClient.Insert(&us)
if ok := IsUserRelationship(in.Faccid, in.Accid); !ok { if ok := IsUserRelationship(in.Faccid, in.Accid,in.Common.Appkey); !ok {
// 被添加者 // 被添加者
ts.Accid = in.Faccid ts.Accid = in.Faccid
ts.Faccid = in.Accid ts.Faccid = in.Accid
...@@ -67,6 +68,7 @@ func AddUserRelationship(in *pb.UserRelationshipAddRequest) error { ...@@ -67,6 +68,7 @@ func AddUserRelationship(in *pb.UserRelationshipAddRequest) error {
ts.Blacklist = open ts.Blacklist = open
ts.Mute = open ts.Mute = open
ts.Createtime = now ts.Createtime = now
ts.Appkey = in.Common.Appkey
_, err1 := db.MysqlClient.Insert(&ts) _, err1 := db.MysqlClient.Insert(&ts)
if err1 != nil { if err1 != nil {
return status.Error(codes.Internal, err.Error()) return status.Error(codes.Internal, err.Error())
...@@ -106,7 +108,7 @@ func DBAll(in *pb.UserRelationshipListRequest) ([]db.ImUserRelationship, error) ...@@ -106,7 +108,7 @@ func DBAll(in *pb.UserRelationshipListRequest) ([]db.ImUserRelationship, error)
func SetSpecialRelationDb(in *pb.SetSpecialRelationReq) error { func SetSpecialRelationDb(in *pb.SetSpecialRelationReq) error {
if ok := IsUserRelationship(in.Accid, in.TargetAcc); !ok { if ok := IsUserRelationship(in.Accid, in.TargetAcc, in.Common.Appkey); !ok {
return errors.New("被操作用户不是该用户好友") return errors.New("被操作用户不是该用户好友")
} }
orm_params := make(orm.Params) orm_params := make(orm.Params)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment