Skip to content

Refactor - Clean Code and S.O.L.I.D #4

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

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,13 @@ android {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode VERSIONCODE as Integer
versionName "4.12.0"
versionName "4.13.0"
vectorDrawables.useSupportLibrary = true
if (isPlay) {
manifestPlaceholders = [BugsnagAPIKey: BugsnagAPIKey as String]
missingDimensionStrategy "RNNotifications.reactNativeVersion", "reactNative60" // See note below!
}
resValue "string", "rn_config_reader_custom_package", "chat.rocket.reactnative"
}

signingConfigs {
Expand Down Expand Up @@ -198,7 +199,6 @@ android {
applicationId "chat.rocket.android"
dimension = "type"
buildConfigField "boolean", "FDROID_BUILD", "true"
resValue "string", "rn_config_reader_custom_package", "chat.rocket.reactnative"
}
play {
dimension = "type"
Expand Down
1 change: 1 addition & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
android:theme="@style/AppTheme"
android:networkSecurityConfig="@xml/network_security_config"
android:allowBackup="false"
android:requestLegacyExternalStorage="true"
tools:replace="android:allowBackup"
>
<activity
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ buildscript {
supportLibVersion = "28.0.0"
libre_build = !(isPlay.toBoolean())
jitsi_url = isPlay ? "https://github.com/RocketChat/jitsi-maven-repository/raw/master/releases" : "https://github.com/RocketChat/jitsi-maven-repository/raw/libre/releases"
jitsi_version = isPlay ? "+" : "2.10.0-libre"
jitsi_version = isPlay ? "2.10.2-rc" : "2.10.0-libre"
}

repositories {
Expand Down
5 changes: 2 additions & 3 deletions app/containers/message/Thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ const Thread = React.memo(({
}

const {
getBadgeColor, toggleFollowThread, user, replies
threadBadgeColor, toggleFollowThread, user, replies
} = useContext(MessageContext);
const time = formatDateThreads(tlm);
const buttonText = formatMessageCount(tcount, THREAD);
const badgeColor = getBadgeColor?.(id);
const isFollowing = replies?.find(u => u === user.id);
return (
<View style={styles.buttonContainer}>
Expand All @@ -35,7 +34,7 @@ const Thread = React.memo(({
<Text style={[styles.buttonText, { color: themes[theme].buttonText }]}>{buttonText}</Text>
</View>
<Text style={[styles.time, { color: themes[theme].auxiliaryText }]}>{time}</Text>
{badgeColor ? <View style={[styles.threadBadge, { backgroundColor: badgeColor }]} /> : null}
{threadBadgeColor ? <View style={[styles.threadBadge, { backgroundColor: threadBadgeColor }]} /> : null}
<Touchable onPress={() => toggleFollowThread(isFollowing, id)}>
<CustomIcon
name={isFollowing ? 'notification' : 'notification-disabled'}
Expand Down
11 changes: 7 additions & 4 deletions app/containers/message/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class MessageContainer extends React.Component {
callJitsi: PropTypes.func,
blockAction: PropTypes.func,
theme: PropTypes.string,
getBadgeColor: PropTypes.func,
threadBadgeColor: PropTypes.string,
toggleFollowThread: PropTypes.func
}

Expand Down Expand Up @@ -84,10 +84,13 @@ class MessageContainer extends React.Component {
}

shouldComponentUpdate(nextProps) {
const { theme } = this.props;
const { theme, threadBadgeColor } = this.props;
if (nextProps.theme !== theme) {
return true;
}
if (nextProps.threadBadgeColor !== threadBadgeColor) {
return true;
}
return false;
}

Expand Down Expand Up @@ -244,7 +247,7 @@ class MessageContainer extends React.Component {

render() {
const {
item, user, style, archived, baseUrl, useRealName, broadcast, fetchThreadName, showAttachment, timeFormat, isReadReceiptEnabled, autoTranslateRoom, autoTranslateLanguage, navToRoomInfo, getCustomEmoji, isThreadRoom, callJitsi, blockAction, rid, theme, getBadgeColor, toggleFollowThread
item, user, style, archived, baseUrl, useRealName, broadcast, fetchThreadName, showAttachment, timeFormat, isReadReceiptEnabled, autoTranslateRoom, autoTranslateLanguage, navToRoomInfo, getCustomEmoji, isThreadRoom, callJitsi, blockAction, rid, theme, threadBadgeColor, toggleFollowThread
} = this.props;
const {
id, msg, ts, attachments, urls, reactions, t, avatar, emoji, u, alias, editedBy, role, drid, dcount, dlm, tmid, tcount, tlm, tmsg, mentions, channels, unread, blocks, autoTranslate: autoTranslateMessage, replies
Expand All @@ -271,7 +274,7 @@ class MessageContainer extends React.Component {
onEncryptedPress: this.onEncryptedPress,
onDiscussionPress: this.onDiscussionPress,
onReactionLongPress: this.onReactionLongPress,
getBadgeColor,
threadBadgeColor,
toggleFollowThread,
replies
}}
Expand Down
37 changes: 30 additions & 7 deletions app/i18n/locales/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default {
alerts: 'Benachrichtigungen',
All_users_in_the_channel_can_write_new_messages: 'Alle Benutzer im Kanal können neue Nachrichten schreiben',
A_meaningful_name_for_the_discussion_room: 'Ein aussagekräftiger Name für den Diskussionsraum',
All: 'Alles',
All: 'alle',
All_Messages: 'Alle Nachrichten',
Allow_Reactions: 'Reaktionen zulassen',
Alphabetical: 'Alphabetisch',
Expand Down Expand Up @@ -183,8 +183,8 @@ export default {
deleting_room: 'lösche Raum',
description: 'Beschreibung',
Description: 'Beschreibung',
DESKTOP_OPTIONS: 'DESKTOP-EINSTELLUNGEN',
DESKTOP_NOTIFICATIONS: 'DESKTOP-BENACHRICHTIGUNGEN',
Desktop_Options: 'Desktop-Einstellungen',
Desktop_Notifications: 'Desktop-Benachrichtigungen',
Directory: 'Verzeichnis',
Direct_Messages: 'Direkte Nachrichten',
Disable_notifications: 'Benachrichtigungen deaktiveren',
Expand All @@ -196,8 +196,9 @@ export default {
Do_you_have_an_account: 'Du hast schon ein Konto?',
Do_you_have_a_certificate: 'Hast du ein Zertifikat?',
Do_you_really_want_to_key_this_room_question_mark: 'Möchtest du diesen Raum wirklich {{key}}?',
E2E_Encryption: 'E2E-Verschlüsselung',
E2E_How_It_Works_info1: 'Du kannst nun verschlüsselte private Gruppen und Direktnachrichten versenden. Du kannst außerdem deine bestehenden privaten Gruppen und Direktnachrichten auf Verschlüsselung umstellen.',
E2E_How_It_Works_info2: 'Dies ist *Ende-zu-Ende-Verschlüsselung*, daher wird der Key um die Nachrichten zu ver-/entschlüsseln nicht auf dem Server gespeichert. Aus diesem Grund musst du dieses Passwort an einem sicheren Ort speichern, so dass du später bei Bedarf darauf zugreifen kannst.',
E2E_How_It_Works_info2: 'Dies ist *Ende-zu-Ende-Verschlüsselung*, daher wird der Schlüssel um die Nachrichten zu ver-/entschlüsseln nicht auf dem Server gespeichert. Aus diesem Grund musst du dieses Passwort an einem sicheren Ort speichern, so dass du später bei Bedarf darauf zugreifen kannst.',
E2E_How_It_Works_info3: 'Wenn du fortfährst, wird automatisch ein ein E2E-Passwort erzeugt.',
E2E_How_It_Works_info4: 'Du kannst außerdem jederzeit, in jedem Browser, in dem du das bestehende Passwort eingegeben hast, ein neues Passwort setzen.',
edit: 'bearbeiten',
Expand Down Expand Up @@ -395,7 +396,7 @@ export default {
Profile: 'Profil',
Public_Channel: 'Öffentlicher Kanal',
Public: 'Öffentlich',
PUSH_NOTIFICATIONS: 'PUSH-BENACHRICHTIGUNGEN',
Push_Notifications: 'Push-Benachrichtigungen',
Push_Notifications_Alert_Info: 'Diese Benachrichtigungen werden dir zugestellt, wenn die App nicht geöffnet ist.',
Desktop_Alert_info: 'Diese Benachrichtigungen werden auf dem Desktop angezeigt',
Quote: 'Zitat',
Expand Down Expand Up @@ -435,6 +436,7 @@ export default {
Roles: 'Rollen',
Room_actions: 'Raumaktionen',
Room_changed_announcement: 'Raumansage geändert in: {{announcement}} von {{userBy}}',
Room_changed_avatar: 'Raum-Avatar durch Nutzer {{userBy}} gändert',
Room_changed_description: 'Raumbeschreibung geändert in: {{description}} von {{userBy}}',
Room_changed_privacy: 'Raumtyp geändert in: {{type}} von {{userBy}}',
Room_changed_topic: 'Raumthema geändert in: {{topic}} von {{userBy}}',
Expand All @@ -461,6 +463,7 @@ export default {
Search_global_users: 'Suche nach globalen Benutzern',
Search_global_users_description: 'Wenn aktiviert, kannst du nach Benutzern von anderen Unternehmen oder Servern suchen.',
Seconds: '{{second}} Sekunden',
Security_and_privacy: 'Sicherheit und Datenschutz',
Select_Avatar: 'Wähle einen Avatar aus',
Select_Server: 'Server auswählen',
Select_Users: 'Benutzer auswählen',
Expand Down Expand Up @@ -539,7 +542,7 @@ export default {
unmuted: 'Stummschaltung aufgehoben',
Unpin: 'Nachricht nicht mehr anheften',
unread_messages: 'ungelesene',
Unread: 'Ungelesen',
Unread: 'ungelesene',
Unread_on_top: 'Ungelesene oben',
Unstar: 'von Favoriten entfernen',
Updating: 'Aktualisierung …',
Expand Down Expand Up @@ -657,5 +660,25 @@ export default {
You_will_be_logged_out_from_other_locations: 'Du wirst auf anderen Geräten abgemeldet.',
Logged_out_of_other_clients_successfully: 'Erfolgreich von anderen Geräten abgemeldet.',
Logout_failed: 'Abmeldung fehlgeschlagen!',
Log_analytics_events: 'Analyse-Ereignisse loggen'
Log_analytics_events: 'Analyse-Ereignisse loggen',
E2E_encryption_change_password_title: 'Verschlüsselungs-Passwort ändern',
E2E_encryption_change_password_description: 'Du kannst nun verschlüsselte private Gruppen und Direktnachrichten versenden. Du kannst außerdem deine bestehenden privaten Gruppen und Direktnachrichten auf Verschlüsselung umstellen. \nDies ist Ende-zu-Ende-Verschlüsselung, daher wird der Schlüssel um die Nachrichten zu ver-/entschlüsseln nicht auf dem Server gespeichert. Aus diesem Grund musst du dieses Passwort an einem sicheren Ort speichern, du wirst es auf anderen Geräten benötigen auf denen du E2E-Verschlüsselung nutzen möchtest.',
E2E_encryption_change_password_error: 'Fehler beim Ändern des E2E-Passworts!',
E2E_encryption_change_password_success: 'E2E-Passwort erfolgreich geändert!',
E2E_encryption_change_password_message: 'Stelle sicher, dass du es noch an einer anderen Stelle gesichert hasst.',
E2E_encryption_change_password_confirmation: 'Ja, ändern',
E2E_encryption_reset_title: 'E2E-Schlüssel zurücksetzen',
E2E_encryption_reset_description: 'Diese Option wird deinen aktuellen E2E-Schlüssel entfernen und dich abmelden. \nWenn du dich wieder anmeldest, wird Rocket.Chat einen neuen Schlüssel erzeugen und deinen Zugang zu allen Kanälen mit einer oder mehreren anwesenden Personen wieder herstellen. \nAufgrund der Funktionsweise von E2E-Verschlüsselung, kann Rocket.Chat nicht deinen Zugang zu Kanälen wieder herstellen, in denen keine andere Person anwesend ist.',
E2E_encryption_reset_button: 'E2E-Schlüssel zurücksetzen',
E2E_encryption_reset_error: 'Fehler beim Zurücksetzen des E2E-Schlüssels!',
E2E_encryption_reset_message: 'Du wirst abgemeldet.',
E2E_encryption_reset_confirmation: 'Ja, zurücksetzen',
Following: 'verfolgte',
Threads_displaying_all: 'zeige alle',
Threads_displaying_following: 'zeige gefolgte',
Threads_displaying_unread: 'zeige ungelesene',
No_threads: 'Es gibt keine Threads',
No_threads_following: 'Du folgst keinen Threads',
No_threads_unread: 'Es gibt keine ungelesenen Threads',
Messagebox_Send_to_channel: 'an Kanal senden'
};
4 changes: 0 additions & 4 deletions app/lib/database/model/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,5 @@ export default class User extends Model {

@field('avatar_etag') avatarETag;

@field('login_email_password') loginEmailPassword;

@field('show_message_in_main_thread') showMessageInMainThread;

@json('roles', sanitizer) roles;
}
4 changes: 4 additions & 0 deletions app/lib/database/model/servers/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ export default class User extends Model {
@json('roles', sanitizer) roles;

@field('avatar_etag') avatarETag;

@field('login_email_password') loginEmailPassword;

@field('show_message_in_main_thread') showMessageInMainThread;
}
17 changes: 17 additions & 0 deletions app/lib/invite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const Invite = {
findOrCreateInvite({ rid, days, maxUses }) {
// RC 2.4.0
return this.post('findOrCreateInvite', { rid, days, maxUses });
},
validateInviteToken(token) {
// RC 2.4.0
return this.post('validateInviteToken', { token });
},
useInviteToken(token) {
// RC 2.4.0
return this.post('useInviteToken', { token });
}

}

export default Invite;
2 changes: 1 addition & 1 deletion app/lib/methods/subscriptions/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ export default function subscribeRooms() {
notification.avatar = RocketChat.getRoomAvatar(room);

// If it's from a encrypted room
if (message.t === E2E_MESSAGE_TYPE) {
if (message?.t === E2E_MESSAGE_TYPE) {
// Decrypt this message content
const { msg } = await Encryption.decryptMessage({ ...message, rid });
// If it's a direct the content is the message decrypted
Expand Down
58 changes: 1 addition & 57 deletions app/lib/rocketchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -1350,67 +1350,11 @@ const RocketChat = {
query, count, offset, sort
});
},
async canAutoTranslate() {
const db = database.active;
try {
const AutoTranslate_Enabled = reduxStore.getState().settings && reduxStore.getState().settings.AutoTranslate_Enabled;
if (!AutoTranslate_Enabled) {
return false;
}
const permissionsCollection = db.collections.get('permissions');
const autoTranslatePermission = await permissionsCollection.find('auto-translate');
const userRoles = (reduxStore.getState().login.user && reduxStore.getState().login.user.roles) || [];
return autoTranslatePermission.roles.some(role => userRoles.includes(role));
} catch (e) {
log(e);
return false;
}
},
saveAutoTranslate({
rid, field, value, options
}) {
return this.methodCallWrapper('autoTranslate.saveSettings', rid, field, value, options);
},
getSupportedLanguagesAutoTranslate() {
return this.methodCallWrapper('autoTranslate.getSupportedLanguages', 'en');
},
translateMessage(message, targetLanguage) {
return this.methodCallWrapper('autoTranslate.translateMessage', message, targetLanguage);
},
getSenderName(sender) {
const { UI_Use_Real_Name: useRealName } = reduxStore.getState().settings;
return useRealName ? sender.name : sender.username;
},
getRoomTitle(room) {
const { UI_Use_Real_Name: useRealName, UI_Allow_room_names_with_special_chars: allowSpecialChars } = reduxStore.getState().settings;
const { username } = reduxStore.getState().login.user;
if (RocketChat.isGroupChat(room) && !(room.name && room.name.length)) {
return room.usernames.filter(u => u !== username).sort((u1, u2) => u1.localeCompare(u2)).join(', ');
}
if (allowSpecialChars && room.t !== 'd') {
return room.fname || room.name;
}
return ((room.prid || useRealName) && room.fname) || room.name;
},
getRoomAvatar(room) {
if (RocketChat.isGroupChat(room)) {
return room.uids?.length + room.usernames?.join();
}
return room.prid ? room.fname : room.name;
},

findOrCreateInvite({ rid, days, maxUses }) {
// RC 2.4.0
return this.post('findOrCreateInvite', { rid, days, maxUses });
},
validateInviteToken(token) {
// RC 2.4.0
return this.post('validateInviteToken', { token });
},
useInviteToken(token) {
// RC 2.4.0
return this.post('useInviteToken', { token });
}

};

export default RocketChat;
24 changes: 24 additions & 0 deletions app/lib/rooms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import RocketChat from '../rocketchat';

const Room = {
getRoomTitle(room) {
const { UI_Use_Real_Name: useRealName, UI_Allow_room_names_with_special_chars: allowSpecialChars } = reduxStore.getState().settings;
const { username } = reduxStore.getState().login.user;
if (RocketChat.isGroupChat(room) && !(room.name && room.name.length)) {
return room.usernames.filter(u => u !== username).sort((u1, u2) => u1.localeCompare(u2)).join(', ');
}
if (allowSpecialChars && room.t !== 'd') {
return room.fname || room.name;
}
return ((room.prid || useRealName) && room.fname) || room.name;
},
getRoomAvatar(room) {
if (RocketChat.isGroupChat(room)) {
return room.uids?.length + room.usernames?.join();
}
return room.prid ? room.fname : room.name;
}

}

export default Room;
31 changes: 31 additions & 0 deletions app/lib/translate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const Translate = {
async canAutoTranslate() {
const db = database.active;
try {
const AutoTranslate_Enabled = reduxStore.getState().settings && reduxStore.getState().settings.AutoTranslate_Enabled;
if (!AutoTranslate_Enabled) {
return false;
}
const permissionsCollection = db.collections.get('permissions');
const autoTranslatePermission = await permissionsCollection.find('auto-translate');
const userRoles = (reduxStore.getState().login.user && reduxStore.getState().login.user.roles) || [];
return autoTranslatePermission.roles.some(role => userRoles.includes(role));
} catch (e) {
log(e);
return false;
}
},
saveAutoTranslate({
rid, field, value, options
}) {
return this.methodCallWrapper('autoTranslate.saveSettings', rid, field, value, options);
},
getSupportedLanguagesAutoTranslate() {
return this.methodCallWrapper('autoTranslate.getSupportedLanguages', 'en');
},
translateMessage(message, targetLanguage) {
return this.methodCallWrapper('autoTranslate.translateMessage', message, targetLanguage);
}
}

export default Translate;
Loading