Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: a proposal to fix the admin user message flow #32

Conversation

AllanPazRibeiro
Copy link
Contributor

@AllanPazRibeiro AllanPazRibeiro commented Aug 6, 2023

This PR addresses the messaging flow issue that occurs when the user who created the bridge sends a message to both Teams and Rocket.Chat. The following changes have been made to resolve the problem:

  • Modified the logic that prevented messages from admins being set as senders. Now, admin messages can be properly processed as senders.

  • Introduced a footprint mechanism to determine whether a message has already been sent based on its text, user, room, and file name. This ensures that duplicate messages are avoided.

  • Implemented a persistence feature to store information about sent messages. Before sending a message, the system checks the persistence records to prevent messaging loops between Rocket.Chat and Teams.

@AllanPazRibeiro AllanPazRibeiro marked this pull request as ready for review August 7, 2023 20:53
Copy link

@AlenDavid AlenDavid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎖️ good work!

@AllanPazRibeiro AllanPazRibeiro self-assigned this Aug 8, 2023
const persistenceRead: IPersistenceRead = read.getPersistenceReader();
const results = await persistenceRead.readByAssociations(associations) as Array<UserRegistrationModel>;

if (results === undefined || results === null || results.length == 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (results === undefined || results === null || results.length == 0) {
if (results == null || results.length == 0) {

undefined == null is true

@@ -1001,3 +1019,181 @@ export const retrieveLoginMessageSentStatus = async ({

return result[0].isLoginMessageSent;
};

type LastBridgedMessageInfo = {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for a 1000+ lines file please avoid defining types here, its better to import them

Copy link

@AlenDavid AlenDavid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider only my last comment - the try/catch block - in this request changes. Every other feedback is to enhance the quality of the source code, but its ok to go forward if you feel the need of speed.

return result[0];
};

const simpleHash = (input: string): string => sha256(input).toString()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be in another file

rocketChatUserId,
messageFootprint,
// source
}: {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please avoid adding types later as it increases the number of lines and complexity of the file.

messageFootprint: string
persistence: IPersistence,
rocketChatUserId: string;
// source: 'rocket.chat' | 'msteams'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid commenting unused code

),
];

return (await read.getPersistenceReader().readByAssociations(associations)).shift() as MessageFootprintInfo

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in a promise, avoid return await expressions.

lib/PersistHelper.ts Show resolved Hide resolved
@casalsgh casalsgh merged commit f94daa6 into main Oct 10, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants