EditUserMention changed to MarkUserMentionAsRead.
This commit is contained in:
parent
0a28ffb9c4
commit
a67f46bec5
10 changed files with 58 additions and 55 deletions
10
docs/src/contributing_websocket_http_api.md
vendored
10
docs/src/contributing_websocket_http_api.md
vendored
|
@ -464,14 +464,14 @@ Only the first user will be able to be the admin.
|
||||||
|
|
||||||
`GET /user/mentions`
|
`GET /user/mentions`
|
||||||
|
|
||||||
#### Edit User Mention
|
#### Mark User Mention as read
|
||||||
##### Request
|
##### Request
|
||||||
```rust
|
```rust
|
||||||
{
|
{
|
||||||
op: "EditUserMention",
|
op: "MarkUserMentionAsRead",
|
||||||
data: {
|
data: {
|
||||||
user_mention_id: i32,
|
user_mention_id: i32,
|
||||||
read: Option<bool>,
|
read: bool,
|
||||||
auth: String,
|
auth: String,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -479,7 +479,7 @@ Only the first user will be able to be the admin.
|
||||||
##### Response
|
##### Response
|
||||||
```rust
|
```rust
|
||||||
{
|
{
|
||||||
op: "EditUserMention",
|
op: "MarkUserMentionAsRead",
|
||||||
data: {
|
data: {
|
||||||
mention: UserMentionView,
|
mention: UserMentionView,
|
||||||
}
|
}
|
||||||
|
@ -487,7 +487,7 @@ Only the first user will be able to be the admin.
|
||||||
```
|
```
|
||||||
##### HTTP
|
##### HTTP
|
||||||
|
|
||||||
`PUT /user/mention`
|
`POST /user/mention/mark_as_read`
|
||||||
|
|
||||||
#### Get Private Messages
|
#### Get Private Messages
|
||||||
##### Request
|
##### Request
|
||||||
|
|
|
@ -52,6 +52,30 @@ impl Crud<UserMentionForm> for UserMention {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl UserMention {
|
||||||
|
pub fn update_read(
|
||||||
|
conn: &PgConnection,
|
||||||
|
user_mention_id: i32,
|
||||||
|
new_read: bool,
|
||||||
|
) -> Result<Self, Error> {
|
||||||
|
use crate::schema::user_mention::dsl::*;
|
||||||
|
diesel::update(user_mention.find(user_mention_id))
|
||||||
|
.set(read.eq(new_read))
|
||||||
|
.get_result::<Self>(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn mark_all_as_read(conn: &PgConnection, for_recipient_id: i32) -> Result<Vec<Self>, Error> {
|
||||||
|
use crate::schema::user_mention::dsl::*;
|
||||||
|
diesel::update(
|
||||||
|
user_mention
|
||||||
|
.filter(recipient_id.eq(for_recipient_id))
|
||||||
|
.filter(read.eq(false)),
|
||||||
|
)
|
||||||
|
.set(read.eq(true))
|
||||||
|
.get_results::<Self>(conn)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
|
@ -174,9 +174,9 @@ pub struct GetUserMentions {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct EditUserMention {
|
pub struct MarkUserMentionAsRead {
|
||||||
user_mention_id: i32,
|
user_mention_id: i32,
|
||||||
read: Option<bool>,
|
read: bool,
|
||||||
auth: String,
|
auth: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -874,7 +874,7 @@ impl Perform for Oper<GetUserMentions> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for Oper<EditUserMention> {
|
impl Perform for Oper<MarkUserMentionAsRead> {
|
||||||
type Response = UserMentionResponse;
|
type Response = UserMentionResponse;
|
||||||
|
|
||||||
async fn perform(
|
async fn perform(
|
||||||
|
@ -882,7 +882,7 @@ impl Perform for Oper<EditUserMention> {
|
||||||
pool: &DbPool,
|
pool: &DbPool,
|
||||||
_websocket_info: Option<WebsocketInfo>,
|
_websocket_info: Option<WebsocketInfo>,
|
||||||
) -> Result<UserMentionResponse, LemmyError> {
|
) -> Result<UserMentionResponse, LemmyError> {
|
||||||
let data: &EditUserMention = &self.data;
|
let data: &MarkUserMentionAsRead = &self.data;
|
||||||
|
|
||||||
let claims = match Claims::decode(&data.auth) {
|
let claims = match Claims::decode(&data.auth) {
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
|
@ -899,15 +899,9 @@ impl Perform for Oper<EditUserMention> {
|
||||||
return Err(APIError::err("couldnt_update_comment").into());
|
return Err(APIError::err("couldnt_update_comment").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let user_mention_form = UserMentionForm {
|
|
||||||
recipient_id: read_user_mention.recipient_id,
|
|
||||||
comment_id: read_user_mention.comment_id,
|
|
||||||
read: data.read.to_owned(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let user_mention_id = read_user_mention.id;
|
let user_mention_id = read_user_mention.id;
|
||||||
let update_mention =
|
let read = data.read;
|
||||||
move |conn: &'_ _| UserMention::update(conn, user_mention_id, &user_mention_form);
|
let update_mention = move |conn: &'_ _| UserMention::update_read(conn, user_mention_id, read);
|
||||||
if blocking(pool, update_mention).await?.is_err() {
|
if blocking(pool, update_mention).await?.is_err() {
|
||||||
return Err(APIError::err("couldnt_update_comment").into());
|
return Err(APIError::err("couldnt_update_comment").into());
|
||||||
};
|
};
|
||||||
|
@ -960,31 +954,11 @@ impl Perform for Oper<MarkAllAsRead> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mentions
|
// Mark all user mentions as read
|
||||||
let mentions = blocking(pool, move |conn| {
|
let update_user_mentions = move |conn: &'_ _| UserMention::mark_all_as_read(conn, user_id);
|
||||||
UserMentionQueryBuilder::create(conn, user_id)
|
if blocking(pool, update_user_mentions).await?.is_err() {
|
||||||
.unread_only(true)
|
|
||||||
.page(1)
|
|
||||||
.limit(999)
|
|
||||||
.list()
|
|
||||||
})
|
|
||||||
.await??;
|
|
||||||
|
|
||||||
// TODO: this should probably be a bulk operation
|
|
||||||
for mention in &mentions {
|
|
||||||
let mention_form = UserMentionForm {
|
|
||||||
recipient_id: mention.to_owned().recipient_id,
|
|
||||||
comment_id: mention.to_owned().id,
|
|
||||||
read: Some(true),
|
|
||||||
};
|
|
||||||
|
|
||||||
let user_mention_id = mention.user_mention_id;
|
|
||||||
let update_mention =
|
|
||||||
move |conn: &'_ _| UserMention::update(conn, user_mention_id, &mention_form);
|
|
||||||
if blocking(pool, update_mention).await?.is_err() {
|
|
||||||
return Err(APIError::err("couldnt_update_comment").into());
|
return Err(APIError::err("couldnt_update_comment").into());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Mark all private_messages as read
|
// Mark all private_messages as read
|
||||||
let update_pm = move |conn: &'_ _| PrivateMessage::mark_all_as_read(conn, user_id);
|
let update_pm = move |conn: &'_ _| PrivateMessage::mark_all_as_read(conn, user_id);
|
||||||
|
|
|
@ -115,7 +115,10 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) {
|
||||||
.wrap(rate_limit.message())
|
.wrap(rate_limit.message())
|
||||||
.route("", web::get().to(route_get::<GetUserDetails>))
|
.route("", web::get().to(route_get::<GetUserDetails>))
|
||||||
.route("/mention", web::get().to(route_get::<GetUserMentions>))
|
.route("/mention", web::get().to(route_get::<GetUserMentions>))
|
||||||
.route("/mention", web::put().to(route_post::<EditUserMention>))
|
.route(
|
||||||
|
"/mention/mark_as_read",
|
||||||
|
web::post().to(route_post::<MarkUserMentionAsRead>),
|
||||||
|
)
|
||||||
.route("/replies", web::get().to(route_get::<GetReplies>))
|
.route("/replies", web::get().to(route_get::<GetReplies>))
|
||||||
.route(
|
.route(
|
||||||
"/followed_communities",
|
"/followed_communities",
|
||||||
|
|
|
@ -40,7 +40,7 @@ pub enum UserOperation {
|
||||||
GetUserDetails,
|
GetUserDetails,
|
||||||
GetReplies,
|
GetReplies,
|
||||||
GetUserMentions,
|
GetUserMentions,
|
||||||
EditUserMention,
|
MarkUserMentionAsRead,
|
||||||
GetModlog,
|
GetModlog,
|
||||||
BanFromCommunity,
|
BanFromCommunity,
|
||||||
AddModToCommunity,
|
AddModToCommunity,
|
||||||
|
|
|
@ -443,7 +443,9 @@ impl ChatServer {
|
||||||
UserOperation::AddAdmin => do_user_operation::<AddAdmin>(args).await,
|
UserOperation::AddAdmin => do_user_operation::<AddAdmin>(args).await,
|
||||||
UserOperation::BanUser => do_user_operation::<BanUser>(args).await,
|
UserOperation::BanUser => do_user_operation::<BanUser>(args).await,
|
||||||
UserOperation::GetUserMentions => do_user_operation::<GetUserMentions>(args).await,
|
UserOperation::GetUserMentions => do_user_operation::<GetUserMentions>(args).await,
|
||||||
UserOperation::EditUserMention => do_user_operation::<EditUserMention>(args).await,
|
UserOperation::MarkUserMentionAsRead => {
|
||||||
|
do_user_operation::<MarkUserMentionAsRead>(args).await
|
||||||
|
}
|
||||||
UserOperation::MarkAllAsRead => do_user_operation::<MarkAllAsRead>(args).await,
|
UserOperation::MarkAllAsRead => do_user_operation::<MarkAllAsRead>(args).await,
|
||||||
UserOperation::DeleteAccount => do_user_operation::<DeleteAccount>(args).await,
|
UserOperation::DeleteAccount => do_user_operation::<DeleteAccount>(args).await,
|
||||||
UserOperation::PasswordReset => do_user_operation::<PasswordReset>(args).await,
|
UserOperation::PasswordReset => do_user_operation::<PasswordReset>(args).await,
|
||||||
|
|
6
ui/src/components/comment-node.tsx
vendored
6
ui/src/components/comment-node.tsx
vendored
|
@ -4,7 +4,7 @@ import {
|
||||||
CommentNode as CommentNodeI,
|
CommentNode as CommentNodeI,
|
||||||
CommentLikeForm,
|
CommentLikeForm,
|
||||||
CommentForm as CommentFormI,
|
CommentForm as CommentFormI,
|
||||||
EditUserMentionForm,
|
MarkUserMentionAsReadForm,
|
||||||
SaveCommentForm,
|
SaveCommentForm,
|
||||||
BanFromCommunityForm,
|
BanFromCommunityForm,
|
||||||
BanUserForm,
|
BanUserForm,
|
||||||
|
@ -969,11 +969,11 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
|
||||||
handleMarkRead(i: CommentNode) {
|
handleMarkRead(i: CommentNode) {
|
||||||
// if it has a user_mention_id field, then its a mention
|
// if it has a user_mention_id field, then its a mention
|
||||||
if (i.props.node.comment.user_mention_id) {
|
if (i.props.node.comment.user_mention_id) {
|
||||||
let form: EditUserMentionForm = {
|
let form: MarkUserMentionAsReadForm = {
|
||||||
user_mention_id: i.props.node.comment.user_mention_id,
|
user_mention_id: i.props.node.comment.user_mention_id,
|
||||||
read: !i.props.node.comment.read,
|
read: !i.props.node.comment.read,
|
||||||
};
|
};
|
||||||
WebSocketService.Instance.editUserMention(form);
|
WebSocketService.Instance.markUserMentionAsRead(form);
|
||||||
} else {
|
} else {
|
||||||
let form: CommentFormI = {
|
let form: CommentFormI = {
|
||||||
content: i.props.node.comment.content,
|
content: i.props.node.comment.content,
|
||||||
|
|
2
ui/src/components/inbox.tsx
vendored
2
ui/src/components/inbox.tsx
vendored
|
@ -500,7 +500,7 @@ export class Inbox extends Component<any, InboxState> {
|
||||||
this.sendUnreadCount();
|
this.sendUnreadCount();
|
||||||
this.setState(this.state);
|
this.setState(this.state);
|
||||||
setupTippy();
|
setupTippy();
|
||||||
} else if (res.op == UserOperation.EditUserMention) {
|
} else if (res.op == UserOperation.MarkUserMentionAsRead) {
|
||||||
let data = res.data as UserMentionResponse;
|
let data = res.data as UserMentionResponse;
|
||||||
|
|
||||||
let found = this.state.mentions.find(c => c.id == data.mention.id);
|
let found = this.state.mentions.find(c => c.id == data.mention.id);
|
||||||
|
|
8
ui/src/interfaces.ts
vendored
8
ui/src/interfaces.ts
vendored
|
@ -21,7 +21,7 @@ export enum UserOperation {
|
||||||
GetUserDetails,
|
GetUserDetails,
|
||||||
GetReplies,
|
GetReplies,
|
||||||
GetUserMentions,
|
GetUserMentions,
|
||||||
EditUserMention,
|
MarkUserMentionAsRead,
|
||||||
GetModlog,
|
GetModlog,
|
||||||
BanFromCommunity,
|
BanFromCommunity,
|
||||||
AddModToCommunity,
|
AddModToCommunity,
|
||||||
|
@ -357,9 +357,9 @@ export interface GetUserMentionsResponse {
|
||||||
mentions: Array<Comment>;
|
mentions: Array<Comment>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EditUserMentionForm {
|
export interface MarkUserMentionAsReadForm {
|
||||||
user_mention_id: number;
|
user_mention_id: number;
|
||||||
read?: boolean;
|
read: boolean;
|
||||||
auth?: string;
|
auth?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -901,7 +901,7 @@ export type MessageType =
|
||||||
| GetUserDetailsForm
|
| GetUserDetailsForm
|
||||||
| GetRepliesForm
|
| GetRepliesForm
|
||||||
| GetUserMentionsForm
|
| GetUserMentionsForm
|
||||||
| EditUserMentionForm
|
| MarkUserMentionAsReadForm
|
||||||
| GetModlogForm
|
| GetModlogForm
|
||||||
| SiteForm
|
| SiteForm
|
||||||
| SearchForm
|
| SearchForm
|
||||||
|
|
6
ui/src/services/WebSocketService.ts
vendored
6
ui/src/services/WebSocketService.ts
vendored
|
@ -28,7 +28,7 @@ import {
|
||||||
UserView,
|
UserView,
|
||||||
GetRepliesForm,
|
GetRepliesForm,
|
||||||
GetUserMentionsForm,
|
GetUserMentionsForm,
|
||||||
EditUserMentionForm,
|
MarkUserMentionAsReadForm,
|
||||||
SearchForm,
|
SearchForm,
|
||||||
UserSettingsForm,
|
UserSettingsForm,
|
||||||
DeleteAccountForm,
|
DeleteAccountForm,
|
||||||
|
@ -247,9 +247,9 @@ export class WebSocketService {
|
||||||
this.ws.send(this.wsSendWrapper(UserOperation.GetUserMentions, form));
|
this.ws.send(this.wsSendWrapper(UserOperation.GetUserMentions, form));
|
||||||
}
|
}
|
||||||
|
|
||||||
public editUserMention(form: EditUserMentionForm) {
|
public markUserMentionAsRead(form: MarkUserMentionAsReadForm) {
|
||||||
this.setAuth(form);
|
this.setAuth(form);
|
||||||
this.ws.send(this.wsSendWrapper(UserOperation.EditUserMention, form));
|
this.ws.send(this.wsSendWrapper(UserOperation.MarkUserMentionAsRead, form));
|
||||||
}
|
}
|
||||||
|
|
||||||
public getModlog(form: GetModlogForm) {
|
public getModlog(form: GetModlogForm) {
|
||||||
|
|
Loading…
Reference in a new issue