public LastFriendTimestampModel RemoveLastTimestamp(string userId) { LastFriendTimestampModel timestampToRemove = latestTimestampsOrdered.FirstOrDefault(t => t.userId == userId); if (timestampToRemove == null) { return(null); } latestTimestampsOrdered.Remove(timestampToRemove); return(timestampToRemove); }
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; }
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(); } }