Browse Source

feat: set room by you self

master
hole-thu 3 years ago
parent
commit
7fb201d742
  1. 56
      src/Config.js
  2. 5
      src/Flows.js
  3. 2
      src/Title.js
  4. 4
      src/UserAction.js
  5. 4
      src/flows_api.js

56
src/Config.js

@ -32,6 +32,7 @@ const DEFAULT_CONFIG = {
block_cw: ['xxg', 'zzxg'], block_cw: ['xxg', 'zzxg'],
block_words_v4: ['🕷', '[系统自动代发]'], block_words_v4: ['🕷', '[系统自动代发]'],
whitelist_cw: [], whitelist_cw: [],
room_id: process.env.REACT_APP_ROOM_ID,
}; };
export function load_config() { export function load_config() {
@ -217,6 +218,57 @@ class ConfigColorScheme extends PureComponent {
} }
} }
class ConfigRoomId extends PureComponent {
constructor(props) {
super(props);
this.state = {
room_id: window.config.room_id,
};
}
save_changes() {
this.props.callback({
room_id: this.state.room_id,
});
}
on_select(e) {
let value = e.target.value;
this.setState(
{
room_id: value,
},
this.save_changes.bind(this),
);
}
render() {
return (
<div>
<p>
<b>分区编号</b>
<select
className="config-select"
value={this.state.room_id}
onChange={this.on_select.bind(this)}
>
<option value="0">0(默认分区)</option>
<option value="1">1(友善分区)</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
&nbsp;<small>#room_id</small>
</p>
<p className="config-description">
选择分区编号会作为发言时的分区和影响查看到的内容
</p>
</div>
);
}
}
class ConfigTextArea extends PureComponent { class ConfigTextArea extends PureComponent {
constructor(props) { constructor(props) {
super(props); super(props);
@ -364,6 +416,8 @@ export class ConfigUI extends PureComponent {
callback={this.save_changes_bound} callback={this.save_changes_bound}
/> />
<hr /> <hr />
<ConfigRoomId id="room-id" callback={this.save_changes_bound} />
<hr />
<ConfigSwitch <ConfigSwitch
callback={this.save_changes_bound} callback={this.save_changes_bound}
id="show_all_rooms" id="show_all_rooms"
@ -375,7 +429,7 @@ export class ConfigUI extends PureComponent {
callback={this.save_changes_bound} callback={this.save_changes_bound}
id="block_tmp" id="block_tmp"
name="屏蔽临时帐号" name="屏蔽临时帐号"
description="屏蔽所有临时帐号的发言" description="屏蔽所有临时帐号的发言,不展示其他分区的情况下强制屏蔽"
/> />
<hr /> <hr />
<ConfigTextArea <ConfigTextArea

5
src/Flows.js

@ -35,7 +35,8 @@ const DZ_NAME = '洞主';
function check_block(info) { function check_block(info) {
return ( return (
((window.config.block_tmp && info.is_tmp) || (((window.config.block_tmp || !window.config.show_all_rooms) &&
info.is_tmp) ||
window.config.block_words_v4.some((word) => info.text.includes(word)) || window.config.block_words_v4.some((word) => info.text.includes(word)) ||
(info.cw && (info.cw &&
window.config.block_words_v4 window.config.block_words_v4
@ -294,7 +295,7 @@ class FlowItem extends PureComponent {
<code className="box-id"> <code className="box-id">
<a href={'##' + info.pid} onClick={this.copy_link.bind(this)}> <a href={'##' + info.pid} onClick={this.copy_link.bind(this)}>
#{info.pid} #{info.pid}
{info.room_id !== parseInt(process.env.REACT_APP_ROOM_ID) && ( {info.room_id !== parseInt(window.config.room_id) && (
<> @{info.room_id}</> <> @{info.room_id}</>
)} )}
</a> </a>

2
src/Title.js

@ -206,7 +206,7 @@ export function Title(props) {
} }
> >
新T树洞 新T树洞
<sup>{process.env.REACT_APP_ROOM_ID || '?'}</sup> <sup>{window.config.room_id || '?'}</sup>
</span> </span>
</p> </p>
</div> </div>

4
src/UserAction.js

@ -588,7 +588,7 @@ export class PostForm extends Component {
text: text, text: text,
allow_search: allow_search ? '1' : '', allow_search: allow_search ? '1' : '',
use_title: use_title ? '1' : '', use_title: use_title ? '1' : '',
room_id: process.env.REACT_APP_ROOM_ID, room_id: window.config.room_id,
}); });
if (has_poll) { if (has_poll) {
poll_options.forEach((opt) => { poll_options.forEach((opt) => {
@ -881,7 +881,7 @@ export class PostForm extends Component {
<a href="/policy.html" target="_blank"> <a href="/policy.html" target="_blank">
树洞管理规范试行 树洞管理规范试行
</a> </a>
文明发言 和所在分区的规定文明发言
</small> </small>
</p> </p>
<p> <p>

4
src/flows_api.js

@ -169,7 +169,7 @@ export const API = {
get_list: async (page, token, submode) => { get_list: async (page, token, submode) => {
let response = await fetch( let response = await fetch(
`${get_api_base()}/getlist?p=${page}&order_mode=${submode}&room_id=${ `${get_api_base()}/getlist?p=${page}&order_mode=${submode}&room_id=${
window.config.show_all_rooms ? '' : process.env.REACT_APP_ROOM_ID window.config.show_all_rooms ? '' : window.config.room_id
}`, }`,
{ {
headers: { 'User-Token': token }, headers: { 'User-Token': token },
@ -181,7 +181,7 @@ export const API = {
get_search: async (page, keyword, token, submode) => { get_search: async (page, keyword, token, submode) => {
let response = await fetch( let response = await fetch(
`${get_api_base()}/search?search_mode=${submode}&page=${page}&room_id=${ `${get_api_base()}/search?search_mode=${submode}&page=${page}&room_id=${
window.config.show_all_rooms ? '' : process.env.REACT_APP_ROOM_ID window.config.show_all_rooms ? '' : window.config.room_id
}&keywords=${encodeURIComponent(keyword)}&pagesize=${SEARCH_PAGESIZE}`, }&keywords=${encodeURIComponent(keyword)}&pagesize=${SEARCH_PAGESIZE}`,
{ {
headers: { 'User-Token': token }, headers: { 'User-Token': token },

Loading…
Cancel
Save