feat: export withReplies of UserList
This commit is contained in:
parent
5603cb7e22
commit
752fea9e76
|
@ -91,7 +91,7 @@ export class UserListService implements OnApplicationShutdown, OnModuleInit {
|
|||
}
|
||||
|
||||
@bindThis
|
||||
public async addMember(target: MiUser, list: MiUserList, me: MiUser) {
|
||||
public async addMember(target: MiUser, list: MiUserList, me: MiUser, options: { withReplies?: boolean } = {}) {
|
||||
const currentCount = await this.userListMembershipsRepository.countBy({
|
||||
userListId: list.id,
|
||||
});
|
||||
|
@ -104,6 +104,7 @@ export class UserListService implements OnApplicationShutdown, OnModuleInit {
|
|||
userId: target.id,
|
||||
userListId: list.id,
|
||||
userListUserId: list.userId,
|
||||
withReplies: options.withReplies ?? false,
|
||||
} as MiUserListMembership);
|
||||
|
||||
this.globalEventService.publishInternalEvent('userListMemberAdded', { userListId: list.id, memberId: target.id });
|
||||
|
|
|
@ -67,10 +67,12 @@ export class ExportUserListsProcessorService {
|
|||
const users = await this.usersRepository.findBy({
|
||||
id: In(memberships.map(j => j.userId)),
|
||||
});
|
||||
const usersWithReplies = new Set(memberships.filter(m => m.withReplies).map(m => m.userId));
|
||||
|
||||
for (const u of users) {
|
||||
const acct = this.utilityService.getFullApAccount(u.username, u.host);
|
||||
const content = `${list.name},${acct}`;
|
||||
// 3rd column and later will be key=value pairs
|
||||
const content = `${list.name},${acct},withReplies=${usersWithReplies.has(u.id)}`;
|
||||
await new Promise<void>((res, rej) => {
|
||||
stream.write(content + '\n', err => {
|
||||
if (err) {
|
||||
|
|
|
@ -70,8 +70,19 @@ export class ImportUserListsProcessorService {
|
|||
linenum++;
|
||||
|
||||
try {
|
||||
const listName = line.split(',')[0].trim();
|
||||
const { username, host } = Acct.parse(line.split(',')[1].trim());
|
||||
const parts = line.split(',');
|
||||
const listName = parts[0].trim();
|
||||
const { username, host } = Acct.parse(parts[1].trim());
|
||||
let withReplies = false;
|
||||
|
||||
for (const keyValue of parts.slice(2)) {
|
||||
const [key, value] = keyValue.split('=');
|
||||
switch (key) {
|
||||
case 'withReplies':
|
||||
withReplies = value === 'true';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let list = await this.userListsRepository.findOneBy({
|
||||
userId: user.id,
|
||||
|
@ -100,7 +111,9 @@ export class ImportUserListsProcessorService {
|
|||
|
||||
if (await this.userListMembershipsRepository.findOneBy({ userListId: list!.id, userId: target.id }) != null) continue;
|
||||
|
||||
this.userListService.addMember(target, list!, user);
|
||||
await this.userListService.addMember(target, list, user, {
|
||||
withReplies: withReplies,
|
||||
});
|
||||
} catch (e) {
|
||||
this.logger.warn(`Error in line:${linenum} ${e}`);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue