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] Save room's last message #8979

Merged
merged 11 commits into from
Dec 4, 2017
189 changes: 97 additions & 92 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,7 @@
"No_integration_found": "No integration found by the provided id.",
"No_livechats": "You have no livechats",
"No_mentions_found": "No mentions found",
"No_messages_yet": "No messages yet",
"No_pinned_messages": "No pinned messages",
"No_results_found": "No results found",
"No_snippet_messages": "No snippet",
Expand Down Expand Up @@ -1592,6 +1593,7 @@
"Send_welcome_email": "Send welcome email",
"Send_your_JSON_payloads_to_this_URL": "Send your JSON payloads to this URL.",
"Sending": "Sending...",
"Sent_an_attachment": "Sent an attachment",
"Served_By": "Served By",
"Service": "Service",
"Service_account_key": "Service account key",
Expand Down Expand Up @@ -1708,6 +1710,8 @@
"Stats_Total_Users": "Total Users",
"Status": "Status",
"Stop_Recording": "Stop Recording",
"Store_Last_Message": "Store Last Message",
"Store_Last_Message_Sent_per_Room": "Store last message sent on each room.",
"Stream_Cast": "Stream Cast",
"Stream_Cast_Address": "Stream Cast Address",
"Stream_Cast_Address_Description": "IP or Host of your Rocket.Chat central Stream Cast. E.g. `192.168.1.1:3000` or `localhost:4000`",
Expand Down Expand Up @@ -1913,6 +1917,7 @@
"User_removed": "User removed",
"User_removed_by": "User <em>__user_removed__</em> removed by <em>__user_by__</em>.",
"User_Settings": "User Settings",
"user_sent_an_attachment": "__user__ sent an attachment",
"User_unmuted_by": "User <em>__user_unmuted__</em> unmuted by <em>__user_by__</em>.",
"User_unmuted_in_room": "User unmuted in room",
"User_updated_successfully": "User updated successfully",
Expand Down Expand Up @@ -2024,6 +2029,7 @@
"Yes_mute_user": "Yes, mute user!",
"Yes_remove_user": "Yes, remove user!",
"Yes_unarchive_it": "Yes, unarchive it!",
"yesterday": "yesterday",
"You": "You",
"you_are_in_preview_mode_of": "You are in preview mode of channel #<strong>__room_name__</strong>",
"You_are_logged_in_as": "You are logged in as",
Expand Down
5 changes: 5 additions & 0 deletions packages/rocketchat-lib/lib/getAvatarColor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const colors = ['#F44336', '#E91E63', '#9C27B0', '#673AB7', '#3F51B5', '#2196F3', '#03A9F4', '#00BCD4', '#009688', '#4CAF50', '#8BC34A', '#CDDC39', '#FFC107', '#FF9800', '#FF5722', '#795548', '#9E9E9E', '#607D8B'];

