(**** * * This file defines the objs and ops related to the chatting interface. * *) object Chat is components: conv:Conversation* and currentConv:integer and isVisible:boolean; operations: addConveration; description: (* This is the class that govers how the conversations are handled. *); end Chat; object Conversation is components: mess:Message* and un:UserName* and convId:integer and lc:Lecture; operations: addMessage, addUser, displayList; description: (* This is the list that keeps track of all the messages sent in the conversation. *); end Conversation; object Message is components: string and un:UserName; operations: generateMessage, addMessage; description: (* This is the actual message that an user writes in order to send it out to other users. *); end Message; operation addConversation inputs: chat:Chat, conv:Conversation; outputs: chat':Chat; precondition: ; postcondition: (* * The conversation is added to the conversation list. *) (exists(c in chat'.conv) c = conv) and (* * The new conversation is set as the current conversation. *) (chat'.currentConv = conv.convId); description: (* Adds a new Conversation to the Conversation* that Chat contains, and makes it the current conversation. *); end addConversation; operation addMessage inputs: mess:Message, conv:Conversation; outputs: conv':Conversation; precondition: ; postcondition: (* * The message is added to the coversation. *) (exists(m in conv'.mess) m = mess); description: (* The operation adds this Message to the end of the Conversation specified by the pointer. *); end addMessage; operation addUser inputs: un:UserName, conv: Conversation, chat:Chat; outputs: conv':Conversation; precondition: ; postcondition: (* * If the conversation doesnt belong to chat, then a new * conversation is added. *) (if( not(conv in chat.conv)) then (conv in chat.conv)) and (* * The user is added to the conversation. *) (exists(u in conv'.un) u = un); description: (* This operation will add an user to the desired conversation. Post-condition creates a conversation if there are none. *); end addUser; operation deleteUser inputs: un:UserName, conv:Conversation, chat:Chat; outputs: conv':Conversation; precondition: (* * The conversation belongs to the chat. *) conv in chat.conv; postcondition: (* * Only the usernames already in the conversation and different * and different from the one to be erased belong in the conversation. *) (forall (un':UserName) (un' in conv'.un) iff ((un' != un) and (un' in conv.un))) and (* * If the number of users in the conversation previous to the deletion * is one, then the conversation is erased. *) (if(#(conv.un)=1) then(not (conv' in chat.conv))); description: (* This operation will delete an user from a conversation. Post-condition deletes conversation if there are no users left. *); end deleteUser; operation selectCurrent inputs: conv:Conversation and chat:Chat; outputs: integer; precondition: (* * The conversation belongs to the chat; *) conv in chat.conv; postcondition: (* * The conversation is set as the current conversation. *) chat.currentConv = conv.convId; description: (* This operation changes the current conversation on display signaled by currentC to the desired conversation pointed to by convId. *); end selectCurrent;