Skip to content

Commit

Permalink
Merge branch 'mattermost:main' into android-theme
Browse files Browse the repository at this point in the history
  • Loading branch information
harshal2030 authored Oct 11, 2023
2 parents 903db10 + ef9eb59 commit 8f0139d
Show file tree
Hide file tree
Showing 68 changed files with 7,958 additions and 51 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Mattermost Mobile v2

- **Minimum Server versions:** Current ESR version (7.8.0+)
- **Supported iOS versions:** 13.4+
- **Supported iOS versions:** 12.4+
- **Supported Android versions:** 7.0+

Mattermost is an open source Slack-alternative used by thousands of companies around the world in 21 languages. Learn more at [https://mattermost.com](https://mattermost.com).
Expand Down
11 changes: 8 additions & 3 deletions app/actions/remote/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,14 @@ export async function createChannel(serverUrl: string, displayName: string, purp
}
}

export async function patchChannel(serverUrl: string, channelPatch: Partial<Channel> & {id: string}) {
export async function patchChannel(serverUrl: string, channelId: string, channelPatch: ChannelPatch) {
try {
const client = NetworkManager.getClient(serverUrl);
const {database, operator} = DatabaseManager.getServerDatabaseAndOperator(serverUrl);

const channelData = await client.patchChannel(channelPatch.id, channelPatch);
const channelData = await client.patchChannel(channelId, channelPatch);
const models = [];

const channelInfo = (await getChannelInfo(database, channelData.id));
if (channelInfo && (channelInfo.purpose !== channelData.purpose || channelInfo.header !== channelData.header)) {
channelInfo.prepareUpdate((v) => {
Expand All @@ -264,10 +265,14 @@ export async function patchChannel(serverUrl: string, channelPatch: Partial<Chan
});
models.push(channelInfo);
}

const channel = await getChannelById(database, channelData.id);
if (channel && (channel.displayName !== channelData.display_name || channel.type !== channelData.type)) {
channel.prepareUpdate((v) => {
v.displayName = channelData.display_name;
// DM and GM display names cannot be patched and are formatted client-side; do not overwrite
if (channelData.type !== General.DM_CHANNEL && channelData.type !== General.GM_CHANNEL) {
v.displayName = channelData.display_name;
}
v.type = channelData.type;
});
models.push(channel);
Expand Down
2 changes: 1 addition & 1 deletion app/client/rest/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const ClientChannels = <TBase extends Constructor<ClientBase>>(superclass: TBase
);
};

patchChannel = async (channelId: string, channelPatch: Partial<Channel>) => {
patchChannel = async (channelId: string, channelPatch: ChannelPatch) => {
this.analytics?.trackAPI('api_channels_patch', {channel_id: channelId});

return this.doFetch(
Expand Down
8 changes: 8 additions & 0 deletions app/client/websocket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ export default class WebSocketClient {

// Check again if the client is the same, to avoid race conditions
if (this.conn === client) {
// In case turning on/off Wi-fi on Samsung devices
// the websocket will call onClose then onError then initialize again with readyState CLOSED, we need to open it again
if (this.conn.readyState === WebSocketReadyState.CLOSED) {
if (this.connectionTimeout) {
clearTimeout(this.connectionTimeout);
}
this.conn.open();
}
return;
}
this.conn = client;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AttachmentAuthor it matches snapshot when both name and icon are provided 1`] = `
<View
style={
{
"flex": 1,
"flexDirection": "row",
}
}
>
<View
style={
[
{
"overflow": "hidden",
},
{
"height": 12,
"marginRight": 3,
"width": 12,
},
]
}
>
<FastImageView
defaultSource={null}
resizeMode="cover"
source={
{
"uri": "https://images.com/image.png",
}
}
style={
{
"bottom": 0,
"left": 0,
"position": "absolute",
"right": 0,
"top": 0,
}
}
/>
</View>
<Text
onPress={[Function]}
style={
[
{
"color": "rgba(63,67,80,0.5)",
"fontSize": 11,
},
{
"color": "rgba(28,88,217,0.5)",
},
]
}
>
jhondoe
</Text>
</View>
`;

exports[`AttachmentAuthor it matches snapshot when only icon is provided 1`] = `
<View
style={
{
"flex": 1,
"flexDirection": "row",
}
}
>
<View
style={
[
{
"overflow": "hidden",
},
{
"height": 12,
"marginRight": 3,
"width": 12,
},
]
}
>
<FastImageView
defaultSource={null}
resizeMode="cover"
source={
{
"uri": "https://images.com/image.png",
}
}
style={
{
"bottom": 0,
"left": 0,
"position": "absolute",
"right": 0,
"top": 0,
}
}
/>
</View>
</View>
`;

exports[`AttachmentAuthor it matches snapshot when only name is provided 1`] = `
<View
style={
{
"flex": 1,
"flexDirection": "row",
}
}
>
<Text
onPress={[Function]}
style={
[
{
"color": "rgba(63,67,80,0.5)",
"fontSize": 11,
},
{
"color": "rgba(28,88,217,0.5)",
},
]
}
>
jhondoe
</Text>
</View>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import React from 'react';

import Preferences from '@constants/preferences';
import {renderWithIntl} from '@test/intl-test-helper';

import AttachmentAuthor from './attachment_author';

describe('AttachmentAuthor', () => {
const baseProps = {
link: 'http://linktoatachment.com',
name: 'jhondoe',
icon: 'https://images.com/image.png',
theme: Preferences.THEMES.denim,
};

test('it matches snapshot when both name and icon are provided', () => {
const wrapper = renderWithIntl(<AttachmentAuthor {...baseProps}/>);
expect(wrapper.toJSON()).toMatchSnapshot();
});

test('it matches snapshot when only name is provided', () => {
const props = {
...baseProps,
icon: undefined,
};

const wrapper = renderWithIntl(<AttachmentAuthor {...props}/>);
expect(wrapper.toJSON()).toMatchSnapshot();
});

test('it matches snapshot when only icon is provided', () => {
const props = {
...baseProps,
name: undefined,
};

const wrapper = renderWithIntl(<AttachmentAuthor {...props}/>);
expect(wrapper.toJSON()).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default function MessageAttachment({attachment, channelId, layoutWidth, l
value={attachment.pretext}
/>
<View style={[style.container, style.border, borderStyle]}>
{Boolean(attachment.author_icon && attachment.author_name) &&
{Boolean(attachment.author_icon || attachment.author_name) &&
<AttachmentAuthor
icon={attachment.author_icon}
link={attachment.author_link}
Expand Down
16 changes: 16 additions & 0 deletions app/constants/snack_bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,24 @@ export const SNACK_BAR_TYPE = keyMirror({
MESSAGE_COPIED: null,
MUTE_CHANNEL: null,
REMOVE_CHANNEL_USER: null,
TEXT_COPIED: null,
UNFAVORITE_CHANNEL: null,
UNMUTE_CHANNEL: null,
UNFOLLOW_THREAD: null,
});

export const MESSAGE_TYPE = {
SUCCESS: 'success',
ERROR: 'error',
DEFAULT: 'default',
};

type SnackBarConfig = {
id: string;
defaultMessage: string;
iconName: string;
canUndo: boolean;
type?: typeof MESSAGE_TYPE[keyof typeof MESSAGE_TYPE];
};

export const SNACK_BAR_CONFIG: Record<string, SnackBarConfig> = {
Expand Down Expand Up @@ -55,6 +63,7 @@ export const SNACK_BAR_CONFIG: Record<string, SnackBarConfig> = {
defaultMessage: 'Link copied to clipboard',
iconName: 'link-variant',
canUndo: false,
type: MESSAGE_TYPE.SUCCESS,
},
MESSAGE_COPIED: {
id: t('snack.bar.message.copied'),
Expand All @@ -74,6 +83,13 @@ export const SNACK_BAR_CONFIG: Record<string, SnackBarConfig> = {
iconName: 'check',
canUndo: true,
},
TEXT_COPIED: {
id: t('snack.bar.text.copied'),
defaultMessage: 'Copied to clipboard',
iconName: 'content-copy',
canUndo: false,
type: MESSAGE_TYPE.SUCCESS,
},
UNFAVORITE_CHANNEL: {
id: t('snack.bar.unfavorite.channel'),
defaultMessage: 'This channel was unfavorited',
Expand Down
7 changes: 7 additions & 0 deletions app/constants/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@
// See LICENSE.txt for license information.

export const GM_AS_DM_VERSION = [9, 1, 0];

export const OS_VERSION = {
ANDROID: 'android',
IOS: 'ios',
};

export const ANDROID_33 = 33;
14 changes: 14 additions & 0 deletions app/queries/servers/role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,17 @@ export function observeCanManageChannelMembers(database: Database, channelId: st
distinctUntilChanged(),
);
}

export function observeCanManageChannelSettings(database: Database, channelId: string, user: UserModel) {
return observeChannel(database, channelId).pipe(
switchMap((c) => {
if (!c || c.deleteAt !== 0 || isDMorGM(c)) {
return of$(false);
}

const permission = c.type === General.OPEN_CHANNEL ? Permissions.MANAGE_PUBLIC_CHANNEL_PROPERTIES : Permissions.MANAGE_PRIVATE_CHANNEL_PROPERTIES;
return observePermissionForChannel(database, c, user, permission, true);
}),
distinctUntilChanged(),
);
}
Loading

0 comments on commit 8f0139d

Please sign in to comment.