Skip to content

Commit

Permalink
Merge pull request #2299 from shubhamkmr04/shubham/link-channel-pubke…
Browse files Browse the repository at this point in the history
…y-to-contact

Link Channel to the stored contacts
  • Loading branch information
kaloudis authored Aug 30, 2024
2 parents 048e58b + e82d2c0 commit bae0331
Showing 1 changed file with 67 additions and 3 deletions.
70 changes: 67 additions & 3 deletions views/Channels/Channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
ScrollView,
StyleSheet,
TouchableOpacity,
View
View,
Image
} from 'react-native';

import { Divider, Icon, ListItem } from 'react-native-elements';
Expand Down Expand Up @@ -34,10 +35,12 @@ import BackendUtils from '../../utils/BackendUtils';
import { localeString } from '../../utils/LocaleUtils';
import { themeColor } from '../../utils/ThemeUtils';
import UrlUtils from '../../utils/UrlUtils';
import { getPhoto } from '../../utils/PhotoUtils';

import ChannelsStore from '../../stores/ChannelsStore';
import SettingsStore from '../../stores/SettingsStore';
import NodeInfoStore from '../../stores/NodeInfoStore';
import ContactStore from '../../stores/ContactStore';

import Edit from '../../assets/images/SVG/Edit.svg';
import HourglassIcon from '../../assets/images/SVG/Hourglass.svg';
Expand All @@ -47,6 +50,7 @@ interface ChannelProps {
ChannelsStore: ChannelsStore;
SettingsStore: SettingsStore;
NodeInfoStore: NodeInfoStore;
ContactStore: ContactStore;
route: Route<'Channel', { channel: Channel }>;
}

Expand All @@ -58,7 +62,7 @@ interface ChannelState {
channel: Channel;
}

@inject('ChannelsStore', 'NodeInfoStore', 'SettingsStore')
@inject('ChannelsStore', 'NodeInfoStore', 'SettingsStore', 'ContactStore')
@observer
export default class ChannelView extends React.Component<
ChannelProps,
Expand All @@ -83,6 +87,51 @@ export default class ChannelView extends React.Component<
}
}

findContactByPubkey = (pubkey: string) => {
const { ContactStore } = this.props;
const { contacts } = ContactStore;
return contacts.find((contact) => contact.pubkey.includes(pubkey));
};

renderContactLink = (remotePubkey: string) => {
const contact = this.findContactByPubkey(remotePubkey);
if (contact) {
return (
<TouchableOpacity
style={{
...styles.container,
backgroundColor: themeColor('secondary')
}}
onPress={() => {
this.props.navigation.navigate('ContactDetails', {
contactId: contact.contactId || contact.id,
isNostrContact: false
});
}}
>
{contact.photo && (
<Image
source={{ uri: getPhoto(contact.photo) }}
style={styles.image}
/>
)}
<View>
<Text
style={{
fontSize: 18,
color: themeColor('highlight'),
fontFamily: 'PPNeueMontreal-Book'
}}
>
{contact.name}
</Text>
</View>
</TouchableOpacity>
);
}
return null;
};

closeChannel = async (
channelPoint?: string,
channelId?: string,
Expand Down Expand Up @@ -295,6 +344,7 @@ export default class ChannelView extends React.Component<
</Text>
</TouchableOpacity>
)}
{remotePubkey && this.renderContactLink(remotePubkey)}
</View>
<BalanceSlider
localBalance={lurkerMode ? 50 : localBalance}
Expand Down Expand Up @@ -770,11 +820,25 @@ const styles = StyleSheet.create({
paddingBottom: 10
},
pubkey: {
paddingBottom: 30,
paddingBottom: 24,
textAlign: 'center'
},
button: {
paddingTop: 15,
paddingBottom: 15
},
container: {
paddingHorizontal: 16,
paddingVertical: 12,
borderRadius: 6,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center'
},
image: {
width: 50,
height: 50,
borderRadius: 25,
marginRight: 14
}
});

0 comments on commit bae0331

Please sign in to comment.