({
threads,
is_restrict,
logger,
anonymize,
}: {
threads: (threads & {
messages: (messages & {
author: users | null;
reactions: messageReactions[];
attachments: messageAttachments[];
mentions: (mentions & {
users: users | null;
})[];
})[];
channel: channels & {
memberships: {
usersId: string;
user: {
authsId: string | null;
};
}[];
};
})[];
is_restrict: boolean;
logger: Logger;
anonymize?: AnonymizeType;
})
| 106 | } |
| 107 | |
| 108 | export async function pushToTypesense({ |
| 109 | threads, |
| 110 | is_restrict, |
| 111 | logger, |
| 112 | anonymize, |
| 113 | }: { |
| 114 | threads: (threads & { |
| 115 | messages: (messages & { |
| 116 | author: users | null; |
| 117 | reactions: messageReactions[]; |
| 118 | attachments: messageAttachments[]; |
| 119 | mentions: (mentions & { |
| 120 | users: users | null; |
| 121 | })[]; |
| 122 | })[]; |
| 123 | channel: channels & { |
| 124 | memberships: { |
| 125 | usersId: string; |
| 126 | user: { |
| 127 | authsId: string | null; |
| 128 | }; |
| 129 | }[]; |
| 130 | }; |
| 131 | })[]; |
| 132 | is_restrict: boolean; |
| 133 | logger: Logger; |
| 134 | anonymize?: AnonymizeType; |
| 135 | }) { |
| 136 | const documents = threads |
| 137 | .map((t) => |
| 138 | serializer({ |
| 139 | thread: serializeThread( |
| 140 | anonymize ? anonymizeMessages(t, anonymize) : t |
| 141 | ), |
| 142 | is_public: t.channel.type === 'PUBLIC', |
| 143 | is_restrict, |
| 144 | accessible_to: t.channel.memberships |
| 145 | .filter((m) => !!m.user.authsId) |
| 146 | .map((m) => m.usersId), |
| 147 | }) |
| 148 | ) |
| 149 | .filter((t) => !!t.body); |
| 150 | |
| 151 | await client |
| 152 | .collections(collectionSchema.name) |
| 153 | .documents() |
| 154 | .import(documents, { action: 'upsert' }) |
| 155 | .catch((error: any) => { |
| 156 | logger.error( |
| 157 | error.importResults |
| 158 | ?.filter((result: any) => !result.success) |
| 159 | ?.map((result: any) => result.error) || error |
| 160 | ); |
| 161 | }); |
| 162 | } |
| 163 | |
| 164 | export async function createUserKeyAndPersist({ |
| 165 | account, |
no test coverage detected