Resolve conflicts
This commit is contained in:
@ -15,9 +15,9 @@ import getFriends from '../../common/get-friends';
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
// Get 'user_id' parameter
|
||||
const [userId, userIdErr] = $(params.user_id).id().$;
|
||||
if (userIdErr) return rej('invalid user_id param');
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).id().$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Get 'iknow' parameter
|
||||
const [iknow = false, iknowErr] = $(params.iknow).optional.boolean().$;
|
||||
@ -46,8 +46,8 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
|
||||
// Construct query
|
||||
const query = {
|
||||
followee_id: user._id,
|
||||
deleted_at: { $exists: false }
|
||||
followeeId: user._id,
|
||||
deletedAt: { $exists: false }
|
||||
} as any;
|
||||
|
||||
// ログインしていてかつ iknow フラグがあるとき
|
||||
@ -55,7 +55,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
// Get my friends
|
||||
const myFriends = await getFriends(me._id);
|
||||
|
||||
query.follower_id = {
|
||||
query.followerId = {
|
||||
$in: myFriends
|
||||
};
|
||||
}
|
||||
@ -82,7 +82,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
|
||||
// Serialize
|
||||
const users = await Promise.all(following.map(async f =>
|
||||
await pack(f.follower_id, me, { detail: true })));
|
||||
await pack(f.followerId, me, { detail: true })));
|
||||
|
||||
// Response
|
||||
res({
|
||||
|
@ -15,9 +15,9 @@ import getFriends from '../../common/get-friends';
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
// Get 'user_id' parameter
|
||||
const [userId, userIdErr] = $(params.user_id).id().$;
|
||||
if (userIdErr) return rej('invalid user_id param');
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).id().$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Get 'iknow' parameter
|
||||
const [iknow = false, iknowErr] = $(params.iknow).optional.boolean().$;
|
||||
@ -46,8 +46,8 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
|
||||
// Construct query
|
||||
const query = {
|
||||
follower_id: user._id,
|
||||
deleted_at: { $exists: false }
|
||||
followerId: user._id,
|
||||
deletedAt: { $exists: false }
|
||||
} as any;
|
||||
|
||||
// ログインしていてかつ iknow フラグがあるとき
|
||||
@ -55,7 +55,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
// Get my friends
|
||||
const myFriends = await getFriends(me._id);
|
||||
|
||||
query.followee_id = {
|
||||
query.followeeId = {
|
||||
$in: myFriends
|
||||
};
|
||||
}
|
||||
@ -82,7 +82,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
|
||||
// Serialize
|
||||
const users = await Promise.all(following.map(async f =>
|
||||
await pack(f.followee_id, me, { detail: true })));
|
||||
await pack(f.followeeId, me, { detail: true })));
|
||||
|
||||
// Response
|
||||
res({
|
||||
|
@ -6,9 +6,9 @@ import Post from '../../models/post';
|
||||
import User, { pack } from '../../models/user';
|
||||
|
||||
module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
// Get 'user_id' parameter
|
||||
const [userId, userIdErr] = $(params.user_id).id().$;
|
||||
if (userIdErr) return rej('invalid user_id param');
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).id().$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
||||
@ -29,8 +29,8 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
|
||||
// Fetch recent posts
|
||||
const recentPosts = await Post.find({
|
||||
user_id: user._id,
|
||||
reply_id: {
|
||||
userId: user._id,
|
||||
replyId: {
|
||||
$exists: true,
|
||||
$ne: null
|
||||
}
|
||||
@ -41,7 +41,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
limit: 1000,
|
||||
fields: {
|
||||
_id: false,
|
||||
reply_id: true
|
||||
replyId: true
|
||||
}
|
||||
});
|
||||
|
||||
@ -52,15 +52,15 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
|
||||
const replyTargetPosts = await Post.find({
|
||||
_id: {
|
||||
$in: recentPosts.map(p => p.reply_id)
|
||||
$in: recentPosts.map(p => p.replyId)
|
||||
},
|
||||
user_id: {
|
||||
userId: {
|
||||
$ne: user._id
|
||||
}
|
||||
}, {
|
||||
fields: {
|
||||
_id: false,
|
||||
user_id: true
|
||||
userId: true
|
||||
}
|
||||
});
|
||||
|
||||
@ -68,7 +68,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
|
||||
// Extract replies from recent posts
|
||||
replyTargetPosts.forEach(post => {
|
||||
const userId = post.user_id.toString();
|
||||
const userId = post.userId.toString();
|
||||
if (repliedUsers[userId]) {
|
||||
repliedUsers[userId]++;
|
||||
} else {
|
||||
|
@ -14,16 +14,16 @@ import User from '../../models/user';
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
// Get 'user_id' parameter
|
||||
const [userId, userIdErr] = $(params.user_id).optional.id().$;
|
||||
if (userIdErr) return rej('invalid user_id param');
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).optional.id().$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Get 'username' parameter
|
||||
const [username, usernameErr] = $(params.username).optional.string().$;
|
||||
if (usernameErr) return rej('invalid username param');
|
||||
|
||||
if (userId === undefined && username === undefined) {
|
||||
return rej('user_id or pair of username and host is required');
|
||||
return rej('userId or pair of username and host is required');
|
||||
}
|
||||
|
||||
// Get 'host' parameter
|
||||
@ -31,45 +31,45 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
if (hostErr) return rej('invalid host param');
|
||||
|
||||
if (userId === undefined && host === undefined) {
|
||||
return rej('user_id or pair of username and host is required');
|
||||
return rej('userId or pair of username and host is required');
|
||||
}
|
||||
|
||||
// Get 'include_replies' parameter
|
||||
const [includeReplies = true, includeRepliesErr] = $(params.include_replies).optional.boolean().$;
|
||||
if (includeRepliesErr) return rej('invalid include_replies param');
|
||||
// Get 'includeReplies' parameter
|
||||
const [includeReplies = true, includeRepliesErr] = $(params.includeReplies).optional.boolean().$;
|
||||
if (includeRepliesErr) return rej('invalid includeReplies param');
|
||||
|
||||
// Get 'with_media' parameter
|
||||
const [withMedia = false, withMediaErr] = $(params.with_media).optional.boolean().$;
|
||||
if (withMediaErr) return rej('invalid with_media param');
|
||||
// Get 'withMedia' parameter
|
||||
const [withMedia = false, withMediaErr] = $(params.withMedia).optional.boolean().$;
|
||||
if (withMediaErr) return rej('invalid withMedia param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'since_id' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
|
||||
if (sinceIdErr) return rej('invalid since_id param');
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||
if (sinceIdErr) return rej('invalid sinceId param');
|
||||
|
||||
// Get 'until_id' parameter
|
||||
const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
|
||||
if (untilIdErr) return rej('invalid until_id param');
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||
if (untilIdErr) return rej('invalid untilId param');
|
||||
|
||||
// Get 'since_date' parameter
|
||||
const [sinceDate, sinceDateErr] = $(params.since_date).optional.number().$;
|
||||
if (sinceDateErr) throw 'invalid since_date param';
|
||||
// Get 'sinceDate' parameter
|
||||
const [sinceDate, sinceDateErr] = $(params.sinceDate).optional.number().$;
|
||||
if (sinceDateErr) throw 'invalid sinceDate param';
|
||||
|
||||
// Get 'until_date' parameter
|
||||
const [untilDate, untilDateErr] = $(params.until_date).optional.number().$;
|
||||
if (untilDateErr) throw 'invalid until_date param';
|
||||
// Get 'untilDate' parameter
|
||||
const [untilDate, untilDateErr] = $(params.untilDate).optional.number().$;
|
||||
if (untilDateErr) throw 'invalid untilDate param';
|
||||
|
||||
// Check if only one of since_id, until_id, since_date, until_date specified
|
||||
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
|
||||
if ([sinceId, untilId, sinceDate, untilDate].filter(x => x != null).length > 1) {
|
||||
throw 'only one of since_id, until_id, since_date, until_date can be specified';
|
||||
throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified';
|
||||
}
|
||||
|
||||
const q = userId !== undefined
|
||||
? { _id: userId }
|
||||
: { username_lower: username.toLowerCase(), host_lower: getHostLower(host) } ;
|
||||
: { usernameLower: username.toLowerCase(), hostLower: getHostLower(host) } ;
|
||||
|
||||
// Lookup user
|
||||
const user = await User.findOne(q, {
|
||||
@ -88,7 +88,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
};
|
||||
|
||||
const query = {
|
||||
user_id: user._id
|
||||
userId: user._id
|
||||
} as any;
|
||||
|
||||
if (sinceId) {
|
||||
@ -102,21 +102,21 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
};
|
||||
} else if (sinceDate) {
|
||||
sort._id = 1;
|
||||
query.created_at = {
|
||||
query.createdAt = {
|
||||
$gt: new Date(sinceDate)
|
||||
};
|
||||
} else if (untilDate) {
|
||||
query.created_at = {
|
||||
query.createdAt = {
|
||||
$lt: new Date(untilDate)
|
||||
};
|
||||
}
|
||||
|
||||
if (!includeReplies) {
|
||||
query.reply_id = null;
|
||||
query.replyId = null;
|
||||
}
|
||||
|
||||
if (withMedia) {
|
||||
query.media_ids = {
|
||||
query.mediaIds = {
|
||||
$exists: true,
|
||||
$ne: null
|
||||
};
|
||||
|
@ -32,7 +32,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
},
|
||||
$or: [
|
||||
{
|
||||
'account.last_used_at': {
|
||||
'account.lastUsedAt': {
|
||||
$gte: new Date(Date.now() - ms('7days'))
|
||||
}
|
||||
}, {
|
||||
@ -43,7 +43,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
limit: limit,
|
||||
skip: offset,
|
||||
sort: {
|
||||
followers_count: -1
|
||||
followersCount: -1
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -41,7 +41,7 @@ async function byNative(res, rej, me, query, offset, max) {
|
||||
const users = await User
|
||||
.find({
|
||||
$or: [{
|
||||
username_lower: new RegExp(escapedQuery.replace('@', '').toLowerCase())
|
||||
usernameLower: new RegExp(escapedQuery.replace('@', '').toLowerCase())
|
||||
}, {
|
||||
name: new RegExp(escapedQuery)
|
||||
}]
|
||||
|
@ -26,7 +26,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
|
||||
const users = await User
|
||||
.find({
|
||||
username_lower: new RegExp(query.toLowerCase())
|
||||
usernameLower: new RegExp(query.toLowerCase())
|
||||
}, {
|
||||
limit: limit,
|
||||
skip: offset
|
||||
|
@ -56,9 +56,9 @@ function webFingerAndVerify(query, verifier) {
|
||||
module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
let user;
|
||||
|
||||
// Get 'user_id' parameter
|
||||
const [userId, userIdErr] = $(params.user_id).optional.id().$;
|
||||
if (userIdErr) return rej('invalid user_id param');
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).optional.id().$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Get 'username' parameter
|
||||
const [username, usernameErr] = $(params.username).optional.string().$;
|
||||
@ -69,25 +69,25 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
if (hostErr) return rej('invalid username param');
|
||||
|
||||
if (userId === undefined && typeof username !== 'string') {
|
||||
return rej('user_id or pair of username and host is required');
|
||||
return rej('userId or pair of username and host is required');
|
||||
}
|
||||
|
||||
// Lookup user
|
||||
if (typeof host === 'string') {
|
||||
const username_lower = username.toLowerCase();
|
||||
const host_lower_ascii = toASCII(host).toLowerCase();
|
||||
const host_lower = toUnicode(host_lower_ascii);
|
||||
const usernameLower = username.toLowerCase();
|
||||
const hostLower_ascii = toASCII(host).toLowerCase();
|
||||
const hostLower = toUnicode(hostLower_ascii);
|
||||
|
||||
user = await findUser({ username_lower, host_lower });
|
||||
user = await findUser({ usernameLower, hostLower });
|
||||
|
||||
if (user === null) {
|
||||
const acct_lower = `${username_lower}@${host_lower_ascii}`;
|
||||
const acct_lower = `${usernameLower}@${hostLower_ascii}`;
|
||||
let activityStreams;
|
||||
let finger;
|
||||
let followers_count;
|
||||
let following_count;
|
||||
let followersCount;
|
||||
let followingCount;
|
||||
let likes_count;
|
||||
let posts_count;
|
||||
let postsCount;
|
||||
|
||||
if (!validateUsername(username)) {
|
||||
return rej('username validation failed');
|
||||
@ -122,7 +122,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
activityStreams['@context'] === 'https://www.w3.org/ns/activitystreams') &&
|
||||
activityStreams.type === 'Person' &&
|
||||
typeof activityStreams.preferredUsername === 'string' &&
|
||||
activityStreams.preferredUsername.toLowerCase() === username_lower &&
|
||||
activityStreams.preferredUsername.toLowerCase() === usernameLower &&
|
||||
isValidName(activityStreams.name) &&
|
||||
isValidDescription(activityStreams.summary)
|
||||
)) {
|
||||
@ -130,7 +130,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
}
|
||||
|
||||
try {
|
||||
[followers_count, following_count, likes_count, posts_count] = await Promise.all([
|
||||
[followersCount, followingCount, likes_count, postsCount] = await Promise.all([
|
||||
getCollectionCount(activityStreams.followers),
|
||||
getCollectionCount(activityStreams.following),
|
||||
getCollectionCount(activityStreams.liked),
|
||||
@ -145,21 +145,21 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
|
||||
// Create user
|
||||
user = await User.insert({
|
||||
avatar_id: null,
|
||||
banner_id: null,
|
||||
created_at: new Date(),
|
||||
avatarId: null,
|
||||
bannerId: null,
|
||||
createdAt: new Date(),
|
||||
description: summaryDOM.textContent,
|
||||
followers_count,
|
||||
following_count,
|
||||
followersCount,
|
||||
followingCount,
|
||||
name: activityStreams.name,
|
||||
posts_count,
|
||||
postsCount,
|
||||
likes_count,
|
||||
liked_count: 0,
|
||||
drive_capacity: 1073741824, // 1GB
|
||||
driveCapacity: 1073741824, // 1GB
|
||||
username: username,
|
||||
username_lower,
|
||||
usernameLower,
|
||||
host: toUnicode(finger.subject.replace(/^.*?@/, '')),
|
||||
host_lower,
|
||||
hostLower,
|
||||
account: {
|
||||
uri: activityStreams.id,
|
||||
},
|
||||
@ -182,18 +182,18 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
|
||||
User.update({ _id: user._id }, {
|
||||
$set: {
|
||||
avatar_id: icon._id,
|
||||
banner_id: image._id,
|
||||
avatarId: icon._id,
|
||||
bannerId: image._id,
|
||||
},
|
||||
});
|
||||
|
||||
user.avatar_id = icon._id;
|
||||
user.banner_id = icon._id;
|
||||
user.avatarId = icon._id;
|
||||
user.bannerId = icon._id;
|
||||
}
|
||||
} else {
|
||||
const q = userId !== undefined
|
||||
? { _id: userId }
|
||||
: { username_lower: username.toLowerCase(), host: null };
|
||||
: { usernameLower: username.toLowerCase(), host: null };
|
||||
|
||||
user = await findUser(q);
|
||||
|
||||
|
Reference in New Issue
Block a user