reorder relay activities to avoid delivery race condition
This commit is contained in:
parent
d39a56c1b7
commit
c302a5c2d7
11 changed files with 40 additions and 44 deletions
|
|
@ -49,7 +49,7 @@ export class NotePiningService {
|
|||
* @param noteId
|
||||
*/
|
||||
@bindThis
|
||||
public async addPinned(user: { id: MiUser['id']; host: MiUser['host']; }, noteId: MiNote['id']) {
|
||||
public async addPinned(user: MiUser, noteId: MiNote['id']) {
|
||||
// Fetch pinee
|
||||
const note = await this.notesRepository.findOneBy({
|
||||
id: noteId,
|
||||
|
|
@ -78,7 +78,7 @@ export class NotePiningService {
|
|||
|
||||
// Deliver to remote followers
|
||||
if (this.userEntityService.isLocalUser(user) && !note.localOnly && ['public', 'home'].includes(note.visibility)) {
|
||||
this.deliverPinnedChange(user.id, note.id, true);
|
||||
this.deliverPinnedChange(user, note.id, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ export class NotePiningService {
|
|||
* @param noteId
|
||||
*/
|
||||
@bindThis
|
||||
public async removePinned(user: { id: MiUser['id']; host: MiUser['host']; }, noteId: MiNote['id']) {
|
||||
public async removePinned(user: MiUser, noteId: MiNote['id']) {
|
||||
// Fetch unpinee
|
||||
const note = await this.notesRepository.findOneBy({
|
||||
id: noteId,
|
||||
|
|
@ -106,22 +106,19 @@ export class NotePiningService {
|
|||
|
||||
// Deliver to remote followers
|
||||
if (this.userEntityService.isLocalUser(user) && !note.localOnly && ['public', 'home'].includes(note.visibility)) {
|
||||
this.deliverPinnedChange(user.id, noteId, false);
|
||||
this.deliverPinnedChange(user, noteId, false);
|
||||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async deliverPinnedChange(userId: MiUser['id'], noteId: MiNote['id'], isAddition: boolean) {
|
||||
const user = await this.usersRepository.findOneBy({ id: userId });
|
||||
if (user == null) throw new Error('user not found');
|
||||
|
||||
public async deliverPinnedChange(user: MiUser, noteId: MiNote['id'], isAddition: boolean) {
|
||||
if (!this.userEntityService.isLocalUser(user)) return;
|
||||
|
||||
const target = `${this.config.url}/users/${user.id}/collections/featured`;
|
||||
const item = `${this.config.url}/notes/${noteId}`;
|
||||
const content = this.apRendererService.addContext(isAddition ? this.apRendererService.renderAdd(user, target, item) : this.apRendererService.renderRemove(user, target, item));
|
||||
|
||||
this.apDeliverManagerService.deliverToFollowers(user, content);
|
||||
this.relayService.deliverToRelays(user, content);
|
||||
await this.apDeliverManagerService.deliverToFollowers(user, content);
|
||||
await this.relayService.deliverToRelays(user, content);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue