diff --git a/src/adapters/pubsub.ts b/src/adapters/pubsub.ts index edcc862..64a28f8 100644 --- a/src/adapters/pubsub.ts +++ b/src/adapters/pubsub.ts @@ -1,13 +1,7 @@ -import { IBaseComponent } from '@well-known-components/interfaces' -import { AppComponents, SubscriptionEventsEmitter } from '../types' +import { AppComponents, IPubSubComponent } from '../types' const FRIENDSHIP_UPDATES_CHANNEL = 'FRIENDSHIP_UPDATES' -export type IPubSubComponent = IBaseComponent & { - subscribeToFriendshipUpdates(cb: (message: string) => void): Promise - publishFriendshipUpdate(update: SubscriptionEventsEmitter['update']): Promise -} - export default function createPubSubComponent(components: Pick): IPubSubComponent { const { logs, redis } = components const logger = logs.getLogger('pubsub-component') diff --git a/src/logic/friendships.ts b/src/logic/friendships.ts index 9027ccc..90ff560 100644 --- a/src/logic/friendships.ts +++ b/src/logic/friendships.ts @@ -1,10 +1,12 @@ import { FriendshipUpdate, UpsertFriendshipPayload, - FriendshipStatus as FriendshipRequestStatus + FriendshipStatus as FriendshipRequestStatus, + ConnectivityStatus } from '@dcl/protocol/out-js/decentraland/social_service/v3/social_service_v3.gen' import { Action, + Friend, FRIENDSHIP_ACTION_TRANSITIONS, FriendshipAction, FriendshipStatus, @@ -195,3 +197,21 @@ export function getFriendshipRequestStatus( const statusResolver = FRIENDSHIP_STATUS_BY_ACTION[action] return statusResolver?.(acting_user, loggedUserAddress) ?? FriendshipRequestStatus.UNRECOGNIZED } + +const filtersByConnectivityStatus = { + [ConnectivityStatus.ONLINE]: (friend: Friend, connectedPeers: Record) => + connectedPeers[friend.address], + [ConnectivityStatus.OFFLINE]: (friend: Friend, connectedPeers: Record) => + !connectedPeers[friend.address], + [ConnectivityStatus.AWAY]: (friend: Friend, connectedPeers: Record) => + !connectedPeers[friend.address], + [ConnectivityStatus.UNRECOGNIZED]: () => true +} + +export function byConnectivityStatus(status: ConnectivityStatus, connectedPeers: Record) { + const filter = filtersByConnectivityStatus[status] + + if (!filter) () => true + + return (friend: Friend) => filter(friend, connectedPeers) +} diff --git a/test/mocks/components/db.ts b/test/mocks/components/db.ts index 7c9a105..56ace21 100644 --- a/test/mocks/components/db.ts +++ b/test/mocks/components/db.ts @@ -1,4 +1,4 @@ -import { IDatabaseComponent } from '../../../src/adapters/db' +import { IDatabaseComponent } from '../../../src/types' export const mockDb: jest.Mocked = { createFriendship: jest.fn(), diff --git a/test/mocks/components/index.ts b/test/mocks/components/index.ts index f8808c1..ead9c89 100644 --- a/test/mocks/components/index.ts +++ b/test/mocks/components/index.ts @@ -4,3 +4,5 @@ export * from './pubsub' export * from './pg' export * from './config' export * from './uws' +export * from './redis' +export * from './archipelago-stats' diff --git a/test/mocks/components/logs.ts b/test/mocks/components/logs.ts index 0235740..ad53e69 100644 --- a/test/mocks/components/logs.ts +++ b/test/mocks/components/logs.ts @@ -1,6 +1,4 @@ -import { IMetricsComponent } from '@well-known-components/interfaces' import { ILoggerComponent } from '@well-known-components/interfaces/dist/components/logger' -import { createLogComponent } from '@well-known-components/logger' export const mockLogs: jest.Mocked = { getLogger: jest.fn().mockReturnValue({ diff --git a/test/mocks/components/pg.ts b/test/mocks/components/pg.ts index d341699..33d234f 100644 --- a/test/mocks/components/pg.ts +++ b/test/mocks/components/pg.ts @@ -1,5 +1,4 @@ import { IPgComponent } from '@well-known-components/pg-component' -import { release } from 'os' export const mockPg: jest.Mocked = { streamQuery: jest.fn(), diff --git a/test/mocks/components/pubsub.ts b/test/mocks/components/pubsub.ts index 95f6485..f846ee6 100644 --- a/test/mocks/components/pubsub.ts +++ b/test/mocks/components/pubsub.ts @@ -1,4 +1,4 @@ -import { IPubSubComponent } from '../../../src/adapters/pubsub' +import { IPubSubComponent } from '../../../src/types' export const mockPubSub: jest.Mocked = { start: jest.fn(),