Implement notifications

zio/stable
Paul Frazee 2022-10-03 10:53:36 -05:00
parent b05a334dcb
commit c7d7e152a0
16 changed files with 456 additions and 81 deletions

View File

@ -9,6 +9,7 @@ import {ShellModel} from './models/shell'
const ROOT_STATE_STORAGE_KEY = 'root' const ROOT_STATE_STORAGE_KEY = 'root'
const DEFAULT_SERVICE = 'http://localhost:2583' const DEFAULT_SERVICE = 'http://localhost:2583'
const STATE_FETCH_INTERVAL = 15e3
export async function setupState() { export async function setupState() {
let rootStore: RootStoreModel let rootStore: RootStoreModel
@ -32,8 +33,14 @@ export async function setupState() {
}) })
await rootStore.session.setup() await rootStore.session.setup()
await rootStore.fetchStateUpdate()
console.log(rootStore.me) console.log(rootStore.me)
// periodic state fetch
setInterval(() => {
rootStore.fetchStateUpdate()
}, STATE_FETCH_INTERVAL)
return rootStore return rootStore
} }

View File

@ -6,6 +6,7 @@ export class MeModel {
name?: string name?: string
displayName?: string displayName?: string
description?: string description?: string
notificationCount: number = 0
constructor(public rootStore: RootStoreModel) { constructor(public rootStore: RootStoreModel) {
makeAutoObservable(this, {rootStore: false}, {autoBind: true}) makeAutoObservable(this, {rootStore: false}, {autoBind: true})
@ -16,6 +17,7 @@ export class MeModel {
this.name = undefined this.name = undefined
this.displayName = undefined this.displayName = undefined
this.description = undefined this.description = undefined
this.notificationCount = 0
} }
async load() { async load() {
@ -39,4 +41,11 @@ export class MeModel {
this.clear() this.clear()
} }
} }
async fetchStateUpdate() {
const res = await this.rootStore.api.todo.social.getNotificationCount({})
runInAction(() => {
this.notificationCount = res.data.count
})
}
} }

View File

