-
Notifications
You must be signed in to change notification settings - Fork 382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Put back announcement channel user listing #11518
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can just skip trying to load users if they don't have permission to view it anyway.
Or maybe return
users: []
with the channel if they have no permission to load users andnull
otherwise 🤔 (or both)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll look into that... eventually...
probably not changing existing json fields though.