summaryrefslogtreecommitdiffstats
path: root/ui/src/components/user.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'ui/src/components/user.tsx')
-rw-r--r--ui/src/components/user.tsx75
1 files changed, 64 insertions, 11 deletions
diff --git a/ui/src/components/user.tsx b/ui/src/components/user.tsx
index 606d85ab..09129d67 100644
--- a/ui/src/components/user.tsx
+++ b/ui/src/components/user.tsx
@@ -18,6 +18,7 @@ import {
BanUserResponse,
AddAdminResponse,
DeleteAccountForm,
+ CreatePostLikeResponse,
WebSocketJsonResponse,
} from '../interfaces';
import { WebSocketService, UserService } from '../services';
@@ -30,6 +31,7 @@ import {
setTheme,
languages,
showAvatars,
+ toast,
} from '../utils';
import { PostListing } from './post-listing';
import { SortSelect } from './sort-select';
@@ -308,7 +310,6 @@ export class User extends Component<any, UserState> {
post={i.data as Post}
admins={this.state.admins}
showCommunity
- viewOnly
/>
) : (
<CommentNodes
@@ -341,12 +342,7 @@ export class User extends Component<any, UserState> {
return (
<div>
{this.state.posts.map(post => (
- <PostListing
- post={post}
- admins={this.state.admins}
- showCommunity
- viewOnly
- />
+ <PostListing post={post} admins={this.state.admins} showCommunity />
))}
</div>
);
@@ -411,13 +407,30 @@ export class User extends Component<any, UserState> {
</tr>
</table>
</div>
- {this.isCurrentUser && (
+ {this.isCurrentUser ? (
<button
class="btn btn-block btn-secondary mt-3"
onClick={linkEvent(this, this.handleLogoutClick)}
>
<T i18nKey="logout">#</T>
</button>
+ ) : (
+ <>
+ <a
+ className={`btn btn-block btn-secondary mt-3 ${!this.state
+ .user.matrix_user_id && 'disabled'}`}
+ target="_blank"
+ href={`https://matrix.to/#/${this.state.user.matrix_user_id}`}
+ >
+ {i18n.t('send_secure_message')}
+ </a>
+ <Link
+ class="btn btn-block btn-secondary mt-3"
+ to={`/create_private_message?recipient_id=${this.state.user.id}`}
+ >
+ {i18n.t('send_message')}
+ </Link>
+ </>
)}
</div>
</div>
@@ -547,6 +560,26 @@ export class User extends Component<any, UserState> {
</div>
<div class="form-group row">
<label class="col-lg-5 col-form-label">
+ <a href="https://about.riot.im/" target="_blank">
+ {i18n.t('matrix_user_id')}
+ </a>
+ </label>
+ <div class="col-lg-7">
+ <input
+ type="text"
+ class="form-control"
+ placeholder="@user:example.com"
+ value={this.state.userSettingsForm.matrix_user_id}
+ onInput={linkEvent(
+ this,
+ this.handleUserSettingsMatrixUserIdChange
+ )}
+ minLength={3}
+ />
+ </div>
+ </div>
+ <div class="form-group row">
+ <label class="col-lg-5 col-form-label">
<T i18nKey="new_password">#</T>
</label>
<div class="col-lg-7">
@@ -881,6 +914,17 @@ export class User extends Component<any, UserState> {
i.setState(i.state);
}
+ handleUserSettingsMatrixUserIdChange(i: User, event: any) {
+ i.state.userSettingsForm.matrix_user_id = event.target.value;
+ if (
+ i.state.userSettingsForm.matrix_user_id == '' &&
+ !i.state.user.matrix_user_id
+ ) {
+ i.state.userSettingsForm.matrix_user_id = undefined;
+ }
+ i.setState(i.state);
+ }
+
handleUserSettingsNewPasswordChange(i: User, event: any) {
i.state.userSettingsForm.new_password = event.target.value;
if (i.state.userSettingsForm.new_password == '') {
@@ -933,7 +977,7 @@ export class User extends Component<any, UserState> {
.catch(error => {
i.state.avatarLoading = false;
i.setState(i.state);
- alert(error);
+ toast(error, 'danger');
});
}
@@ -973,7 +1017,7 @@ export class User extends Component<any, UserState> {
console.log(msg);
let res = wsJsonToRes(msg);
if (res.error) {
- alert(i18n.t(res.error));
+ toast(i18n.t(msg.error), 'danger');
this.state.deleteAccountLoading = false;
this.state.avatarLoading = false;
this.state.userSettingsLoading = false;
@@ -1007,6 +1051,7 @@ export class User extends Component<any, UserState> {
this.state.userSettingsForm.send_notifications_to_email = this.state.user.send_notifications_to_email;
this.state.userSettingsForm.show_avatars =
UserService.Instance.user.show_avatars;
+ this.state.userSettingsForm.matrix_user_id = this.state.user.matrix_user_id;
}
document.title = `/u/${this.state.user.name} - ${WebSocketService.Instance.site.name}`;
window.scrollTo(0, 0);
@@ -1026,7 +1071,7 @@ export class User extends Component<any, UserState> {
this.setState(this.state);
} else if (res.op == UserOperation.CreateComment) {
// let res: CommentResponse = msg;
- alert(i18n.t('reply_sent'));
+ toast(i18n.t('reply_sent'));
// this.state.comments.unshift(res.comment); // TODO do this right
// this.setState(this.state);
} else if (res.op == UserOperation.SaveComment) {
@@ -1044,6 +1089,14 @@ export class User extends Component<any, UserState> {
found.downvotes = data.comment.downvotes;
if (data.comment.my_vote !== null) found.my_vote = data.comment.my_vote;
this.setState(this.state);
+ } else if (res.op == UserOperation.CreatePostLike) {
+ let data = res.data as CreatePostLikeResponse;
+ let found = this.state.posts.find(c => c.id == data.post.id);
+ found.my_vote = data.post.my_vote;
+ found.score = data.post.score;
+ found.upvotes = data.post.upvotes;
+ found.downvotes = data.post.downvotes;
+ this.setState(this.state);
} else if (res.op == UserOperation.BanUser) {
let data = res.data as BanUserResponse;
this.state.comments