Dev:Chat and Messaging
aMSN Internals Overview: Chat and Messaging
Privates and conferences
We usually use the name private to refer a one-to-one chat, where only the local user and one remote user are involved. We use the word conference for chats where more than two people are involved.
SBs and chatids
Every chat (private or conference) is done through a "SB". A SB (short name for SwitchBoard) is a connection to a SwitchBoard server, where messages are sent to, and where messages come from. All communications are done through this server.
Due to the dinamic nature of instant messaging, there can be cases where there's more than one SB for the same chat. For example, you can create a chat and SB connection, and at the same time the remote user is doing exactly the same, so you'll have crossed invitations.
AMSN tries to manage this correctly, and will keep a list of SB connections associated to every chat. When a message arrives from a SB connection, that SB will be moved to first position in the list. When sending messages, they'll be sent to the first SB in the list. When a SB connection is closed, it will be removed from that list, unless it's the Preferred SB, that is, the first in the list. So, if there's only one SB associated to that chat, it will be kept even if the connection is closed (until we close the conversation window. Then the list is cleared).
So, every chat has a list of associated SBs, and this list is carefully managed. Every chat has also a name. Only the protocol layer knows about SBs, so there has to be a way for the GUI layer and the protocol layer to communicate and associate chat connections with chat windows. The common identifier for a chat is called __chatid__.
Usually (but this could change in the future), the chatid for a private chat is the same as the login of the person you're chatting to. For example, if you have a chat with firstname.lastname@example.org, the chatid for that chat will be email@example.com. When the GUI layer has to tell the Protocol layer about a chat, it will use the chatid, and viceversa. So, the GUI layer knows nothing about SBs.
When we have a private chat, and someone is invited, this private becomes a conferences. Then, the protocolo layer will ask the GUI layer to change the name of the chatid:
The SB is always the same in a conference (in a single chat there can be more than one SB, because there can be crossed invitations, and things like that, but in a conference there's only one SB, let's call it __sb_99__). About the chatid... when there's a private chat (one-to-one), and someone invites a new person into the chat, the chatid will change from firstname.lastname@example.org to sb_99, being sb_99 the name of the sb used for the conference. If more people are invited, the chatid will be kept. When someone leaves, the chatid is kept until eveyone leaves (except one person). In that case, the protocol layer will ask to GUI layer to change the chatid from sb_99 back to email@example.com. If a window for firstname.lastname@example.org does not exist, the change will suceed. If not, the chatid will be kept as sb_99.
The protocol layer will try to change the chatid on every received message, until success.