forked from Hay1tsme/artemis
add implement of GetUserFriendCheckApi and UserFriendRegistApi
This commit is contained in:
@ -58,3 +58,70 @@ class Mai2BuddiesPlus(Mai2Buddies):
|
|||||||
"friendBonusFlag": False
|
"friendBonusFlag": False
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async def handle_get_user_friend_check_api_request(self, data: Dict) -> Dict:
|
||||||
|
user1rivalList = await self.data.profile.get_rivals(data["userId1"])
|
||||||
|
user2rivalList = await self.data.profile.get_rivals(data["userId2"])
|
||||||
|
|
||||||
|
is_user2_in_user1_rivals = any(rival["rival"] == data["userId2"] for rival in user1rivalList)
|
||||||
|
is_user1_in_user2_rivals = any(rival["rival"] == data["userId1"] for rival in user2rivalList)
|
||||||
|
|
||||||
|
if is_user2_in_user1_rivals and is_user1_in_user2_rivals:
|
||||||
|
return {"returnCode": 0}
|
||||||
|
else:
|
||||||
|
return {"returnCode": 1}
|
||||||
|
|
||||||
|
async def handle_user_friend_regist_api_request(self, data: Dict) -> Dict:
|
||||||
|
user1rivalList = await self.data.profile.get_rivals(data["userId1"]) or []
|
||||||
|
user2rivalList = await self.data.profile.get_rivals(data["userId2"]) or []
|
||||||
|
|
||||||
|
is_user2_in_user1_rivals = any(rival["rival"] == data["userId2"] for rival in user1rivalList)
|
||||||
|
is_user1_in_user2_rivals = any(rival["rival"] == data["userId1"] for rival in user2rivalList)
|
||||||
|
user1_show_count = sum(1 for rival in user1rivalList if rival.get("show") == 1)
|
||||||
|
user2_show_count = sum(1 for rival in user2rivalList if rival.get("show") == 1)
|
||||||
|
|
||||||
|
# initialize returnCode
|
||||||
|
returnCode1 = 2
|
||||||
|
returnCode2 = 2
|
||||||
|
|
||||||
|
# Case1 no rival
|
||||||
|
if not is_user2_in_user1_rivals and not is_user1_in_user2_rivals:
|
||||||
|
if user1_show_count >= 3 and user2_show_count >= 3:
|
||||||
|
returnCode1, returnCode2 = 1, 1
|
||||||
|
elif user1_show_count >= 3:
|
||||||
|
returnCode1, returnCode2 = 1, 2
|
||||||
|
elif user2_show_count >= 3:
|
||||||
|
returnCode1, returnCode2 = 2, 1
|
||||||
|
|
||||||
|
# Case2 has single rival
|
||||||
|
elif is_user2_in_user1_rivals != is_user1_in_user2_rivals:
|
||||||
|
if is_user2_in_user1_rivals and not is_user1_in_user2_rivals:
|
||||||
|
if user1_show_count >= 3 and user2_show_count >= 3:
|
||||||
|
returnCode1, returnCode2 = 1, 1
|
||||||
|
elif user1_show_count >= 3:
|
||||||
|
returnCode1, returnCode2 = 1, 2
|
||||||
|
elif user2_show_count >= 3:
|
||||||
|
returnCode1, returnCode2 = 2, 1
|
||||||
|
else:
|
||||||
|
if user1_show_count >= 3 and user2_show_count >= 3:
|
||||||
|
returnCode1, returnCode2 = 1, 1
|
||||||
|
elif user1_show_count >= 3:
|
||||||
|
returnCode1, returnCode2 = 1, 2
|
||||||
|
elif user2_show_count >= 3:
|
||||||
|
returnCode1, returnCode2 = 2, 1
|
||||||
|
|
||||||
|
# execute add_rival and show_rival
|
||||||
|
if not is_user2_in_user1_rivals:
|
||||||
|
await self.data.profile.add_rival(data["userId1"], data["userId2"])
|
||||||
|
if returnCode1 == 2 and user1_show_count < 3:
|
||||||
|
await self.data.profile.set_rival_shown(data["userId1"], data["userId2"], True)
|
||||||
|
|
||||||
|
if not is_user1_in_user2_rivals:
|
||||||
|
await self.data.profile.add_rival(data["userId2"], data["userId1"])
|
||||||
|
if returnCode2 == 2 and user2_show_count < 3:
|
||||||
|
await self.data.profile.set_rival_shown(data["userId2"], data["userId1"], True)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"returnCode1": returnCode1,
|
||||||
|
"returnCode2": returnCode2
|
||||||
|
}
|
Reference in New Issue
Block a user