Chat¶
This feature of the GOG GALAXY SDK allows GOG users to chat with each other independently from the in-game messaging. GOG chat is available on the website (after a user logs in), in the GOG GALAXY client application (when a user clicks a friend on the friends list) and in the overlay, and can be accessed directly by a game using the GOG GALAXY SDK.
Getting Chat Room Info¶
- First, call
IChat::RequestChatRoomWithUser()
, providing the ID of the user you want to start a chat with. (The ID is this user’s GalaxyID). - The response comes to
IChatRoomWithUserRetrieveListener
. If the request was successful, theOnChatRoomWithUserRetrieveSuccess()
method will return the ID of the entered chat room (chatRoomID
), which is essential for theIChat
methods. -
Having this
chatRoomID
, you can:- get the total number of users in this chat room with the
IChat::GetChatRoomMemberCount()
method, - get the ID of a particular user in this chat room with the
IChat::GetChatRoomMemberUserIDByIndex()
method, - get the number of unread messages with the
IChat::GetChatRoomUnreadMessageCount()
method.
- get the total number of users in this chat room with the
Sending Messages¶
- Request the chat room info as described in the steps #1 and #2.
- Call the
IChat::SendChatRoomMessage()
method, giving the chat room ID and the message text as its input parameters. - If the message was sent successfully, the
IChatRoomMessageSendListener::OnChatRoomMessageSendSuccess()
callback method will be called, providing the ID of the chat room along with the internal index, the ID and the timestamp of the sent message, so you can track the sent messages (or indicate that sending is in progress). - The recipients (members of the chat room) will receive a notification about an incoming message using the
IChatRoomMessagesListener::OnChatRoomMessagesReceived()
callback method, which provides the ID of the chat room, the number of messages received in this chat room and the length of the longest message, so you can allocate a buffer of an appropriate size.
Receiving Messages¶
You don’t have to call the IChat::RequestChatRoomWithUser()
explicitly in order to receive new incoming messages. The notification about a new message comes to IChatRoomMessagesListener::OnChatRoomMessagesReceived()
callback method, providing the ID of the chat room, the number of messages received in this chat room and the length of the longest message, so you can allocate a buffer of an appropriate size.
Within the OnChatRoomMessagesReceived()
call, you can retrieve the subsequent messages with the IChat::GetChatRoomMessageByIndex()
method, providing their index number and the size of the output buffer as input parameters. As a result, this method returns:
- the global ID of the message,
- the type of the message,
- the message sender’s ID,
- the time when the message was sent,
- the contents of the message.
When the retrieval is completed, you can mark this chat room as read with the IChat::MarkChatRoomAsRead()
method.
Fetching Historical Messages¶
- Request the chat room info as described in the steps #1 and #2.
- Call the
IChat::RequestChatRoomMessages()
method in order to retrieve:- messages older than the one defined by its ID in the
referenceMessageID
parameter, or - a specific number of latest messages defined by the
limit
parameter (when thereferenceMessageID
parameter is left empty).
- messages older than the one defined by its ID in the
- The response comes to
IChatRoomMessagesRetrieveListener
. If the operation was successful, theOnChatRoomMessagesRetrieveSuccess()
callback method will provide the number of messages received along with the length of the longest message, so you can allocate a buffer of an appropriate size. - Now you can retrieve the subsequent messages with the
IChat::GetChatRoomMessageByIndex()
method, providing their index number and the size of the output buffer as input parameters. As a result, this method returns:- the global ID of the message,
- the type of the message,
- the message sender’s ID,
- the time when the message was sent,
- the contents of the message.
- When the retrieval is completed, you can mark this chat room as read with the
IChat::MarkChatRoomAsRead()
method.