/// <summary> /// Updates information about given clan. /// Fails if user has no premissions to update clan information. /// Returns the reference to newly updated clan's <see cref="IApiGroup"/>. /// If <paramref name="isPublic"/> is false, this clan will not be shown during clan search. /// </summary> public static async Task <IApiGroup> UpdateClanInfoAsync(Client client, ISession session, IApiGroup clan, string name, string description, string avatarUrl, bool isPublic) { try { await client.UpdateGroupAsync(session, clan.Id, name, isPublic, description, avatarUrl, null); // Getting list of all clans local user has joined. // In this demo a user can join only one clan at a time, so the first clan should always be the clan we updated. IApiGroupList clanList = await client.ListGroupsAsync(session, name, 1, null); IApiGroup updatedClan = clanList.Groups.First(); if (updatedClan != null && updatedClan.Id == clan.Id) { return(updatedClan); } else { Debug.LogWarning("An error has occured when retrieving updated clan data"); return(null); } } catch (Exception e) { Debug.LogWarning("An exception has occured when updating clan info: " + e); return(null); } }
/// <summary> /// Searches Nakama database in order to find clans containing a keyword in their names. /// The keyword is determined by <see cref="_clanSearchText"/> textfield. /// </summary> private async void SearchClan() { string name = _clanSearchInput.text; IApiGroupList clanList = await ClanManager.ListClansAsync(Client, Session, "%" + name + "%", _clansPerPage, null); if (clanList != null) { OnClanListFound(clanList); } }
/// <summary> /// Returns a list of clans containing given <paramref name="keyword"/> in their name as well as current cursor pointing to the next page. /// Returned list will contain up to <paramref name="perPageLimit"/> entries and can be iterated using <paramref name="cursor"/>. /// Supplying null <paramref name="cursor"/> will return the first page of results, otherwise returned list will depend on where /// the cursor points. /// </summary> public static async Task <IApiGroupList> ListClansAsync(Client client, ISession session, string keyword, int perPageLimit, string cursor) { try { IApiGroupList clanList = await client.ListGroupsAsync(session, keyword, perPageLimit, cursor); return(clanList); } catch (Exception e) { Debug.LogWarning("An exception has occured when listing clans: " + e); return(null); } }
/// <summary> /// Searches Nakama database in order to find clans containing a keyword in their names. /// The keyword is determined by <see cref="_clanSearchText"/> textfield. /// </summary> private async void SearchClan() { string name = _clanSearchInput.text; try { IApiGroupList clanList = await _connection.Client.ListGroupsAsync(_connection.Session, name); OnClanListFound(clanList); } catch (ApiResponseException e) { Debug.LogWarning("An exception has occured when searching clans: " + e); } }
/// <summary> /// Invoked when server returns a list of clans we searched for. /// Parameter <paramref name="cursor"/> is used to iterate through results. /// </summary> private void OnClanListFound(IApiGroupList clans) { // Removing previous results foreach (Transform transform in _clanSearchList) { Destroy(transform.gameObject); } if (clans.Groups.Count() > 0) { // Creating entiries for every clan found foreach (IApiGroup clan in clans.Groups) { Debug.Log("Found clan: " + clan.Name); ClanSearchResult result = Instantiate(_clanSearchResultPrefab, _clanSearchList); result.SetClan(clan, ShowClanDetails); } } else { Debug.Log("No clans found"); } }
/// <summary> /// Invoked when server returns a list of clans we searched for. /// Parameter <paramref name="cursor"/> is used to iterate through results. /// </summary> private void OnClanListFound(IApiGroupList clans) { // Removing previous results foreach (Transform transform in _clanSearchList) { Destroy(transform.gameObject); } if (clans.Groups.Any()) { // Creating entiries for every clan found foreach (IApiGroup clan in clans.Groups) { ClanSearchResult result = Instantiate(_clanSearchResultPrefab, _clanSearchList); result.SetClan(clan, clickedClan => { _state.DisplayedClan = clickedClan; _state.SubMenu = ClanSubMenu.Details; RefreshUI(_state); }); } } }