55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package friend
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
func (this *apiComp) QiecuoCheck(session comm.IUserSession, req *pb.FriendQiecuoReq) (code pb.ErrorCode) {
|
|
if req.TargetUid == "" {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Qiecuo(session comm.IUserSession, req *pb.FriendQiecuoReq) (code pb.ErrorCode, data proto.Message) {
|
|
if code = this.QiecuoCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
//目标是否在线
|
|
if !this.moduleFriend.ModuleUser.IsOnline(req.TargetUid) {
|
|
code = pb.ErrorCode_UserOffline
|
|
return
|
|
}
|
|
|
|
//判断是否已发送切磋请求
|
|
qr := this.moduleFriend.ModelFriendQiecuo.getQiecuo(session.GetUserId())
|
|
if qr == nil {
|
|
code = pb.ErrorCode_FriendQiecuoTimeout
|
|
return
|
|
}
|
|
if qr.Status == 1 { //已发送切磋
|
|
code = pb.ErrorCode_FriendQiecuoRequested
|
|
return
|
|
}
|
|
|
|
//保存切磋请求10s
|
|
this.moduleFriend.ModelFriendQiecuo.updateQiecuoRecord(session.GetUserId(), req.TargetUid, 1)
|
|
|
|
resp := &pb.FriendQiecuoResp{
|
|
TargetUid: req.TargetUid,
|
|
Uid: session.GetUserId(),
|
|
}
|
|
if err := session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeQiecuo, resp); err != nil {
|
|
code = pb.ErrorCode_SystemError
|
|
return
|
|
}
|
|
this.moduleFriend.SendMsgToUser(string(this.moduleFriend.GetType()), "qiecuonotify",
|
|
&pb.FriendQiecuonotifyPush{Uid: session.GetUserId(), NotifyType: 1}, req.TargetUid)
|
|
|
|
return
|
|
}
|