1 import { Component } from 'inferno';
2 import { Subscription } from 'rxjs';
3 import { retryWhen, delay, take } from 'rxjs/operators';
4 import { PrivateMessageForm } from './private-message-form';
5 import { WebSocketService } from '../services';
10 PrivateMessageFormParams,
11 } from '../interfaces';
12 import { toast, wsJsonToRes } from '../utils';
13 import { i18n } from '../i18next';
15 export class CreatePrivateMessage extends Component<any, any> {
16 private subscription: Subscription;
17 constructor(props: any, context: any) {
18 super(props, context);
19 this.handlePrivateMessageCreate = this.handlePrivateMessageCreate.bind(
23 this.subscription = WebSocketService.Instance.subject
24 .pipe(retryWhen(errors => errors.pipe(delay(3000), take(10))))
26 msg => this.parseMessage(msg),
27 err => console.error(err),
28 () => console.log('complete')
31 WebSocketService.Instance.getSite();
34 componentWillUnmount() {
35 this.subscription.unsubscribe();
40 <div class="container">
42 <div class="col-12 col-lg-6 offset-lg-3 mb-4">
43 <h5>{i18n.t('create_private_message')}</h5>
45 onCreate={this.handlePrivateMessageCreate}
54 get params(): PrivateMessageFormParams {
55 let urlParams = new URLSearchParams(this.props.location.search);
56 let params: PrivateMessageFormParams = {
57 recipient_id: Number(urlParams.get('recipient_id')),
63 handlePrivateMessageCreate() {
64 toast(i18n.t('message_sent'));
66 // Navigate to the front
67 this.props.history.push(`/`);
70 parseMessage(msg: WebSocketJsonResponse) {
72 let res = wsJsonToRes(msg);
74 toast(i18n.t(msg.error), 'danger');
76 } else if (res.op == UserOperation.GetSite) {
77 let data = res.data as GetSiteResponse;
78 document.title = `${i18n.t('create_private_message')} - ${