Skip to content
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

Include channel message length limit data #10305

Merged
merged 2 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion app/Models/Chat/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,13 @@ public function isValid()
return $this->validationErrors()->isEmpty();
}

public function messageLengthLimit(): int
{
return $this->isAnnouncement()
? static::ANNOUNCE_MESSAGE_LENGTH_LIMIT
: config('osu.chat.message_length_limit');
}

public function multiplayerMatch()
{
return $this->belongsTo(LegacyMatch::class, 'match_id');
Expand Down Expand Up @@ -430,7 +437,7 @@ public function receiveMessage(User $sender, ?string $content, bool $isAction =
throw new API\ChatMessageEmptyException(osu_trans('api.error.chat.empty'));
}

$maxLength = $this->isAnnouncement() ? static::ANNOUNCE_MESSAGE_LENGTH_LIMIT : config('osu.chat.message_length_limit');
$maxLength = $this->messageLengthLimit();
if (mb_strlen($content, 'UTF-8') > $maxLength) {
throw new API\ChatMessageTooLongException(osu_trans('api.error.chat.too_long'));
}
Expand Down
1 change: 1 addition & 0 deletions app/Transformers/Chat/ChannelTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function transform(Channel $channel)
'channel_id' => $channel->channel_id,
'description' => $channel->description,
'icon' => $channel->displayIconFor($this->user),
'message_length_limit' => $channel->messageLengthLimit(),
'moderated' => $channel->moderated,
'name' => $channel->displayNameFor($this->user),
'type' => $channel->type,
Expand Down
5 changes: 3 additions & 2 deletions resources/js/chat/input-box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import BigButton from 'components/big-button';
import { trim } from 'lodash';
import { action, autorun, computed, makeObservable, reaction } from 'mobx';
import { disposeOnUnmount, observer } from 'mobx-react';
import Message, { maxLength } from 'models/chat/message';
import { maxMessageLength } from 'models/chat/channel';
import Message from 'models/chat/message';
import core from 'osu-core-singleton';
import * as React from 'react';
import TextareaAutosize from 'react-autosize-textarea';
Expand Down Expand Up @@ -112,7 +113,7 @@ export default class InputBox extends React.Component<Props> {
autoComplete='off'
className={classWithModifiers('chat-input__box', { disabled: this.inputDisabled })}
disabled={this.inputDisabled}
maxLength={maxLength}
maxLength={channel?.messageLengthLimit ?? maxMessageLength}
maxRows={channel?.type === 'ANNOUNCE' ? 10 : 3}
name='textbox'
onChange={this.handleChange}
Expand Down
1 change: 1 addition & 0 deletions resources/js/interfaces/chat/channel-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default interface ChannelJson {
description?: string;
icon?: string;
last_message_id?: number;
message_length_limit: number;
name: string;
type: ChannelType;
users?: number[];
Expand Down
4 changes: 4 additions & 0 deletions resources/js/models/chat/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import Message from './message';

const hideableChannelTypes: Set<ChannelType> = new Set(['ANNOUNCE', 'PM']);

export const maxMessageLength = 1024;

export default class Channel {
private static readonly defaultIcon = '/images/layout/chat/channel-default.png'; // TODO: update with channel-specific icons?

Expand All @@ -24,6 +26,7 @@ export default class Channel {
@observable lastReadId?: number;
@observable loadingEarlierMessages = false;
@observable loadingMessages = false;
@observable messageLengthLimit = maxMessageLength;
@observable name = '';
needsRefresh = true;
@observable newPmChannel = false;
Expand Down Expand Up @@ -261,6 +264,7 @@ export default class Channel {
this.description = json.description;
this.type = json.type;
this.icon = json.icon ?? Channel.defaultIcon;
this.messageLengthLimit = json.message_length_limit;
this.userIds = json.users ?? this.userIds;

this.serverLastMessageId = json.last_message_id;
Expand Down
4 changes: 2 additions & 2 deletions resources/js/models/chat/create-announcement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import core from 'osu-core-singleton';
import { onError } from 'utils/ajax';
import { uuid } from 'utils/seq';
import { presence, present } from 'utils/string';
import { maxLength } from './message';
import { maxMessageLength } from './channel';

interface LocalStorageProps extends Record<InputKey, string> {
validUsers: number[];
Expand All @@ -23,7 +23,7 @@ const localStorageKey = 'createAnnouncement';

export const maxLengths = Object.freeze({
description: 255,
message: maxLength,
message: maxMessageLength,
name: 50,
});

Expand Down
2 changes: 0 additions & 2 deletions resources/js/models/chat/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import * as moment from 'moment';
import core from 'osu-core-singleton';
import { uuid } from 'utils/seq';

export const maxLength = 1024;

export default class Message {
@observable channelId = -1;
@observable content = '';
Expand Down