Skip to content

Commit

Permalink
[NEW] Threads V 1.0 (#13996)
Browse files Browse the repository at this point in the history
* first commit

* empty reply method

* permissions and settings

* hooks

* canSendMessage server function

* follow unfollow methods

* message tmid index

* removed useless permissons

* Notification and Hooks

* remove edit-room-title

* flextab threads and thread view

* improved message render

* open threads on click

* group message

* Save unread threads on subscription

* group thread messages

* useless css

* follow unfollow methods

* Fix unread threads

* follow unfollow actions and badge on flextab

* unread button

* fix multiple getThreadMessages

* Add notifications

* Move thread queries to models

* Move lib file to server folder

* Fix notifications for users in thread

* small changes

* Remove stub thread reply

* Normalize thread files

* message template

* Fix notification on first reply

* Fix follow/unfollow

* Fix removing a thread on last message delete

* fix open flextab

* getmessages instead getSinglemessage

* Fix remove thread message

* Fix delete thread

* fix open multiple threads

* Fix removing threads

* Add more tests to todo

* fix

* fix

* icons and i18n

* Fix thread title on replies

* Fix async

* onViewRendered

* fix reactions and removed css code

* fix blaze variable

* threads tab order

* thread replies button

* i18n

* fix test

* fix tests and css

* removed limits to thread list

* fix grouping time

* fix load message

* style changes

* fix unread badge

* fix role description

* clear read thread

* ajust badge

* time ago threads

* jump to messages

* mention link

* tick mention

* fix reloading threadlist after reply

* Pass rid and showFormattingTips as parameters to messageBox template

* Remove references to RoomManager in messageBox template

* Remove some invalid references

* Remove some invalid references

* Reduce messageBox coupling

* Add small fixes

* Extract more parameters from messageBox

* Fix emoji picker button

* Remove all references to chatMessages in messageBox

* Change focus handling

* Refactor autogrow plugin

* Fix calling modal.open() on modal confirm callback

* Disable message reply action for same user

* Refactor ChatMessages

* Pass rid to messagePopupConfig

* Fix attachment description update

* Move RTL change logic to messageBox

* Pass rid to fileUpload helper

* Don't use openedRoom session variable in room template

* Add tmid support

* Rename mountReply helper as prependReplies

* scroll at bottom thread

* Simplify messageBox events

* Refactor ChatMessages.send

* Fix messagePopupConfig for emojis

* Split chatMessages initialization

* Revert "Disable message reply action for same user"

This reverts commit f9dc0b4.

* Set outline style for open thread buttons

* Test atBottom condition on thread template before request scroll

* Update join button

* Protect messageBox from rid absence

* Embed messageBox into thread template

* Wait thread update before request scroll

* Increase font-weight for rc-button
  • Loading branch information
ggazzo authored and rodrigok committed Apr 7, 2019
1 parent 7d18278 commit 14b79fe
Show file tree
Hide file tree
Showing 135 changed files with 3,407 additions and 1,938 deletions.
13 changes: 8 additions & 5 deletions app/action-links/client/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,28 @@ import { Blaze } from 'meteor/blaze';
import { Template } from 'meteor/templating';
import { handleError } from '../../utils';
import { fireGlobalEvent, Layout } from '../../ui-utils';
import { messageArgs } from '../../ui-utils/client/lib/messageArgs';
import { actionLinks } from '../both/lib/actionLinks';



Template.room.events({
'click .action-link'(event, instance) {
event.preventDefault();
event.stopPropagation();

const data = Blaze.getData(event.currentTarget);

const { msg } = messageArgs(data);
if (Layout.isEmbedded()) {
return fireGlobalEvent('click-action-link', {
actionlink: $(event.currentTarget).data('actionlink'),
value: data._arguments[1]._id,
message: data._arguments[1],
value: msg._id,
message: msg,
});
}

if (data && data._arguments && data._arguments[1] && data._arguments[1]._id) {
actionLinks.run($(event.currentTarget).data('actionlink'), data._arguments[1]._id, instance, (err) => {
if (msg._id) {
actionLinks.run($(event.currentTarget).data('actionlink'), msg._id, instance, (err) => {
if (err) {
handleError(err);
}
Expand Down
22 changes: 22 additions & 0 deletions app/authorization/server/functions/canSendMessage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Meteor } from 'meteor/meteor';
import { Rooms, Subscriptions } from '../../../models';
import { canAccessRoom } from './canAccessRoom';

export const canSendMessage = (rid, { uid, username }, extraData) => {
const room = Rooms.findOneById(rid);

if (!canAccessRoom.call(this, room, { _id: uid, username }, extraData)) {
throw new Meteor.Error('error-not-allowed');
}

const subscription = Subscriptions.findOneByRoomIdAndUserId(rid, uid);
if (subscription && (subscription.blocked || subscription.blocker)) {
throw new Meteor.Error('room_is_blocked');
}

if ((room.muted || []).includes(username)) {
throw new Meteor.Error('You_have_been_muted');
}

return room;
};
2 changes: 2 additions & 0 deletions app/authorization/server/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { addUserRoles } from './functions/addUserRoles';
import { addRoomAccessValidator, canAccessRoom, roomAccessValidators } from './functions/canAccessRoom';
import { canSendMessage } from './functions/canSendMessage';
import { getRoles } from './functions/getRoles';
import { getUsersInRole } from './functions/getUsersInRole';
import { hasAllPermission, hasAtLeastOnePermission, hasPermission } from './functions/hasPermission';
Expand All @@ -25,6 +26,7 @@ export {
hasRole,
removeUserFromRoles,
canAccessRoom,
canSendMessage,
addRoomAccessValidator,
roomAccessValidators,
addUserRoles,
Expand Down
3 changes: 2 additions & 1 deletion app/autotranslate/client/lib/actionButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Tracker } from 'meteor/tracker';
import { settings } from '../../../settings';
import { hasAtLeastOnePermission } from '../../../authorization';
import { MessageAction } from '../../../ui-utils';
import { messageArgs } from '../../../ui-utils/client/lib/messageArgs';
import { Messages } from '../../../models';
import { AutoTranslate } from './autotranslate';

Expand All @@ -18,7 +19,7 @@ Meteor.startup(function() {
'message-mobile',
],
action() {
const message = this._arguments[1];
const { msg: message } = messageArgs(this);
const language = AutoTranslate.getLanguage(message.rid);
if ((!message.translations || !message.translations[language])) { // } && !_.find(message.attachments, attachment => { return attachment.translations && attachment.translations[language]; })) {
AutoTranslate.messageIdsToWait[message._id] = true;
Expand Down
2 changes: 1 addition & 1 deletion app/channel-settings/client/startup/tabBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ Meteor.startup(() => {
i18nTitle: 'Room_Info',
icon: 'info-circled',
template: 'channelSettings',
order: 0,
order: 1,
});
});
3 changes: 2 additions & 1 deletion app/discussion/client/createDiscussionMessageAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Subscriptions } from '../../models/client';
import { settings } from '../../settings/client';
import { hasPermission } from '../../authorization/client';
import { MessageAction, modal } from '../../ui-utils/client';
import { messageArgs } from '../../ui-utils/client/lib/messageArgs';
import { t } from '../../utils/client';

const condition = (rid, uid) => {
Expand All @@ -26,7 +27,7 @@ Meteor.startup(function() {
label: 'Discussion_start',
context: ['message', 'message-mobile'],
async action() {
const [, message] = this._arguments;
const { msg: message } = messageArgs(this);

modal.open({
title: t('Discussion_title'),
Expand Down
6 changes: 3 additions & 3 deletions app/discussion/client/views/DiscussionTabbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ <h2>{{_ "No_discussions_yet"}}</h2>
{{/if}}
<div class="flex-tab__result discussions-list js-list">
<ul class="list clearfix">
{{#each messages}}
{{#nrr nrrargs 'message' message}}{{/nrr}}
{{/each}}
{{# with messageContext}}
{{#each msg in messages}}{{#nrr nrrargs 'message' msg=msg room=room subscription=subscription settings=settings u=u}}{{/nrr}}{{/each}}
{{/with}}
</ul>

{{#if hasMore}}
Expand Down
23 changes: 12 additions & 11 deletions app/discussion/client/views/DiscussionTabbar.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
import _ from 'underscore';
import { ReactiveVar } from 'meteor/reactive-var';
import { Template } from 'meteor/templating';

import { messageContext } from '../../../ui-utils/client/lib/messageContext';
import { DiscussionOfRoom } from '../lib/discussionsOfRoom';

import './DiscussionTabbar.html';

Template.discussionsTabbar.helpers({
hasMessages() {
return DiscussionOfRoom.find({
rid: this.rid,
}).count() > 0;
return Template.instance().cursor > 0;
},
messages() {
return DiscussionOfRoom.find({
rid: this.rid,
}, {
sort: {
ts: -1,
},
});
Template.instance().cursor;
},
message() {
return _.extend(this, { customClass: 'pinned', actionContext: 'pinned' });
},
hasMore() {
return Template.instance().hasMore.get();
},
messageContext,
});

Template.discussionsTabbar.onCreated(function() {
this.rid = this.data.rid;
this.cursor = DiscussionOfRoom.find({
rid: this.rid,
}, {
sort: {
ts: -1,
},
});
this.hasMore = new ReactiveVar(true);
this.limit = new ReactiveVar(50);
return this.autorun(() => {
Expand Down
1 change: 1 addition & 0 deletions app/file-upload/server/methods/sendFileMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Meteor.methods({
alias: Match.Optional(String),
groupable: Match.Optional(Boolean),
msg: Match.Optional(String),
tmid: Match.Optional(String),
});

Uploads.updateFileComplete(file._id, Meteor.userId(), _.omit(file, '_id'));
Expand Down
2 changes: 1 addition & 1 deletion app/lib/client/defaultTabBars.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ TabBar.addButton({
i18nTitle: 'Search_Messages',
icon: 'magnifier',
template: 'RocketSearch',
order: 1,
order: 2,
});

TabBar.addButton({
Expand Down
13 changes: 12 additions & 1 deletion app/lib/client/lib/formatDate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { getUserPreference } from '../../../utils';
import { getUserPreference, t } from '../../../utils';
import { settings } from '../../../settings';
import moment from 'moment';

Expand All @@ -25,4 +25,15 @@ export const formatDateAndTime = (time) => {
}
};

export const timeAgo = (time) => {
const now = new Date();
const yesterday = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1);

return (
(now.getDate() === time.getDate() && moment(time).format('LT')) ||
(yesterday.getDate() === time.getDate() && t('yesterday')) ||
moment(time).format('L')
);
};

export const formatDate = (time) => moment(time).format(settings.get('Message_DateFormat'));
4 changes: 1 addition & 3 deletions app/lib/server/functions/deleteMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ export const deleteMessage = function(message, user) {
}

const room = Rooms.findOneById(message.rid, { fields: { lastMessage: 1, prid: 1, mid: 1 } });
Meteor.defer(function() {
callbacks.run('afterDeleteMessage', deletedMsg);
});
callbacks.run('afterDeleteMessage', deletedMsg, room, user);

// update last message
if (settings.get('Store_Last_Message')) {
Expand Down
5 changes: 3 additions & 2 deletions app/lib/server/functions/notifications/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ export function shouldNotifyAudio({
hasMentionToHere,
isHighlighted,
hasMentionToUser,
hasReplyToThread,
roomType,
}) {
if (disableAllMessageNotifications && audioNotifications == null) {
if (disableAllMessageNotifications && audioNotifications == null && !hasReplyToThread) {
return false;
}

Expand All @@ -25,7 +26,7 @@ export function shouldNotifyAudio({
return true;
}

return roomType === 'd' || (!disableAllMessageNotifications && (hasMentionToAll || hasMentionToHere)) || isHighlighted || audioNotifications === 'all' || hasMentionToUser;
return roomType === 'd' || (!disableAllMessageNotifications && (hasMentionToAll || hasMentionToHere)) || isHighlighted || audioNotifications === 'all' || hasMentionToUser || hasReplyToThread;
}

export function notifyAudioUser(userId, message, room) {
Expand Down
5 changes: 3 additions & 2 deletions app/lib/server/functions/notifications/desktop.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ export function shouldNotifyDesktop({
hasMentionToHere,
isHighlighted,
hasMentionToUser,
hasReplyToThread,
roomType,
}) {
if (disableAllMessageNotifications && desktopNotifications == null && !isHighlighted && !hasMentionToUser) {
if (disableAllMessageNotifications && desktopNotifications == null && !isHighlighted && !hasMentionToUser && !hasReplyToThread) {
return false;
}

Expand All @@ -69,5 +70,5 @@ export function shouldNotifyDesktop({
}
}

return roomType === 'd' || (!disableAllMessageNotifications && (hasMentionToAll || hasMentionToHere)) || isHighlighted || desktopNotifications === 'all' || hasMentionToUser;
return roomType === 'd' || (!disableAllMessageNotifications && (hasMentionToAll || hasMentionToHere)) || isHighlighted || desktopNotifications === 'all' || hasMentionToUser || hasReplyToThread;
}
5 changes: 3 additions & 2 deletions app/lib/server/functions/notifications/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export function shouldNotifyEmail({
isHighlighted,
hasMentionToUser,
hasMentionToAll,
hasReplyToThread,
roomType,
}) {

Expand All @@ -149,7 +150,7 @@ export function shouldNotifyEmail({

// no user or room preference
if (emailNotifications == null) {
if (disableAllMessageNotifications && !isHighlighted && !hasMentionToUser) {
if (disableAllMessageNotifications && !isHighlighted && !hasMentionToUser && !hasReplyToThread) {
return false;
}

Expand All @@ -159,5 +160,5 @@ export function shouldNotifyEmail({
}
}

return roomType === 'd' || isHighlighted || emailNotifications === 'all' || hasMentionToUser || (!disableAllMessageNotifications && hasMentionToAll);
return roomType === 'd' || isHighlighted || emailNotifications === 'all' || hasMentionToUser || hasReplyToThread || (!disableAllMessageNotifications && hasMentionToAll);
}
5 changes: 3 additions & 2 deletions app/lib/server/functions/notifications/mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ export function shouldNotifyMobile({
hasMentionToAll,
isHighlighted,
hasMentionToUser,
hasReplyToThread,
statusConnection,
roomType,
}) {
if (disableAllMessageNotifications && mobilePushNotifications == null && !isHighlighted && !hasMentionToUser) {
if (disableAllMessageNotifications && mobilePushNotifications == null && !isHighlighted && !hasMentionToUser && !hasReplyToThread) {
return false;
}

Expand All @@ -94,5 +95,5 @@ export function shouldNotifyMobile({
}
}

return roomType === 'd' || (!disableAllMessageNotifications && hasMentionToAll) || isHighlighted || mobilePushNotifications === 'all' || hasMentionToUser;
return roomType === 'd' || (!disableAllMessageNotifications && hasMentionToAll) || isHighlighted || mobilePushNotifications === 'all' || hasMentionToUser || hasReplyToThread;
}
1 change: 1 addition & 0 deletions app/lib/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import './methods/getRoomJoinCode';
import './methods/getRoomRoles';
import './methods/getServerInfo';
import './methods/getSingleMessage';
import './methods/getMessages';
import './methods/getSlashCommandPreviews';
import './methods/getUsernameSuggestion';
import './methods/getUserRoles';
Expand Down
Loading

0 comments on commit 14b79fe

Please sign in to comment.