Chat message per sender

edited February 3 in Photon Chat
Hello everyone, I've been using Photon for my studio for like 8 months, subbed to the 100 CCU also. Must say, Photon is really amazing.

Jwoe6RG.png

I have been using Photon Chat as well but in the standard/traditional way just like the tutorial and demo. Now my game is using chat bubbles for displaying chat messages. I can't seem to find any way to create this, because as I see in the docs, PhotonChat Messages are in Dictionary of Dictionary<string, ChatChannel> PublicChannels. What I need is to get separate messages with their respective sender/owner. So I can instantiate the chat bubble according to who is the sender/owner.

Short version, how to get individual message + owner so I can create individual chat bubbles?

Comments

  • JohnTubeJohnTube mod
    edited February 4
    Hi @SPStudio_Satyaloka,

    Thank you for choosing Photon and for your kind words!

    each Photon Chat Channel in the C# SDKs contains the list of received messages as a list and respective list for the senders' UserIDs.
    For per message you can get the content and sender as follows:
    chatChannel.Messages[i]
    chatChannel.Senders[i]
    

    Otherwise you could get the messages from the callbacks:
    IChatClientListener.OnGetMessages()
    
    or
    IChatClientListener.OnPrivateMessage
    
  • Thanks for the reply! I actually did just that lol. Went through the IChatClientListener source to get the hang of how it works and managed to get it to work.

    This is how I did it for anyone who is interested:
    for(int i = 0; i < messages.Length; i++)
            {
                ShowMessage(senders[i], messages[i]);
            }
    
    public void ShowMessage(string sender, object message)
        {
            if(sender != PhotonNetwork.NickName)
            {
                GameObject chatBubble = Instantiate(otherChatBubblePrefab, chatScrollViewContent.transform);
                chatBubble.transform.GetChild(0).gameObject.GetComponent<Text>().text = sender;
                chatBubble.transform.GetChild(1).gameObject.GetComponent<Text>().text = message.ToString();
            }
            else
            {
                GameObject chatBubble = Instantiate(selfChatBubblePrefab, chatScrollViewContent.transform);
                chatBubble.transform.GetChild(0).gameObject.GetComponent<Text>().text = sender;
                chatBubble.transform.GetChild(1).gameObject.GetComponent<Text>().text = message.ToString();
            }
        }
    
Sign In or Register to comment.