Returns the amount of unread messages for this user

        :param user:
            A Django :class:`User`

        :return:
            An integer with the amount of unread messages.
174850
def count_unread_messages_for(self, user):
        
        unread_total = self.filter(user=user,
                                   read_at__isnull=True,
                                   deleted_at__isnull=True).count()

        return unread_total
1250696
def new_messages_handler(stream):
    
    # TODO: handle no user found exception
    while True:
        packet = yield from stream.get()
        session_id = packet.get('session_key')
        msg = packet.get('message')
        username_opponent = packet.get('username')
        if session_id and msg and username_opponent:
            user_owner = get_user_from_session(session_id)
            if user_owner:
                user_opponent = get_user_model().objects.get(username=username_opponent)
                dialog = get_dialogs_with_user(user_owner, user_opponent)
                if len(dialog) > 0:
                    # Save the message
                    msg = models.Message.objects.create(
                        dialog=dialog[0],
                        sender=user_owner,
                        text=packet['message'],
                        read=False
                    )
                    packet['created'] = msg.get_formatted_create_datetime()
                    packet['sender_name'] = msg.sender.username
                    packet['message_id'] = msg.id

                    # Send the message
                    connections = []
                    # Find socket of the user which sent the message
                    if (user_owner.username, user_opponent.username) in ws_connections:
                        connections.append(ws_connections[(user_owner.username, user_opponent.username)])
                    # Find socket of the opponent
                    if (user_opponent.username, user_owner.username) in ws_connections:
                        connections.append(ws_connections[(user_opponent.username, user_owner.username)])
                    else:
                        # Find sockets of people who the opponent is talking with
                        opponent_connections = list(filter(lambda x: x[0] == user_opponent.username, ws_connections))
                        opponent_connections_sockets = [ws_connections[i] for i in opponent_connections]
                        connections.extend(opponent_connections_sockets)

                    yield from fanout_message(connections, packet)
                else:
                    pass  # no dialog found
            else:
                pass  # no user_owner
        else:
            pass
100183
public function getReadIds(User $user)
    {
        return Discussion::leftJoin('discussion_user', 'discussion_user.discussion_id', '=', 'discussions.id')
            ->where('discussion_user.user_id', $user->id)
            ->whereColumn('last_read_post_number', '>=', 'last_post_number')
            ->pluck('id')
            ->all();
    }
45356
def _bulk_flag(self, request, queryset, action, done_message):
        
        n_comments = 0
        for comment in queryset:
            action(request, comment)
            n_comments += 1

        msg = ungettext('1 comment was successfully %(action)s.',
                        '%(count)s comments were successfully %(action)s.',
                        n_comments)
        self.message_user(request, msg % {'count': n_comments, 'action': done_message(n_comments)})
627482
public function getUnreadMessagesCount($uid)
	{
		if (!$uid)
		{
			return 0;
		}

		$r = $this->getTableName();
		$m = Message::blank()->getTableName();
		$s = Seen::blank()->getTableName();

		$entries = Message::blank()
			->join($r, $m . '.id', $r . '.mid', 'inner')
			->whereEquals($r . '.uid', $uid)
			->where($r . '.state', '!=', 2)
			->whereRaw($m . ".id NOT IN (SELECT s.mid FROM `" . $s . "` AS s WHERE s.uid=" . $uid . ")");

		return $entries->total();
	}
1109321
def user_deleted(sender, **kwargs):
    
    if kwargs.get('created'):
        write('user_variations', {'variation': 1}, tags={'action': 'created'})
        write('user_count', {'total': User.objects.count()})
312082
public function index(User $user, $unread = false)
    {
        $notifications = [];
        $rows = $user->notifications;
        if ($unread) {
            $rows = $user->unreadNotifications;
        }

        foreach ($rows as $k => $notification) {
            $notifications[] = [
                'id'         => $notification->id,
                'created_at' => $notification->created_at->format('l d F H:i'),
                'type'       => $notification->type,
                'message'    => $notification->data['message'],
                'read_at'    => $notification->read_at,
                'user_id'    => $user->id,
            ];
        }

        return json_response($notifications);
    }
750393
public static int getUnReadCount(final Long _userId)
    {
        int ret = 0;
        if (MessageStatusHolder.CACHE.userID2UnRead.containsKey(_userId)) {
            ret = MessageStatusHolder.CACHE.userID2UnRead.get(_userId);
        }
        return ret;
    }
827296
private int getUnSeenMessageCount() 
   {
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc,"getUnseenMessageCount");
      
      int remain = 0;
      for (int x = nextIndex; x < messages.length; x++)
      {
         if (messages[x] != null) remain++;
      }
      
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc,"getUnseenMessageCount", ""+remain);
      return remain;
   }
1302240
def user(self, user):
        
        if user is None:
            raise ValueError("Invalid value for `user`, must not be `None`")
        if user is not None and len(user) > 1024:
            raise ValueError("Invalid value for `user`, length must be less than or equal to `1024`")

        self._user = user
204991
def get_unread_messages():
    """"""
    mark_seen = request.args.get('mark_seen', True)
    unread_msg = g.driver.get_unread()

    if mark_seen:
        for msg in unread_msg:
            msg.chat.send_seen()

    return jsonify(unread_msg)
843312
def count(cls, user_id):
        
        return cls.query.with_entities(
            cls.user_id).filter_by(user_id=user_id).count()
212299
def get_unread_forums_from_list(self, user, forums):
        
        unread_forums = []

        # A user which is not authenticated will never see a forum as unread
        if not user.is_authenticated:
            return unread_forums

        unread = ForumReadTrack.objects.get_unread_forums_from_list(forums, user)
        unread_forums.extend(unread)

        return unread_forums
853515
def matrix_undirected_unweighted(user):
    
    matrix = matrix_undirected_weighted(user, interaction=None)
    for a, b in combinations(range(len(matrix)), 2):
        if matrix[a][b] is None or matrix[b][a] is None:
            continue

        if matrix[a][b] > 0 and matrix[b][a] > 0:
            matrix[a][b], matrix[b][a] = 1, 1

    return matrix
400635
def unread(thread, user):
    
    return bool(thread.userthread_set.filter(user=user, unread=True))
350410
def get_client_unread_messages_count(self, client_name=None):
        
        client = self._clients.get_with_name(client_name)[0]
        return client.get_messages_count_in_buffer()
1332697
def read_all(self, user=None):
        
        qs = self.unread()
        if user:
            qs = qs.filter(recipient=user)
        qs.update(read=True)