48 lines
1.0 KiB
Go
48 lines
1.0 KiB
Go
package friend
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
func (this *apiComp) SearchCheck(session comm.IUserSession, req *pb.FriendSearchReq) (code pb.ErrorCode) {
|
|
if req.NickName == "" {
|
|
code = pb.ErrorCode_FriendSearchNameEmpty
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
//搜索
|
|
func (this *apiComp) Search(session comm.IUserSession, req *pb.FriendSearchReq) (code pb.ErrorCode, data proto.Message) {
|
|
if code = this.SearchCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
resp := &pb.FriendSearchResp{}
|
|
|
|
users, err := this.moduleFriend.ModuleUser.CrossSearchUser(req.NickName)
|
|
if err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
|
|
for _, u := range users {
|
|
resp.Friends = append(resp.Friends, &pb.FriendBase{
|
|
UserId: u.Uid,
|
|
NickName: u.Name,
|
|
Level: u.Lv,
|
|
Avatar: u.Avatar,
|
|
ServerId: u.Sid,
|
|
})
|
|
}
|
|
|
|
if err := session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeSearch, resp); err != nil {
|
|
code = pb.ErrorCode_SystemError
|
|
}
|
|
|
|
return
|
|
}
|