Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions app/message-attachments/client/messageAttachment.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';

import { DateFormat } from '../../lib';
import { getUserPreference, getURL } from '../../utils/client';
import { Users } from '../../models';
import { getURL } from '../../utils/client';
import { renderMessageBody } from '../../ui-utils';

const colors = {
Expand All @@ -27,15 +25,18 @@ Template.messageAttachment.helpers({
});
},
loadImage() {
if (this.downloadImages !== true) {
const user = Users.findOne({ _id: Meteor.userId() }, { fields: { 'settings.autoImageLoad': 1 } });
if (getUserPreference(user, 'autoImageLoad') === false) {
return false;
}
if (Meteor.Device.isPhone() && getUserPreference(user, 'saveMobileBandwidth') !== true) {
return false;
}
if (this.downloadImages) {
return true;
}

if (this.settings.autoImageLoad === false) {
return false;
}

if (this.settings.saveMobileBandwidth === true) {
return false;
}

return true;
},
getImageHeight(height = 200) {
Expand All @@ -54,7 +55,7 @@ Template.messageAttachment.helpers({
if (this.collapsed != null) {
return this.collapsed;
}
return getUserPreference(Meteor.userId(), 'collapseMediaByDefault') === true;
return this.settings.collapseMediaByDefault === true;
},
time() {
const messageDate = new Date(this.ts);
Expand Down
2 changes: 1 addition & 1 deletion app/ui-account/client/avatar/avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const getUsername = ({ userId, username }) => {
}

if (userId) {
const user = Meteor.users.findOne(this.userId, { fields: { username: 1 } });
const user = Meteor.users.findOne(userId, { fields: { username: 1 } });
return user && user.username;
}
};
Expand Down
4 changes: 3 additions & 1 deletion app/ui-message/client/message.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@
{{/each}}
{{/if}}
{{#each msg.attachments}}
{{injectIndex . @index}} {{> messageAttachment}}
{{injectSettings . ../settings}}
{{injectIndex . @index}}
{{> messageAttachment}}
{{/each}}

{{#if msg.drid}}
Expand Down
3 changes: 3 additions & 0 deletions app/ui-message/client/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ Template.message.helpers({
injectIndex(data, index) {
data.index = index;
},
injectSettings(data, settings) {
data.settings = settings;
},
channelName() {
const { subscription } = this;
// const subscription = Subscriptions.findOne({ rid: this.rid });
Expand Down
16 changes: 10 additions & 6 deletions app/ui-utils/client/lib/MessageAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export const MessageAction = new class {
return Tracker.nonreactive(() => {
const btns = this.buttons.get();
btns[config.id] = config;
mem.clear(this._getButtons);
mem.clear(this._getButtonsByGroup);
return this.buttons.set(btns);
});
}
Expand Down Expand Up @@ -94,14 +96,14 @@ export const MessageAction = new class {

_getButtons = mem(function() {
return _.sortBy(_.toArray(this.buttons.get()), 'order');
}, { maxAge: 100 })
})

getButtons(message, context, group) {
let allButtons = this._getButtons();
_getButtonsByGroup = mem(function(group) {
return this._getButtons().filter((button) => button.group === group);
})

if (group) {
allButtons = allButtons.filter((button) => button.group === group);
}
getButtons(message, context, group) {
const allButtons = group ? this._getButtonsByGroup(group) : this._getButtons();

if (message) {
return allButtons.filter(function(button) {
Expand All @@ -115,6 +117,8 @@ export const MessageAction = new class {
}

resetButtons() {
mem.clear(this._getButtons);
mem.clear(this._getButtonsByGroup);
return this.buttons.set({});
}

Expand Down
10 changes: 8 additions & 2 deletions app/ui-utils/client/lib/messageContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import { settings } from '../../../settings/client';
import { getUserPreference } from '../../../utils/client';
import { AutoTranslate } from '../../../autotranslate/client';

const fields = { name: 1, username: 1, 'settings.autoImageLoad': 1, 'settings.saveMobileBandwidth': 1, 'settings.collapseMediaByDefault': 1, 'settings.hideRoles': 1 };

export function messageContext({ rid } = Template.instance()) {
const uid = Meteor.userId();
const user = Users.findOne({ _id: uid }, { fields });
return {
u: Users.findOne({ _id: uid }, { fields: { name: 1, username: 1 } }) || {},
u: user,
room: Rooms.findOne({ _id: rid }, {
reactive: false,
fields: {
Expand All @@ -27,11 +30,14 @@ export function messageContext({ rid } = Template.instance()) {
}),
settings: {
translateLanguage: AutoTranslate.getLanguage(rid),
autoImageLoad: getUserPreference(user, 'saveMobileBandwidth'),

Choose a reason for hiding this comment

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

This references 'saveMobileBandwidth' instead of autoImageLoad. Maybe the problem regarding #15890 ?

saveMobileBandwidth: Meteor.Device.isPhone() && getUserPreference(user, 'saveMobileBandwidth'),
collapseMediaByDefault: getUserPreference(user, 'collapseMediaByDefault'),
showreply: true,
showReplyButton: true,
hasPermissionDeleteMessage: hasPermission('delete-message', rid),
hasPermissionDeleteOwnMessage: hasPermission('delete-own-message'),
hideRoles: !settings.get('UI_DisplayRoles') || getUserPreference(uid, 'hideRoles'),
hideRoles: !settings.get('UI_DisplayRoles') || getUserPreference(user, 'hideRoles'),
UI_Use_Real_Name: settings.get('UI_Use_Real_Name'),
Chatops_Username: settings.get('Chatops_Username'),
AutoTranslate_Enabled: settings.get('AutoTranslate_Enabled'),
Expand Down