Put activity pub sends inside transactions
This commit is contained in:
parent
5cd8054542
commit
25ed141c7c
|
@ -58,11 +58,11 @@ async function rateVideo (req: express.Request, res: express.Response) {
|
||||||
else if (previousRate.type === VIDEO_RATE_TYPES.DISLIKE) dislikesToIncrement--
|
else if (previousRate.type === VIDEO_RATE_TYPES.DISLIKE) dislikesToIncrement--
|
||||||
|
|
||||||
if (rateType === 'none') { // Destroy previous rate
|
if (rateType === 'none') { // Destroy previous rate
|
||||||
await previousRate.destroy()
|
await previousRate.destroy({ transaction: t })
|
||||||
} else { // Update previous rate
|
} else { // Update previous rate
|
||||||
previousRate.type = rateType
|
previousRate.type = rateType
|
||||||
|
|
||||||
await previousRate.save()
|
await previousRate.save({ transaction: t })
|
||||||
}
|
}
|
||||||
} else if (rateType !== 'none') { // There was not a previous rate, insert a new one if there is a rate
|
} else if (rateType !== 'none') { // There was not a previous rate, insert a new one if there is a rate
|
||||||
const query = {
|
const query = {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import * as Bluebird from 'bluebird'
|
||||||
import { VideoChannelObject, VideoTorrentObject } from '../../../../shared'
|
import { VideoChannelObject, VideoTorrentObject } from '../../../../shared'
|
||||||
import { ActivityUpdate } from '../../../../shared/models/activitypub/activity'
|
import { ActivityUpdate } from '../../../../shared/models/activitypub/activity'
|
||||||
import { retryTransactionWrapper } from '../../../helpers/database-utils'
|
import { retryTransactionWrapper } from '../../../helpers/database-utils'
|
||||||
|
@ -6,9 +7,8 @@ import { resetSequelizeInstance } from '../../../helpers/utils'
|
||||||
import { database as db } from '../../../initializers'
|
import { database as db } from '../../../initializers'
|
||||||
import { AccountInstance } from '../../../models/account/account-interface'
|
import { AccountInstance } from '../../../models/account/account-interface'
|
||||||
import { VideoInstance } from '../../../models/video/video-interface'
|
import { VideoInstance } from '../../../models/video/video-interface'
|
||||||
import { videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc'
|
|
||||||
import Bluebird = require('bluebird')
|
|
||||||
import { getOrCreateAccountAndServer } from '../account'
|
import { getOrCreateAccountAndServer } from '../account'
|
||||||
|
import { videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc'
|
||||||
|
|
||||||
async function processUpdateActivity (activity: ActivityUpdate) {
|
async function processUpdateActivity (activity: ActivityUpdate) {
|
||||||
const account = await getOrCreateAccountAndServer(activity.actor)
|
const account = await getOrCreateAccountAndServer(activity.actor)
|
||||||
|
|
|
@ -25,8 +25,8 @@ async function forwardActivity (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const toAccountFollowers = await db.Account.listByFollowersUrls(followersUrls)
|
const toAccountFollowers = await db.Account.listByFollowersUrls(followersUrls, t)
|
||||||
const uris = await computeFollowerUris(toAccountFollowers, followersException)
|
const uris = await computeFollowerUris(toAccountFollowers, followersException, t)
|
||||||
|
|
||||||
if (uris.length === 0) {
|
if (uris.length === 0) {
|
||||||
logger.info('0 followers for %s, no forwarding.', toAccountFollowers.map(a => a.id).join(', '))
|
logger.info('0 followers for %s, no forwarding.', toAccountFollowers.map(a => a.id).join(', '))
|
||||||
|
@ -50,7 +50,7 @@ async function broadcastToFollowers (
|
||||||
t: Transaction,
|
t: Transaction,
|
||||||
followersException: AccountInstance[] = []
|
followersException: AccountInstance[] = []
|
||||||
) {
|
) {
|
||||||
const uris = await computeFollowerUris(toAccountFollowers, followersException)
|
const uris = await computeFollowerUris(toAccountFollowers, followersException, t)
|
||||||
if (uris.length === 0) {
|
if (uris.length === 0) {
|
||||||
logger.info('0 followers for %s, no broadcasting.', toAccountFollowers.map(a => a.id).join(', '))
|
logger.info('0 followers for %s, no broadcasting.', toAccountFollowers.map(a => a.id).join(', '))
|
||||||
return undefined
|
return undefined
|
||||||
|
@ -100,22 +100,22 @@ function getObjectFollowersAudience (accountsInvolvedInObject: AccountInstance[]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getAccountsInvolvedInVideo (video: VideoInstance) {
|
async function getAccountsInvolvedInVideo (video: VideoInstance, t: Transaction) {
|
||||||
const accountsToForwardView = await db.VideoShare.loadAccountsByShare(video.id)
|
const accountsToForwardView = await db.VideoShare.loadAccountsByShare(video.id, t)
|
||||||
accountsToForwardView.push(video.VideoChannel.Account)
|
accountsToForwardView.push(video.VideoChannel.Account)
|
||||||
|
|
||||||
return accountsToForwardView
|
return accountsToForwardView
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getAccountsInvolvedInVideoChannel (videoChannel: VideoChannelInstance) {
|
async function getAccountsInvolvedInVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) {
|
||||||
const accountsToForwardView = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id)
|
const accountsToForwardView = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id, t)
|
||||||
accountsToForwardView.push(videoChannel.Account)
|
accountsToForwardView.push(videoChannel.Account)
|
||||||
|
|
||||||
return accountsToForwardView
|
return accountsToForwardView
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getAudience (accountSender: AccountInstance, isPublic = true) {
|
async function getAudience (accountSender: AccountInstance, t: Transaction, isPublic = true) {
|
||||||
const followerInboxUrls = await accountSender.getFollowerSharedInboxUrls()
|
const followerInboxUrls = await accountSender.getFollowerSharedInboxUrls(t)
|
||||||
|
|
||||||
// Thanks Mastodon: https://github.com/tootsuite/mastodon/blob/master/app/lib/activitypub/tag_manager.rb#L47
|
// Thanks Mastodon: https://github.com/tootsuite/mastodon/blob/master/app/lib/activitypub/tag_manager.rb#L47
|
||||||
let to = []
|
let to = []
|
||||||
|
@ -132,10 +132,10 @@ async function getAudience (accountSender: AccountInstance, isPublic = true) {
|
||||||
return { to, cc }
|
return { to, cc }
|
||||||
}
|
}
|
||||||
|
|
||||||
async function computeFollowerUris (toAccountFollower: AccountInstance[], followersException: AccountInstance[]) {
|
async function computeFollowerUris (toAccountFollower: AccountInstance[], followersException: AccountInstance[], t: Transaction) {
|
||||||
const toAccountFollowerIds = toAccountFollower.map(a => a.id)
|
const toAccountFollowerIds = toAccountFollower.map(a => a.id)
|
||||||
|
|
||||||
const result = await db.AccountFollow.listAcceptedFollowerSharedInboxUrls(toAccountFollowerIds)
|
const result = await db.AccountFollow.listAcceptedFollowerSharedInboxUrls(toAccountFollowerIds, t)
|
||||||
const followersSharedInboxException = followersException.map(f => f.sharedInboxUrl)
|
const followersSharedInboxException = followersException.map(f => f.sharedInboxUrl)
|
||||||
const uris = result.data.filter(sharedInbox => followersSharedInboxException.indexOf(sharedInbox) === -1)
|
const uris = result.data.filter(sharedInbox => followersSharedInboxException.indexOf(sharedInbox) === -1)
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ async function sendAccept (accountFollow: AccountFollowInstance, t: Transaction)
|
||||||
const me = accountFollow.AccountFollowing
|
const me = accountFollow.AccountFollowing
|
||||||
|
|
||||||
const url = getAccountFollowAcceptActivityPubUrl(accountFollow)
|
const url = getAccountFollowAcceptActivityPubUrl(accountFollow)
|
||||||
const data = await acceptActivityData(url, me)
|
const data = acceptActivityData(url, me)
|
||||||
|
|
||||||
return unicastTo(data, me, follower.inboxUrl, t)
|
return unicastTo(data, me, follower.inboxUrl, t)
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ export {
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
async function acceptActivityData (url: string, byAccount: AccountInstance) {
|
function acceptActivityData (url: string, byAccount: AccountInstance) {
|
||||||
const activity: ActivityAccept = {
|
const activity: ActivityAccept = {
|
||||||
type: 'Accept',
|
type: 'Accept',
|
||||||
id: url,
|
id: url,
|
||||||
|
|
|
@ -8,15 +8,22 @@ async function sendAddVideo (video: VideoInstance, t: Transaction) {
|
||||||
const byAccount = video.VideoChannel.Account
|
const byAccount = video.VideoChannel.Account
|
||||||
|
|
||||||
const videoObject = video.toActivityPubObject()
|
const videoObject = video.toActivityPubObject()
|
||||||
const data = await addActivityData(video.url, byAccount, video, video.VideoChannel.url, videoObject)
|
const data = await addActivityData(video.url, byAccount, video, video.VideoChannel.url, videoObject, t)
|
||||||
|
|
||||||
return broadcastToFollowers(data, byAccount, [ byAccount ], t)
|
return broadcastToFollowers(data, byAccount, [ byAccount ], t)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addActivityData (url: string, byAccount: AccountInstance, video: VideoInstance, target: string, object: any) {
|
async function addActivityData (
|
||||||
|
url: string,
|
||||||
|
byAccount: AccountInstance,
|
||||||
|
video: VideoInstance,
|
||||||
|
target: string,
|
||||||
|
object: any,
|
||||||
|
t: Transaction
|
||||||
|
) {
|
||||||
const videoPublic = video.privacy === VideoPrivacy.PUBLIC
|
const videoPublic = video.privacy === VideoPrivacy.PUBLIC
|
||||||
|
|
||||||
const { to, cc } = await getAudience(byAccount, videoPublic)
|
const { to, cc } = await getAudience(byAccount, t, videoPublic)
|
||||||
const activity: ActivityAdd = {
|
const activity: ActivityAdd = {
|
||||||
type: 'Add',
|
type: 'Add',
|
||||||
id: url,
|
id: url,
|
||||||
|
|
|
@ -21,11 +21,11 @@ async function buildVideoAnnounceToFollowers (byAccount: AccountInstance, video:
|
||||||
const url = getAnnounceActivityPubUrl(video.url, byAccount)
|
const url = getAnnounceActivityPubUrl(video.url, byAccount)
|
||||||
|
|
||||||
const videoChannel = video.VideoChannel
|
const videoChannel = video.VideoChannel
|
||||||
const announcedActivity = await addActivityData(url, videoChannel.Account, video, videoChannel.url, video.toActivityPubObject())
|
const announcedActivity = await addActivityData(url, videoChannel.Account, video, videoChannel.url, video.toActivityPubObject(), t)
|
||||||
|
|
||||||
const accountsToForwardView = await getAccountsInvolvedInVideo(video)
|
const accountsToForwardView = await getAccountsInvolvedInVideo(video, t)
|
||||||
const audience = getObjectFollowersAudience(accountsToForwardView)
|
const audience = getObjectFollowersAudience(accountsToForwardView)
|
||||||
const data = await announceActivityData(url, byAccount, announcedActivity, audience)
|
const data = await announceActivityData(url, byAccount, announcedActivity, t, audience)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
@ -40,22 +40,22 @@ async function sendVideoAnnounceToOrigin (byAccount: AccountInstance, video: Vid
|
||||||
const url = getAnnounceActivityPubUrl(video.url, byAccount)
|
const url = getAnnounceActivityPubUrl(video.url, byAccount)
|
||||||
|
|
||||||
const videoChannel = video.VideoChannel
|
const videoChannel = video.VideoChannel
|
||||||
const announcedActivity = await addActivityData(url, videoChannel.Account, video, videoChannel.url, video.toActivityPubObject())
|
const announcedActivity = await addActivityData(url, videoChannel.Account, video, videoChannel.url, video.toActivityPubObject(), t)
|
||||||
|
|
||||||
const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video)
|
const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t)
|
||||||
const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
|
const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
|
||||||
const data = await createActivityData(url, byAccount, announcedActivity, audience)
|
const data = await createActivityData(url, byAccount, announcedActivity, t, audience)
|
||||||
|
|
||||||
return unicastTo(data, byAccount, videoChannel.Account.sharedInboxUrl, t)
|
return unicastTo(data, byAccount, videoChannel.Account.sharedInboxUrl, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function buildVideoChannelAnnounceToFollowers (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Transaction) {
|
async function buildVideoChannelAnnounceToFollowers (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Transaction) {
|
||||||
const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount)
|
const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount)
|
||||||
const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject())
|
const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject(), t)
|
||||||
|
|
||||||
const accountsToForwardView = await getAccountsInvolvedInVideoChannel(videoChannel)
|
const accountsToForwardView = await getAccountsInvolvedInVideoChannel(videoChannel, t)
|
||||||
const audience = getObjectFollowersAudience(accountsToForwardView)
|
const audience = getObjectFollowersAudience(accountsToForwardView)
|
||||||
const data = await announceActivityData(url, byAccount, announcedActivity, audience)
|
const data = await announceActivityData(url, byAccount, announcedActivity, t, audience)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
@ -68,11 +68,11 @@ async function sendVideoChannelAnnounceToFollowers (byAccount: AccountInstance,
|
||||||
|
|
||||||
async function sendVideoChannelAnnounceToOrigin (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Transaction) {
|
async function sendVideoChannelAnnounceToOrigin (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Transaction) {
|
||||||
const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount)
|
const url = getAnnounceActivityPubUrl(videoChannel.url, byAccount)
|
||||||
const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject())
|
const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject(), t)
|
||||||
|
|
||||||
const accountsInvolvedInVideo = await getAccountsInvolvedInVideoChannel(videoChannel)
|
const accountsInvolvedInVideo = await getAccountsInvolvedInVideoChannel(videoChannel, t)
|
||||||
const audience = getOriginVideoChannelAudience(videoChannel, accountsInvolvedInVideo)
|
const audience = getOriginVideoChannelAudience(videoChannel, accountsInvolvedInVideo)
|
||||||
const data = await createActivityData(url, byAccount, announcedActivity, audience)
|
const data = await createActivityData(url, byAccount, announcedActivity, t, audience)
|
||||||
|
|
||||||
return unicastTo(data, byAccount, videoChannel.Account.sharedInboxUrl, t)
|
return unicastTo(data, byAccount, videoChannel.Account.sharedInboxUrl, t)
|
||||||
}
|
}
|
||||||
|
@ -81,10 +81,11 @@ async function announceActivityData (
|
||||||
url: string,
|
url: string,
|
||||||
byAccount: AccountInstance,
|
byAccount: AccountInstance,
|
||||||
object: ActivityCreate | ActivityAdd,
|
object: ActivityCreate | ActivityAdd,
|
||||||
|
t: Transaction,
|
||||||
audience?: ActivityAudience
|
audience?: ActivityAudience
|
||||||
) {
|
) {
|
||||||
if (!audience) {
|
if (!audience) {
|
||||||
audience = await getAudience(byAccount)
|
audience = await getAudience(byAccount, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
const activity: ActivityAnnounce = {
|
const activity: ActivityAnnounce = {
|
||||||
|
|
|
@ -8,8 +8,8 @@ import {
|
||||||
broadcastToFollowers,
|
broadcastToFollowers,
|
||||||
getAccountsInvolvedInVideo,
|
getAccountsInvolvedInVideo,
|
||||||
getAudience,
|
getAudience,
|
||||||
getOriginVideoAudience,
|
|
||||||
getObjectFollowersAudience,
|
getObjectFollowersAudience,
|
||||||
|
getOriginVideoAudience,
|
||||||
unicastTo
|
unicastTo
|
||||||
} from './misc'
|
} from './misc'
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ async function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Tr
|
||||||
const byAccount = videoChannel.Account
|
const byAccount = videoChannel.Account
|
||||||
|
|
||||||
const videoChannelObject = videoChannel.toActivityPubObject()
|
const videoChannelObject = videoChannel.toActivityPubObject()
|
||||||
const data = await createActivityData(videoChannel.url, byAccount, videoChannelObject)
|
const data = await createActivityData(videoChannel.url, byAccount, videoChannelObject, t)
|
||||||
|
|
||||||
return broadcastToFollowers(data, byAccount, [ byAccount ], t)
|
return broadcastToFollowers(data, byAccount, [ byAccount ], t)
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ async function sendVideoAbuse (byAccount: AccountInstance, videoAbuse: VideoAbus
|
||||||
const url = getVideoAbuseActivityPubUrl(videoAbuse)
|
const url = getVideoAbuseActivityPubUrl(videoAbuse)
|
||||||
|
|
||||||
const audience = { to: [ video.VideoChannel.Account.url ], cc: [] }
|
const audience = { to: [ video.VideoChannel.Account.url ], cc: [] }
|
||||||
const data = await createActivityData(url, byAccount, videoAbuse.toActivityPubObject(), audience)
|
const data = await createActivityData(url, byAccount, videoAbuse.toActivityPubObject(), t, audience)
|
||||||
|
|
||||||
return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
|
return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
|
||||||
}
|
}
|
||||||
|
@ -35,9 +35,9 @@ async function sendCreateViewToOrigin (byAccount: AccountInstance, video: VideoI
|
||||||
const url = getVideoViewActivityPubUrl(byAccount, video)
|
const url = getVideoViewActivityPubUrl(byAccount, video)
|
||||||
const viewActivity = createViewActivityData(byAccount, video)
|
const viewActivity = createViewActivityData(byAccount, video)
|
||||||
|
|
||||||
const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video)
|
const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t)
|
||||||
const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
|
const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
|
||||||
const data = await createActivityData(url, byAccount, viewActivity, audience)
|
const data = await createActivityData(url, byAccount, viewActivity, t, audience)
|
||||||
|
|
||||||
return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
|
return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
|
||||||
}
|
}
|
||||||
|
@ -46,9 +46,9 @@ async function sendCreateViewToVideoFollowers (byAccount: AccountInstance, video
|
||||||
const url = getVideoViewActivityPubUrl(byAccount, video)
|
const url = getVideoViewActivityPubUrl(byAccount, video)
|
||||||
const viewActivity = createViewActivityData(byAccount, video)
|
const viewActivity = createViewActivityData(byAccount, video)
|
||||||
|
|
||||||
const accountsToForwardView = await getAccountsInvolvedInVideo(video)
|
const accountsToForwardView = await getAccountsInvolvedInVideo(video, t)
|
||||||
const audience = getObjectFollowersAudience(accountsToForwardView)
|
const audience = getObjectFollowersAudience(accountsToForwardView)
|
||||||
const data = await createActivityData(url, byAccount, viewActivity, audience)
|
const data = await createActivityData(url, byAccount, viewActivity, t, audience)
|
||||||
|
|
||||||
// Use the server account to send the view, because it could be an unregistered account
|
// Use the server account to send the view, because it could be an unregistered account
|
||||||
const serverAccount = await getServerAccount()
|
const serverAccount = await getServerAccount()
|
||||||
|
@ -60,9 +60,9 @@ async function sendCreateDislikeToOrigin (byAccount: AccountInstance, video: Vid
|
||||||
const url = getVideoDislikeActivityPubUrl(byAccount, video)
|
const url = getVideoDislikeActivityPubUrl(byAccount, video)
|
||||||
const dislikeActivity = createDislikeActivityData(byAccount, video)
|
const dislikeActivity = createDislikeActivityData(byAccount, video)
|
||||||
|
|
||||||
const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video)
|
const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t)
|
||||||
const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
|
const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
|
||||||
const data = await createActivityData(url, byAccount, dislikeActivity, audience)
|
const data = await createActivityData(url, byAccount, dislikeActivity, t, audience)
|
||||||
|
|
||||||
return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
|
return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
|
||||||
}
|
}
|
||||||
|
@ -71,17 +71,17 @@ async function sendCreateDislikeToVideoFollowers (byAccount: AccountInstance, vi
|
||||||
const url = getVideoDislikeActivityPubUrl(byAccount, video)
|
const url = getVideoDislikeActivityPubUrl(byAccount, video)
|
||||||
const dislikeActivity = createDislikeActivityData(byAccount, video)
|
const dislikeActivity = createDislikeActivityData(byAccount, video)
|
||||||
|
|
||||||
const accountsToForwardView = await getAccountsInvolvedInVideo(video)
|
const accountsToForwardView = await getAccountsInvolvedInVideo(video, t)
|
||||||
const audience = getObjectFollowersAudience(accountsToForwardView)
|
const audience = getObjectFollowersAudience(accountsToForwardView)
|
||||||
const data = await createActivityData(url, byAccount, dislikeActivity, audience)
|
const data = await createActivityData(url, byAccount, dislikeActivity, t, audience)
|
||||||
|
|
||||||
const followersException = [ byAccount ]
|
const followersException = [ byAccount ]
|
||||||
return broadcastToFollowers(data, byAccount, accountsToForwardView, t, followersException)
|
return broadcastToFollowers(data, byAccount, accountsToForwardView, t, followersException)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createActivityData (url: string, byAccount: AccountInstance, object: any, audience?: ActivityAudience) {
|
async function createActivityData (url: string, byAccount: AccountInstance, object: any, t: Transaction, audience?: ActivityAudience) {
|
||||||
if (!audience) {
|
if (!audience) {
|
||||||
audience = await getAudience(byAccount)
|
audience = await getAudience(byAccount, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
const activity: ActivityCreate = {
|
const activity: ActivityCreate = {
|
||||||
|
|
|
@ -7,9 +7,9 @@ import { broadcastToFollowers } from './misc'
|
||||||
async function sendDeleteVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) {
|
async function sendDeleteVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) {
|
||||||
const byAccount = videoChannel.Account
|
const byAccount = videoChannel.Account
|
||||||
|
|
||||||
const data = await deleteActivityData(videoChannel.url, byAccount)
|
const data = deleteActivityData(videoChannel.url, byAccount)
|
||||||
|
|
||||||
const accountsInvolved = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id)
|
const accountsInvolved = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id, t)
|
||||||
accountsInvolved.push(byAccount)
|
accountsInvolved.push(byAccount)
|
||||||
|
|
||||||
return broadcastToFollowers(data, byAccount, accountsInvolved, t)
|
return broadcastToFollowers(data, byAccount, accountsInvolved, t)
|
||||||
|
@ -18,9 +18,9 @@ async function sendDeleteVideoChannel (videoChannel: VideoChannelInstance, t: Tr
|
||||||
async function sendDeleteVideo (video: VideoInstance, t: Transaction) {
|
async function sendDeleteVideo (video: VideoInstance, t: Transaction) {
|
||||||
const byAccount = video.VideoChannel.Account
|
const byAccount = video.VideoChannel.Account
|
||||||
|
|
||||||
const data = await deleteActivityData(video.url, byAccount)
|
const data = deleteActivityData(video.url, byAccount)
|
||||||
|
|
||||||
const accountsInvolved = await db.VideoShare.loadAccountsByShare(video.id)
|
const accountsInvolved = await db.VideoShare.loadAccountsByShare(video.id, t)
|
||||||
accountsInvolved.push(byAccount)
|
accountsInvolved.push(byAccount)
|
||||||
|
|
||||||
return broadcastToFollowers(data, byAccount, accountsInvolved, t)
|
return broadcastToFollowers(data, byAccount, accountsInvolved, t)
|
||||||
|
@ -42,7 +42,7 @@ export {
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
async function deleteActivityData (url: string, byAccount: AccountInstance) {
|
function deleteActivityData (url: string, byAccount: AccountInstance) {
|
||||||
const activity: ActivityDelete = {
|
const activity: ActivityDelete = {
|
||||||
type: 'Delete',
|
type: 'Delete',
|
||||||
id: url,
|
id: url,
|
||||||
|
|
|
@ -5,17 +5,17 @@ import { AccountFollowInstance } from '../../../models/account/account-follow-in
|
||||||
import { getAccountFollowActivityPubUrl } from '../url'
|
import { getAccountFollowActivityPubUrl } from '../url'
|
||||||
import { unicastTo } from './misc'
|
import { unicastTo } from './misc'
|
||||||
|
|
||||||
async function sendFollow (accountFollow: AccountFollowInstance, t: Transaction) {
|
function sendFollow (accountFollow: AccountFollowInstance, t: Transaction) {
|
||||||
const me = accountFollow.AccountFollower
|
const me = accountFollow.AccountFollower
|
||||||
const following = accountFollow.AccountFollowing
|
const following = accountFollow.AccountFollowing
|
||||||
|
|
||||||
const url = getAccountFollowActivityPubUrl(accountFollow)
|
const url = getAccountFollowActivityPubUrl(accountFollow)
|
||||||
const data = await followActivityData(url, me, following)
|
const data = followActivityData(url, me, following)
|
||||||
|
|
||||||
return unicastTo(data, me, following.inboxUrl, t)
|
return unicastTo(data, me, following.inboxUrl, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function followActivityData (url: string, byAccount: AccountInstance, targetAccount: AccountInstance) {
|
function followActivityData (url: string, byAccount: AccountInstance, targetAccount: AccountInstance) {
|
||||||
const activity: ActivityFollow = {
|
const activity: ActivityFollow = {
|
||||||
type: 'Follow',
|
type: 'Follow',
|
||||||
id: url,
|
id: url,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Transaction } from 'sequelize'
|
import { Transaction } from 'sequelize'
|
||||||
import { ActivityLike } from '../../../../shared/models/activitypub/activity'
|
import { ActivityAudience, ActivityLike } from '../../../../shared/models/activitypub/activity'
|
||||||
import { AccountInstance, VideoInstance } from '../../../models'
|
import { AccountInstance, VideoInstance } from '../../../models'
|
||||||
import { getVideoLikeActivityPubUrl } from '../url'
|
import { getVideoLikeActivityPubUrl } from '../url'
|
||||||
import {
|
import {
|
||||||
|
@ -14,9 +14,9 @@ import {
|
||||||
async function sendLikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
|
async function sendLikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
|
||||||
const url = getVideoLikeActivityPubUrl(byAccount, video)
|
const url = getVideoLikeActivityPubUrl(byAccount, video)
|
||||||
|
|
||||||
const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video)
|
const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t)
|
||||||
const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
|
const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
|
||||||
const data = await likeActivityData(url, byAccount, video, audience)
|
const data = await likeActivityData(url, byAccount, video, t, audience)
|
||||||
|
|
||||||
return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
|
return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
|
||||||
}
|
}
|
||||||
|
@ -24,19 +24,23 @@ async function sendLikeToOrigin (byAccount: AccountInstance, video: VideoInstanc
|
||||||
async function sendLikeToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
|
async function sendLikeToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
|
||||||
const url = getVideoLikeActivityPubUrl(byAccount, video)
|
const url = getVideoLikeActivityPubUrl(byAccount, video)
|
||||||
|
|
||||||
const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video)
|
const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t)
|
||||||
const audience = getObjectFollowersAudience(accountsInvolvedInVideo)
|
const audience = getObjectFollowersAudience(accountsInvolvedInVideo)
|
||||||
const data = await likeActivityData(url, byAccount, video, audience)
|
const data = await likeActivityData(url, byAccount, video, t, audience)
|
||||||
|
|
||||||
const toAccountsFollowers = await getAccountsInvolvedInVideo(video)
|
|
||||||
|
|
||||||
const followersException = [ byAccount ]
|
const followersException = [ byAccount ]
|
||||||
return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException)
|
return broadcastToFollowers(data, byAccount, accountsInvolvedInVideo, t, followersException)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function likeActivityData (url: string, byAccount: AccountInstance, video: VideoInstance, audience?: { to: string[], cc: string[] }) {
|
async function likeActivityData (
|
||||||
|
url: string,
|
||||||
|
byAccount: AccountInstance,
|
||||||
|
video: VideoInstance,
|
||||||
|
t: Transaction,
|
||||||
|
audience?: ActivityAudience
|
||||||
|
) {
|
||||||
if (!audience) {
|
if (!audience) {
|
||||||
audience = await getAudience(byAccount)
|
audience = await getAudience(byAccount, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
const activity: ActivityLike = {
|
const activity: ActivityLike = {
|
||||||
|
|
|
@ -29,8 +29,8 @@ async function sendUndoFollow (accountFollow: AccountFollowInstance, t: Transact
|
||||||
const followUrl = getAccountFollowActivityPubUrl(accountFollow)
|
const followUrl = getAccountFollowActivityPubUrl(accountFollow)
|
||||||
const undoUrl = getUndoActivityPubUrl(followUrl)
|
const undoUrl = getUndoActivityPubUrl(followUrl)
|
||||||
|
|
||||||
const object = await followActivityData(followUrl, me, following)
|
const object = followActivityData(followUrl, me, following)
|
||||||
const data = await undoActivityData(undoUrl, me, object)
|
const data = await undoActivityData(undoUrl, me, object, t)
|
||||||
|
|
||||||
return unicastTo(data, me, following.inboxUrl, t)
|
return unicastTo(data, me, following.inboxUrl, t)
|
||||||
}
|
}
|
||||||
|
@ -39,10 +39,10 @@ async function sendUndoLikeToOrigin (byAccount: AccountInstance, video: VideoIns
|
||||||
const likeUrl = getVideoLikeActivityPubUrl(byAccount, video)
|
const likeUrl = getVideoLikeActivityPubUrl(byAccount, video)
|
||||||
const undoUrl = getUndoActivityPubUrl(likeUrl)
|
const undoUrl = getUndoActivityPubUrl(likeUrl)
|
||||||
|
|
||||||
const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video)
|
const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t)
|
||||||
const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
|
const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
|
||||||
const object = await likeActivityData(likeUrl, byAccount, video)
|
const object = await likeActivityData(likeUrl, byAccount, video, t)
|
||||||
const data = await undoActivityData(undoUrl, byAccount, object, audience)
|
const data = await undoActivityData(undoUrl, byAccount, object, t, audience)
|
||||||
|
|
||||||
return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
|
return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
|
||||||
}
|
}
|
||||||
|
@ -51,10 +51,10 @@ async function sendUndoLikeToVideoFollowers (byAccount: AccountInstance, video:
|
||||||
const likeUrl = getVideoLikeActivityPubUrl(byAccount, video)
|
const likeUrl = getVideoLikeActivityPubUrl(byAccount, video)
|
||||||
const undoUrl = getUndoActivityPubUrl(likeUrl)
|
const undoUrl = getUndoActivityPubUrl(likeUrl)
|
||||||
|
|
||||||
const toAccountsFollowers = await getAccountsInvolvedInVideo(video)
|
const toAccountsFollowers = await getAccountsInvolvedInVideo(video, t)
|
||||||
const audience = getObjectFollowersAudience(toAccountsFollowers)
|
const audience = getObjectFollowersAudience(toAccountsFollowers)
|
||||||
const object = await likeActivityData(likeUrl, byAccount, video)
|
const object = await likeActivityData(likeUrl, byAccount, video, t)
|
||||||
const data = await undoActivityData(undoUrl, byAccount, object, audience)
|
const data = await undoActivityData(undoUrl, byAccount, object, t, audience)
|
||||||
|
|
||||||
const followersException = [ byAccount ]
|
const followersException = [ byAccount ]
|
||||||
return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException)
|
return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException)
|
||||||
|
@ -64,12 +64,12 @@ async function sendUndoDislikeToOrigin (byAccount: AccountInstance, video: Video
|
||||||
const dislikeUrl = getVideoDislikeActivityPubUrl(byAccount, video)
|
const dislikeUrl = getVideoDislikeActivityPubUrl(byAccount, video)
|
||||||
const undoUrl = getUndoActivityPubUrl(dislikeUrl)
|
const undoUrl = getUndoActivityPubUrl(dislikeUrl)
|
||||||
|
|
||||||
const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video)
|
const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t)
|
||||||
const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
|
const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
|
||||||
const dislikeActivity = createDislikeActivityData(byAccount, video)
|
const dislikeActivity = createDislikeActivityData(byAccount, video)
|
||||||
const object = await createActivityData(undoUrl, byAccount, dislikeActivity, audience)
|
const object = await createActivityData(undoUrl, byAccount, dislikeActivity, t, audience)
|
||||||
|
|
||||||
const data = await undoActivityData(undoUrl, byAccount, object)
|
const data = await undoActivityData(undoUrl, byAccount, object, t)
|
||||||
|
|
||||||
return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
|
return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
|
||||||
}
|
}
|
||||||
|
@ -79,11 +79,11 @@ async function sendUndoDislikeToVideoFollowers (byAccount: AccountInstance, vide
|
||||||
const undoUrl = getUndoActivityPubUrl(dislikeUrl)
|
const undoUrl = getUndoActivityPubUrl(dislikeUrl)
|
||||||
|
|
||||||
const dislikeActivity = createDislikeActivityData(byAccount, video)
|
const dislikeActivity = createDislikeActivityData(byAccount, video)
|
||||||
const object = await createActivityData(undoUrl, byAccount, dislikeActivity)
|
const object = await createActivityData(undoUrl, byAccount, dislikeActivity, t)
|
||||||
|
|
||||||
const data = await undoActivityData(undoUrl, byAccount, object)
|
const data = await undoActivityData(undoUrl, byAccount, object, t)
|
||||||
|
|
||||||
const toAccountsFollowers = await getAccountsInvolvedInVideo(video)
|
const toAccountsFollowers = await getAccountsInvolvedInVideo(video, t)
|
||||||
|
|
||||||
const followersException = [ byAccount ]
|
const followersException = [ byAccount ]
|
||||||
return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException)
|
return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException)
|
||||||
|
@ -105,10 +105,11 @@ async function undoActivityData (
|
||||||
url: string,
|
url: string,
|
||||||
byAccount: AccountInstance,
|
byAccount: AccountInstance,
|
||||||
object: ActivityFollow | ActivityLike | ActivityCreate,
|
object: ActivityFollow | ActivityLike | ActivityCreate,
|
||||||
|
t: Transaction,
|
||||||
audience?: ActivityAudience
|
audience?: ActivityAudience
|
||||||
) {
|
) {
|
||||||
if (!audience) {
|
if (!audience) {
|
||||||
audience = await getAudience(byAccount)
|
audience = await getAudience(byAccount, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
const activity: ActivityUndo = {
|
const activity: ActivityUndo = {
|
||||||
|
|
|
@ -10,9 +10,9 @@ async function sendUpdateVideoChannel (videoChannel: VideoChannelInstance, t: Tr
|
||||||
|
|
||||||
const url = getUpdateActivityPubUrl(videoChannel.url, videoChannel.updatedAt.toISOString())
|
const url = getUpdateActivityPubUrl(videoChannel.url, videoChannel.updatedAt.toISOString())
|
||||||
const videoChannelObject = videoChannel.toActivityPubObject()
|
const videoChannelObject = videoChannel.toActivityPubObject()
|
||||||
const data = await updateActivityData(url, byAccount, videoChannelObject)
|
const data = await updateActivityData(url, byAccount, videoChannelObject, t)
|
||||||
|
|
||||||
const accountsInvolved = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id)
|
const accountsInvolved = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id, t)
|
||||||
accountsInvolved.push(byAccount)
|
accountsInvolved.push(byAccount)
|
||||||
|
|
||||||
return broadcastToFollowers(data, byAccount, accountsInvolved, t)
|
return broadcastToFollowers(data, byAccount, accountsInvolved, t)
|
||||||
|
@ -23,9 +23,9 @@ async function sendUpdateVideo (video: VideoInstance, t: Transaction) {
|
||||||
|
|
||||||
const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString())
|
const url = getUpdateActivityPubUrl(video.url, video.updatedAt.toISOString())
|
||||||
const videoObject = video.toActivityPubObject()
|
const videoObject = video.toActivityPubObject()
|
||||||
const data = await updateActivityData(url, byAccount, videoObject)
|
const data = await updateActivityData(url, byAccount, videoObject, t)
|
||||||
|
|
||||||
const accountsInvolved = await db.VideoShare.loadAccountsByShare(video.id)
|
const accountsInvolved = await db.VideoShare.loadAccountsByShare(video.id, t)
|
||||||
accountsInvolved.push(byAccount)
|
accountsInvolved.push(byAccount)
|
||||||
|
|
||||||
return broadcastToFollowers(data, byAccount, accountsInvolved, t)
|
return broadcastToFollowers(data, byAccount, accountsInvolved, t)
|
||||||
|
@ -40,8 +40,8 @@ export {
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
async function updateActivityData (url: string, byAccount: AccountInstance, object: any) {
|
async function updateActivityData (url: string, byAccount: AccountInstance, object: any, t: Transaction) {
|
||||||
const { to, cc } = await getAudience(byAccount)
|
const { to, cc } = await getAudience(byAccount, t)
|
||||||
const activity: ActivityUpdate = {
|
const activity: ActivityUpdate = {
|
||||||
type: 'Update',
|
type: 'Update',
|
||||||
id: url,
|
id: url,
|
||||||
|
|
|
@ -14,9 +14,19 @@ export namespace AccountFollowMethods {
|
||||||
export type ListFollowingForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountFollowInstance>>
|
export type ListFollowingForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountFollowInstance>>
|
||||||
export type ListFollowersForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountFollowInstance>>
|
export type ListFollowersForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountFollowInstance>>
|
||||||
|
|
||||||
export type ListAcceptedFollowerUrlsForApi = (accountId: number[], start?: number, count?: number) => Promise< ResultList<string> >
|
export type ListAcceptedFollowerUrlsForApi = (
|
||||||
export type ListAcceptedFollowingUrlsForApi = (accountId: number[], start?: number, count?: number) => Promise< ResultList<string> >
|
accountId: number[],
|
||||||
export type ListAcceptedFollowerSharedInboxUrls = (accountId: number[]) => Promise< ResultList<string> >
|
t: Sequelize.Transaction,
|
||||||
|
start?: number,
|
||||||
|
count?: number
|
||||||
|
) => Promise< ResultList<string> >
|
||||||
|
export type ListAcceptedFollowingUrlsForApi = (
|
||||||
|
accountId: number[],
|
||||||
|
t: Sequelize.Transaction,
|
||||||
|
start?: number,
|
||||||
|
count?: number
|
||||||
|
) => Promise< ResultList<string> >
|
||||||
|
export type ListAcceptedFollowerSharedInboxUrls = (accountId: number[], t: Sequelize.Transaction) => Promise< ResultList<string> >
|
||||||
export type ToFormattedJSON = (this: AccountFollowInstance) => AccountFollow
|
export type ToFormattedJSON = (this: AccountFollowInstance) => AccountFollow
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -181,16 +181,16 @@ listFollowersForApi = function (id: number, start: number, count: number, sort:
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
listAcceptedFollowerUrlsForApi = function (accountIds: number[], start?: number, count?: number) {
|
listAcceptedFollowerUrlsForApi = function (accountIds: number[], t: Sequelize.Transaction, start?: number, count?: number) {
|
||||||
return createListAcceptedFollowForApiQuery('followers', accountIds, start, count)
|
return createListAcceptedFollowForApiQuery('followers', accountIds, t, start, count)
|
||||||
}
|
}
|
||||||
|
|
||||||
listAcceptedFollowerSharedInboxUrls = function (accountIds: number[]) {
|
listAcceptedFollowerSharedInboxUrls = function (accountIds: number[], t: Sequelize.Transaction) {
|
||||||
return createListAcceptedFollowForApiQuery('followers', accountIds, undefined, undefined, 'sharedInboxUrl')
|
return createListAcceptedFollowForApiQuery('followers', accountIds, t, undefined, undefined, 'sharedInboxUrl')
|
||||||
}
|
}
|
||||||
|
|
||||||
listAcceptedFollowingUrlsForApi = function (accountIds: number[], start?: number, count?: number) {
|
listAcceptedFollowingUrlsForApi = function (accountIds: number[], t: Sequelize.Transaction, start?: number, count?: number) {
|
||||||
return createListAcceptedFollowForApiQuery('following', accountIds, start, count)
|
return createListAcceptedFollowForApiQuery('following', accountIds, t, start, count)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------ UTILS ------------------------------
|
// ------------------------------ UTILS ------------------------------
|
||||||
|
@ -198,6 +198,7 @@ listAcceptedFollowingUrlsForApi = function (accountIds: number[], start?: number
|
||||||
async function createListAcceptedFollowForApiQuery (
|
async function createListAcceptedFollowForApiQuery (
|
||||||
type: 'followers' | 'following',
|
type: 'followers' | 'following',
|
||||||
accountIds: number[],
|
accountIds: number[],
|
||||||
|
t: Sequelize.Transaction,
|
||||||
start?: number,
|
start?: number,
|
||||||
count?: number,
|
count?: number,
|
||||||
columnUrl = 'url'
|
columnUrl = 'url'
|
||||||
|
@ -227,7 +228,8 @@ async function createListAcceptedFollowForApiQuery (
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
bind: { accountIds },
|
bind: { accountIds },
|
||||||
type: Sequelize.QueryTypes.SELECT
|
type: Sequelize.QueryTypes.SELECT,
|
||||||
|
transaction: t
|
||||||
}
|
}
|
||||||
tasks.push(AccountFollow['sequelize'].query(query, options))
|
tasks.push(AccountFollow['sequelize'].query(query, options))
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,12 +12,12 @@ export namespace AccountMethods {
|
||||||
export type LoadByUrl = (url: string, transaction?: Sequelize.Transaction) => Bluebird<AccountInstance>
|
export type LoadByUrl = (url: string, transaction?: Sequelize.Transaction) => Bluebird<AccountInstance>
|
||||||
export type LoadLocalByName = (name: string) => Bluebird<AccountInstance>
|
export type LoadLocalByName = (name: string) => Bluebird<AccountInstance>
|
||||||
export type LoadByNameAndHost = (name: string, host: string) => Bluebird<AccountInstance>
|
export type LoadByNameAndHost = (name: string, host: string) => Bluebird<AccountInstance>
|
||||||
export type ListByFollowersUrls = (followerUrls: string[], transaction?: Sequelize.Transaction) => Bluebird<AccountInstance[]>
|
export type ListByFollowersUrls = (followerUrls: string[], transaction: Sequelize.Transaction) => Bluebird<AccountInstance[]>
|
||||||
|
|
||||||
export type ToActivityPubObject = (this: AccountInstance) => ActivityPubActor
|
export type ToActivityPubObject = (this: AccountInstance) => ActivityPubActor
|
||||||
export type ToFormattedJSON = (this: AccountInstance) => FormattedAccount
|
export type ToFormattedJSON = (this: AccountInstance) => FormattedAccount
|
||||||
export type IsOwned = (this: AccountInstance) => boolean
|
export type IsOwned = (this: AccountInstance) => boolean
|
||||||
export type GetFollowerSharedInboxUrls = (this: AccountInstance) => Bluebird<string[]>
|
export type GetFollowerSharedInboxUrls = (this: AccountInstance, t: Sequelize.Transaction) => Bluebird<string[]>
|
||||||
export type GetFollowingUrl = (this: AccountInstance) => string
|
export type GetFollowingUrl = (this: AccountInstance) => string
|
||||||
export type GetFollowersUrl = (this: AccountInstance) => string
|
export type GetFollowersUrl = (this: AccountInstance) => string
|
||||||
export type GetPublicKeyUrl = (this: AccountInstance) => string
|
export type GetPublicKeyUrl = (this: AccountInstance) => string
|
||||||
|
|
|
@ -28,7 +28,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
|
||||||
{
|
{
|
||||||
indexes: [
|
indexes: [
|
||||||
{
|
{
|
||||||
fields: [ 'videoId', 'accountId', 'type' ],
|
fields: [ 'videoId', 'accountId' ],
|
||||||
unique: true
|
unique: true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -10,7 +10,6 @@ import {
|
||||||
import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
|
import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
|
||||||
import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers/constants'
|
import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers/constants'
|
||||||
import { sendDeleteAccount } from '../../lib/activitypub/send/send-delete'
|
import { sendDeleteAccount } from '../../lib/activitypub/send/send-delete'
|
||||||
|
|
||||||
import { addMethodsToModel } from '../utils'
|
import { addMethodsToModel } from '../utils'
|
||||||
import { AccountAttributes, AccountInstance, AccountMethods } from './account-interface'
|
import { AccountAttributes, AccountInstance, AccountMethods } from './account-interface'
|
||||||
|
|
||||||
|
@ -315,7 +314,7 @@ isOwned = function (this: AccountInstance) {
|
||||||
return this.serverId === null
|
return this.serverId === null
|
||||||
}
|
}
|
||||||
|
|
||||||
getFollowerSharedInboxUrls = function (this: AccountInstance) {
|
getFollowerSharedInboxUrls = function (this: AccountInstance, t: Sequelize.Transaction) {
|
||||||
const query: Sequelize.FindOptions<AccountAttributes> = {
|
const query: Sequelize.FindOptions<AccountAttributes> = {
|
||||||
attributes: [ 'sharedInboxUrl' ],
|
attributes: [ 'sharedInboxUrl' ],
|
||||||
include: [
|
include: [
|
||||||
|
@ -327,7 +326,8 @@ getFollowerSharedInboxUrls = function (this: AccountInstance) {
|
||||||
targetAccountId: this.id
|
targetAccountId: this.id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
transaction: t
|
||||||
}
|
}
|
||||||
|
|
||||||
return Account.findAll(query)
|
return Account.findAll(query)
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import * as Bluebird from 'bluebird'
|
import * as Bluebird from 'bluebird'
|
||||||
import * as Sequelize from 'sequelize'
|
import * as Sequelize from 'sequelize'
|
||||||
|
import { Transaction } from 'sequelize'
|
||||||
import { AccountInstance } from '../account/account-interface'
|
import { AccountInstance } from '../account/account-interface'
|
||||||
import { VideoChannelInstance } from './video-channel-interface'
|
import { VideoChannelInstance } from './video-channel-interface'
|
||||||
|
|
||||||
export namespace VideoChannelShareMethods {
|
export namespace VideoChannelShareMethods {
|
||||||
export type LoadAccountsByShare = (videoChannelId: number) => Bluebird<AccountInstance[]>
|
export type LoadAccountsByShare = (videoChannelId: number, t: Transaction) => Bluebird<AccountInstance[]>
|
||||||
export type Load = (accountId: number, videoId: number) => Bluebird<VideoChannelShareInstance>
|
export type Load = (accountId: number, videoId: number, t: Transaction) => Bluebird<VideoChannelShareInstance>
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface VideoChannelShareClass {
|
export interface VideoChannelShareClass {
|
||||||
|
|
|
@ -52,7 +52,7 @@ function associate (models) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
load = function (accountId: number, videoChannelId: number) {
|
load = function (accountId: number, videoChannelId: number, t: Sequelize.Transaction) {
|
||||||
return VideoChannelShare.findOne({
|
return VideoChannelShare.findOne({
|
||||||
where: {
|
where: {
|
||||||
accountId,
|
accountId,
|
||||||
|
@ -61,11 +61,12 @@ load = function (accountId: number, videoChannelId: number) {
|
||||||
include: [
|
include: [
|
||||||
VideoChannelShare['sequelize'].models.Account,
|
VideoChannelShare['sequelize'].models.Account,
|
||||||
VideoChannelShare['sequelize'].models.VideoChannel
|
VideoChannelShare['sequelize'].models.VideoChannel
|
||||||
]
|
],
|
||||||
|
transaction: t
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
loadAccountsByShare = function (videoChannelId: number) {
|
loadAccountsByShare = function (videoChannelId: number, t: Sequelize.Transaction) {
|
||||||
const query = {
|
const query = {
|
||||||
where: {
|
where: {
|
||||||
videoChannelId
|
videoChannelId
|
||||||
|
@ -75,7 +76,8 @@ loadAccountsByShare = function (videoChannelId: number) {
|
||||||
model: VideoChannelShare['sequelize'].models.Account,
|
model: VideoChannelShare['sequelize'].models.Account,
|
||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
transaction: t
|
||||||
}
|
}
|
||||||
|
|
||||||
return VideoChannelShare.findAll(query)
|
return VideoChannelShare.findAll(query)
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import * as Bluebird from 'bluebird'
|
import * as Bluebird from 'bluebird'
|
||||||
import * as Sequelize from 'sequelize'
|
import * as Sequelize from 'sequelize'
|
||||||
|
import { Transaction } from 'sequelize'
|
||||||
import { AccountInstance } from '../account/account-interface'
|
import { AccountInstance } from '../account/account-interface'
|
||||||
import { VideoInstance } from './video-interface'
|
import { VideoInstance } from './video-interface'
|
||||||
|
|
||||||
export namespace VideoShareMethods {
|
export namespace VideoShareMethods {
|
||||||
export type LoadAccountsByShare = (videoId: number) => Bluebird<AccountInstance[]>
|
export type LoadAccountsByShare = (videoId: number, t: Transaction) => Bluebird<AccountInstance[]>
|
||||||
export type Load = (accountId: number, videoId: number) => Bluebird<VideoShareInstance>
|
export type Load = (accountId: number, videoId: number, t: Transaction) => Bluebird<VideoShareInstance>
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface VideoShareClass {
|
export interface VideoShareClass {
|
||||||
|
|
|
@ -52,7 +52,7 @@ function associate (models) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
load = function (accountId: number, videoId: number) {
|
load = function (accountId: number, videoId: number, t: Sequelize.Transaction) {
|
||||||
return VideoShare.findOne({
|
return VideoShare.findOne({
|
||||||
where: {
|
where: {
|
||||||
accountId,
|
accountId,
|
||||||
|
@ -60,11 +60,12 @@ load = function (accountId: number, videoId: number) {
|
||||||
},
|
},
|
||||||
include: [
|
include: [
|
||||||
VideoShare['sequelize'].models.Account
|
VideoShare['sequelize'].models.Account
|
||||||
]
|
],
|
||||||
|
transaction: t
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
loadAccountsByShare = function (videoId: number) {
|
loadAccountsByShare = function (videoId: number, t: Sequelize.Transaction) {
|
||||||
const query = {
|
const query = {
|
||||||
where: {
|
where: {
|
||||||
videoId
|
videoId
|
||||||
|
@ -74,7 +75,8 @@ loadAccountsByShare = function (videoId: number) {
|
||||||
model: VideoShare['sequelize'].models.Account,
|
model: VideoShare['sequelize'].models.Account,
|
||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
transaction: t
|
||||||
}
|
}
|
||||||
|
|
||||||
return VideoShare.findAll(query)
|
return VideoShare.findAll(query)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user