Update current user online status

This commit is contained in:
Alexander Zinchuk 2021-06-19 00:25:40 +03:00
parent 5f6010bbd0
commit 36cc443e26
8 changed files with 31 additions and 9 deletions

View File

@ -47,6 +47,7 @@ export {
fetchAuthorizations, terminateAuthorization, terminateAllAuthorizations,
fetchNotificationExceptions, fetchNotificationSettings, updateContactSignUpNotification, updateNotificationSettings,
fetchLanguages, fetchLangPack, fetchPrivacySettings, setPrivacySettings, registerDevice, unregisterDevice,
updateIsOnline,
} from './settings';
export {

View File

@ -366,9 +366,15 @@ export async function setPrivacySettings(
return buildPrivacyRules(result.rules);
}
export async function updateIsOnline(isOnline: boolean) {
await invokeRequest(new GramJs.account.UpdateStatus({ offline: !isOnline }));
}
function updateLocalDb(
result: GramJs.account.PrivacyRules | GramJs.contacts.Blocked | GramJs.contacts.BlockedSlice |
GramJs.Updates | GramJs.UpdatesCombined,
result: (
GramJs.account.PrivacyRules | GramJs.contacts.Blocked | GramJs.contacts.BlockedSlice |
GramJs.Updates | GramJs.UpdatesCombined
),
) {
result.users.forEach((user) => {
if (user instanceof GramJs.User) {

View File

@ -49,7 +49,7 @@ type StateProps = {
};
type DispatchProps = Pick<GlobalActions, (
'loadAnimatedEmojis' | 'loadNotificationSettings' | 'loadNotificationExceptions'
'loadAnimatedEmojis' | 'loadNotificationSettings' | 'loadNotificationExceptions' | 'updateIsOnline'
)>;
const ANIMATION_DURATION = 350;
@ -75,6 +75,7 @@ const Main: FC<StateProps & DispatchProps> = ({
loadAnimatedEmojis,
loadNotificationSettings,
loadNotificationExceptions,
updateIsOnline,
}) => {
if (DEBUG && !DEBUG_isLogged) {
DEBUG_isLogged = true;
@ -85,11 +86,12 @@ const Main: FC<StateProps & DispatchProps> = ({
// Initial API calls
useEffect(() => {
if (lastSyncTime) {
updateIsOnline(true);
loadAnimatedEmojis();
loadNotificationSettings();
loadNotificationExceptions();
}
}, [lastSyncTime, loadAnimatedEmojis, loadNotificationExceptions, loadNotificationSettings]);
}, [lastSyncTime, loadAnimatedEmojis, loadNotificationExceptions, loadNotificationSettings, updateIsOnline]);
const {
transitionClassNames: middleColumnTransitionClassNames,
@ -129,6 +131,13 @@ const Main: FC<StateProps & DispatchProps> = ({
}
}, [animationLevel, isRightColumnShown]);
useBackgroundMode(() => {
updateIsOnline(false);
}, () => {
updateIsOnline(true);
});
// Browser tab indicators
useBackgroundMode(() => {
const initialUnread = selectCountNotMutedUnread(getGlobal());
let index = 0;
@ -220,6 +229,6 @@ export default memo(withGlobal(
};
},
(setGlobal, actions): DispatchProps => pick(actions, [
'loadAnimatedEmojis', 'loadNotificationSettings', 'loadNotificationExceptions',
'loadAnimatedEmojis', 'loadNotificationSettings', 'loadNotificationExceptions', 'updateIsOnline',
]),
)(Main));

View File

@ -446,7 +446,7 @@ export type ActionTypes = (
'loadAuthorizations' | 'terminateAuthorization' | 'terminateAllAuthorizations' |
'loadNotificationSettings' | 'updateContactSignUpNotification' | 'updateNotificationSettings' |
'loadLanguages' | 'loadPrivacySettings' | 'setPrivacyVisibility' | 'setPrivacySettings' |
'loadNotificationExceptions' | 'setThemeSettings' |
'loadNotificationExceptions' | 'setThemeSettings' | 'updateIsOnline' |
// Stickers & GIFs
'loadStickerSets' | 'loadAddedStickers' | 'loadRecentStickers' | 'loadFavoriteStickers' | 'loadFeaturedStickers' |
'loadStickers' | 'setStickerSearchQuery' | 'loadSavedGifs' | 'setGifSearchQuery' | 'searchMoreGifs' |

View File

@ -285,7 +285,7 @@ namespace Api {
export type TypeAccessPointRule = AccessPointRule;
export type TypeTlsClientHello = TlsClientHello;
export type TypeTlsBlock = TlsBlockString | TlsBlockRandom | TlsBlockZero | TlsBlockDomain | TlsBlockGrease | TlsBlockScope;
export namespace storage {
export type TypeFileType = storage.FileUnknown | storage.FilePartial | storage.FileJpeg | storage.FileGif | storage.FilePng | storage.FilePdf | storage.FileMp3 | storage.FileMov | storage.FileMp4 | storage.FileWebp;
@ -7001,7 +7001,7 @@ namespace Api {
}> {
entries: Api.TypeTlsBlock[];
};
export namespace storage {
export class FileUnknown extends VirtualClass<void> {};
@ -8500,7 +8500,7 @@ namespace Api {
}>, Api.TypeDestroySessionRes> {
sessionId: long;
};
export namespace auth {
export class SendCode extends Request<Partial<{

View File

@ -922,6 +922,7 @@ account.unregisterDevice#3076c4bf token_type:int token:string other_uids:Vector<
account.updateNotifySettings#84be5b93 peer:InputNotifyPeer settings:InputPeerNotifySettings = Bool;
account.getNotifySettings#12b3ad31 peer:InputNotifyPeer = PeerNotifySettings;
account.updateProfile#78515775 flags:# first_name:flags.0?string last_name:flags.1?string about:flags.2?string = User;
account.updateStatus#6628562c offline:Bool = Bool;
account.getWallPapers#aabb1763 hash:int = account.WallPapers;
account.checkUsername#2714d86c username:string = Bool;
account.updateUsername#3e0bdd7c username:string = User;

View File

@ -922,6 +922,7 @@ account.unregisterDevice#3076c4bf token_type:int token:string other_uids:Vector<
account.updateNotifySettings#84be5b93 peer:InputNotifyPeer settings:InputPeerNotifySettings = Bool;
account.getNotifySettings#12b3ad31 peer:InputNotifyPeer = PeerNotifySettings;
account.updateProfile#78515775 flags:# first_name:flags.0?string last_name:flags.1?string about:flags.2?string = User;
account.updateStatus#6628562c offline:Bool = Bool;
account.getWallPapers#aabb1763 hash:int = account.WallPapers;
account.checkUsername#2714d86c username:string = Bool;
account.updateUsername#3e0bdd7c username:string = User;

View File

@ -513,3 +513,7 @@ function buildInputPrivacyRules(global: GlobalState, {
return rules;
}
addReducer('updateIsOnline', (global, actions, payload) => {
callApi('updateIsOnline', payload);
});