Implement Talk has read federation (#5636)
* Talk read * fix * 複数のRead ActivityはCollectionとして送るように * あ
This commit is contained in:
@ -1,8 +1,9 @@
|
||||
import { IObject, isCreate, isDelete, isUpdate, isFollow, isAccept, isReject, isAdd, isRemove, isAnnounce, isLike, isUndo, isBlock, isCollectionOrOrderedCollection, isCollection } from '../type';
|
||||
import { IObject, isCreate, isDelete, isUpdate, isRead, isFollow, isAccept, isReject, isAdd, isRemove, isAnnounce, isLike, isUndo, isBlock, isCollectionOrOrderedCollection, isCollection } from '../type';
|
||||
import { IRemoteUser } from '../../../models/entities/user';
|
||||
import create from './create';
|
||||
import performDeleteActivity from './delete';
|
||||
import performUpdateActivity from './update';
|
||||
import { performReadActivity } from './read';
|
||||
import follow from './follow';
|
||||
import undo from './undo';
|
||||
import like from './like';
|
||||
@ -41,6 +42,8 @@ async function performOneActivity(actor: IRemoteUser, activity: IObject): Promis
|
||||
await performDeleteActivity(actor, activity);
|
||||
} else if (isUpdate(activity)) {
|
||||
await performUpdateActivity(actor, activity);
|
||||
} else if (isRead(activity)) {
|
||||
await performReadActivity(actor, activity);
|
||||
} else if (isFollow(activity)) {
|
||||
await follow(actor, activity);
|
||||
} else if (isAccept(activity)) {
|
||||
|
27
src/remote/activitypub/kernel/read.ts
Normal file
27
src/remote/activitypub/kernel/read.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { IRemoteUser } from '../../../models/entities/user';
|
||||
import { IRead, getApId } from '../type';
|
||||
import { isSelfHost, extractDbHost } from '../../../misc/convert-host';
|
||||
import { MessagingMessages } from '../../../models';
|
||||
import { readUserMessagingMessage } from '../../../server/api/common/read-messaging-message';
|
||||
|
||||
export const performReadActivity = async (actor: IRemoteUser, activity: IRead): Promise<string> => {
|
||||
const id = await getApId(activity.object);
|
||||
|
||||
if (!isSelfHost(extractDbHost(id))) {
|
||||
return `skip: Read to foreign host (${id})`;
|
||||
}
|
||||
|
||||
const messageId = id.split('/').pop();
|
||||
|
||||
const message = await MessagingMessages.findOne(messageId);
|
||||
if (message == null) {
|
||||
return `skip: message not found`;
|
||||
}
|
||||
|
||||
if (actor.id != message.recipientId) {
|
||||
return `skip: actor is not a message recipient`;
|
||||
}
|
||||
|
||||
await readUserMessagingMessage(message.recipientId!, message.userId, [message.id]);
|
||||
return `ok: mark as read (${message.userId} => ${message.recipientId} ${message.id})`;
|
||||
};
|
@ -226,7 +226,7 @@ export async function createNote(value: string | IObject, resolver?: Resolver, s
|
||||
|
||||
if (note._misskey_talk && visibility === 'specified') {
|
||||
for (const recipient of visibleUsers) {
|
||||
await createMessage(actor, recipient, undefined, text || undefined, (files && files.length > 0) ? files[0] : null);
|
||||
await createMessage(actor, recipient, undefined, text || undefined, (files && files.length > 0) ? files[0] : null, object.id);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
* @param last URL of last page (optional)
|
||||
* @param orderedItems attached objects (optional)
|
||||
*/
|
||||
export default function(id: string, totalItems: any, first?: string, last?: string, orderedItems?: object) {
|
||||
export default function(id: string | null, totalItems: any, first?: string, last?: string, orderedItems?: object) {
|
||||
const page: any = {
|
||||
id,
|
||||
type: 'OrderedCollection',
|
||||
|
9
src/remote/activitypub/renderer/read.ts
Normal file
9
src/remote/activitypub/renderer/read.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import config from '../../../config';
|
||||
import { ILocalUser } from '../../../models/entities/user';
|
||||
import { MessagingMessage } from '../../../models/entities/messaging-message';
|
||||
|
||||
export const renderReadActivity = (user: ILocalUser, message: MessagingMessage) => ({
|
||||
type: 'Read',
|
||||
actor: `${config.url}/users/${user.id}`,
|
||||
object: message.uri
|
||||
});
|
@ -140,6 +140,10 @@ export interface IUpdate extends IActivity {
|
||||
type: 'Update';
|
||||
}
|
||||
|
||||
export interface IRead extends IActivity {
|
||||
type: 'Read';
|
||||
}
|
||||
|
||||
export interface IUndo extends IActivity {
|
||||
type: 'Undo';
|
||||
}
|
||||
@ -180,6 +184,7 @@ export interface IBlock extends IActivity {
|
||||
export const isCreate = (object: IObject): object is ICreate => object.type === 'Create';
|
||||
export const isDelete = (object: IObject): object is IDelete => object.type === 'Delete';
|
||||
export const isUpdate = (object: IObject): object is IUpdate => object.type === 'Update';
|
||||
export const isRead = (object: IObject): object is IRead => object.type === 'Read';
|
||||
export const isUndo = (object: IObject): object is IUndo => object.type === 'Undo';
|
||||
export const isFollow = (object: IObject): object is IFollow => object.type === 'Follow';
|
||||
export const isAccept = (object: IObject): object is IAccept => object.type === 'Accept';
|
||||
|
Reference in New Issue
Block a user