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

[NEW] Star message, report and delete message events #25383

Merged
merged 8 commits into from
May 22, 2022
34 changes: 28 additions & 6 deletions apps/meteor/app/apps/server/bridges/listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export class AppListenerBridge {
case AppInterface.IPostMessageReacted:
case AppInterface.IPostMessageFollowed:
case AppInterface.IPostMessagePinned:
case AppInterface.IPostMessageStarred:
case AppInterface.IPostMessageReported:
return 'messageEvent';
case AppInterface.IPreRoomCreatePrevent:
case AppInterface.IPreRoomCreateExtend:
Expand Down Expand Up @@ -70,27 +72,47 @@ export class AppListenerBridge {

const params = (() => {
switch (inte) {
case AppInterface.IPostMessageDeleted:
const [userDeleted] = payload;
return {
message: msg,
user: this.orch.getConverters().get('users').convertToApp(userDeleted),
};
case AppInterface.IPostMessageReacted:
const [userReacted, reaction, isReacted] = payload;
const [userReacted, reaction, isRemoved] = payload;
return {
message: msg,
user: this.orch.getConverters().get('users').convertToApp(userReacted),
reaction,
isReacted,
isRemoved,
};
case AppInterface.IPostMessageFollowed:
const [userFollowed, isFollowed] = payload;
const [userFollowed, isUnfollow] = payload;
return {
message: msg,
user: this.orch.getConverters().get('users').convertToApp(userFollowed),
isFollowed,
isUnfollow,
};
case AppInterface.IPostMessagePinned:
const [userPinned, isPinned] = payload;
const [userPinned, isUnpinned] = payload;
return {
message: msg,
user: this.orch.getConverters().get('users').convertToApp(userPinned),
isPinned,
isUnpinned,
};
case AppInterface.IPostMessageStarred:
const [userStarred, isStarred] = payload;
return {
message: msg,
user: this.orch.getConverters().get('users').convertToApp(userStarred),
isStarred,
};
case AppInterface.IPostMessageReported:
const [userReported, reason] = payload;
return {
message: msg,
user: this.orch.getConverters().get('users').convertToApp(userReported),
reason,
};
default:
return msg;
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/lib/server/functions/deleteMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ export const deleteMessage = async function (message: IMessage, user: IUser): Pr
}

if (bridges) {
bridges.getListenerBridge().messageEvent('IPostMessageDeleted', deletedMsg);
bridges.getListenerBridge().messageEvent('IPostMessageDeleted', deletedMsg, user);
}
};
3 changes: 3 additions & 0 deletions apps/meteor/app/message-star/server/starMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { settings } from '../../settings/server';
import { isTheLastMessage } from '../../lib/server';
import { canAccessRoom, roomAccessAttributes } from '../../authorization/server';
import { Subscriptions, Rooms, Messages } from '../../models/server';
import { Apps, AppEvents } from '../../apps/server/orchestrator';

Meteor.methods({
starMessage(message) {
Expand Down Expand Up @@ -40,6 +41,8 @@ Meteor.methods({
Rooms.updateLastMessageStar(room._id, Meteor.userId(), message.starred);
}

Promise.await(Apps.triggerEvent(AppEvents.IPostMessageStarred, message, Meteor.user(), message.starred));

return Messages.updateUserStarById(message._id, Meteor.userId(), message.starred);
},
});
1 change: 0 additions & 1 deletion apps/meteor/app/reactions/server/setReaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const removeUserReaction = (message, reaction, username) => {
if (message.reactions[reaction].usernames.length === 0) {
delete message.reactions[reaction];
}

return message;
};

Expand Down
3 changes: 3 additions & 0 deletions apps/meteor/server/methods/reportMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { check } from 'meteor/check';
import { Messages } from '../../app/models/server';
import { Reports, Rooms } from '../../app/models/server/raw';
import { canAccessRoomAsync } from '../../app/authorization/server/functions/canAccessRoom';
import { AppEvents, Apps } from '../../app/apps/server';

Meteor.methods({
async reportMessage(messageId, description) {
Expand Down Expand Up @@ -41,6 +42,8 @@ Meteor.methods({

await Reports.createWithMessageDescriptionAndUserId(message, description, uid);

Promise.await(Apps.triggerEvent(AppEvents.IPostMessageReported, message, Meteor.user(), description));

return true;
},
});