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, fetchAuthorizations, terminateAuthorization, terminateAllAuthorizations,
fetchNotificationExceptions, fetchNotificationSettings, updateContactSignUpNotification, updateNotificationSettings, fetchNotificationExceptions, fetchNotificationSettings, updateContactSignUpNotification, updateNotificationSettings,
fetchLanguages, fetchLangPack, fetchPrivacySettings, setPrivacySettings, registerDevice, unregisterDevice, fetchLanguages, fetchLangPack, fetchPrivacySettings, setPrivacySettings, registerDevice, unregisterDevice,
updateIsOnline,
} from './settings'; } from './settings';
export { export {

View File

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

View File

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

View File

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

View File

@ -285,7 +285,7 @@ namespace Api {
export type TypeAccessPointRule = AccessPointRule; export type TypeAccessPointRule = AccessPointRule;
export type TypeTlsClientHello = TlsClientHello; export type TypeTlsClientHello = TlsClientHello;
export type TypeTlsBlock = TlsBlockString | TlsBlockRandom | TlsBlockZero | TlsBlockDomain | TlsBlockGrease | TlsBlockScope; export type TypeTlsBlock = TlsBlockString | TlsBlockRandom | TlsBlockZero | TlsBlockDomain | TlsBlockGrease | TlsBlockScope;
export namespace storage { 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; 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[]; entries: Api.TypeTlsBlock[];
}; };
export namespace storage { export namespace storage {
export class FileUnknown extends VirtualClass<void> {}; export class FileUnknown extends VirtualClass<void> {};
@ -8500,7 +8500,7 @@ namespace Api {
}>, Api.TypeDestroySessionRes> { }>, Api.TypeDestroySessionRes> {
sessionId: long; sessionId: long;
}; };
export namespace auth { export namespace auth {
export class SendCode extends Request<Partial<{ 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.updateNotifySettings#84be5b93 peer:InputNotifyPeer settings:InputPeerNotifySettings = Bool;
account.getNotifySettings#12b3ad31 peer:InputNotifyPeer = PeerNotifySettings; 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.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.getWallPapers#aabb1763 hash:int = account.WallPapers;
account.checkUsername#2714d86c username:string = Bool; account.checkUsername#2714d86c username:string = Bool;
account.updateUsername#3e0bdd7c username:string = User; 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.updateNotifySettings#84be5b93 peer:InputNotifyPeer settings:InputPeerNotifySettings = Bool;
account.getNotifySettings#12b3ad31 peer:InputNotifyPeer = PeerNotifySettings; 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.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.getWallPapers#aabb1763 hash:int = account.WallPapers;
account.checkUsername#2714d86c username:string = Bool; account.checkUsername#2714d86c username:string = Bool;
account.updateUsername#3e0bdd7c username:string = User; account.updateUsername#3e0bdd7c username:string = User;

View File

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