@ -3,9 +3,11 @@ import * as GetNotifications from '../../third-party/api/src/types/todo/social/g
import {RootStoreModel} from './root-store' import {RootStoreModel} from './root-store'
import {hasProp} from '../lib/type-guards' import {hasProp} from '../lib/type-guards'
export class NotificationsViewItemModel export interface GroupedNotification extends GetNotifications.Notification {
implements GetNotifications.Notification additional?: GetNotifications.Notification[]
{ }
export class NotificationsViewItemModel implements GroupedNotification {
// ui state // ui state
_reactKey: string = '' _reactKey: string = ''
@ -14,57 +16,65 @@ export class NotificationsViewItemModel
author: { author: {
did: string did: string
name: string name: string
displayName: string displayName?: string
} = {did: '', name: '', displayName: ''} } = {did: '', name: ''}
reason: string = ''
reasonSubject?: string
record: any = {} record: any = {}
isRead: boolean = false isRead: boolean = false
indexedAt: string = '' indexedAt: string = ''
additional?: NotificationsViewItemModel[]
constructor( constructor(
public rootStore: RootStoreModel, public rootStore: RootStoreModel,
reactKey: string, reactKey: string,
v: GetNotifications.Notification, v: GroupedNotification,
) { ) {
makeAutoObservable(this, {rootStore: false}) makeAutoObservable(this, {rootStore: false})
this._reactKey = reactKey this._reactKey = reactKey
this.copy(v) this.copy(v)
} }
copy(v: GetNotifications.Notification) { copy(v: GroupedNotification) {
this.uri = v.uri this.uri = v.uri
this.author = v.author this.author = v.author
this.reason = v.reason
this.reasonSubject = v.reasonSubject
this.record = v.record this.record = v.record
this.isRead = v.isRead this.isRead = v.isRead
this.indexedAt = v.indexedAt this.indexedAt = v.indexedAt
if (v.additional?.length) {
this.additional = []
for (const add of v.additional) {
this.additional.push(
new NotificationsViewItemModel(this.rootStore, '', add),
)
}
} else {
this.additional = undefined
}
} }
get isLike() { get isLike() {
return ( return this.reason === 'like'
hasProp(this.record, '$type') && this.record.$type === 'todo.social.like'
)
} }
get isRepost() { get isRepost() {
return ( return this.reason === 'repost'
hasProp(this.record, '$type') &&
this.record.$type === 'todo.social.repost'
)
} }
get isReply() { get isReply() {
return ( return this.reason === 'reply'
hasProp(this.record, '$type') && this.record.$type === 'todo.social.post'
)
} }
get isFollow() { get isFollow() {
return ( return this.reason === 'follow'
hasProp(this.record, '$type') &&
this.record.$type === 'todo.social.follow'
)
} }
get subjectUri() { get subjectUri() {
if (this.reasonSubject) {
return this.reasonSubject
}
if ( if (
hasProp(this.record, 'subject') && hasProp(this.record, 'subject') &&
typeof this.record.subject === 'string' typeof this.record.subject === 'string'
@ -121,7 +131,15 @@ export class NotificationsViewModel {
get loadMoreCursor() { get loadMoreCursor() {
if (this.hasContent) { if (this.hasContent) {
return this.notifications[this.notifications.length - 1].indexedAt const last = this.notifications[this.notifications.length - 1]
if (last.additional?.length) {
// get the lowest indexedAt from all available
return [last, ...last.additional].reduce(
(acc, v) => (v.indexedAt < acc ? v.indexedAt : acc),
last.indexedAt,
)
}
return last.indexedAt
} }
return undefined return undefined
} }
@ -139,6 +157,7 @@ export class NotificationsViewModel {
await this._pendingWork() await this._pendingWork()
this._loadPromise = this._initialLoad(isRefreshing) this._loadPromise = this._initialLoad(isRefreshing)
await this._loadPromise await this._loadPromise
this._updateReadState()
this._loadPromise = undefined this._loadPromise = undefined
} }
@ -265,12 +284,12 @@ export class NotificationsViewModel {
private _appendAll(res: GetNotifications.Response) { private _appendAll(res: GetNotifications.Response) {
let counter = this.notifications.length let counter = this.notifications.length
for (const item of res.data.notifications) { for (const item of groupNotifications(res.data.notifications)) {
this._append(counter++, item) this._append(counter++, item)
} }
} }
private _append(keyId: number, item: GetNotifications.Notification) { private _append(keyId: number, item: GroupedNotification) {
// TODO: validate .record // TODO: validate .record
this.notifications.push( this.notifications.push(
new NotificationsViewItemModel(this.rootStore, `item-${keyId}`, item), new NotificationsViewItemModel(this.rootStore, `item-${keyId}`, item),
@ -280,7 +299,7 @@ export class NotificationsViewModel {
private _updateAll(res: GetNotifications.Response) { private _updateAll(res: GetNotifications.Response) {
for (const item of res.data.notifications) { for (const item of res.data.notifications) {
const existingItem = this.notifications.find( const existingItem = this.notifications.find(
// this find function has a key subtley- the indexedAt comparison // this find function has a key subtlety- the indexedAt comparison
// the reason for this is reposts: they set the URI of the original post, not of the repost record // the reason for this is reposts: they set the URI of the original post, not of the repost record
// the indexedAt time will be for the repost however, so we use that to help us // the indexedAt time will be for the repost however, so we use that to help us
item2 => item.uri === item2.uri && item.indexedAt === item2.indexedAt, item2 => item.uri === item2.uri && item.indexedAt === item2.indexedAt,
@ -290,4 +309,39 @@ export class NotificationsViewModel {
} }
} }
} }
private async _updateReadState() {
try {
await this.rootStore.api.todo.social.postNotificationsSeen(
{},
{seenAt: new Date().toISOString()},
)
} catch (e) {
console.log('Failed to update notifications read state', e)
}
}
}
function groupNotifications(
items: GetNotifications.Notification[],
): GroupedNotification[] {
const items2: GroupedNotification[] = []
for (const item of items) {
let grouped = false
for (const item2 of items2) {
if (
item.reason === item2.reason &&
item.reasonSubject === item2.reasonSubject
) {
item2.additional = item2.additional || []
item2.additional.push(item)
grouped = true
break
}
}
if (!grouped) {
items2.push(item)
}
}
return items2
} }

View File

@ -38,6 +38,17 @@ export class RootStoreModel {
return res.data.did return res.data.did
} }
async fetchStateUpdate() {
if (!this.session.isAuthed) {
return
}
try {
await this.me.fetchStateUpdate()
} catch (e) {
console.error('Failed to fetch latest state', e)
}
}
serialize(): unknown { serialize(): unknown {
return { return {
session: this.session.serialize(), session: this.session.serialize(),

View File

@ -6969,6 +6969,7 @@ __export(src_exports, {
TodoSocialFollow: () => follow_exports, TodoSocialFollow: () => follow_exports,
TodoSocialGetFeed: () => getFeed_exports, TodoSocialGetFeed: () => getFeed_exports,
TodoSocialGetLikedBy: () => getLikedBy_exports, TodoSocialGetLikedBy: () => getLikedBy_exports,
TodoSocialGetNotificationCount: () => getNotificationCount_exports,
TodoSocialGetNotifications: () => getNotifications_exports, TodoSocialGetNotifications: () => getNotifications_exports,
TodoSocialGetPostThread: () => getPostThread_exports, TodoSocialGetPostThread: () => getPostThread_exports,
TodoSocialGetProfile: () => getProfile_exports, TodoSocialGetProfile: () => getProfile_exports,
@ -6978,6 +6979,7 @@ __export(src_exports, {
TodoSocialLike: () => like_exports, TodoSocialLike: () => like_exports,
TodoSocialMediaEmbed: () => mediaEmbed_exports, TodoSocialMediaEmbed: () => mediaEmbed_exports,
TodoSocialPost: () => post_exports, TodoSocialPost: () => post_exports,
TodoSocialPostNotificationsSeen: () => postNotificationsSeen_exports,
TodoSocialProfile: () => profile_exports, TodoSocialProfile: () => profile_exports,
TodoSocialRepost: () => repost_exports, TodoSocialRepost: () => repost_exports,
default: () => src_default default: () => src_default
@ -10307,12 +10309,15 @@ var methodSchemas = [
encoding: "application/json", encoding: "application/json",
schema: { schema: {
type: "object", type: "object",
required: ["username", "did", "password"], required: ["username", "email", "password"],
properties: { properties: {
email: {
type: "string"
},
username: { username: {
type: "string" type: "string"
}, },
did: { inviteCode: {
type: "string" type: "string"
}, },
password: { password: {
@ -10325,10 +10330,16 @@ var methodSchemas = [
encoding: "application/json", encoding: "application/json",
schema: { schema: {
type: "object", type: "object",
required: ["jwt"], required: ["jwt", "username", "did"],
properties: { properties: {
jwt: { jwt: {
type: "string" type: "string"
},
username: {
type: "string"
},
did: {
type: "string"
} }
} }
} }
@ -11114,6 +11125,24 @@ var methodSchemas = [
} }
} }
}, },
{
lexicon: 1,
id: "todo.social.getNotificationCount",
type: "query",
parameters: {},
output: {
encoding: "application/json",
schema: {
type: "object",
required: ["count"],
properties: {
count: {
type: "number"
}
}
}
}
},
{ {
lexicon: 1, lexicon: 1,
id: "todo.social.getNotifications", id: "todo.social.getNotifications",
@ -11143,7 +11172,14 @@ var methodSchemas = [
$defs: { $defs: {
notification: { notification: {
type: "object", type: "object",
required: ["uri", "author", "record", "isRead", "indexedAt"], required: [
"uri",
"author",
"reason",
"record",
"isRead",
"indexedAt"
],
properties: { properties: {
uri: { uri: {
type: "string", type: "string",
@ -11151,7 +11187,7 @@ var methodSchemas = [
}, },
author: { author: {
type: "object", type: "object",
required: ["did", "name", "displayName"], required: ["did", "name"],
properties: { properties: {
did: { did: {
type: "string" type: "string"
@ -11165,6 +11201,13 @@ var methodSchemas = [
} }
} }
}, },
reason: {
type: "string",
$comment: "Expected values are 'like', 'repost', 'follow', 'badge', 'mention' and 'reply'."
},
reasonSubject: {
type: "string"
},
record: { record: {
type: "object" type: "object"
}, },
@ -11647,6 +11690,30 @@ var methodSchemas = [
} }
} }
} }
},
{
lexicon: 1,
id: "todo.social.postNotificationsSeen",
type: "procedure",
description: "Notify server that the user has seen notifications",
parameters: {},
input: {
encoding: "application/json",
schema: {
type: "object",
required: ["seenAt"],
properties: {
seenAt: {
type: "string",
format: "date-time"
}
}
}
},
output: {
encoding: "application/json",
schema: {}
}
} }
]; ];
@ -11894,9 +11961,9 @@ function toKnownErr20(e) {
return e; return e;
} }
// src/types/todo/social/getNotifications.ts // src/types/todo/social/getNotificationCount.ts
var getNotifications_exports = {}; var getNotificationCount_exports = {};
__export(getNotifications_exports, { __export(getNotificationCount_exports, {
toKnownErr: () => toKnownErr21 toKnownErr: () => toKnownErr21
}); });
function toKnownErr21(e) { function toKnownErr21(e) {
@ -11905,9 +11972,9 @@ function toKnownErr21(e) {
return e; return e;
} }
// src/types/todo/social/getPostThread.ts // src/types/todo/social/getNotifications.ts
var getPostThread_exports = {}; var getNotifications_exports = {};
__export(getPostThread_exports, { __export(getNotifications_exports, {
toKnownErr: () => toKnownErr22 toKnownErr: () => toKnownErr22
}); });
function toKnownErr22(e) { function toKnownErr22(e) {
@ -11916,9 +11983,9 @@ function toKnownErr22(e) {
return e; return e;
} }
// src/types/todo/social/getProfile.ts // src/types/todo/social/getPostThread.ts
var getProfile_exports = {}; var getPostThread_exports = {};
__export(getProfile_exports, { __export(getPostThread_exports, {
toKnownErr: () => toKnownErr23 toKnownErr: () => toKnownErr23
}); });
function toKnownErr23(e) { function toKnownErr23(e) {
@ -11927,9 +11994,9 @@ function toKnownErr23(e) {
return e; return e;
} }
// src/types/todo/social/getRepostedBy.ts // src/types/todo/social/getProfile.ts
var getRepostedBy_exports = {}; var getProfile_exports = {};
__export(getRepostedBy_exports, { __export(getProfile_exports, {
toKnownErr: () => toKnownErr24 toKnownErr: () => toKnownErr24
}); });
function toKnownErr24(e) { function toKnownErr24(e) {
@ -11938,9 +12005,9 @@ function toKnownErr24(e) {
return e; return e;
} }
// src/types/todo/social/getUserFollowers.ts // src/types/todo/social/getRepostedBy.ts
var getUserFollowers_exports = {}; var getRepostedBy_exports = {};
__export(getUserFollowers_exports, { __export(getRepostedBy_exports, {
toKnownErr: () => toKnownErr25 toKnownErr: () => toKnownErr25
}); });
function toKnownErr25(e) { function toKnownErr25(e) {
@ -11949,9 +12016,9 @@ function toKnownErr25(e) {
return e; return e;
} }
// src/types/todo/social/getUserFollows.ts // src/types/todo/social/getUserFollowers.ts
var getUserFollows_exports = {}; var getUserFollowers_exports = {};
__export(getUserFollows_exports, { __export(getUserFollowers_exports, {
toKnownErr: () => toKnownErr26 toKnownErr: () => toKnownErr26
}); });
function toKnownErr26(e) { function toKnownErr26(e) {
@ -11960,6 +12027,28 @@ function toKnownErr26(e) {
return e; return e;
} }
// src/types/todo/social/getUserFollows.ts
var getUserFollows_exports = {};
__export(getUserFollows_exports, {
toKnownErr: () => toKnownErr27
});
function toKnownErr27(e) {
if (e instanceof XRPCError) {
}
return e;
}
// src/types/todo/social/postNotificationsSeen.ts
var postNotificationsSeen_exports = {};
__export(postNotificationsSeen_exports, {
toKnownErr: () => toKnownErr28
});
function toKnownErr28(e) {
if (e instanceof XRPCError) {
}
return e;
}
// src/types/todo/social/badge.ts // src/types/todo/social/badge.ts
var badge_exports = {}; var badge_exports = {};
@ -12126,34 +12215,44 @@ var SocialNS = class {
throw toKnownErr20(e); throw toKnownErr20(e);
}); });
} }
getNotificationCount(params, data, opts) {
return this._service.xrpc.call("todo.social.getNotificationCount", params, data, opts).catch((e) => {
throw toKnownErr21(e);
});
}
getNotifications(params, data, opts) { getNotifications(params, data, opts) {
return this._service.xrpc.call("todo.social.getNotifications", params, data, opts).catch((e) => { return this._service.xrpc.call("todo.social.getNotifications", params, data, opts).catch((e) => {
throw toKnownErr21(e); throw toKnownErr22(e);
}); });
} }
getPostThread(params, data, opts) { getPostThread(params, data, opts) {
return this._service.xrpc.call("todo.social.getPostThread", params, data, opts).catch((e) => { return this._service.xrpc.call("todo.social.getPostThread", params, data, opts).catch((e) => {
throw toKnownErr22(e); throw toKnownErr23(e);
}); });
} }
getProfile(params, data, opts) { getProfile(params, data, opts) {
return this._service.xrpc.call("todo.social.getProfile", params, data, opts).catch((e) => { return this._service.xrpc.call("todo.social.getProfile", params, data, opts).catch((e) => {
throw toKnownErr23(e); throw toKnownErr24(e);
}); });
} }
getRepostedBy(params, data, opts) { getRepostedBy(params, data, opts) {
return this._service.xrpc.call("todo.social.getRepostedBy", params, data, opts).catch((e) => { return this._service.xrpc.call("todo.social.getRepostedBy", params, data, opts).catch((e) => {
throw toKnownErr24(e); throw toKnownErr25(e);
}); });
} }
getUserFollowers(params, data, opts) { getUserFollowers(params, data, opts) {
return this._service.xrpc.call("todo.social.getUserFollowers", params, data, opts).catch((e) => { return this._service.xrpc.call("todo.social.getUserFollowers", params, data, opts).catch((e) => {
throw toKnownErr25(e); throw toKnownErr26(e);
}); });
} }
getUserFollows(params, data, opts) { getUserFollows(params, data, opts) {
return this._service.xrpc.call("todo.social.getUserFollows", params, data, opts).catch((e) => { return this._service.xrpc.call("todo.social.getUserFollows", params, data, opts).catch((e) => {
throw toKnownErr26(e); throw toKnownErr27(e);
});
}
postNotificationsSeen(params, data, opts) {
return this._service.xrpc.call("todo.social.postNotificationsSeen", params, data, opts).catch((e) => {
throw toKnownErr28(e);
}); });
} }
}; };
@ -12522,6 +12621,7 @@ var RepostRecord = class {
TodoSocialFollow, TodoSocialFollow,
TodoSocialGetFeed, TodoSocialGetFeed,
TodoSocialGetLikedBy, TodoSocialGetLikedBy,
TodoSocialGetNotificationCount,
TodoSocialGetNotifications, TodoSocialGetNotifications,
TodoSocialGetPostThread, TodoSocialGetPostThread,
TodoSocialGetProfile, TodoSocialGetProfile,
@ -12531,6 +12631,7 @@ var RepostRecord = class {
TodoSocialLike, TodoSocialLike,
TodoSocialMediaEmbed, TodoSocialMediaEmbed,
TodoSocialPost, TodoSocialPost,
TodoSocialPostNotificationsSeen,
TodoSocialProfile, TodoSocialProfile,
TodoSocialRepost TodoSocialRepost
}); });

File diff suppressed because one or more lines are too long

View File

@ -21,6 +21,7 @@ import * as TodoSocialBadge from './types/todo/social/badge';
import * as TodoSocialFollow from './types/todo/social/follow'; import * as TodoSocialFollow from './types/todo/social/follow';
import * as TodoSocialGetFeed from './types/todo/social/getFeed'; import * as TodoSocialGetFeed from './types/todo/social/getFeed';
import * as TodoSocialGetLikedBy from './types/todo/social/getLikedBy'; import * as TodoSocialGetLikedBy from './types/todo/social/getLikedBy';
import * as TodoSocialGetNotificationCount from './types/todo/social/getNotificationCount';
import * as TodoSocialGetNotifications from './types/todo/social/getNotifications'; import * as TodoSocialGetNotifications from './types/todo/social/getNotifications';
import * as TodoSocialGetPostThread from './types/todo/social/getPostThread'; import * as TodoSocialGetPostThread from './types/todo/social/getPostThread';
import * as TodoSocialGetProfile from './types/todo/social/getProfile'; import * as TodoSocialGetProfile from './types/todo/social/getProfile';
@ -30,6 +31,7 @@ import * as TodoSocialGetUserFollows from './types/todo/social/getUserFollows';
import * as TodoSocialLike from './types/todo/social/like'; import * as TodoSocialLike from './types/todo/social/like';
import * as TodoSocialMediaEmbed from './types/todo/social/mediaEmbed'; import * as TodoSocialMediaEmbed from './types/todo/social/mediaEmbed';
import * as TodoSocialPost from './types/todo/social/post'; import * as TodoSocialPost from './types/todo/social/post';
import * as TodoSocialPostNotificationsSeen from './types/todo/social/postNotificationsSeen';
import * as TodoSocialProfile from './types/todo/social/profile'; import * as TodoSocialProfile from './types/todo/social/profile';
import * as TodoSocialRepost from './types/todo/social/repost'; import * as TodoSocialRepost from './types/todo/social/repost';
export * as TodoAdxCreateAccount from './types/todo/adx/createAccount'; export * as TodoAdxCreateAccount from './types/todo/adx/createAccount';
@ -54,6 +56,7 @@ export * as TodoSocialBadge from './types/todo/social/badge';
export * as TodoSocialFollow from './types/todo/social/follow'; export * as TodoSocialFollow from './types/todo/social/follow';
export * as TodoSocialGetFeed from './types/todo/social/getFeed'; export * as TodoSocialGetFeed from './types/todo/social/getFeed';
export * as TodoSocialGetLikedBy from './types/todo/social/getLikedBy'; export * as TodoSocialGetLikedBy from './types/todo/social/getLikedBy';
export * as TodoSocialGetNotificationCount from './types/todo/social/getNotificationCount';
export * as TodoSocialGetNotifications from './types/todo/social/getNotifications'; export * as TodoSocialGetNotifications from './types/todo/social/getNotifications';
export * as TodoSocialGetPostThread from './types/todo/social/getPostThread'; export * as TodoSocialGetPostThread from './types/todo/social/getPostThread';
export * as TodoSocialGetProfile from './types/todo/social/getProfile'; export * as TodoSocialGetProfile from './types/todo/social/getProfile';
@ -63,6 +66,7 @@ export * as TodoSocialGetUserFollows from './types/todo/social/getUserFollows';
export * as TodoSocialLike from './types/todo/social/like'; export * as TodoSocialLike from './types/todo/social/like';
export * as TodoSocialMediaEmbed from './types/todo/social/mediaEmbed'; export * as TodoSocialMediaEmbed from './types/todo/social/mediaEmbed';
export * as TodoSocialPost from './types/todo/social/post'; export * as TodoSocialPost from './types/todo/social/post';
export * as TodoSocialPostNotificationsSeen from './types/todo/social/postNotificationsSeen';
export * as TodoSocialProfile from './types/todo/social/profile'; export * as TodoSocialProfile from './types/todo/social/profile';
export * as TodoSocialRepost from './types/todo/social/repost'; export * as TodoSocialRepost from './types/todo/social/repost';
export declare class Client { export declare class Client {
@ -119,12 +123,14 @@ export declare class SocialNS {
constructor(service: ServiceClient); constructor(service: ServiceClient);
getFeed(params: TodoSocialGetFeed.QueryParams, data?: TodoSocialGetFeed.InputSchema, opts?: TodoSocialGetFeed.CallOptions): Promise<TodoSocialGetFeed.Response>; getFeed(params: TodoSocialGetFeed.QueryParams, data?: TodoSocialGetFeed.InputSchema, opts?: TodoSocialGetFeed.CallOptions): Promise<TodoSocialGetFeed.Response>;
getLikedBy(params: TodoSocialGetLikedBy.QueryParams, data?: TodoSocialGetLikedBy.InputSchema, opts?: TodoSocialGetLikedBy.CallOptions): Promise<TodoSocialGetLikedBy.Response>; getLikedBy(params: TodoSocialGetLikedBy.QueryParams, data?: TodoSocialGetLikedBy.InputSchema, opts?: TodoSocialGetLikedBy.CallOptions): Promise<TodoSocialGetLikedBy.Response>;
getNotificationCount(params: TodoSocialGetNotificationCount.QueryParams, data?: TodoSocialGetNotificationCount.InputSchema, opts?: TodoSocialGetNotificationCount.CallOptions): Promise<TodoSocialGetNotificationCount.Response>;
getNotifications(params: TodoSocialGetNotifications.QueryParams, data?: TodoSocialGetNotifications.InputSchema, opts?: TodoSocialGetNotifications.CallOptions): Promise<TodoSocialGetNotifications.Response>; getNotifications(params: TodoSocialGetNotifications.QueryParams, data?: TodoSocialGetNotifications.InputSchema, opts?: TodoSocialGetNotifications.CallOptions): Promise<TodoSocialGetNotifications.Response>;
getPostThread(params: TodoSocialGetPostThread.QueryParams, data?: TodoSocialGetPostThread.InputSchema, opts?: TodoSocialGetPostThread.CallOptions): Promise<TodoSocialGetPostThread.Response>; getPostThread(params: TodoSocialGetPostThread.QueryParams, data?: TodoSocialGetPostThread.InputSchema, opts?: TodoSocialGetPostThread.CallOptions): Promise<TodoSocialGetPostThread.Response>;
getProfile(params: TodoSocialGetProfile.QueryParams, data?: TodoSocialGetProfile.InputSchema, opts?: TodoSocialGetProfile.CallOptions): Promise<TodoSocialGetProfile.Response>; getProfile(params: TodoSocialGetProfile.QueryParams, data?: TodoSocialGetProfile.InputSchema, opts?: TodoSocialGetProfile.CallOptions): Promise<TodoSocialGetProfile.Response>;
getRepostedBy(params: TodoSocialGetRepostedBy.QueryParams, data?: TodoSocialGetRepostedBy.InputSchema, opts?: TodoSocialGetRepostedBy.CallOptions): Promise<TodoSocialGetRepostedBy.Response>; getRepostedBy(params: TodoSocialGetRepostedBy.QueryParams, data?: TodoSocialGetRepostedBy.InputSchema, opts?: TodoSocialGetRepostedBy.CallOptions): Promise<TodoSocialGetRepostedBy.Response>;
getUserFollowers(params: TodoSocialGetUserFollowers.QueryParams, data?: TodoSocialGetUserFollowers.InputSchema, opts?: TodoSocialGetUserFollowers.CallOptions): Promise<TodoSocialGetUserFollowers.Response>; getUserFollowers(params: TodoSocialGetUserFollowers.QueryParams, data?: TodoSocialGetUserFollowers.InputSchema, opts?: TodoSocialGetUserFollowers.CallOptions): Promise<TodoSocialGetUserFollowers.Response>;
getUserFollows(params: TodoSocialGetUserFollows.QueryParams, data?: TodoSocialGetUserFollows.InputSchema, opts?: TodoSocialGetUserFollows.CallOptions): Promise<TodoSocialGetUserFollows.Response>; getUserFollows(params: TodoSocialGetUserFollows.QueryParams, data?: TodoSocialGetUserFollows.InputSchema, opts?: TodoSocialGetUserFollows.CallOptions): Promise<TodoSocialGetUserFollows.Response>;
postNotificationsSeen(params: TodoSocialPostNotificationsSeen.QueryParams, data?: TodoSocialPostNotificationsSeen.InputSchema, opts?: TodoSocialPostNotificationsSeen.CallOptions): Promise<TodoSocialPostNotificationsSeen.Response>;
} }
export declare class BadgeRecord { export declare class BadgeRecord {
_service: ServiceClient; _service: ServiceClient;

View File

@ -6,12 +6,15 @@ export interface CallOptions {
encoding: 'application/json'; encoding: 'application/json';
} }
export interface InputSchema { export interface InputSchema {
email: string;
username: string; username: string;
did: string; inviteCode?: string;
password: string; password: string;
} }
export interface OutputSchema { export interface OutputSchema {
jwt: string; jwt: string;
username: string;
did: string;
} }
export interface Response { export interface Response {
success: boolean; success: boolean;

View File

@ -0,0 +1,16 @@
import { Headers } from '@adxp/xrpc';
export interface QueryParams {
}
export interface CallOptions {
headers?: Headers;
}
export declare type InputSchema = undefined;
export interface OutputSchema {
count: number;
}
export interface Response {
success: boolean;
headers: Headers;
data: OutputSchema;
}
export declare function toKnownErr(e: any): any;

View File

@ -15,8 +15,10 @@ export interface Notification {
author: { author: {
did: string; did: string;
name: string; name: string;
displayName: string; displayName?: string;
}; };
reason: string;
reasonSubject?: string;
record: {}; record: {};
isRead: boolean; isRead: boolean;
indexedAt: string; indexedAt: string;

View File

@ -0,0 +1,19 @@
import { Headers } from '@adxp/xrpc';
export interface QueryParams {
}
export interface CallOptions {
headers?: Headers;
encoding: 'application/json';
}
export interface InputSchema {
seenAt: string;
}
export interface OutputSchema {
[k: string]: unknown;
}
export interface Response {
success: boolean;
headers: Headers;
data: OutputSchema;
}
export declare function toKnownErr(e: any): any;

File diff suppressed because one or more lines are too long

View File

@ -5,12 +5,14 @@ import {AdxUri} from '../../../third-party/uri'
import {FontAwesomeIcon, Props} from '@fortawesome/react-native-fontawesome' import {FontAwesomeIcon, Props} from '@fortawesome/react-native-fontawesome'
import {NotificationsViewItemModel} from '../../../state/models/notifications-view' import {NotificationsViewItemModel} from '../../../state/models/notifications-view'
import {s, colors} from '../../lib/styles' import {s, colors} from '../../lib/styles'
import {ago} from '../../lib/strings' import {ago, pluralize} from '../../lib/strings'
import {DEF_AVATER} from '../../lib/assets' import {DEF_AVATER} from '../../lib/assets'
import {PostText} from '../post/PostText' import {PostText} from '../post/PostText'
import {Post} from '../post/Post' import {Post} from '../post/Post'
import {Link} from '../util/Link' import {Link} from '../util/Link'
const MAX_AUTHORS = 8
export const FeedItem = observer(function FeedItem({ export const FeedItem = observer(function FeedItem({
item, item,
}: { }: {
@ -37,39 +39,108 @@ export const FeedItem = observer(function FeedItem({
return 'Post' return 'Post'
} }
}, [item]) }, [item])
const authorHref = `/profile/${item.author.name}`
const authorTitle = item.author.name if (item.isReply) {
return (
<Link
style={[
styles.outerMinimal,
item.isRead ? undefined : styles.outerUnread,
]}
href={itemHref}
title={itemTitle}>
<Post uri={item.uri} />
</Link>
)
}
let action = '' let action = ''
let icon: Props['icon'] let icon: Props['icon']
let iconStyle: Props['style'] = []
if (item.isLike) { if (item.isLike) {
action = 'liked your post' action = 'liked your post'
icon = ['far', 'heart'] icon = ['fas', 'heart']
iconStyle = [s.blue3]
} else if (item.isRepost) { } else if (item.isRepost) {
action = 'reposted your post' action = 'reposted your post'
icon = 'retweet' icon = 'retweet'
iconStyle = [s.blue3]
} else if (item.isReply) { } else if (item.isReply) {
action = 'replied to your post' action = 'replied to your post'
icon = ['far', 'comment'] icon = ['far', 'comment']
} else if (item.isFollow) { } else if (item.isFollow) {
action = 'followed you' action = 'followed you'
icon = 'plus' icon = 'user-plus'
iconStyle = [s.blue3]
} else { } else {
return <></> return <></>
} }
let authors: {href: string; name: string; displayName?: string}[] = [
{
href: `/profile/${item.author.name}`,
name: item.author.name,
displayName: item.author.displayName,
},
]
if (item.additional?.length) {
authors = authors.concat(
item.additional.map(item2 => ({
href: `/profile/${item2.author.name}`,
name: item2.author.name,
displayName: item2.author.displayName,
})),
)
}
return ( return (
<Link style={styles.outer} href={itemHref} title={itemTitle}> <Link
style={[styles.outer, item.isRead ? undefined : styles.outerUnread]}
href={itemHref}
title={itemTitle}>
<View style={styles.layout}> <View style={styles.layout}>
<Link style={styles.layoutAvi} href={authorHref} title={authorTitle}> <View style={styles.layoutIcon}>
<Image style={styles.avi} source={DEF_AVATER} /> <FontAwesomeIcon
</Link> icon={icon}
size={22}
style={[styles.icon, ...iconStyle]}
/>
</View>
<View style={styles.layoutContent}> <View style={styles.layoutContent}>
<View style={styles.avis}>
{authors.slice(0, MAX_AUTHORS).map(author => (
<Link
style={s.mr2}
key={author.href}
href={author.href}
title={`@${author.name}`}>
<Image style={styles.avi} source={DEF_AVATER} />
</Link>
))}
{authors.length > MAX_AUTHORS ? (
<Text style={styles.aviExtraCount}>
+{authors.length - MAX_AUTHORS}
</Text>
) : undefined}
</View>
<View style={styles.meta}> <View style={styles.meta}>
<FontAwesomeIcon icon={icon} size={14} style={[s.mt2, s.mr5]} /> <Link
<Link style={styles.metaItem} href={authorHref} title={authorTitle}> key={authors[0].href}
<Text style={[s.f14, s.bold]}>{item.author.displayName}</Text> style={styles.metaItem}
href={authors[0].href}
title={`@${authors[0].name}`}>
<Text style={[s.f14, s.bold]}>
{authors[0].displayName || authors[0].name}
</Text>
</Link> </Link>
{authors.length > 1 ? (
<>
<Text style={[styles.metaItem, s.f14]}>and</Text>
<Text style={[styles.metaItem, s.f14, s.bold]}>
{authors.length - 1} {pluralize(authors.length - 1, 'other')}
</Text>
</>
) : undefined}
<Text style={[styles.metaItem, s.f14]}>{action}</Text> <Text style={[styles.metaItem, s.f14]}>{action}</Text>
<Text style={[styles.metaItem, s.f14, s.gray5]}> <Text style={[styles.metaItem, s.f14, s.gray5]}>
{ago(item.indexedAt)} {ago(item.indexedAt)}
@ -97,13 +168,34 @@ const styles = StyleSheet.create({
outer: { outer: {
backgroundColor: colors.white, backgroundColor: colors.white,
padding: 10, padding: 10,
paddingBottom: 0, borderRadius: 6,
margin: 2,
marginBottom: 0,
},
outerMinimal: {
backgroundColor: colors.white,
borderRadius: 6,
margin: 2,
marginBottom: 0,
},
outerUnread: {
borderWidth: 1,
borderColor: colors.blue2,
}, },
layout: { layout: {
flexDirection: 'row', flexDirection: 'row',
}, },
layoutAvi: { layoutIcon: {
width: 40, width: 35,
alignItems: 'flex-end',
},
icon: {
marginRight: 10,
marginTop: 4,
},
avis: {
flexDirection: 'row',
alignItems: 'center',
}, },
avi: { avi: {
width: 30, width: 30,
@ -111,6 +203,11 @@ const styles = StyleSheet.create({
borderRadius: 15, borderRadius: 15,
resizeMode: 'cover', resizeMode: 'cover',
}, },
aviExtraCount: {
fontWeight: 'bold',
paddingLeft: 6,
color: colors.gray5,
},
layoutContent: { layoutContent: {
flex: 1, flex: 1,
}, },

View File

@ -14,6 +14,7 @@ import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import {PostThreadViewModel} from '../../../state/models/post-thread-view' import {PostThreadViewModel} from '../../../state/models/post-thread-view'
import {ComposePostModel} from '../../../state/models/shell' import {ComposePostModel} from '../../../state/models/shell'
import {Link} from '../util/Link' import {Link} from '../util/Link'
import {UserInfoText} from '../util/UserInfoText'
import {useStores} from '../../../state' import {useStores} from '../../../state'
import {s, colors} from '../../lib/styles' import {s, colors} from '../../lib/styles'
import {ago} from '../../lib/strings' import {ago} from '../../lib/strings'
@ -57,13 +58,18 @@ export const Post = observer(function Post({uri}: {uri: string}) {
const item = view.thread const item = view.thread
const record = view.thread?.record as unknown as PostType.Record const record = view.thread?.record as unknown as PostType.Record
const itemHref = useMemo(() => { const itemUrip = new AdxUri(item.uri)
const urip = new AdxUri(item.uri) const itemHref = `/profile/${item.author.name}/post/${itemUrip.recordKey}`
return `/profile/${item.author.name}/post/${urip.recordKey}`
}, [item.uri, item.author.name])
const itemTitle = `Post by ${item.author.name}` const itemTitle = `Post by ${item.author.name}`
const authorHref = `/profile/${item.author.name}` const authorHref = `/profile/${item.author.name}`
const authorTitle = item.author.name const authorTitle = item.author.name
let replyAuthorDid = ''
let replyHref = ''
if (record.reply) {
const urip = new AdxUri(record.reply.parent || record.reply.root)
replyAuthorDid = urip.hostname
replyHref = `/profile/${urip.hostname}/post/${urip.recordKey}`
}
const onPressReply = () => { const onPressReply = () => {
store.shell.openModal(new ComposePostModel(item.uri)) store.shell.openModal(new ComposePostModel(item.uri))
} }
@ -96,6 +102,19 @@ export const Post = observer(function Post({uri}: {uri: string}) {
&middot; {ago(item.indexedAt)} &middot; {ago(item.indexedAt)}
</Text> </Text>
</View> </View>
{replyHref !== '' && (
<View style={[s.flexRow, s.mb2, {alignItems: 'center'}]}>
<FontAwesomeIcon icon="reply" size={9} style={[s.gray4, s.mr5]} />
<Text style={[s.gray4, s.f12, s.mr2]}>Reply to</Text>
<Link href={replyHref} title="Parent post">
<UserInfoText
did={replyAuthorDid}
style={[s.f12, s.gray5]}
prefix="@"
/>
</Link>
</View>
)}
<Text style={[styles.postText, s.f15, s['lh15-1.3']]}> <Text style={[styles.postText, s.f15, s['lh15-1.3']]}>
{record.text} {record.text}
</Text> </Text>

View File

@ -38,6 +38,7 @@ import {faReply} from '@fortawesome/free-solid-svg-icons/faReply'
import {faRetweet} from '@fortawesome/free-solid-svg-icons/faRetweet' import {faRetweet} from '@fortawesome/free-solid-svg-icons/faRetweet'
import {faUser} from '@fortawesome/free-regular-svg-icons/faUser' import {faUser} from '@fortawesome/free-regular-svg-icons/faUser'
import {faUsers} from '@fortawesome/free-solid-svg-icons/faUsers' import {faUsers} from '@fortawesome/free-solid-svg-icons/faUsers'
import {faUserPlus} from '@fortawesome/free-solid-svg-icons/faUserPlus'
import {faTicket} from '@fortawesome/free-solid-svg-icons/faTicket' import {faTicket} from '@fortawesome/free-solid-svg-icons/faTicket'
import {faX} from '@fortawesome/free-solid-svg-icons/faX' import {faX} from '@fortawesome/free-solid-svg-icons/faX'
@ -81,6 +82,7 @@ export function setup() {
faShield, faShield,
faUser, faUser,
faUsers, faUsers,
faUserPlus,
faTicket, faTicket,
faX, faX,
) )

View File

@ -78,11 +78,13 @@ const Location = ({
const Btn = ({ const Btn = ({
icon, icon,
inactive, inactive,
notificationCount,
onPress, onPress,
onLongPress, onLongPress,
}: { }: {
icon: IconProp icon: IconProp
inactive?: boolean inactive?: boolean
notificationCount?: number
onPress?: (event: GestureResponderEvent) => void onPress?: (event: GestureResponderEvent) => void
onLongPress?: (event: GestureResponderEvent) => void onLongPress?: (event: GestureResponderEvent) => void
}) => { }) => {
@ -98,6 +100,11 @@ const Btn = ({
if (inactive) { if (inactive) {
return ( return (
<View style={styles.ctrl}> <View style={styles.ctrl}>
{notificationCount ? (
<View style={styles.ctrlCount}>
<Text style={styles.ctrlCountLabel}>{notificationCount}</Text>
</View>
) : undefined}
<IconEl <IconEl
size={21} size={21}
style={[styles.ctrlIcon, styles.inactive]} style={[styles.ctrlIcon, styles.inactive]}
@ -111,6 +118,11 @@ const Btn = ({
style={styles.ctrl} style={styles.ctrl}
onPress={onPress} onPress={onPress}
onLongPress={onLongPress}> onLongPress={onLongPress}>
{notificationCount ? (
<View style={styles.ctrlCount}>
<Text style={styles.ctrlCountLabel}>{notificationCount}</Text>
</View>
) : undefined}
<IconEl size={21} style={styles.ctrlIcon} icon={icon} /> <IconEl size={21} style={styles.ctrlIcon} icon={icon} />
</TouchableOpacity> </TouchableOpacity>
) )
@ -250,7 +262,11 @@ export const MobileShell: React.FC = observer(() => {
onLongPress={onLongPressForward} onLongPress={onLongPressForward}
/> />
<Btn icon="house" onPress={onPressHome} /> <Btn icon="house" onPress={onPressHome} />
<Btn icon={['far', 'bell']} onPress={onPressNotifications} /> <Btn
icon={['far', 'bell']}
onPress={onPressNotifications}
notificationCount={store.me.notificationCount}
/>
<Btn icon="bars" onPress={onPressTabs} /> <Btn icon="bars" onPress={onPressTabs} />
</View> </View>
<Modal /> <Modal />
@ -393,6 +409,19 @@ const styles = StyleSheet.create({
paddingTop: 15, paddingTop: 15,
paddingBottom: 15, paddingBottom: 15,
}, },
ctrlCount: {
position: 'absolute',
left: 46,
top: 10,
backgroundColor: colors.pink3,
paddingHorizontal: 3,
borderRadius: 3,
},
ctrlCountLabel: {
fontSize: 12,
fontWeight: 'bold',
color: colors.white,
},
ctrlIcon: { ctrlIcon: {
marginLeft: 'auto', marginLeft: 'auto',
marginRight: 'auto', marginRight: 'auto',