iOS Share extension, fix teams and dm channels (#1389)

* iOS Share extension, fix teams and dm channels

* Feedback review

* Feedback review 2
This commit is contained in:
enahum 2018-01-29 13:59:30 -03:00 committed by GitHub
parent 712e3019eb
commit aebea2688b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 12 deletions

View file

@ -119,28 +119,51 @@ export default class ExtensionChannels extends PureComponent {
const {currentUserId, teamId} = this.props;
const channelsMap = {};
// get the channels for the specified team
const myChannels = await Client4.getMyChannels(teamId);
const myPreferences = await Client4.getMyPreferences();
const usersInDms = myPreferences.filter((pref) => pref.category === Preferences.CATEGORY_DIRECT_CHANNEL_SHOW).map((pref) => pref.name);
// filter channels that are direct and group messages
const dms = myChannels.filter((channel) => {
const teammateId = getUserIdFromChannelName(currentUserId, channel.name);
return (channel.type === General.DM_CHANNEL && usersInDms.includes(teammateId)) || channel.type === General.GM_CHANNEL;
return channel.type === General.DM_CHANNEL || channel.type === General.GM_CHANNEL;
});
const dmProfiles = await Client4.getProfilesByIds(usersInDms);
const usersInDms = dms.filter((channel) => {
return channel.type === General.DM_CHANNEL;
}).map((channel) => {
return getUserIdFromChannelName(currentUserId, channel.name);
}).reduce((acc, teammateId) => {
if (!acc.includes(teammateId)) {
acc.push(teammateId);
}
return acc;
}, []);
// get the user ids that belong to DMs & GMs
let dmProfiles;
if (usersInDms.length) {
try {
dmProfiles = await Client4.getProfilesByIds(usersInDms);
} catch (e) {
// do nothing
}
}
for (let i = 0; i < dms.length; i++) {
const channel = dms[i];
if (channel.type === General.DM_CHANNEL) {
if (channel.type === General.DM_CHANNEL && dmProfiles) {
const teammateId = getUserIdFromChannelName(currentUserId, channel.name);
const profile = dmProfiles.find((p) => p.id === teammateId);
channelsMap[channel.id] = displayUsername(profile, Preferences.DISPLAY_PREFER_FULL_NAME);
} else if (channel.type === General.GM_CHANNEL) {
const members = await Client4.getChannelMembers(channel.id, 0, General.MAX_USERS_IN_GM);
const userIds = members.filter((m) => m.user_id !== currentUserId).map((m) => m.user_id);
const gmProfiles = await Client4.getProfilesByIds(userIds);
channelsMap[channel.id] = this.getGroupDisplayNameFromUserIds(userIds, gmProfiles);
try {
const members = await Client4.getChannelMembers(channel.id, 0, General.MAX_USERS_IN_GM);
const userIds = members.filter((m) => m.user_id !== currentUserId).map((m) => m.user_id);
const gmProfiles = await Client4.getProfilesByIds(userIds);
channelsMap[channel.id] = this.getGroupDisplayNameFromUserIds(userIds, gmProfiles);
} catch (e) {
// do nothing
}
}
}

View file

@ -220,6 +220,7 @@ export default class ExtensionPost extends PureComponent {
Client4.setUrl(credentials.url);
Client4.setToken(credentials.token);
Client4.setUserId(currentUserId);
this.setState({channel, currentUserId, files, team, value});
} catch (error) {
this.setState({error});

View file

@ -57,14 +57,15 @@ export default class ExtensionTeams extends PureComponent {
const myMembers = await Client4.getMyTeamMembers();
const myTeams = [];
teams.forEach(async (team) => {
for (let i = 0; i < teams.length; i++) {
const team = teams[i];
const belong = myMembers.find((member) => member.team_id === team.id);
if (belong) {
const channels = await Client4.getMyChannels(team.id);
defaultChannels[team.id] = channels.find((channel) => channel.name === General.DEFAULT_CHANNEL);
myTeams.push(team);
}
});
}
this.setState({
defaultChannels,