indexing description: "User request friendship use case." author: "Marco Zietzling " date: "$Date$" revision: "$Revision$" class USER_REQUEST_FRIENDSHIP inherit AUTH_USE_CASE O_USER_CONSTANTS O_ERRORS create make feature -- Access namespace: STRING is -- Namespace of this use case. once Result := user_namespace end type: STRING is -- Message type of this use case. once Result := user_request_friendship_type end feature -- Basic operation start (a_msg: O_MESSAGE) is -- Start the use case by a_msg. local l_msg: O_SESSION_MESSAGE do l_msg ?= a_msg check session_message: l_msg /= Void end -- check if the user is authorized and act accordingly is_authorized_for_project (l_msg, "user_add_friendship", 0, auth_node) end feature {NONE} -- Callbacks handle_auth_success (a_msg: O_MESSAGE) is -- a_msg has been authorized, execute it. local l_user_request_friendship_message: O_USER_REQUEST_FRIENDSHIP_MESSAGE l_storage_message: O_USER_REQUEST_FRIENDSHIP_MESSAGE do l_user_request_friendship_message ?= a_msg check valid_message: l_user_request_friendship_message /= Void end -- send message to storage node to insert DB entry and retrieve reply with more information create l_storage_message.make (l_user_request_friendship_message.session, l_user_request_friendship_message.requestee) l_storage_message.set_reply_handler (agent process_storage_reply (?, a_msg)) node.send_message_node (l_storage_message, "storage1") end process_storage_reply (a_msg, an_orig_msg: O_MESSAGE) is -- Process reply from storage node. Reply includes email address. require a_msg_not_void: a_msg /= Void an_orig_msg_not_void: an_orig_msg /= Void local l_user_request_friendship_message: O_USER_REQUEST_FRIENDSHIP_MESSAGE l_storage_reply_message: O_USER_REQUEST_FRIENDSHIP_REPLY_MESSAGE l_mail_message: O_MAIL_MESSAGE l_status_message: O_GENERAL_STATUS_MESSAGE l_requester_name: STRING l_recipient: STRING l_subject: STRING l_text: STRING do l_user_request_friendship_message ?= an_orig_msg check valid_message: l_user_request_friendship_message /= Void end -- storage replies with O_USER_REQUEST_FRIENDSHIP_REPLY_MESSAGE if everything was ok -- or with a O_GENERAL_STATUS_MESSAGE if there was an error l_storage_reply_message ?= a_msg l_status_message ?= a_msg if l_storage_reply_message /= Void then -- correct reply received, continue if l_storage_reply_message.requester_name.is_empty then l_requester_name := l_storage_reply_message.requester_username else l_requester_name := l_storage_reply_message.requester_name + " (" + l_storage_reply_message.requester_username + ")" end l_recipient := l_storage_reply_message.requestee_mail_address l_subject := "[Origo] Friendship Request" l_text := "User " + l_requester_name + " wants to be your friend.%N%N" + "Click on this link to confirm " + l_requester_name + " as your friend:%N" + "http://" + config_parser.get ("origo_domain") + "/confirm_friend/" + l_storage_reply_message.requester_username + "%N%N%N" + "Ignore this message if you don't want to add " + l_requester_name + " as your friend.%N%N%N" + "This friendship request is valid for 14 days." -- generate and send message to mail node to send mail to requestee create l_mail_message.make (l_recipient, l_requester_name, l_subject, l_text) node.send_message_node (l_mail_message, "mail1") -- send reply to api create l_status_message.make (True, Void) node.send_message_reply (l_status_message, an_orig_msg) elseif l_status_message /= Void then -- redirect storage reply to api node.send_message_reply (l_status_message, an_orig_msg) else -- something went completely wrong -> create own status and sent it to api create l_status_message.make (False, err_database_error) node.send_message_reply (l_status_message, an_orig_msg) end end end