Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions Explorer/Assets/DCL/Chat/ChatConversationsToolbarViewItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@
using DCL.UI.ProfileElements;
using DCL.Utilities;
using DG.Tweening;
using System;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace DCL.Chat
{
public class ChatConversationsToolbarViewItem : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
public class ChatConversationsToolbarViewItem : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IDisposable
{
public delegate void OpenButtonClickedDelegate(ChatConversationsToolbarViewItem item);
public delegate void RemoveButtonClickedDelegate(ChatConversationsToolbarViewItem item);
public delegate void TooltipShownDelegate(GameObject tooltip);

[SerializeField]
private ProfilePictureView profilePictureView;

[SerializeField]
protected GameObject thumbnailView;

Expand Down Expand Up @@ -78,17 +79,17 @@ public class ChatConversationsToolbarViewItem : MonoBehaviour, IPointerEnterHand
/// <summary>
/// Raised when the button to select / open the conversation is clicked.
/// </summary>
public event OpenButtonClickedDelegate OpenButtonClicked;
public event OpenButtonClickedDelegate? OpenButtonClicked;

/// <summary>
/// Raised when the button to remove the conversation is clicked.
/// </summary>
public event RemoveButtonClickedDelegate RemoveButtonClicked;
public event RemoveButtonClickedDelegate? RemoveButtonClicked;

/// <summary>
/// Raised when the tooltip of the icon appears.
/// </summary>
public event TooltipShownDelegate TooltipShown;
public event TooltipShownDelegate? TooltipShown;

// Also called by the component in the tooltip
public void OnPointerEnter(PointerEventData eventData)
Expand Down Expand Up @@ -270,5 +271,14 @@ public virtual void BindProfileThumbnail(IReactiveProperty<ProfileThumbnailViewM
profilePictureView.gameObject.SetActive(true);
profilePictureView.Bind(viewModel);
}

public void Dispose()
{
openButton.onClick.RemoveAllListeners();
removeButton.onClick.RemoveAllListeners();
OpenButtonClicked = null;
RemoveButtonClicked = null;
TooltipShown = null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void Release<T>(T item) where T : ChatConversationsToolbarViewItem

private void CreateObjectPool<T>(T prefab) where T: ChatConversationsToolbarViewItem
{
GameObjectPool<T> pool = new (containersRoot, () => GameObject.Instantiate(prefab), onGet: HandleGetObject);
GameObjectPool<T> pool = new (containersRoot, () => GameObject.Instantiate(prefab), onGet: HandleGetObject, onRelease: HandleReleaseObject);
poolRegistry[typeof(T)] = (pool, obj => pool.Release((T)obj));
}

Expand All @@ -44,6 +44,9 @@ private void HandleGetObject<T>(T obj) where T : ChatConversationsToolbarViewIte
obj.transform.localScale = Vector3.one;
}

private void HandleReleaseObject<T>(T obj) where T: ChatConversationsToolbarViewItem =>
obj.Dispose();

public ChatConversationsToolbarViewItemPool(
RectTransform itemsContainer,
ChatConversationsToolbarViewItem nearbyConversationItemPrefab,
Expand Down
6 changes: 3 additions & 3 deletions Explorer/Assets/DCL/Chat/ChatEntryView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private void Awake()

messageBubbleElement.OnPointerEnterEvent += HandlePointerEnter;
messageBubbleElement.OnPointerExitEvent += HandlePointerExit;

messageBubbleElement.messageOptionsButton.onClick.AddListener(() =>
{
if (currentViewModel != null)
Expand Down Expand Up @@ -111,7 +111,7 @@ private string GetDateRepresentation(DateTime date)
else
return date.ToString("ddd, d MMM, yyyy", CultureInfo.InvariantCulture);
}

public void SetItemData(ChatMessageViewModel viewModel,
Action<string, ChatEntryView> onMessageContextMenuClicked,
ChatEntryClickedDelegate? onProfileContextMenuClicked,
Expand Down Expand Up @@ -217,7 +217,7 @@ public void Reset()
if (!isPointerInside)
messageBubbleElement.Reset();
}

private void UpdateTranslationViewVisibility()
{
// Handle universal conditions where the view should ALWAYS be hidden.
Expand Down
2 changes: 1 addition & 1 deletion Explorer/Assets/DCL/Chat/History/ChatMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static ChatMessage CopyWithNewMessage(string newMessage, ChatMessage chat

public static ChatMessage NewFromSystem(string message) =>
new (message, DCL_SYSTEM_SENDER, string.Empty, true,
DCL_SYSTEM_SENDER, DateTime.UtcNow.ToOADate(), false, true);
string.Empty, DateTime.UtcNow.ToOADate(), false, true);

public bool Equals(ChatMessage other) => MessageId == other.MessageId;
public override bool Equals(object? obj) => obj is ChatMessage other && Equals(other);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Cysharp.Threading.Tasks;
using DCL.Chat.ChatCommands;
using DCL.Chat.ControllerShowParams;
using DCL.UI.SharedSpaceManager;
using MVC;
Expand All @@ -21,15 +22,18 @@ public class ChatMainSharedAreaController : ControllerBase<ChatMainSharedAreaVie
private readonly EventSubscriptionScope eventScope = new ();

public event IPanelInSharedSpace.ViewShowingCompleteDelegate? ViewShowingComplete;
public readonly CommandRegistry CommandRegistry;

public bool IsVisibleInSharedSpace { get; private set; }

public ChatMainSharedAreaController(ViewFactoryMethod viewFactory,
IMVCManager mvcManager,
ChatSharedAreaEventBus chatSharedAreaEventBus) : base(viewFactory)
ChatSharedAreaEventBus chatSharedAreaEventBus,
CommandRegistry commandRegistry) : base(viewFactory)
{
this.mvcManager = mvcManager;
this.chatSharedAreaEventBus = chatSharedAreaEventBus;
this.CommandRegistry = commandRegistry;
}

public override CanvasOrdering.SortingLayer Layer => CanvasOrdering.SortingLayer.Persistent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public ChatChannelsPresenter(ChatChannelsView view,
this.chatEventBus.OpenCommunityConversationRequested += OnOpenCommunityConversation;

this.communityDataService.CommunityMetadataUpdated += CommunityChannelMetadataUpdated;

scope.Add(this.eventBus.Subscribe<ChatEvents.ChatResetEvent>(OnChatResetEvent));
scope.Add(this.eventBus.Subscribe<ChatEvents.InitialChannelsLoadedEvent>(OnInitialChannelsLoaded));
scope.Add(this.eventBus.Subscribe<ChatEvents.ChannelUpdatedEvent>(OnChannelUpdated));
Expand Down Expand Up @@ -198,7 +198,8 @@ private void OnChannelAdded(ChatEvents.ChannelAddedEvent evt)

private void OnSystemChannelSelected(ChatEvents.ChannelSelectedEvent evt)
{
view.SelectConversation(evt.Channel.Id);
if (evt.FromInitialization)
view.SelectConversation(evt.Channel.Id);
}

private void OnViewConversationSelected(ChatChannel.ChannelId channelId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using DCL.Diagnostics;
using DCL.Prefs;
using DCL.Web3.Identities;
using System;

namespace DCL.Chat.ChatCommands
{
Expand All @@ -10,6 +11,8 @@ namespace DCL.Chat.ChatCommands
/// </summary>
public class CloseChannelCommand
{
public event Action? ChannelClosed;

private readonly IChatHistory chatHistory;
private readonly IWeb3IdentityCache identityCache;

Expand All @@ -31,6 +34,8 @@ public void Execute(ChatChannel.ChannelId channelId)
AddCommunityToClosedPrefs(channelId.Id);

chatHistory.RemoveChannel(channelId);

ChannelClosed?.Invoke();
}

private void AddCommunityToClosedPrefs(string communityId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private void SetDefaultChannel(ChatChannel nearbyChannel)
{
nearbyUserStateService.Activate();
currentChannelService.SetCurrentChannel(nearbyChannel, nearbyUserStateService);
eventBus.Publish(new ChatEvents.ChannelSelectedEvent { Channel = nearbyChannel });
eventBus.Publish(new ChatEvents.ChannelSelectedEvent { Channel = nearbyChannel, FromInitialization = true} );
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using Cysharp.Threading.Tasks;
using DCL.Chat.ChatServices;
using DCL.Chat.ChatServices;
using DCL.Chat.History;
using DCL.Diagnostics;
using DCL.Utilities.Extensions;
using System.Threading;
using DCL.Chat.EventBus;
using System;
using Utility;

namespace DCL.Chat.ChatCommands
{
public class SelectChannelCommand
{
public event Action<bool>? ChannelOpened;

private readonly IEventBus eventBus;
private readonly IChatEventBus chatEventBus;
private readonly IChatHistory chatHistory;
Expand Down Expand Up @@ -43,7 +43,10 @@ public SelectChannelCommand(
public void Execute(ChatChannel.ChannelId channelId, CancellationToken ct)
{
if (currentChannelService.CurrentChannelId.Equals(channelId))
{
ChannelOpened?.Invoke(true);
return;
}

if (chatHistory.Channels.TryGetValue(channelId, out ChatChannel? channel))
{
Expand Down Expand Up @@ -73,6 +76,7 @@ public void Execute(ChatChannel.ChannelId channelId, CancellationToken ct)
currentChannelService.SetCurrentChannel(channel, userStateService);

eventBus.Publish(new ChatEvents.ChannelSelectedEvent { Channel = channel });
ChannelOpened?.Invoke(false);
}

// If the channel doesn't exist, we simply do nothing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public struct ChannelUpdatedEvent
public struct ChannelSelectedEvent
{
public ChatChannel Channel;
public bool FromInitialization;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Cysharp.Threading.Tasks;
using DCL.AuthenticationScreenFlow;
using DCL.Chat;
using DCL.ChatArea;
using DCL.ExplorePanel;
using DCL.Friends.UI.FriendPanel;
using DCL.InWorldCamera.PhotoDetail;
Expand Down Expand Up @@ -34,6 +35,7 @@ public MVCManagerAnalyticsDecorator(MVCManager core, IAnalyticsController analyt

controllerAnalyticsFactory = new Dictionary<Type, Func<IController, IDisposable>>
{
{ typeof(ChatMainSharedAreaController), CreateAnalytics<ChatMainSharedAreaController>(c => new ChatEventsAnalytics(analytics, c)) },
{ typeof(PhotoDetailController), CreateAnalytics<PhotoDetailController>(c => new PhotoDetailAnalytics(analytics, c)) },
{ typeof(PassportController), CreateAnalytics<PassportController>(c => new PassportAnalytics(analytics, c)) },
{ typeof(AuthenticationScreenController), CreateAnalytics<AuthenticationScreenController>(c => new AuthenticationScreenAnalytics(analytics, c)) },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using DCL.Chat;
using DCL.ChatArea;
using Segment.Serialization;
using System;

Expand All @@ -7,36 +7,30 @@ namespace DCL.PerformanceAndDiagnostics.Analytics.EventBased
public class ChatEventsAnalytics : IDisposable
{
private readonly IAnalyticsController analytics;
private readonly ChatPanelPresenter chatController;
private readonly ChatMainSharedAreaController chatController;

private bool isInitChatBubble = true;

public ChatEventsAnalytics(IAnalyticsController analytics, ChatPanelPresenter chatController)
public ChatEventsAnalytics(IAnalyticsController analytics, ChatMainSharedAreaController chatController)
{
this.analytics = analytics;
this.chatController = chatController;
//TODO: This needs re-implementing
//chatController.ConversationOpened += OnConversationOpened;
//chatController.ConversationClosed += OnConversationClosed;

chatController.CommandRegistry.SelectChannel.ChannelOpened += OnConversationOpened;
chatController.CommandRegistry.CloseChannel.ChannelClosed += OnConversationClosed;
}

public void Dispose()
{
//chatController.ConversationOpened -= OnConversationOpened;
//chatController.ConversationClosed -= OnConversationClosed;
chatController.CommandRegistry.SelectChannel.ChannelOpened -= OnConversationOpened;
chatController.CommandRegistry.CloseChannel.ChannelClosed -= OnConversationClosed;
}

private void OnConversationClosed()
{
private void OnConversationClosed() =>
analytics.Track(AnalyticsEvents.UI.CHAT_CONVERSATION_CLOSED);
}

private void OnConversationOpened(bool wasAlreadyOpen)
{
private void OnConversationOpened(bool wasAlreadyOpen) =>
analytics.Track(AnalyticsEvents.UI.CHAT_CONVERSATION_OPENED, new JsonObject
{
{ "was_already_open", wasAlreadyOpen },
});
}
}
}
3 changes: 2 additions & 1 deletion Explorer/Assets/DCL/PluginSystem/Global/ChatPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@ public async UniTask InitializeAsync(ChatPluginSettings settings, CancellationTo
return view;
},
mvcManager,
chatSharedAreaEventBus
chatSharedAreaEventBus,
commandRegistry
);

chatBusListenerService = new ChatHistoryService(chatMessagesBus,
Expand Down
Loading