-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🌟 Added link preview service (#2204)
* 🌟 added link preview service * unit tests * moved links preview callback handler to message service * added publish message in realtime helper * publish message in realtime after preview generation * publish message only to channels
- Loading branch information
Showing
27 changed files
with
618 additions
and
71 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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module "get-website-favicon"; |
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
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
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
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
73 changes: 73 additions & 0 deletions
73
twake/backend/node/src/services/messages/services/engine/processors/links/index.ts
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { logger, TwakeContext } from "../../../../../../core/platform/framework"; | ||
import { PubsubHandler } from "../../../../../../core/platform/services/pubsub/api"; | ||
import { Message } from "../../../../entities/messages"; | ||
import Repository from "../../../../../../core/platform/services/database/services/orm/repository/repository"; | ||
import { LinkPreviewPubsubCallback } from "../../../../../previews/types"; | ||
import { Thread } from "../../../../entities/threads"; | ||
import { publishMessageInRealtime } from "../../../utils"; | ||
|
||
export class MessageLinksPreviewFinishedProcessor | ||
implements PubsubHandler<LinkPreviewPubsubCallback, string> | ||
{ | ||
constructor( | ||
private MessageRepository: Repository<Message>, | ||
private ThreadRepository: Repository<Thread>, | ||
) {} | ||
readonly name = "MessageLinksPreviewFinishedProcessor"; | ||
readonly topics = { | ||
in: "services:preview:links:callback", | ||
}; | ||
|
||
readonly options = { | ||
unique: true, | ||
ack: true, | ||
}; | ||
|
||
init?(context?: TwakeContext): Promise<this> { | ||
throw new Error("Method not implemented."); | ||
} | ||
|
||
validate(message: LinkPreviewPubsubCallback): boolean { | ||
return !!(message && message.previews && message.previews.length); | ||
} | ||
|
||
async process(localMessage: LinkPreviewPubsubCallback): Promise<string> { | ||
logger.info( | ||
`${this.name} - updating message links with generated previews: ${localMessage.previews.length}`, | ||
); | ||
|
||
const entity = await this.MessageRepository.findOne({ | ||
thread_id: localMessage.message.resource.thread_id, | ||
id: localMessage.message.resource.thread_id, | ||
}); | ||
|
||
if (!entity) { | ||
logger.error(`${this.name} - message not found`); | ||
return ""; | ||
} | ||
|
||
entity.links = localMessage.previews; | ||
|
||
await this.MessageRepository.save(entity); | ||
|
||
const thread: Thread = await this.ThreadRepository.findOne({ | ||
id: localMessage.message.resource.thread_id, | ||
}); | ||
|
||
if (!thread) { | ||
logger.error(`${this.name} - thread not found`); | ||
return ""; | ||
} | ||
|
||
const updatedMessage = { | ||
...localMessage.message, | ||
resource: entity, | ||
}; | ||
|
||
for (const participant of thread.participants.filter(p => p.type === "channel")) { | ||
publishMessageInRealtime(updatedMessage, participant); | ||
} | ||
|
||
return "done"; | ||
} | ||
} |
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
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
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
8 changes: 4 additions & 4 deletions
8
...ervices/previews/services/engine/clear.ts → ...s/previews/services/files/engine/clear.ts
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
Oops, something went wrong.