1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00
This commit is contained in:
Zhiyuan Zheng
2021-01-23 02:41:50 +01:00
parent aa467f6911
commit 86231fb7b7
36 changed files with 614 additions and 481 deletions

View File

@ -242,8 +242,16 @@ export type MutationVarsTimelineUpdateStatusProperty = {
reblog?: boolean
payload:
| {
property: 'bookmarked' | 'favourited' | 'muted' | 'pinned' | 'reblogged'
property: 'bookmarked' | 'muted' | 'pinned'
currentValue: boolean
propertyCount: undefined
countValue: undefined
}
| {
property: 'favourited' | 'reblogged'
currentValue: boolean
propertyCount: 'favourites_count' | 'reblogs_count'
countValue: number
}
| {
property: 'poll'

View File

@ -19,6 +19,13 @@ const updateConversation = ({
typeof payload.currentValue === 'boolean'
? !payload.currentValue
: true
if (payload.propertyCount) {
if (typeof payload.currentValue === 'boolean' && payload.currentValue) {
item.last_status[payload.propertyCount] = payload.countValue - 1
} else {
item.last_status[payload.propertyCount] = payload.countValue + 1
}
}
}
return item
}

View File

@ -16,6 +16,13 @@ const updateNotification = ({
typeof payload.currentValue === 'boolean'
? !payload.currentValue
: true
if (payload.propertyCount) {
if (typeof payload.currentValue === 'boolean' && payload.currentValue) {
item.status[payload.propertyCount] = payload.countValue - 1
} else {
item.status[payload.propertyCount] = payload.countValue + 1
}
}
}
return item
}

View File

@ -23,11 +23,25 @@ const updateStatus = ({
typeof payload.currentValue === 'boolean'
? !payload.currentValue
: true
if (payload.propertyCount) {
if (typeof payload.currentValue === 'boolean' && payload.currentValue) {
item.reblog![payload.propertyCount] = payload.countValue - 1
} else {
item.reblog![payload.propertyCount] = payload.countValue + 1
}
}
} else {
item[payload.property] =
typeof payload.currentValue === 'boolean'
? !payload.currentValue
: true
if (payload.propertyCount) {
if (typeof payload.currentValue === 'boolean' && payload.currentValue) {
item[payload.propertyCount] = payload.countValue - 1
} else {
item[payload.propertyCount] = payload.countValue + 1
}
}
}
return item
}

View File

@ -15,6 +15,8 @@ export type InstanceLocal = {
uri: Mastodon.Instance['uri']
account: {
id: Mastodon.Account['id']
acct: Mastodon.Account['acct']
avatarStatic: Mastodon.Account['avatar_static']
preferences: Mastodon.Preferences
}
notification: {
@ -64,7 +66,7 @@ export const localAddInstance = createAsyncThunk(
const instanceLocal: InstancesState['local'] = store.getState().instances
.local
const { id } = await client<Mastodon.Account>({
const { id, acct, avatar_static } = await client<Mastodon.Account>({
method: 'get',
instance: 'remote',
instanceDomain: url,
@ -108,6 +110,8 @@ export const localAddInstance = createAsyncThunk(
uri,
account: {
id,
acct,
avatarStatic: avatar_static,
preferences
},
notification: {
@ -182,6 +186,19 @@ const instancesSlice = createSlice({
throw new Error('Set index cannot be found')
}
},
localUpdateAccount: (
state,
action: PayloadAction<
Pick<InstanceLocal['account'], 'acct' & 'avatarStatic'>
>
) => {
if (state.local.activeIndex !== null) {
state.local.instances[state.local.activeIndex].account = {
...state.local.instances[state.local.activeIndex].account,
...action.payload
}
}
},
localUpdateNotification: (
state,
action: PayloadAction<Partial<InstanceLocal['notification']>>
@ -273,6 +290,7 @@ export const getRemoteUrl = ({ instances: { remote } }: RootState) => remote.url
export const {
localUpdateActiveIndex,
localUpdateAccount,
localUpdateNotification,
remoteUpdate
} = instancesSlice.actions