-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
007dd55
commit 7d85c79
Showing
2 changed files
with
20 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,30 @@ | ||
import type { ILivechatContact, ILivechatContactChannel } from '@rocket.chat/core-typings'; | ||
import { License } from '@rocket.chat/license'; | ||
import { LivechatContacts } from '@rocket.chat/models'; | ||
import type { ILivechatContact, ILivechatContactChannel } from '@rocket.chat/core-typings'; | ||
import { License } from '@rocket.chat/license'; | ||
import { LivechatContacts } from '@rocket.chat/models'; | ||
|
||
import { hasLicense } from '../../../app/license/client'; | ||
import { hasLicense } from '../../../app/license/client'; | ||
import { ContactMerger } from '../../../app/livechat/server/lib/ContactMerger'; | ||
import { mergeContacts } from '../../../app/livechat/server/lib/Contacts'; | ||
|
||
export const runMergeContacts = async ( | ||
_next: any, | ||
contactId: string, | ||
channel: ILivechatContactChannel, | ||
): Promise<ILivechatContact | null> => { | ||
if (!(await hasLicense('contact-id-verification'))) { | ||
return null; | ||
} | ||
|
||
const originalContact = (await LivechatContacts.findOneById(contactId)) as ILivechatContact; | ||
await License.onLicense('contact-id-verification', () => { | ||
mergeContacts.patch(async (_next, contactId: string, channel: ILivechatContactChannel): Promise<ILivechatContact | null> => { | ||
if (!(await hasLicense('contact-id-verification'))) { | ||
return null; | ||
} | ||
|
||
const similarContacts: ILivechatContact[] = await LivechatContacts.findSimilarVerifiedContacts(channel, contactId); | ||
const originalContact = (await LivechatContacts.findOneById(contactId)) as ILivechatContact; | ||
|
||
if (!similarContacts.length) { | ||
return originalContact; | ||
} | ||
const similarContacts: ILivechatContact[] = await LivechatContacts.findSimilarVerifiedContacts(channel, contactId); | ||
|
||
for await (const similarContact of similarContacts) { | ||
await ContactMerger.mergeContact(originalContact, similarContact); | ||
} | ||
if (!similarContacts.length) { | ||
return originalContact; | ||
} | ||
|
||
await LivechatContacts.deleteMany({ _id: { $in: similarContacts.map((c) => c._id) } }); | ||
return LivechatContacts.findOneById(contactId); | ||
}; | ||
for await (const similarContact of similarContacts) { | ||
await ContactMerger.mergeContact(originalContact, similarContact); | ||
} | ||
|
||
await License.onLicense('contact-id-verification', () => { | ||
mergeContacts.patch(runMergeContacts); | ||
await LivechatContacts.deleteMany({ _id: { $in: similarContacts.map((c) => c._id) } }); | ||
return LivechatContacts.findOneById(contactId); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters