Ejemplo n.º 1
0
		def friend_invite():
			session = self.get_session(request)
			if not session:
				return 'Fail', 401

			friend = request.args.get('user')
			accept = 'accept' in request.args
			reject = 'reject' in request.args
			if friend:
				if accept and DB.is_friend(session.user, friend):
					DB.accept_invite(session.user, friend)
					return 'OK'
				elif reject and DB.is_friend(session.user, friend):
					DB.reject_invite(session.user, friend)
					return 'OK'
				elif not (accept or reject or DB.is_friend(session.user, friend)):
					DB.invite_friend(session.user, friend)
					return 'OK'
			return 'Fail'
Ejemplo n.º 2
0
	def user_to_json(self, user, session, color=""):
		(uid, u_name, u_avatar) = user
		status = self.get_user_status(u_name)

		if u_avatar is not None and u_avatar != 'None':
			u_avatar = "/static/avatar/{user_name}{file_ext}".format(user_name=u_name, file_ext=u_avatar)
		else:
			u_avatar = "/static_/svg/account-circle%s.svg" % (("_" + color) if color else "")

		c = DB.connect_()
		mutual_friends = list(map(lambda x: x[0], DB.get_mutual_friends(session.uid, uid, c)))
		c.close()

		return {
			'name': u_name,
			'status': status,
			'avatar': u_avatar,
			'mutual_friends': mutual_friends,
			'is_friend': DB.is_friend(session.user, u_name)
		}