-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11518 from nanaya/announce-channel-users-load
Put back announcement channel user listing
- Loading branch information
Showing
10 changed files
with
152 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
namespace App\Http\Controllers\Chat\Channels; | ||
|
||
use App\Http\Controllers\Chat\Controller; | ||
use App\Models\Chat\Channel; | ||
use App\Models\Chat\UserChannel; | ||
use App\Models\User; | ||
use App\Transformers\UserCompactTransformer; | ||
|
||
class UsersController extends Controller | ||
{ | ||
public function index($channelId) | ||
{ | ||
$channel = Channel::findOrFail($channelId); | ||
|
||
if (!priv_check('ChatChannelListUsers', $channel)->can()) { | ||
return [ | ||
'users' => [], | ||
...cursor_for_response(null), | ||
]; | ||
} | ||
|
||
$channel = Channel::findOrFail($channelId); | ||
$cursorHelper = UserChannel::makeDbCursorHelper(); | ||
[$userChannels, $hasMore] = $channel | ||
->userChannels() | ||
->select('user_id') | ||
->limit(UserChannel::PER_PAGE) | ||
->cursorSort($cursorHelper, cursor_from_params(\Request::all())) | ||
->getWithHasMore(); | ||
$users = User | ||
::with(UserCompactTransformer::CARD_INCLUDES_PRELOAD) | ||
->find($userChannels->pluck('user_id')); | ||
|
||
return [ | ||
'users' => json_collection( | ||
$users, | ||
new UserCompactTransformer(), | ||
UserCompactTransformer::CARD_INCLUDES, | ||
), | ||
...cursor_for_response($cursorHelper->next($userChannels, $hasMore)), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
import { markAsRead, getChannel, getMessages } from 'chat/chat-api'; | ||
import { markAsRead, getChannel, getChannelUsers, getMessages } from 'chat/chat-api'; | ||
import ChannelJson, { ChannelType, SupportedChannelType, supportedTypeLookup } from 'interfaces/chat/channel-json'; | ||
import MessageJson from 'interfaces/chat/message-json'; | ||
import UserJson from 'interfaces/user-json'; | ||
import { sortBy, throttle } from 'lodash'; | ||
import { action, computed, makeObservable, observable, runInAction } from 'mobx'; | ||
import User, { usernameSortAscending } from 'models/user'; | ||
import User from 'models/user'; | ||
import core from 'osu-core-singleton'; | ||
import Message from './message'; | ||
|
||
|
@@ -29,6 +30,7 @@ function getMinMessageIdFrom(messages: Message[]) { | |
export default class Channel { | ||
private static readonly defaultIcon = '/images/layout/chat/channel-default.png'; // TODO: update with channel-specific icons? | ||
|
||
@observable canListUsers: boolean = false; | ||
@observable canMessageError: string | null = null; | ||
@observable channelId: number; | ||
@observable description?: string; | ||
|
@@ -38,6 +40,7 @@ export default class Channel { | |
@observable lastReadId?: number; | ||
@observable loadingEarlierMessages = false; | ||
@observable loadingMessages = false; | ||
@observable loadUsersXhr: ReturnType<typeof getChannelUsers> | undefined; | ||
@observable messageLengthLimit = maxMessageLength; | ||
@observable name = ''; | ||
needsRefresh = true; | ||
|
@@ -49,21 +52,12 @@ export default class Channel { | |
scrollY: 0, | ||
}; | ||
@observable userIds: number[] = []; | ||
@observable users: null | UserJson[] = null; | ||
@observable usersCursor: null | string = ''; | ||
|
||
private markAsReadLastSent = 0; | ||
@observable private readonly messagesMap = new Map<number | string, Message>(); | ||
private serverLastMessageId?: number; | ||
@observable private usersLoaded = false; | ||
|
||
@computed | ||
get announcementUsers() { | ||
return this.usersLoaded | ||
? this.userIds | ||
.map((userId) => core.dataStore.userStore.get(userId)) | ||
.filter((u): u is User => u != null) | ||
.sort(usernameSortAscending) | ||
: null; | ||
} | ||
|
||
@computed | ||
get canMessage() { | ||
|
@@ -204,10 +198,7 @@ export default class Channel { | |
// nothing to load | ||
if (this.newPmChannel) return; | ||
|
||
if (this.type === 'ANNOUNCE' && !this.usersLoaded) { | ||
this.loadMetadata(); | ||
} | ||
|
||
this.loadUsers(); | ||
this.loadRecentMessages(); | ||
} | ||
|
||
|
@@ -246,11 +237,31 @@ export default class Channel { | |
getChannel(this.channelId).done((json) => { | ||
runInAction(() => { | ||
this.updateWithJson(json); | ||
this.usersLoaded = true; | ||
}); | ||
}); | ||
} | ||
|
||
@action | ||
readonly loadUsers = () => { | ||
if (!this.canListUsers) { | ||
this.users = []; | ||
this.usersCursor = null; | ||
return; | ||
} | ||
|
||
if (this.usersCursor == null || this.loadUsersXhr != null) { | ||
return; | ||
} | ||
|
||
this.loadUsersXhr = getChannelUsers(this.channelId, this.usersCursor) | ||
.done((json) => runInAction(() => { | ||
this.users = [...(this.users ?? []), ...json.users]; | ||
this.usersCursor = json.cursor_string; | ||
})).always(action(() => { | ||
this.loadUsersXhr = undefined; | ||
})); | ||
}; | ||
|
||
@action | ||
moveMarkAsReadMarker() { | ||
this.setLastReadId(this.lastMessageId); | ||
|
@@ -282,6 +293,7 @@ export default class Channel { | |
this.serverLastMessageId = json.last_message_id; | ||
|
||
if (json.current_user_attributes != null) { | ||
this.canListUsers = json.current_user_attributes.can_list_users; | ||
this.canMessageError = json.current_user_attributes.can_message_error; | ||
const lastReadId = json.current_user_attributes.last_read_id ?? 0; | ||
this.setLastReadId(lastReadId); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters