Commit 347fc415 by Li Feifei

add appkey field

parent 6a8be980
......@@ -40,6 +40,7 @@ type ImChatRoomUser struct {
type ImUserRelationship struct {
Id int
Accid string
Appkey string
Faccid string
Type int
Msg string
......@@ -67,6 +68,7 @@ type ImUser struct {
type ImFriendRequest struct {
Id int
Accid string
Appkey string
Faccid string
Status int64
Createtime string
......
......@@ -13,6 +13,7 @@ var (
field_accid = "accid"
field_faccid = "faccid"
field_status = "status"
field_key = "appkey"
field_updatetime = "updatetime"
)
......@@ -29,10 +30,11 @@ func All(accid string) ([]db.ImFriendRequest, error){
return list, err
}
func FindExits(accid, faccid string) bool {
func FindExits(accid, faccid, key string) bool {
return db.MysqlClient.QueryTable(table_name).
Filter(field_accid, accid).
Filter(field_faccid, faccid).
Filter(field_key, key).
Filter(field_status,field_status_wait).Exist()
}
......@@ -46,6 +48,7 @@ func AddRecord(in *pb.ImFriendAddReq) error {
db_friend.Status = field_status_wait
db_friend.Createtime = now
db_friend.Updatetime = now
db_friend.Appkey = in.Common.Appkey
_, err := db.MysqlClient.Insert(&db_friend)
return err
}
......
......@@ -61,17 +61,17 @@ func (fs *ImFriendService) Add (ctx context.Context,in *pb.ImFriendAddReq) (repl
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, "已经添加过该好友")
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, "已经添加过该好友")
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, "已经提交过申请")
return
}
......
......@@ -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).
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).
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 {
us.Blacklist = open
us.Mute = open
us.Createtime = now
us.Appkey = in.Common.Appkey
_, 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.Faccid = in.Accid
......@@ -67,6 +68,7 @@ func AddUserRelationship(in *pb.UserRelationshipAddRequest) error {
ts.Blacklist = open
ts.Mute = open
ts.Createtime = now
ts.Appkey = in.Common.Appkey
_, err1 := db.MysqlClient.Insert(&ts)
if err1 != nil {
return status.Error(codes.Internal, err.Error())
......@@ -106,7 +108,7 @@ func DBAll(in *pb.UserRelationshipListRequest) ([]db.ImUserRelationship, 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("被操作用户不是该用户好友")
}
orm_params := make(orm.Params)
......
......@@ -3,7 +3,7 @@ package im_user_relationship
import (
"context"
"fmt"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
......
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