Exemplo n.º 1
0
 async def request_add_friend(self, event):
     bytes_data = event['protobuf']
     notification_item = Notification.NotificationItem()
     notification_item.ParseFromString(bytes_data)
     request_person = await self.get_myuser(notification_item.fromClientId)
     notification_item.fromClientName = request_person.nickname
     notification_item.fromClientId = request_person.user.id
     notification_item.imageUrl = self.get_user_image_url(request_person)
     notification = Notification.Notification()
     notification.notification_item.extend([notification_item])
     print(notification)
     s = notification.SerializeToString()
     await self.send(bytes_data=s)
Exemplo n.º 2
0
    async def connect(self):
        self.user = self.scope["user"]
        self.room_group_name = self.scope['url_route']['kwargs']['myuser_id']
        await self.channel_layer.group_add(self.room_group_name,
                                           self.channel_name)
        await self.accept()
        wait_for_reply_list = RequestReplyFriend.objects.filter(
            reply_user_id=self.user.myuser.id)

        notification = Notification.Notification()
        list_notification_item = []
        for o in wait_for_reply_list:
            notification_item = Notification.NotificationItem()
            notification_item.type = Notification.NotificationItem.REQUEST_ADD_FRIEND
            notification_item.fromClientId = o.request_user.id
            notification_item.fromClientName = o.request_user.nickname
            from_client = await self.get_myuser(notification_item.fromClientId)
            notification_item.imageUrl = self.get_user_image_url(from_client)
            list_notification_item.append(notification_item)
        notification.notification_item.extend(list_notification_item)
        s = notification.SerializeToString()

        await self.send(bytes_data=s)
Exemplo n.º 3
0
    async def receive(self, bytes_data):
        notification_item = Notification.NotificationItem()
        notification_item.ParseFromString(bytes_data)
        print(notification_item)
        # if the user confirms becoming friends, make them friend in the database
        request_person_id = notification_item.fromClientId
        reply_person_id = notification_item.toClientId
        if notification_item.type == Notification.NotificationItem.AGREE_ADD_FRIEND:
            await self.make_friends(request_person_id, reply_person_id)
            await self.delete_request_from_db(request_person_id,
                                              reply_person_id)
            notification_type = "agree_add_friend"
            group_id = str(request_person_id)

        elif notification_item.type == Notification.NotificationItem.REQUEST_ADD_FRIEND:
            await self.add_request_to_db(request_person_id, reply_person_id)
            notification_type = "request_add_friend"
            group_id = str(reply_person_id)

        elif notification_item.type == Notification.NotificationItem.DISAGREE_ADD_FRIEND:
            await self.delete_request_from_db(request_person_id,
                                              reply_person_id)
            notification_type = "disagree_add_friend"
            group_id = str(request_person_id)

        elif notification_item.type == Notification.NotificationItem.REQUEST_DELETE_FRIEND:
            await self.delete_friends(request_person_id, reply_person_id)
            notification_type = "request_delete_friend"
            group_id = str(reply_person_id)

        elif notification_item.type == Notification.NotificationItem.ADD_TAG:
            await self.add_tag_to_db(request_person_id, reply_person_id,
                                     notification_item.tag)
            notification_type = "add_tag"
            group_id = str(reply_person_id)

        elif notification_item.type == Notification.NotificationItem.ADD_COMMENT:
            is_public = notification_item.isPublic
            is_anonymous = notification_item.isAnonymous
            await self.add_comment_to_db(request_person_id, reply_person_id,
                                         notification_item.text, is_public,
                                         is_anonymous)
            notification_type = "add_comment"
            group_id = str(reply_person_id)

        elif notification_item.type == Notification.NotificationItem.LIKE_COMMENT:
            await self.save_comment(notification_item.commentId,
                                    request_person_id, True)
            notification_type = "like_comment"
            group_id = str(reply_person_id)
        elif notification_item.type == Notification.NotificationItem.DISLIKE_COMMENT:
            await self.save_comment(notification_item.commentId,
                                    request_person_id, False)
            notification_type = "dislike_comment"
            group_id = str(reply_person_id)

        elif notification_item.type == Notification.NotificationItem.CANCEL_LIKE_COMMENT:
            await self.cancel_comment(notification_item.commentId,
                                      request_person_id, True)
            notification_type = "cancel_dislike_comment"
            group_id = str(reply_person_id)
        elif notification_item.type == Notification.NotificationItem.CANCEL_DISLIKE_COMMENT:
            await self.cancel_comment(notification_item.commentId,
                                      request_person_id, False)
            notification_type = "cancel_dislike_comment"
            group_id = str(reply_person_id)
        elif notification_item.type == Notification.NotificationItem.CHANGE_STAR:
            print("aaaa", notification_item)
            await self.change_star_to_db(request_person_id, reply_person_id,
                                         notification_item.star)

            notification_type = "change_star"
            group_id = str(reply_person_id)
            # group send to the reply person group
        await self.channel_layer.group_send(group_id, {
            'type': notification_type,
            'protobuf': bytes_data
        })