@@ -13,7 +13,7 @@ import {
13
13
parseGroupId ,
14
14
udToDate ,
15
15
} from './apiUtils' ;
16
- import { poke , scry , subscribe } from './urbit' ;
16
+ import { getCurrentUserId , poke , scry , subscribe } from './urbit' ;
17
17
18
18
const logger = createDevLogger ( 'activityApi' , false ) ;
19
19
@@ -378,6 +378,7 @@ function getInfoFromMessageKey(
378
378
}
379
379
380
380
export type ActivityEvent =
381
+ | { type : 'updateBaseUnread' ; unread : db . BaseUnread }
381
382
| {
382
383
type : 'updateChannelUnread' ;
383
384
activity : db . ChannelUnread ;
@@ -414,6 +415,18 @@ export function subscribeToActivity(handler: (event: ActivityEvent) => void) {
414
415
const source = sourceIdToSource ( sourceId ) ;
415
416
416
417
switch ( source . type ) {
418
+ case 'base' :
419
+ handler ( {
420
+ type : 'updateBaseUnread' ,
421
+ unread : {
422
+ userId : getCurrentUserId ( ) ,
423
+ count : summary . count ,
424
+ notify : summary . notify ,
425
+ notifyCount : summary [ 'notify-count' ] ,
426
+ updatedAt : summary . recency ,
427
+ } ,
428
+ } ) ;
429
+ break ;
417
430
case 'group' :
418
431
handler ( {
419
432
type : 'updateGroupUnread' ,
@@ -724,6 +737,10 @@ export function getMessageKey(
724
737
Sources can be represented as a string or an object (see urbit/activity.ts for details).
725
738
*/
726
739
740
+ interface ClientBaseSource {
741
+ type : 'base' ;
742
+ }
743
+
727
744
interface ClientGroupSource {
728
745
type : 'group' ;
729
746
groupId : string ;
@@ -751,13 +768,18 @@ interface ClientContactSource {
751
768
}
752
769
753
770
export type ClientSource =
771
+ | ClientBaseSource
754
772
| ClientGroupSource
755
773
| ClientChannelSource
756
774
| ClientThreadSource
757
775
| ClientUnknownSource
758
776
| ClientContactSource ;
759
777
760
778
export function sourceIdToSource ( sourceId : string ) : ClientSource {
779
+ if ( sourceId === 'base' ) {
780
+ return { type : 'base' } ;
781
+ }
782
+
761
783
const parts = sourceId . split ( '/' ) ;
762
784
const sourceType = parts [ 0 ] ;
763
785
@@ -934,6 +956,7 @@ export async function getPushNotificationsSetting(): Promise<ub.PushNotification
934
956
}
935
957
936
958
export type ActivityUpdateQueue = {
959
+ baseUnread ?: db . BaseUnread ;
937
960
groupUnreads : db . GroupUnread [ ] ;
938
961
channelUnreads : db . ChannelUnread [ ] ;
939
962
threadUnreads : db . ThreadUnreadState [ ] ;
@@ -942,17 +965,29 @@ export type ActivityUpdateQueue = {
942
965
} ;
943
966
944
967
export type ActivityInit = {
968
+ baseUnread ?: db . BaseUnread ;
945
969
groupUnreads : db . GroupUnread [ ] ;
946
970
channelUnreads : db . ChannelUnread [ ] ;
947
971
threadActivity : db . ThreadUnreadState [ ] ;
948
972
} ;
949
973
950
974
export const toClientUnreads = ( activity : ub . Activity ) : ActivityInit => {
975
+ const userId = getCurrentUserId ( ) ;
951
976
const groupUnreads : db . GroupUnread [ ] = [ ] ;
952
977
const channelUnreads : db . ChannelUnread [ ] = [ ] ;
953
978
const threadActivity : db . ThreadUnreadState [ ] = [ ] ;
979
+ let baseUnread : db . BaseUnread | undefined = undefined ;
954
980
955
981
Object . entries ( activity ) . forEach ( ( [ sourceId , summary ] ) => {
982
+ if ( sourceId === 'base' ) {
983
+ baseUnread = {
984
+ userId,
985
+ count : summary . count ,
986
+ notify : summary . notify ,
987
+ notifyCount : summary [ 'notify-count' ] ,
988
+ updatedAt : summary . recency ,
989
+ } ;
990
+ }
956
991
const [ activityId , ...rest ] = sourceId . split ( '/' ) ;
957
992
if ( activityId === 'ship' || activityId === 'club' ) {
958
993
const channelId = rest . join ( '/' ) ;
@@ -984,7 +1019,7 @@ export const toClientUnreads = (activity: ub.Activity): ActivityInit => {
984
1019
}
985
1020
} ) ;
986
1021
987
- return { channelUnreads, threadActivity, groupUnreads } ;
1022
+ return { baseUnread , channelUnreads, threadActivity, groupUnreads } ;
988
1023
} ;
989
1024
990
1025
export const toGroupUnread = (
0 commit comments