Adding media and recent watch media
This commit is contained in:
@@ -12,6 +12,7 @@ postDB = (DB)=>{
|
||||
}
|
||||
|
||||
DB.removePost = (postid) => {
|
||||
if(!DB.ObjectID.isValid(postid)) return false;
|
||||
const _id = DB.ObjectID(postid);
|
||||
return DB.postCols.deleteOne({_id}).catch((err)=>{
|
||||
console.log(err);
|
||||
@@ -20,6 +21,7 @@ postDB = (DB)=>{
|
||||
}
|
||||
|
||||
DB.updatePost = (postid, newContent, oldContent) => {
|
||||
if(!DB.ObjectID.isValid(postid)) return false;
|
||||
const id = DB.ObjectID(postid);
|
||||
let update = {
|
||||
$set:{
|
||||
@@ -37,6 +39,7 @@ postDB = (DB)=>{
|
||||
}
|
||||
|
||||
DB.newReaction = (postid, profileid, reaction) => {
|
||||
if(!DB.ObjectID.isValid(postid)) return false;
|
||||
const id = DB.ObjectID(postid);
|
||||
let update = {
|
||||
$set:{
|
||||
@@ -51,6 +54,7 @@ postDB = (DB)=>{
|
||||
}
|
||||
|
||||
DB.removeReaction = (postid, profileid) => {
|
||||
if(!DB.ObjectID.isValid(postid)) return false;
|
||||
const id = DB.ObjectID(postid);
|
||||
let update = {
|
||||
$unset:{
|
||||
@@ -67,6 +71,7 @@ postDB = (DB)=>{
|
||||
}
|
||||
|
||||
DB.bookmarkPost = async (postid, profileId)=>{
|
||||
if(!DB.ObjectID.isValid(postid)) return false;
|
||||
const _id = DB.ObjectID(postid);
|
||||
let update = {
|
||||
$addToSet:{
|
||||
@@ -80,6 +85,7 @@ postDB = (DB)=>{
|
||||
}
|
||||
|
||||
DB.unbookmarkPost = async (postid, profileId)=>{
|
||||
if(!DB.ObjectID.isValid(postid)) return false;
|
||||
const _id = DB.ObjectID(postid);
|
||||
let update = {
|
||||
$pull:{
|
||||
@@ -93,6 +99,7 @@ postDB = (DB)=>{
|
||||
}
|
||||
|
||||
DB.newComment = (postid, comment) => {
|
||||
if(!DB.ObjectID.isValid(postid)) return false;
|
||||
const id = DB.ObjectID(postid);
|
||||
return DB.postCols.updateOne({_id: id}, {
|
||||
$push: {
|
||||
@@ -108,6 +115,7 @@ postDB = (DB)=>{
|
||||
}
|
||||
|
||||
DB.newCommentReaction = (postid, commentDate, profileid, reaction) => {
|
||||
if(!DB.ObjectID.isValid(postid)) return false;
|
||||
const id = DB.ObjectID(postid);
|
||||
let update = {
|
||||
$set:{
|
||||
@@ -126,6 +134,7 @@ postDB = (DB)=>{
|
||||
}
|
||||
|
||||
DB.removeCommentReaction = (postid, commentDate, profileid) => {
|
||||
if(!DB.ObjectID.isValid(postid)) return false;
|
||||
const id = DB.ObjectID(postid);
|
||||
let update = {
|
||||
$unset:{
|
||||
@@ -193,6 +202,7 @@ postDB = (DB)=>{
|
||||
}
|
||||
|
||||
DB.getFeed = async (profileId) => {
|
||||
if(!DB.ObjectID.isValid(profileId)) return [];
|
||||
const profile = await DB.getProfile(profileId);
|
||||
if(!profile) return [];
|
||||
let ids = profile.following.map((id)=>DB.ObjectID(id));
|
||||
@@ -226,36 +236,48 @@ postDB = (DB)=>{
|
||||
});
|
||||
}
|
||||
|
||||
DB.getPostsOfUser = (userId) => {
|
||||
DB.getPostsOfUser = (userId, limit = 20) => {
|
||||
if(!DB.ObjectID.isValid(userId)) return [];
|
||||
let userid = DB.ObjectID(userId);
|
||||
console.log("getPostsOfUser")
|
||||
return DB.postCols.find({userid}).sort({_id: -1}).limit(20).toArray().catch((err)=>{
|
||||
return DB.postCols.find({userid}).sort({_id: -1}).limit(limit).toArray().catch((err)=>{
|
||||
console.log(err);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
DB.getImagesOfUser = (userId) => {
|
||||
let userid = DB.ObjectID(userId);
|
||||
DB.getMediaTagPostOfUser = (profileId, mediaTag = "@image:", limit = 20) => {
|
||||
if(!DB.ObjectID.isValid(profileId)) return [];
|
||||
let profileid = DB.ObjectID(profileId);
|
||||
let query = {
|
||||
userid,
|
||||
profileid,
|
||||
content: {
|
||||
$regex: "@image"
|
||||
"$regex": mediaTag
|
||||
}
|
||||
}
|
||||
return DB.postCols.find(query).sort({_id: -1}).limit(20).toArray().catch((err)=>{
|
||||
return DB.postCols.find(query).sort({_id: -1}).limit(limit).toArray().catch((err)=>{
|
||||
console.log(err);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
DB.getPost = (postId) => {
|
||||
if(!DB.ObjectID.isValid(postId)) return [];
|
||||
let _id = DB.ObjectID(postId);
|
||||
return DB.postCols.findOne({_id}).catch((err)=>{
|
||||
console.log(err);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
const postsCache = {};
|
||||
DB.getPostCached = async (postId, refresh = false) => {
|
||||
if(!DB.ObjectID.isValid(postId)) return [];
|
||||
if(!postsCache[postId] || refresh){
|
||||
postsCache[postId] = await DB.getPost(postId);
|
||||
}
|
||||
return postsCache[postId];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user