Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(friends): display outgoing friend requests after send #1348

Merged
merged 1 commit into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions components/views/friends/add/Add.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ export default Vue.extend({
return `${location.origin}/#/friends/list/${this.accounts.active}`
},
},
mounted() {
if (this.$route.params && this.$route.params.id) {
this.$data.accountID = this.$route.params.id
this._searchFriend()
}
},
methods: {
_searchFriend: debounce(async function (this: any) {
if (this.accountID.length >= 40) {
Expand Down Expand Up @@ -95,12 +101,6 @@ export default Vue.extend({
}
},
},
mounted() {
if (this.$route.params && this.$route.params.id) {
this.$data.accountID = this.$route.params.id
this._searchFriend()
}
},
})
</script>
<style scoped lang="less" src="./Add.less"></style>
12 changes: 12 additions & 0 deletions components/views/friends/friend/Friend.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@
<check-icon size="1x" />
</InteractablesButton>
</div>
<div class="controls" v-else-if="outgoing">
<InteractablesButton
type="danger"
size="small"
class="has-tooltip has-tooltip-primary has-tooltip-bottom has-tooltip-desktop-only"
:data-tooltip="$t('friends.cancel')"
:loading="loading === 'options'"
:action="cancelRequest"
>
<x-icon size="1x" />
</InteractablesButton>
</div>
<div class="controls" v-else>
<InteractablesButton
v-if="loading !== 'options'"
Expand Down
8 changes: 7 additions & 1 deletion components/views/friends/friend/Friend.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default Vue.extend({
props: {
friend: {
type: Object as PropType<Friend>,
default: () => {},
required: true,
},
request: {
type: Boolean,
Expand All @@ -51,6 +51,10 @@ export default Vue.extend({
type: Boolean,
default: false,
},
outgoing: {
type: Boolean,
default: false,
},
},
data() {
return {
Expand Down Expand Up @@ -117,6 +121,8 @@ export default Vue.extend({
this.loading = AddFriendEnum.EMPTY
}
},
// todo - remove friend request for both users on click
async cancelRequest() {},
sendMessageRequest() {
this.$router.push(`/chat/direct/${this.$props.friend.address}`)
},
Expand Down
2 changes: 1 addition & 1 deletion cypress
4 changes: 3 additions & 1 deletion locales/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,8 @@ export default {
not_found: "Hmm, we couldn't find a user at that address",
invalid_id: 'Invalid account ID',
request_sent: 'Friend request successfully sent!',
requests: 'Friends request',
requests: 'Friend requests',
outgoing: 'Outgoing requests',
blocked: 'Blocked friends',
search_placeholder: 'Some User...',
add: 'Add Friend',
Expand All @@ -546,6 +547,7 @@ export default {
send: 'Send',
message: 'Message',
options: 'Options',
cancel: 'Cancel request',
},
market_place: {
title: 'Marketplace',
Expand Down
47 changes: 35 additions & 12 deletions pages/friends/list/FriendsList.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,47 @@
<!-- Friends Add -->
<FriendsAdd />
<!-- Friend Requests -->
<div v-if="friends.incomingRequests.length" class="padded_divider">
<TypographyHorizontalRuleText
plaintext
:value="$t('friends.requests')"
/>
</div>
<FriendsFriend
v-for="friend in friends.incomingRequests"
:friend="{
<template v-if="friends.incomingRequests.length">
<div class="padded_divider">
<TypographyHorizontalRuleText
plaintext
:value="$t('friends.requests')"
/>
</div>
<FriendsFriend
v-for="friend in friends.incomingRequests"
:friend="{
name: friend.userInfo.name,
address: friend.from,
state: 'offline',
status: friend.userInfo.status,
request: friend
}"
:key="friend.from"
request
/>
:key="friend.from"
request
/>
</template>
<!-- Outgoing Requests -->
<template v-if="friends.outgoingRequests.length">
<div class="padded_divider">
<TypographyHorizontalRuleText
plaintext
:value="$t('friends.outgoing')"
/>
</div>
<FriendsFriend
v-for="friend in friends.outgoingRequests"
:friend="{
name: friend.userInfo.name,
address: friend.to,
state: 'offline',
status: friend.userInfo.status,
request: friend
}"
:key="friend.to"
outgoing
/>
</template>
</div>
<div class="column is-half-desktop">
<!-- Friends List -->
Expand Down
26 changes: 18 additions & 8 deletions store/friends/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ export default {
}),
)

const outgoingRequests = outgoing.map<OutgoingRequest>((account) =>
friendAccountToOutgoingRequest(account),
const outgoingRequests = await Promise.all(
outgoing.map(async (account) => {
const userInfo = await serverProgram.getUser(new PublicKey(account.to))
return friendAccountToOutgoingRequest(account, userInfo)
}),
)

commit('setIncomingRequests', incomingRequests)
Expand Down Expand Up @@ -130,7 +133,7 @@ export default {
throw new Error(FriendsError.FRIEND_INFO_NOT_FOUND)
}

const friend: Omit<Friend, 'publicKey' | 'typingState'> = {
const friend: Omit<Friend, 'publicKey' | 'typingState' | 'lastUpdate'> = {
account: friendAccount,
name: rawUser.name,
profilePicture: rawUser.photoHash,
Expand Down Expand Up @@ -161,7 +164,7 @@ export default {
)
commit(
'removeOutgoingRequest',
friendAccountToOutgoingRequest(friendAccount).requestId,
friendAccountToOutgoingRequest(friendAccount, null).requestId,
)
return
}
Expand Down Expand Up @@ -212,7 +215,7 @@ export default {
if (account) {
commit(
'removeOutgoingRequest',
friendAccountToOutgoingRequest(account).requestId,
friendAccountToOutgoingRequest(account, null).requestId,
)
}
})
Expand Down Expand Up @@ -254,6 +257,7 @@ export default {
const $SolanaManager: SolanaManager = Vue.prototype.$SolanaManager
const $Crypto: Crypto = Vue.prototype.$Crypto
const $TextileManager: TextileManager = Vue.prototype.$TextileManager
const serverProgram: ServerProgram = new ServerProgram($SolanaManager)

const textilePublicKey = $TextileManager.getIdentityPublicKey()

Expand Down Expand Up @@ -342,11 +346,15 @@ export default {
friendAccountKey,
)

if (parsedFriendRequest)
if (parsedFriendRequest) {
const userInfo = await serverProgram.getUser(
new PublicKey(parsedFriendRequest.to),
)
commit(
'addOutgoingRequest',
friendAccountToOutgoingRequest(parsedFriendRequest),
friendAccountToOutgoingRequest(parsedFriendRequest, userInfo),
)
}
}
},
/**
Expand Down Expand Up @@ -509,7 +517,7 @@ export default {
if (transactionId) {
commit(
'removeOutgoingRequest',
friendAccountToOutgoingRequest(account).requestId,
friendAccountToOutgoingRequest(account, null).requestId,
)
}
},
Expand Down Expand Up @@ -579,11 +587,13 @@ function friendAccountToIncomingRequest(
*/
function friendAccountToOutgoingRequest(
friendAccount: FriendAccount,
userInfo: RawUser | null,
): OutgoingRequest {
return {
requestId: friendAccount.accountId,
to: friendAccount.to,
account: friendAccount,
pending: false,
userInfo,
}
}
2 changes: 1 addition & 1 deletion types/ui/friends.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ export interface FriendRequest {
requestId: string
account: FriendAccount
pending: boolean
userInfo: RawUser | null
}

export interface IncomingRequest extends FriendRequest {
from: string
userInfo: RawUser | null
account: FriendAccount
}

Expand Down