Skip to content

Commit

Permalink
HF 30 - Fix account avatars, and optimize with mini-accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
1aerostorm committed Sep 13, 2024
1 parent eb1958f commit 7c9152d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
18 changes: 8 additions & 10 deletions src/components/elements/Stub.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,15 @@ export const renderStubs = (the_group, to, username, accounts) => {
}

const { privacy } = the_group
if (privacy !== 'public_group') {
const { amBanned, amMember, amModer, amPending } = getRoleInGroup(the_group, username)
const notMember = !amModer && !amMember
if (amBanned || notMember) {
composeStub = { ui: <Stub type='compose' banned={amBanned} notMember={notMember}
const { amBanned, amMember, amModer, amPending } = getRoleInGroup(the_group, username)
const notMember = !amModer && !amMember
if (amBanned || (privacy !== 'public_group' && notMember)) {
composeStub = { ui: <Stub type='compose' banned={amBanned} notMember={notMember}
pending={amPending} group={the_group} /> }
if (privacy === 'private_group') {
composeStub = { disabled: true }
msgsStub = { ui: <Stub type='messages' banned={amBanned} notMember={notMember}
pending={amPending} group={the_group} /> }
if (privacy === 'private_group') {
composeStub = { disabled: true }
msgsStub = { ui: <Stub type='messages' banned={amBanned} notMember={notMember}
pending={amPending} group={the_group} /> }
}
}
}

Expand Down
29 changes: 18 additions & 11 deletions src/redux/FetchDataSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ export function* watchFetchState() {
yield takeLatest('FETCH_STATE', fetchState)
}

const setMiniAccount = (state, account) => {
if (account) {
state.accounts[account.name] = account
}
}
const addMiniAccounts = (state, accounts) => {
if (accounts) {
for (const [n, acc] of Object.entries(accounts)) {
setMiniAccount(state, acc)
}
}
}

export function* fetchState(location_change_action) {
try {

Expand Down Expand Up @@ -59,8 +72,6 @@ export function* fetchState(location_change_action) {

const account = yield select(state => state.user.getIn(['current', 'username']));
if (account) {
accounts.add(account);

const posting = yield select(state => state.user.getIn(['current', 'private_keys', 'posting_private']))

const path = parts[1]
Expand All @@ -75,6 +86,7 @@ export function* fetchState(location_change_action) {
...loginData,
owner: account, limit: 100,
cache: Object.keys(conCache),
accounts: true,
})
}
})
Expand All @@ -83,12 +95,13 @@ export function* fetchState(location_change_action) {
state.contacts = con.contacts
if (hasErr) return
console.timeEnd('prof: getContactsAsync')

addMiniAccounts(state, con.accounts)
}

if (path) {
if (path.startsWith('@')) {
const to = path.replace('@', '');
accounts.add(to);

state.messages = yield callSafe(state, [], 'getThreadAsync', [api, api.getThreadAsync], account, to, {});
if (hasErr) return
Expand Down Expand Up @@ -139,11 +152,7 @@ export function* fetchState(location_change_action) {
thRes = yield call(getThread)
}

if (thRes.accounts) {
for (const [n, acc] of Object.entries(thRes.accounts)) {
state.accounts[n] = acc
}
}
addMiniAccounts(state, thRes.accounts)

console.log('proc:' + thRes._dec_processed)
if (the_group && thRes.error) {
Expand All @@ -159,9 +168,6 @@ export function* fetchState(location_change_action) {
console.timeEnd('prof: getThreadAsync')
}
}
for (let contact of state.contacts) {
accounts.add(contact.contact);
}
}

if (accounts.size > 0) {
Expand Down Expand Up @@ -295,6 +301,7 @@ export function* fetchGroupMembers({ payload: { group, creatingNew, memberTypes,
sort_conditions: sortConditions,
start_member: '',
limit: 100,
accounts: true,
})

yield put(g.actions.receiveGroupMembers({ group, members }))
Expand Down
10 changes: 10 additions & 0 deletions src/redux/GlobalReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,16 @@ export default createModule({
})
return gro
})
for (const mem of (members || [])) {
if (mem.account_data) {
const account = fromJS(mem.account_data)
new_state = new_state.updateIn(
['accounts', account.get('name')],
Map(),
a => a.mergeDeep(account)
)
}
}
return new_state
},
},
Expand Down

0 comments on commit 7c9152d

Please sign in to comment.