backend, mark item as read
parent
abf9a1b818
commit
579fa1f7ca
|
@ -1,8 +1,8 @@
|
||||||
use crate::models::feed::rss_feed::Feed;
|
use crate::models::feed::rss_feed::Feed;
|
||||||
use crate::schema::feed_item;
|
use crate::schema::feed_item;
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use diesel::{Associations, Identifiable, Queryable};
|
use diesel::{Associations, Identifiable, Queryable, Selectable};
|
||||||
#[derive(Clone, Identifiable, Queryable, Associations)]
|
#[derive(Clone, Identifiable, Selectable, Queryable, Associations)]
|
||||||
#[diesel(belongs_to(Feed))]
|
#[diesel(belongs_to(Feed))]
|
||||||
#[diesel(table_name=feed_item)]
|
#[diesel(table_name=feed_item)]
|
||||||
pub struct FeedItem {
|
pub struct FeedItem {
|
||||||
|
|
|
@ -1,8 +1,31 @@
|
||||||
|
use crate::schema::feed_item::{id, read};
|
||||||
|
use crate::{
|
||||||
|
database::establish_connection, json_serialization::read_feed_item::ReadItem,
|
||||||
|
models::feed_item::rss_feed_item::FeedItem, schema::feed_item,
|
||||||
|
};
|
||||||
use actix_web::{web, HttpRequest, HttpResponse, Responder};
|
use actix_web::{web, HttpRequest, HttpResponse, Responder};
|
||||||
|
use diesel::RunQueryDsl;
|
||||||
use crate::json_serialization::read_feed_item::ReadItem;
|
use diesel::{ExpressionMethods, QueryDsl};
|
||||||
|
|
||||||
pub async fn mark_read(_req: HttpRequest, path: web::Path<ReadItem>) -> impl Responder {
|
pub async fn mark_read(_req: HttpRequest, path: web::Path<ReadItem>) -> impl Responder {
|
||||||
|
let mut connection = establish_connection();
|
||||||
log::info!("Id: {}", path.id);
|
log::info!("Id: {}", path.id);
|
||||||
|
let feed_items: Vec<FeedItem> = feed_item::table
|
||||||
|
.filter(id.eq(path.id))
|
||||||
|
.load::<FeedItem>(&mut connection)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
if feed_items.len() != 1 {
|
||||||
|
return HttpResponse::NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
let feed_item: &FeedItem = feed_items.first().unwrap();
|
||||||
|
|
||||||
|
let result: Result<usize, diesel::result::Error> = diesel::update(feed_item)
|
||||||
|
.set(read.eq(true))
|
||||||
|
.execute(&mut connection);
|
||||||
|
|
||||||
|
log::info!("Mark as read: {:?}", result);
|
||||||
|
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted, nextTick } from 'vue';
|
import { ref, unref, onMounted, nextTick } from 'vue';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { Readability } from '@mozilla/readability';
|
import { Readability } from '@mozilla/readability';
|
||||||
|
|
||||||
|
@ -124,12 +124,19 @@ function handleIntersection(entries) {
|
||||||
if (entry.isVisible === false) {
|
if (entry.isVisible === false) {
|
||||||
console.log('Element is out of sight ' + entry.intersectionRatio);
|
console.log('Element is out of sight ' + entry.intersectionRatio);
|
||||||
//console.log(feeds.value[entry.target.id])
|
//console.log(feeds.value[entry.target.id])
|
||||||
markRead(feeds.value[entry.target.id].id)
|
markRead(feeds.value[entry.target.id].id).await
|
||||||
|
removeFeed(entry.target.id)
|
||||||
|
// TODO viewport moves crazy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removeFeed(index) {
|
||||||
|
const array = unref(feeds);
|
||||||
|
array.splice(index, 1);
|
||||||
|
}
|
||||||
|
|
||||||
let initialLoad = false
|
let initialLoad = false
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
initialLoad = false
|
initialLoad = false
|
||||||
|
|
Loading…
Reference in New Issue