コード例 #1
0
 private void addClickListeners()
 {
     btnCreatePri.onClick.AddListener(() => {
         createChatGroup(ChatGroupType.Private);
     });
     btnCreatePub.onClick.AddListener(() => {
         createChatGroup(ChatGroupType.Public);
     });
     btnListGroups.onClick.AddListener(() => {
         BacktoryResponse <ChatGroupsListResponse> response = backtoryApi.RequestListOfChatGroups();
         if (response.Successful)
         {
             writeLine("--+group list returned with json: " + Backtory.ToJson(response.Body, true));
         }
         else
         {
             writeLine("--+group list failed with code: " + response.Code + " and message " + response.Message);
         }
     });
     btnListMembers.onClick.AddListener(() => {
         BacktoryResponse <ChatGroupMembersListResponse> response = backtoryApi.RequestListOfChatGroupMembers(getGroupId());
         if (response.Successful)
         {
             writeLine("--+group member list returned with json: " + Backtory.ToJson(response.Body, true));
         }
         else
         {
             writeLine("--+group member list failed with code: " + response.Code + " and message " + response.Message);
         }
     });
     btnAddMember.onClick.AddListener(() => {
         BacktoryResponse <BacktoryVoid> response = backtoryApi.AddMemberToChatGroup(getGroupId(), getUserId());
         if (response.Successful)
         {
             writeLine("--+member added");
         }
         else
         {
             writeLine("--+member adding failed with code: " + response.Code + " and message " + response.Message);
         }
     });
     btnRemoveMember.onClick.AddListener(() => {
         BacktoryResponse <BacktoryVoid> response = backtoryApi.RemoveMemberFromChatGroup(getGroupId(), getUserId());
         if (response.Successful)
         {
             writeLine("--+member removed");
         }
         else
         {
             writeLine("--+member removing failed with code: " + response.Code + " and message " + response.Message);
         }
     });
     btnAddOwner.onClick.AddListener(() => {
         BacktoryResponse <BacktoryVoid> response = backtoryApi.AddOwnerToChatGroup(getGroupId(), getUserId());
         if (response.Successful)
         {
             writeLine("--+owner added");
         }
         else
         {
             writeLine("--+owner adding failed with code: " + response.Code + " and message " + response.Message);
         }
     });
     btnGroupChat.onClick.AddListener(() => {
         BacktoryResponse <BacktoryVoid> response = backtoryApi.SendChatToGroup(getGroupId(), getMessage());
         if (response.Successful)
         {
             writeLine("--+group chat sent");
         }
         else
         {
             writeLine("--+group chat sending failed with code: " + response.Code + " and message " + response.Message);
         }
     });
     btnDirectChat.onClick.AddListener(() => {
         BacktoryResponse <BacktoryVoid> response = backtoryApi.SendChatToUser(getUserId(), getMessage());
         if (response.Successful)
         {
             writeLine("--+direct chat sent");
         }
         else
         {
             writeLine("--+direct chat sending failed with code: " + response.Code + " and message " + response.Message);
         }
     });
     btnJoin.onClick.AddListener(() => {
         string groupId = getGroupId();
         BacktoryResponse <BacktoryVoid> response = backtoryApi.JoinChatGroup(groupId);
         if (response.Successful)
         {
             writeLine("--+you joined to group with id " + groupId);
         }
         else
         {
             writeLine("--+group creation failed with code: " + response.Code + " and message " + response.Message);
         }
     });
     btnLeave.onClick.AddListener(() => {
         BacktoryResponse <BacktoryVoid> response = backtoryApi.LeaveChatGroup(getGroupId());
         if (response.Successful)
         {
             writeLine("--+you left chat group");
         }
         else
         {
             writeLine("--+group leaving failed with code: " + response.Code + " and message " + response.Message);
         }
     });
     btnInvite.onClick.AddListener(() => {
         BacktoryResponse <BacktoryVoid> response = backtoryApi.InviteUserToChatGroup(getGroupId(), getUserId());
         if (response.Successful)
         {
             writeLine("--+invitation sent");
         }
         else
         {
             writeLine("--+invitation sending failed with code: " + response.Code + " and message " + response.Message);
         }
     });
     btnOffline.onClick.AddListener(() => {
         BacktoryResponse <OfflineMessageResponse> response = backtoryApi.RequestOfflineMessages();
         if (response.Successful)
         {
             writeLine("--+offline list: ");
             List <ChatMessage> list = response.Body.ChatMessageList;
             for (int i = 0; i < list.Count; i++)
             {
                 list[i].OnMessageReceived(this);
             }
         }
         else
         {
             writeLine("--+offline request failed with code: " + response.Code + " and message " + response.Message);
         }
     });
     btnGroupHist.onClick.AddListener(() => {
         BacktoryResponse <GroupChatHistoryResponse> response = backtoryApi.RequestGroupChatHistory(getGroupId(), lastGroupDate);
         if (response.Successful)
         {
             writeLine("--+group history");
             List <ChatMessage> list = response.Body.ChatMessageList;
             if (list.Count > 0)
             {
                 lastGroupDate = list[list.Count - 1].Date;
             }
             else
             {
                 lastGroupDate = 0;
             }
             for (int i = 0; i < list.Count; i++)
             {
                 list[i].OnMessageReceived(this);
             }
         }
         else
         {
             writeLine("--+group history request failed with code: " + response.Code + " and message " + response.Message);
         }
     });
     btnDirectHist.onClick.AddListener(() => {
         BacktoryResponse <UserChatHistoryResponse> response = backtoryApi.RequestUserChatHistory(lastDirectDate);
         if (response.Successful)
         {
             writeLine("--+direct history");
             List <ChatMessage> list = response.Body.ChatMessageList;
             if (list.Count > 0)
             {
                 lastDirectDate = list[list.Count - 1].Date;
             }
             else
             {
                 lastDirectDate = 0;
             }
             for (int i = 0; i < list.Count; i++)
             {
                 list[i].OnMessageReceived(this);
             }
         }
         else
         {
             writeLine("--+direct history request failed with code: " + response.Code + " and message " + response.Message);
         }
     });
     btnReturn.onClick.AddListener(() => {
         int previousLevel = PlayerPrefs.GetInt("MainLevel");
         Application.LoadLevel(previousLevel);
     });
 }