sneakpeek 함수 추가
This commit is contained in:
@ -33,6 +33,11 @@ type invitationDoc struct {
|
||||
Blocked bool `bson:"blocked,omitempty" json:"-"` // From은 To에 의해 차단된 상태를 표시
|
||||
}
|
||||
|
||||
type sneakpeekDoc struct {
|
||||
From primitive.ObjectID `bson:"from,omitempty" json:"-"`
|
||||
To primitive.ObjectID `bson:"to,omitempty" json:"-"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
gob.Register([]invitationDoc{})
|
||||
}
|
||||
@ -226,6 +231,36 @@ func (iv *invitation) Trim(ctx wshandler.ApiCallContext) {
|
||||
}
|
||||
}
|
||||
|
||||
func (iv *invitation) SneakPeekTarget(w http.ResponseWriter, r *http.Request) {
|
||||
var ivdoc sneakpeekDoc
|
||||
|
||||
if err := gocommon.MakeDecoder(r).Decode(&ivdoc); err != nil {
|
||||
logger.Println("InviteAsFriend failed:", err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// ivdoc.To가 invdoc.From을 차단했으면 offline으로 표시
|
||||
exists, err := iv.mongoClient.Exists(block_collection_name, bson.M{"_id": combineObjectID(ivdoc.To, ivdoc.From)})
|
||||
if err != nil {
|
||||
logger.Println("InviteAsFriend failed:", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
enc := gocommon.MakeEncoder(w, r)
|
||||
if exists {
|
||||
enc.Encode("offline")
|
||||
} else {
|
||||
exists, _ := iv.redison.Exists(iv.redison.Context(), ivdoc.To.Hex()).Result()
|
||||
if exists == 0 {
|
||||
enc.Encode("offline")
|
||||
} else {
|
||||
enc.Encode("online")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (iv *invitation) InviteAsFriend(w http.ResponseWriter, r *http.Request) {
|
||||
// 내 현재 친구 숫자 + 내가 보낸 초대 숫자가 FriendsMax를 넘을 수 없다.
|
||||
// TODO : 이미 친구면 초대 불가
|
||||
|
||||
Reference in New Issue
Block a user