haptic feedback to be closer than message appears, also add logical to vibrate properly when focused the room or thread
This commit is contained in:
parent
4d8562628e
commit
eeb40129ff
|
@ -1,6 +1,7 @@
|
|||
import EJSON from 'ejson';
|
||||
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
|
||||
import { InteractionManager } from 'react-native';
|
||||
import * as Haptics from 'expo-haptics';
|
||||
|
||||
import log from '../helpers/log';
|
||||
import protectedFunction from '../helpers/protectedFunction';
|
||||
|
@ -19,6 +20,8 @@ import { IDDPMessage } from '../../../definitions/IDDPMessage';
|
|||
import sdk from '../../services/sdk';
|
||||
import { readMessages } from '../readMessages';
|
||||
import { loadMissedMessages } from '../loadMissedMessages';
|
||||
import userPreferences from '../userPreferences';
|
||||
import { NOTIFICATION_IN_APP_VIBRATION } from '../../constants';
|
||||
|
||||
const WINDOW_TIME = 1000;
|
||||
|
||||
|
@ -39,6 +42,7 @@ export default class RoomSubscription {
|
|||
private notifyRoomListener?: Promise<any>;
|
||||
private messageReceivedListener?: Promise<any>;
|
||||
private lastOpen?: Date;
|
||||
private threadFocused?: string;
|
||||
|
||||
constructor(rid: string) {
|
||||
this.rid = rid;
|
||||
|
@ -306,6 +310,17 @@ export default class RoomSubscription {
|
|||
}
|
||||
}
|
||||
|
||||
// Haptic Feedback when receiving message
|
||||
const { id: userId } = reduxStore.getState().login.user;
|
||||
if (
|
||||
((!message.tmid && !message.tlm && !this.threadFocused) || (message.tmid && message.tmid === this.threadFocused)) &&
|
||||
message.u._id !== userId
|
||||
) {
|
||||
const notificationInAppVibration = userPreferences.getBool(NOTIFICATION_IN_APP_VIBRATION);
|
||||
if (notificationInAppVibration || notificationInAppVibration === null) {
|
||||
Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success);
|
||||
}
|
||||
}
|
||||
return resolve();
|
||||
});
|
||||
|
||||
|
@ -358,4 +373,12 @@ export default class RoomSubscription {
|
|||
const message = buildMessage(EJSON.fromJSONValue(ddpMessage.fields.args[0])) as IMessage;
|
||||
this.queue[message._id] = message;
|
||||
};
|
||||
|
||||
setThreadFocused = (tmid: string) => {
|
||||
this.threadFocused = tmid;
|
||||
};
|
||||
|
||||
removeThreadFocused = () => {
|
||||
this.threadFocused = '';
|
||||
};
|
||||
}
|
||||
|
|
|
@ -230,6 +230,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
|||
};
|
||||
private sub?: RoomClass;
|
||||
private unsubscribeBlur?: () => void;
|
||||
private unsubscribeFocus?: () => void;
|
||||
|
||||
constructor(props: IRoomViewProps) {
|
||||
super(props);
|
||||
|
@ -338,6 +339,11 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
|||
this.unsubscribeBlur = navigation.addListener('blur', () => {
|
||||
audioPlayer.pauseCurrentAudio();
|
||||
});
|
||||
this.unsubscribeFocus = navigation.addListener('focus', () => {
|
||||
if (!this.tmid) {
|
||||
this.sub?.removeThreadFocused();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
shouldComponentUpdate(nextProps: IRoomViewProps, nextState: IRoomViewState) {
|
||||
|
@ -457,6 +463,9 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
|||
if (this.unsubscribeBlur) {
|
||||
this.unsubscribeBlur();
|
||||
}
|
||||
if (this.unsubscribeFocus) {
|
||||
this.unsubscribeFocus();
|
||||
}
|
||||
EventEmitter.removeListener('connected', this.handleConnected);
|
||||
EventEmitter.removeListener('ROOM_REMOVED', this.handleRoomRemoved);
|
||||
if (!this.tmid) {
|
||||
|
@ -1212,6 +1221,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
|||
sendLoadingEvent({ visible: false });
|
||||
}, 300);
|
||||
}
|
||||
this.sub?.setThreadFocused(item.tmid);
|
||||
return navigation.push('RoomView', {
|
||||
rid: this.rid,
|
||||
tmid: item.tmid,
|
||||
|
@ -1223,6 +1233,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
|||
}
|
||||
|
||||
if ('tlm' in item) {
|
||||
this.sub?.setThreadFocused(item.id);
|
||||
return navigation.push('RoomView', {
|
||||
rid: this.rid,
|
||||
tmid: item.id,
|
||||
|
|
Loading…
Reference in New Issue