Beispiel #1
0
        public LastFriendTimestampModel RemoveLastTimestamp(string userId)
        {
            LastFriendTimestampModel timestampToRemove = latestTimestampsOrdered.FirstOrDefault(t => t.userId == userId);

            if (timestampToRemove == null)
            {
                return(null);
            }

            latestTimestampsOrdered.Remove(timestampToRemove);

            return(timestampToRemove);
        }
Beispiel #2
0
    private void ChatController_OnAddMessage(ChatMessage message)
    {
        if (message.messageType != ChatMessage.Type.PRIVATE)
        {
            return;
        }

        FriendEntryBase friend = GetEntry(message.sender != UserProfile.GetOwnUserProfile().userId
            ? message.sender
            : message.recipient);

        if (friend == null)
        {
            return;
        }

        bool reorderFriendEntries = false;

        if (friend.userId != lastProcessedFriend)
        {
            lastProcessedFriend  = friend.userId;
            reorderFriendEntries = true;
        }

        LastFriendTimestampModel timestampToUpdate = new LastFriendTimestampModel
        {
            userId = friend.userId,
            lastMessageTimestamp = message.timestamp
        };

        // Each time a private message is received (or sent by the player), we sort the online and offline lists by timestamp
        if (friend.model.status == PresenceStatus.ONLINE)
        {
            onlineFriendsList.AddOrUpdateLastTimestamp(timestampToUpdate, reorderFriendEntries);
        }
        else
        {
            offlineFriendsList.AddOrUpdateLastTimestamp(timestampToUpdate, reorderFriendEntries);
        }

        lastProcessedFriend = friend.userId;
    }
Beispiel #3
0
        public void AddOrUpdateLastTimestamp(LastFriendTimestampModel timestamp, bool reorderFriendEntries = true)
        {
            if (timestamp == null)
            {
                return;
            }

            LastFriendTimestampModel existingTimestamp = latestTimestampsOrdered.FirstOrDefault(t => t.userId == timestamp.userId);

            if (existingTimestamp == null)
            {
                latestTimestampsOrdered.Add(timestamp);
            }
            else if (timestamp.lastMessageTimestamp > existingTimestamp.lastMessageTimestamp)
            {
                existingTimestamp.lastMessageTimestamp = timestamp.lastMessageTimestamp;
            }

            if (reorderFriendEntries)
            {
                latestTimestampsOrdered = latestTimestampsOrdered.OrderByDescending(f => f.lastMessageTimestamp).ToList();
                ReorderingFriendEntries();
            }
        }