Skip to content

Commit

Permalink
feat(lib): add updates to pinning messages
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-suwala committed Oct 17, 2023
1 parent 026fe94 commit 66de710
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
1 change: 1 addition & 0 deletions lib/src/entities/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class User {
}

get active() {
console.log("userid", this.id, new Date().getTime(), this.lastActiveTimestamp)
return !!(
this.lastActiveTimestamp &&
new Date().getTime() - this.lastActiveTimestamp <= this.chat.config.storeUserActivityInterval
Expand Down
4 changes: 1 addition & 3 deletions samples/react-native-group-chat/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ function MainRoutesNavigator({ route }: StackScreenProps<RootStackParamList, "ma
headerRight: () => {
return (
<TouchableOpacity
onPress={() =>
navigation.navigate("PinnedMessage", { channelId: currentChannel?.id })
}
onPress={() => navigation.navigate("PinnedMessage")}
style={{ paddingRight: 24 }}
>
<MaterialCommunityIcons name="pin-outline" color={colors.neutral0} size={26} />
Expand Down
17 changes: 0 additions & 17 deletions samples/react-native-group-chat/screens/ordinary/chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ export function ChatScreen({}: StackScreenProps<HomeStackParamList, "Chat">) {
}

await message.pin()
await currentChannel.update({ name: "Grupa chatowa 23" + Math.random() })
// const refreshedChannel = await chat.getChannel(currentChannel.id)
// if (refreshedChannel) {
// setCurrentChannel(refreshedChannel)
// }
},
[chat, currentChannel, setCurrentChannel]
)
Expand Down Expand Up @@ -103,18 +98,6 @@ export function ChatScreen({}: StackScreenProps<HomeStackParamList, "Chat">) {
onToggleEmoji: handleEmoji,
})

useEffect(() => {
if (!currentChannel) {
return
}
console.log("hello", currentChannel)
const unstream = currentChannel.streamUpdates((ch) => {
console.log("ch", ch)
})

return unstream
}, [currentChannel])

useEffect(() => {
if (!giftedChatMappedMessages.length) {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,23 @@ export function PinnedMessage({}: StackScreenProps<HomeStackParamList, "PinnedMe
useEffect(() => {
async function init() {
if (!chat || !currentChannel) return
setMessage(await currentChannel.getPinnedMessage())
const refreshedChannel = await chat.getChannel(currentChannel.id)
if (refreshedChannel) {
setMessage(await refreshedChannel.getPinnedMessage())
}
}

init()
}, [chat, currentChannel])

useEffect(() => {
const unstream = currentChannel?.streamUpdates(async (channel) => {
setMessage(await channel.getPinnedMessage())
})

return unstream
}, [currentChannel])

const renderMessageBubble = useCallback(
(props: Bubble<EnhancedIMessage>["props"]) => {
if (!message) {
Expand Down

0 comments on commit 66de710

Please sign in to comment.