RocketChat.getAvatarColor = function(name) {
return colors[name.length % colors.length];
};
1 change: 1 addition & 0 deletions packages/rocketchat-lib/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Package.onUse(function(api) {
api.addFiles('lib/settings.js');
api.addFiles('lib/callbacks.js');
api.addFiles('lib/fileUploadRestrictions.js');
api.addFiles('lib/getAvatarColor.js');
api.addFiles('lib/getValidRoomName.js');
api.addFiles('lib/placeholders.js');
api.addFiles('lib/promises.js');
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-lib/server/lib/notifyUsersOnMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
}

// Update all the room activity tracker fields
RocketChat.models.Rooms.incMsgCountAndSetLastMessageTimestampById(message.rid, 1, message.ts);
RocketChat.models.Rooms.incMsgCountAndSetLastMessageById(message.rid, 1, message.ts, RocketChat.settings.get('Store_Last_Message') && message);

// Update all other subscriptions to alert their owners but witout incrementing
// the unread counter, as it is only for mentions and direct messages
Expand Down
6 changes: 5 additions & 1 deletion packages/rocketchat-lib/server/models/Rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ class ModelRooms extends RocketChat.models._Base {
return this.update(query, update);
}

incMsgCountAndSetLastMessageTimestampById(_id, inc, lastMessageTimestamp) {
incMsgCountAndSetLastMessageById(_id, inc, lastMessageTimestamp, lastMessage) {
if (inc == null) { inc = 1; }
const query = {_id};

Expand All @@ -547,6 +547,10 @@ class ModelRooms extends RocketChat.models._Base {
}
};

if (lastMessage) {
update.$set.lastMessage = lastMessage;
}

return this.update(query, update);
}

Expand Down
5 changes: 5 additions & 0 deletions packages/rocketchat-lib/server/startup/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,11 @@ RocketChat.settings.addGroup('General', function() {
type: 'action',
actionText: 'Restart_the_server'
});
this.add('Store_Last_Message', false, {
type: 'boolean',
public: true,
i18nDescription: 'Store_Last_Message_Sent_per_Room'
});
this.section('UTF8', function() {
this.add('UTF8_Names_Validation', '[0-9a-zA-Z-_.]+', {
type: 'string',
Expand Down
4 changes: 4 additions & 0 deletions packages/rocketchat-theme/client/imports/components/badge.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
font-size: var(--badge-text-size);

&--unread {
margin: 0 3px;

white-space: nowrap;

background-color: var(--badge-unread-background);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@
margin-top: 2rem;
}

&__list {
& .badge {
margin: 0 4px;
}

&:not(:last-child) {
margin-bottom: 32px;
}
&__list:not(:last-child) {
margin-bottom: 32px;
}

&__type {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,51 @@
&:hover {
background-color: var(--sidebar-background-light-hover);
}

&__picture {
color: inherit;
}
}
}

.sidebar--big {
& > .rooms-list,
& .rooms-list__toolbar-search {
& .sidebar-item {
height: var(--sidebar-item-big-height);

&__picture {
flex: 0 0 var(--sidebar-item-big-thumb-size);

width: var(--sidebar-item-big-thumb-size);
height: var(--sidebar-item-big-thumb-size);
}

&__icon {
margin: 0 auto;
}

&__user-thumb {
width: var(--sidebar-item-big-thumb-size);
height: var(--sidebar-item-big-thumb-size);
}

&__message {
flex-direction: column;

&-top,
&-bottom {
display: flex;

width: 100%;
align-items: center;
}

&-bottom {
margin-top: 6px;
}
}
}
}
}

Expand All @@ -19,13 +64,14 @@

cursor: pointer;

border-radius: var(--sidebar-item-radius);
align-items: center;
transition: all 0.3s;

background-color: var(--sidebar-item-background);
color: var(--sidebar-item-text-color);

transition: all 0.3s;
border-radius: var(--sidebar-item-radius);

background-color: var(--sidebar-item-background);
align-items: center;

&:hover {
background-color: var(--sidebar-item-hover-background);
Expand All @@ -41,7 +87,7 @@

&--unread,
&--mention {
color: var(--sidebar-item-unread-color);
color: var(--sidebar-item-unread-color);
}

&__popup-active {
Expand Down Expand Up @@ -107,37 +153,114 @@

margin: 0 4px;

color: var(--sidebar-item-unread-color);
border-radius: var(--sidebar-item-radius);

align-items: center;
}

&__name {
&__body {
display: flex;

overflow: hidden;
flex: 1;

margin: 0 4px;
align-items: center;
}

&__message {
display: flex;
overflow: hidden;
flex-direction: row;
flex: 1;

margin: 0 -3px;
align-items: center;
justify-content: center;

&-top {
overflow: hidden;
flex: 1;
}

&-bottom {
flex: 0 0;
}
}

&__name {
overflow: hidden;

flex: 1;

margin: 0 3px;

white-space: nowrap;
text-overflow: ellipsis;

font-size: var(--sidebar-item-text-size);
line-height: var(--sidebar-item-height);

line-height: 1.2rem;
}

&__last-message {
overflow: hidden;
flex: 1;

margin: 0 3px;

white-space: nowrap;
text-overflow: ellipsis;

font-size: 12px;
line-height: 12px;

& > p, & code, & pre {
display: inline;
white-space: unset;
}

& br {
display: none;
}

& a {
pointer-events: none;
}
}

&__time {
margin: 0 3px;

color: var(--sidebar-item-text-color);

font-size: 10px;
}

&__menu {
padding: 6px;
position: absolute;
right: 0;

display: none;
flex: 0;

padding: 6px;

&-icon {
fill: var(--color-white);
}
}

& .mention-link {
color: inherit;
background: transparent;
}
}

.rtl .sidebar-item__menu {
left: 0;
right: auto;
right: auto;
left: 0;
}

.rtl .sidebar-item__user-status {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
border-radius: 0 0 5px 5px;
}

.rc-old .copyonly {
.copyonly {
display: inline-block;
float: left;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

--color-darkest: #1f2329;
--color-dark: #2f343d;
--color-dark: #2f343d;
--color-dark-medium: #414852;
--color-dark-light: #6c727a;
--color-gray: #9ea2a8;
Expand Down Expand Up @@ -176,7 +176,9 @@
*/
--sidebar-item-radius: 2px;
--sidebar-item-height: 32px;
--sidebar-item-big-height: 62px;
--sidebar-item-thumb-size: 20px;
--sidebar-item-big-thumb-size: 36px;

--sidebar-item-text-color: var(--color-gray);
--sidebar-item-background: inherit;
Expand Down
10 changes: 10 additions & 0 deletions packages/rocketchat-theme/server/colors.less
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,16 @@ input:-webkit-autofill {
}
}

.sidebar-item__last-message {
a:not(.mention-link) {
color: @link-font-color;

&:hover {
color: darken(@link-font-color, 10%);
}
}
}

.message-popup.search-results-list {
background-color: lighten(@primary-background-color, 2.5%);

Expand Down
13 changes: 12 additions & 1 deletion packages/rocketchat-ui-sidenav/client/chatRoomItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Template.chatRoomItem.helpers({
const icon = RocketChat.roomTypes.getIcon(this.t);
const avatar = !icon;

return {
const roomData = {
...this,
icon,
avatar,
Expand All @@ -36,5 +36,16 @@ Template.chatRoomItem.helpers({
archivedClass,
statusClass: this.t === 'd' ? Session.get(`user_${ this.name }_status`) || 'offline' : this.t === 'l' ? RocketChat.roomTypes.getUserStatus(this.t, this.rid) || 'offline' : false
};

if (RocketChat.settings.get('Store_Last_Message')) {
if (this.lastMessage) {
roomData.lastMessage = this.lastMessage;
} else {
const room = RocketChat.models.Rooms.findOne(this.rid || this._id, { fields: { lastMessage: 1 } });
roomData.lastMessage = room && room.lastMessage || { msg: t('No_messages_yet') };
}
}

return roomData;
}
});
Loading