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

feat: deep link to start private message #206

Merged
merged 1 commit into from
Oct 10, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

frontend_directory: ./js
backend_directory: .
js_package_manager: npm
js_package_manager: yarn
main_git_branch: master

secrets:
Expand Down
1 change: 1 addition & 0 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

(new Extend\Frontend('forum'))
->route('/private', 'byobuPrivate', Content\PrivateDiscussionsPage::class)
->route('/private/composer', 'byobuPrivateComposer')
->css(__DIR__.'/resources/less/forum/extension.less')
->js(__DIR__.'/js/dist/forum.js'),

Expand Down
File renamed without changes.
File renamed without changes.
3,594 changes: 0 additions & 3,594 deletions js/package-lock.json

This file was deleted.

4 changes: 4 additions & 0 deletions js/src/admin/extend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Extend from 'flarum/common/extenders';
import commonExtend from '../common/extend';

export default [...commonExtend];
2 changes: 2 additions & 0 deletions js/src/admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import User from 'flarum/common/models/User';
import addPrivateDiscussionPermission from './addPrivateDiscussionPermission';
import ByobuSettings from './components/ByobuSettingsPage';

export { default as extend } from './extend';

app.initializers.add('fof-byobu', () => {
app.store.models.recipients = User;

Expand Down
3 changes: 3 additions & 0 deletions js/src/common/extend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Extend from 'flarum/common/extenders';

export default [];
71 changes: 71 additions & 0 deletions js/src/forum/components/PrivateComposerPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import app from 'flarum/forum/app';
import Page from 'flarum/common/components/Page';
import type Mithril from 'mithril';
import LogInModal from 'flarum/forum/components/LogInModal';
import PrivateDiscussionComposer from '../pages/discussions/PrivateDiscussionComposer';
import ItemList from 'flarum/common/utils/ItemList';
import Group from 'flarum/common/models/Group';
import User from 'flarum/common/models/User';

export default class PrivateComposerPage extends Page {
oninit(vnode: Mithril.Vnode) {
super.oninit(vnode);

this.configComposer();
}

configComposer() {
if (!app.session.user) {
setTimeout(() => app.modal.show(LogInModal), 500);
return m.route.set('/');
}

const params = m.route.param();
const recipients = new ItemList<User | Group>();

recipients.add(`users:${app.session.user.id()}`, app.session.user);

m.route.set(app.route('byobuPrivate'));

setTimeout(() => {
const composerProps = {
user: app.session.user,
recipients: recipients,
originalContent: null,
};

if (params.content) {
composerProps.originalContent = params.content;
}

if (params.recipientUsers) {
params.recipientUsers.split(',').forEach((u: string) => {
const su = app.store.getById<User>('users', u);
if (!su) return;
recipients.add(`users:${u}`, su);
});
}

if (params.recipientGroups) {
params.recipientGroups.split(',').forEach((g: string) => {
const sg = app.store.getById<Group>('groups', g);
if (!sg) return;
recipients.add(`groups:${g}`, sg);
});
}

app.composer.load(PrivateDiscussionComposer, composerProps);

app.composer.show();

if (params.title) {
// @ts-expect-error
app.composer.fields?.title(params.title);
}
}, 0);
}

view() {
return <div />;
}
}
6 changes: 5 additions & 1 deletion js/src/forum/extend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ import MadePublic from './events/MadePublic';
import RecipientLeft from './events/RecipientLeft';
import RecipientsModified from './events/RecipientsModified';
import PrivateDiscussionsUserPage from './pages/PrivateDiscussionsUserPage';
import commonExtend from '../common/extend';
import PrivateComposerPage from './components/PrivateComposerPage';

export default [
...commonExtend,
new Extend.PostTypes() //
.add('recipientsModified', RecipientsModified)
.add('recipientLeft', RecipientLeft)
.add('madePublic', MadePublic),

new Extend.Routes() //
.add('byobuUserPrivate', '/u/:username/private', PrivateDiscussionsUserPage)
.add('byobuPrivate', '/private', IndexPage),
.add('byobuPrivate', '/private', IndexPage)
.add('byobuComposer', '/private/composer', PrivateComposerPage),

new Extend.Model(Discussion)
.hasMany<User>('recipientUsers')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ export default class PrivateDiscussionComposer extends DiscussionComposer {
}

headerItems() {
let items = super.headerItems();
const items = super.headerItems();

items.remove('tags');
items.remove('polls');

if (app.session.user && app.forum.attribute('canStartPrivateDiscussion')) {
const recipients = this.composer.fields.recipients.toArray();
Expand Down
3 changes: 2 additions & 1 deletion js/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"declarationDir": "./dist-typings",
"baseUrl": ".",
"paths": {
"flarum/*": ["../vendor/flarum/core/js/dist-typings/*"]
"flarum/*": ["../vendor/flarum/core/js/dist-typings/*"],
"@flarum/*": ["../vendor/flarum/core/js/dist-typings/*"],
}
}
}
Expand Down
Loading