Example #1
0
        private void HandleCommand(IDictionary <string, object> command)
        {
            if (model == null)
            {
                return;
            }

            if (!command.ContainsKey("type"))
            {
                return;
            }

            var commandType = command["type"] as string;

            command = new Dictionary <string, object>(command);

            switch (commandType)
            {
            case "bookmark-add":
            case "bookmark-remove":
            {
                DoApiAction(commandType, command);
                break;
            }

            case "request-send":
            case "friend-remove":
            {
                command.Add("source_name", selectedCharacter);
                command["dest_name"] = command[Constants.Arguments.Character];
                command.Remove(Constants.Arguments.Character);

                DoApiAction(commandType, command);
                if (commandType == "request-send")
                {
                    requestService.UpdateOutgoingRequests();
                }
                break;
            }

            case "request-accept":
            case "request-cancel":
            case "request-deny":
            {
                var character = command.Get(Constants.Arguments.Character);
                command.Remove(Constants.Arguments.Character);

                var id = requestService.GetRequestForCharacter(character);
                if (id == null)
                {
                    events.NewError($"Could not find any friend requests for/from {character}");
                    return;
                }

                command.Add("request_id", id.ToString());
                DoApiAction(commandType, command);

                if (commandType == "request-deny" || commandType == "request-accept")
                {
                    requestService.UpdatePendingRequests();
                }
                else
                {
                    requestService.UpdateOutgoingRequests();
                }
                break;
            }

            default:
                return;
            }
        }