profiles: online status and friend rework

This commit is contained in:
AdrienLSH
2024-05-07 19:53:28 +02:00
parent c2aafe9a42
commit 17bcee764b
9 changed files with 111 additions and 53 deletions

View File

@ -21,7 +21,14 @@ class NoticeManager:
consumer.send(notice.data)
notice.delete()
for friend in consumer.user.profilemodel.get_friends():
self.notify_user(friend.user, {'type': 'online',
'user': ProfileSerializer(consumer.user.profilemodel).data})
def remove(self, consumer: NoticeConsumer):
for friend in consumer.user.profilemodel.get_friends():
self.notify_user(friend.user, {'type': 'offline',
'user': ProfileSerializer(consumer.user.profilemodel).data})
self._list.remove(consumer)
def get_consumer_by_user(self, user: User):
@ -44,7 +51,16 @@ class NoticeManager:
self.notify_user(user, {'type': 'friend_request_canceled', 'author': ProfileSerializer(friend).data})
def notify_new_friend(self, user: User, friend: ProfileModel):
self.notify_user(user, {'type': 'new_friend', 'friend': ProfileSerializer(friend).data})
serialized_data = ProfileSerializer(friend).data
if self.get_consumer_by_user(user) is not None:
status = 'online'
else:
status = 'offline'
print(status)
self.notify_user(user, {'type': 'new_friend', 'friend': serialized_data})
self.notify_user(user, {'type': 'online', 'user': serialized_data})
self.notify_user(friend.user, {'type': status, 'user': ProfileSerializer(user.profilemodel).data})
def notify_friend_removed(self, user: User, friend: ProfileModel):
self.notify_user(user, {'type': 'friend_removed', 'friend': ProfileSerializer(friend).data})