Skip to content

Commit

Permalink
feat:mobile part
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacper-RF committed Oct 23, 2023
1 parent cf65743 commit 5592a8f
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import red from '@mui/material/colors/red'

import Jdenticon from '../../Jdenticon/Jdenticon'

import { DisplayableMessage, DownloadStatus, InfoMessagesType, MessageSendingStatus, MessageType } from '@quiet/types'
import { DisplayableMessage, DownloadStatus, MessageSendingStatus, MessageType } from '@quiet/types'

import { NestedMessageContent } from './NestedMessageContent'

Expand Down Expand Up @@ -256,7 +256,7 @@ export const BasicMessageComponent: React.FC<BasicMessageProps & FileActionsProp
{messages.map((message, index) => {
const pending = pendingMessages[message.id] !== undefined
const downloadStatus = downloadStatuses[message.id]

console.log({ message })
if (message.type === MessageType.Info && message.nickname !== ownerNickname) {
message = transformUserInfoMessages(message.nickname, message)
if (message.message === '') return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,15 @@ class NotificationHandler(private val context: Context) {
channelName = channelId.substring(0,channelId.indexOf('_'))
}
// Parse message content
val _content = _message.getString("message")
var _content = _message.getString("message")

// Transform message if it is info message about new user
val USER_JOINED = "user-joined"

if(_content == USER_JOINED){
_content =("has joined and will be registered soon")
}

content = String.format("%s", _content)
} catch (e: JSONException) {
Log.e("NOTIFICATION", "incorrect NOTIFICATION payload", e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ import { defaultTheme } from '../../styles/themes/default.theme'
import { truncateWords } from '../../utils/functions/truncateWords/truncateWords'
import { Typography } from '../Typography/Typography.component'
import { ChannelTileProps } from './ChannelTile.types'
import { InfoMessagesType } from '@quiet/types'

export const ChannelTile: FC<ChannelTileProps> = ({ name, id, message, date, unread, redirect, nickname }) => {
if (message === InfoMessagesType.USER_JOINED) {
message = `@${nickname} has joined and will be registered soon. 🎉`
}

export const ChannelTile: FC<ChannelTileProps> = ({ name, id, message, date, unread, redirect }) => {
const _leftSwipe = (_progress: any, dragX: any) => {
const scale = dragX.interpolate({
inputRange: [0, 100],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export interface ChannelTileProps {
message?: string
date?: string
redirect: (id: string) => void
nickname: string
}
4 changes: 4 additions & 0 deletions packages/mobile/src/components/Chat/Chat.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const Chat: FC<ChatProps & FileActionsProps> = ({
openUrl,
duplicatedUsernameHandleBack,
unregisteredUsernameHandleBack,
ownerNickname,
ready = true,
}) => {
const [didKeyboardShow, setKeyboardShow] = useState(false)
Expand Down Expand Up @@ -126,6 +127,7 @@ export const Chat: FC<ChatProps & FileActionsProps> = ({
openUrl={openUrl}
duplicatedUsernameHandleBack={duplicatedUsernameHandleBack}
unregisteredUsernameHandleBack={unregisteredUsernameHandleBack}
ownerNickname={ownerNickname}
/>
)

Expand Down Expand Up @@ -241,6 +243,7 @@ export const ChannelMessagesComponent: React.FC<ChannelMessagesComponentProps &
openUrl,
duplicatedUsernameHandleBack,
unregisteredUsernameHandleBack,
ownerNickname,
}) => {
return (
<View key={day}>
Expand All @@ -260,6 +263,7 @@ export const ChannelMessagesComponent: React.FC<ChannelMessagesComponentProps &
pendingMessages={pendingMessages}
duplicatedUsernameHandleBack={duplicatedUsernameHandleBack}
unregisteredUsernameHandleBack={unregisteredUsernameHandleBack}
ownerNickname={ownerNickname}
/>
)
})}
Expand Down
2 changes: 2 additions & 0 deletions packages/mobile/src/components/Chat/Chat.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface ChatProps extends UserLabelHandlers {
uploadedFiles?: FilePreviewData
openUrl: (url: string) => void
ready?: boolean
ownerNickname: string | null | undefined
}

export interface ChannelMessagesComponentProps extends UserLabelHandlers {
Expand All @@ -41,4 +42,5 @@ export interface ChannelMessagesComponentProps extends UserLabelHandlers {
downloadStatuses?: Dictionary<DownloadStatus>
openImagePreview: (media: FileMetadata) => void
openUrl: (url: string) => void
ownerNickname: string | null | undefined
}
7 changes: 7 additions & 0 deletions packages/mobile/src/components/Message/Message.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Markdown, { MarkdownIt, ASTNode } from '@ronradtke/react-native-markdown-
import { defaultTheme } from '../../styles/themes/default.theme'
import UserLabel from '../UserLabel/UserLabel.component'
import { UserLabelType } from '../UserLabel/UserLabel.types'
import { transformUserInfoMessages } from '@quiet/common'

export const Message: FC<MessageProps & FileActionsProps> = ({
data, // Set of messages merged by sender
Expand All @@ -25,6 +26,7 @@ export const Message: FC<MessageProps & FileActionsProps> = ({
pendingMessages,
duplicatedUsernameHandleBack,
unregisteredUsernameHandleBack,
ownerNickname,
}) => {
const renderMessage = (message: DisplayableMessage, pending: boolean) => {
switch (message.type) {
Expand Down Expand Up @@ -172,6 +174,11 @@ export const Message: FC<MessageProps & FileActionsProps> = ({
<View style={{ flexShrink: 1 }}>
{data.map((message: DisplayableMessage, index: number) => {
const outerDivStyle = index > 0 ? classes.nextMessage : classes.firstMessage

if (message.type === MessageType.Info && message.nickname !== ownerNickname) {
message = transformUserInfoMessages(message.nickname, message)
if (message.message === '') return
}
return (
<View style={outerDivStyle} key={index}>
{renderMessage(message, pending)}
Expand Down
1 change: 1 addition & 0 deletions packages/mobile/src/components/Message/Message.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export interface MessageProps extends UserLabelHandlers {
downloadStatus?: DownloadStatus
openImagePreview: (media: FileMetadata) => void
openUrl: (url: string) => void
ownerNickname: string | null | undefined
}
3 changes: 3 additions & 0 deletions packages/mobile/src/screens/Channel/Channel.screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export const ChannelScreen: FC = () => {

const isWebsocketConnected = useSelector(initSelectors.isWebsocketConnected)

const ownerNickname = useSelector(communities.selectors.ownerNickname)

let contextMenu: UseContextMenuType<Record<string, unknown>> | null = useContextMenu(MenuName.Channel)
if (!community?.CA || !isWebsocketConnected) {
contextMenu = null
Expand Down Expand Up @@ -184,6 +186,7 @@ export const ChannelScreen: FC = () => {
ready={isWebsocketConnected}
duplicatedUsernameHandleBack={duplicatedUsernameHandleBack}
unregisteredUsernameHandleBack={unregisteredUsernameHandleBack}
ownerNickname={ownerNickname}
/>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const ChannelListScreen: FC = () => {

const usernameTaken = useSelector(identity.selectors.usernameTaken)
const duplicateCerts = useSelector(users.selectors.duplicateCerts)
const allUsers = useSelector(users.selectors.allUsers)

useEffect(() => {
if (usernameTaken) {
Expand Down Expand Up @@ -63,6 +64,11 @@ export const ChannelListScreen: FC = () => {

const message = newestMessage?.message || '...'
const date = newestMessage?.createdAt ? formatMessageDisplayDate(newestMessage.createdAt) : undefined
const pubKey = newestMessage?.pubKey
let nickname = ''
if (pubKey) {
nickname = allUsers[newestMessage?.pubKey]?.username
}

const tile: ChannelTileProps = {
name: getChannelNameFromChannelId(status.id),
Expand All @@ -71,6 +77,7 @@ export const ChannelListScreen: FC = () => {
date,
unread: status.unread,
redirect,
nickname,
}

return tile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export function* sendUnregisteredInfoMessage(): Generator {
const generalChannel = yield* select(publicChannelsSelectors.generalChannel)

if (!community?.name || !identity || !generalChannel) return

const payload: WriteMessagePayload = {
type: MessageType.Info,
message: InfoMessagesType.USER_JOINED,
Expand Down

0 comments on commit 5592a8f

Please sign in to comment.