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

Fixed error to save scroll position #1730

Merged
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3cf3512
feat: direct messages in identity contract
Silver-IT Aug 30, 2023
74ff6cd
feat: add/remove getters
Silver-IT Aug 30, 2023
7077eb6
feat: simplified getters
Silver-IT Aug 30, 2023
7832977
wip: merging privateDMs and groupDMs
Silver-IT Aug 31, 2023
b8ee090
fix: coding issues
Silver-IT Aug 31, 2023
e864ee5
feat: UI updates for the DMs with more than 3
Silver-IT Aug 31, 2023
3e77295
fix: add member to dm
Silver-IT Sep 1, 2023
39c90a7
feat: changed base branch from e2e-protocol-ricardo to e2e-protocol
Silver-IT Sep 11, 2023
14bfed0
fix: error in get dm by usernames
Silver-IT Sep 4, 2023
1170c1b
chore: added comments
Silver-IT Sep 4, 2023
c4f5f1a
fix: error in function parameters declaration
Silver-IT Sep 4, 2023
c1271cc
fix: inconsistent naming of members when create a new DM
Silver-IT Sep 4, 2023
4c0fd71
fix: redundant message rendering issue
Silver-IT Sep 4, 2023
2092365
feat: grun tpin
Silver-IT Sep 4, 2023
f38eee0
chore: removed wrong version of contracts
Silver-IT Sep 11, 2023
23a5fb2
feat: grunt pin:0.1.8
Silver-IT Sep 11, 2023
827b975
feat: added comments
Silver-IT Sep 11, 2023
a0b48da
chore: removed changes in chelonia
Silver-IT Sep 11, 2023
52c2946
chore: added comments
Silver-IT Sep 11, 2023
6b885ac
chore: fix typo
Silver-IT Sep 11, 2023
bd919e2
feat: error handling
Silver-IT Sep 12, 2023
7aeec7a
chore: removed unnecessary comment
Silver-IT Sep 12, 2023
d00e43e
feat: improved chatroom types and added comments
Silver-IT Sep 12, 2023
1daccc6
fix: resolved conflicts
Silver-IT Sep 12, 2023
b9063f7
chore: resolved conflicts
Silver-IT Sep 16, 2023
59606c4
feat: simplified getter
Silver-IT Sep 16, 2023
ebb588c
fix: resolved conflicts
Silver-IT Sep 16, 2023
d726496
chore: simplified
Silver-IT Sep 16, 2023
4a9e986
chore: added comments, error handling
Silver-IT Sep 16, 2023
2a98088
fix: error to save scroll position
Silver-IT Sep 19, 2023
3191a31
fix: resolved conflicts
Silver-IT Sep 22, 2023
c198633
chore: removed allowDMInvite
Silver-IT Sep 23, 2023
b58ffb6
Merge branch 'e2e-protocol' into 1711-chatroom-doesnt-save-the-previo…
Silver-IT Sep 24, 2023
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
4 changes: 3 additions & 1 deletion contracts/0.2.0/identity-slim.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ ${this.getErrorInfo()}`;
process({ data }, { state }) {
const initialState = merge({
settings: {},
attributes: {},
attributes: {
allowDMInvite: true
},
chatRooms: {}
}, data);
for (const key in initialState) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/0.2.0/identity.0.2.0.manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"head":{"manifestVersion":"1.0.0"},"body":"{\"version\":\"0.2.0\",\"contract\":{\"hash\":\"21XWnNTMkdh4kSPqYSBg7w2vEbVu6K8VVsTHhmmk7ASyeywTF1\",\"file\":\"identity.js\"},\"authors\":[{\"cipher\":\"algo\",\"key\":\"<pubkey from deploy-key.json>\"},{\"cipher\":\"algo\",\"key\":\"<pubkey from alex.json>\"}],\"contractSlim\":{\"file\":\"identity-slim.js\",\"hash\":\"21XWnNX2cByjzY8L5pxyuBxemFAoWcThiHXkX88WdMQqCi5eBY\"}}","signature":{"key":"<which of the 'authors' keys was used to sign 'body'>","signature":"<signature>"}}
{"head":{"manifestVersion":"1.0.0"},"body":"{\"version\":\"0.2.0\",\"contract\":{\"hash\":\"21XWnNFMx7avBEHobMZvMdS3Z1hsAp7toY9LbhitH9saGh3vVb\",\"file\":\"identity.js\"},\"authors\":[{\"cipher\":\"algo\",\"key\":\"<pubkey from deploy-key.json>\"},{\"cipher\":\"algo\",\"key\":\"<pubkey from alex.json>\"}],\"contractSlim\":{\"file\":\"identity-slim.js\",\"hash\":\"21XWnNWrfPGhkJBtxf1V12x1sw2fx1GhjLEGsa6Mc9mqLwWerA\"}}","signature":{"key":"<which of the 'authors' keys was used to sign 'body'>","signature":"<signature>"}}
4 changes: 3 additions & 1 deletion contracts/0.2.0/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -9368,7 +9368,9 @@ ${this.getErrorInfo()}`;
process({ data }, { state }) {
const initialState = merge({
settings: {},
attributes: {},
attributes: {
allowDMInvite: true
},
chatRooms: {}
}, data);
for (const key in initialState) {
Expand Down
4 changes: 3 additions & 1 deletion frontend/model/contracts/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ sbp('chelonia/defineContract', {
process ({ data }, { state }) {
const initialState = merge({
settings: {},
attributes: {},
attributes: {
allowDMInvite: true
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you merge e2e-protocol back into this PR?

chatRooms: {}
}, data)
for (const key in initialState) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/model/contracts/manifests.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"manifests": {
"gi.contracts/chatroom": "21XWnNSsVaBM6WsvYJBipiE4ckoSom4yBhPePrGS4m2UhhstBi",
"gi.contracts/group": "21XWnNUjCV9K5EhwSAgbSuperYRP8ozuqZqDzUfS66w2TKUZ8V",
"gi.contracts/identity": "21XWnNSxNrVFTMBCUVcZV3CG833gTbJ9V8ZyX7Fxgmpj9rNy4r"
"gi.contracts/identity": "21XWnNQPL3t5hwWCaip4WyVju6aRH35MKQgR47VQqCdDeksp8i"
}
}
32 changes: 13 additions & 19 deletions frontend/views/containers/chatroom/ChatMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,19 @@
:description='summary.attributes.description'
)

div(v-for='(message, index) in messages' :key='index')
template(v-for='(message, index) in messages')
.c-divider(
v-if='changeDay(index) || isNew(message.hash)'
:class='{"is-new": isNew(message.hash)}'
:key='`date-${index}`'
)
i18n.c-new(v-if='isNew(message.hash)' :class='{"is-new-date": changeDay(index)}') New
span(v-else-if='changeDay(index)') {{proximityDate(message.datetime)}}

component(
:is='messageType(message)'
:ref='message.hash'
:key='message.id'
:messageId='message.id'
:messageHash='message.hash'
:text='message.text'
Expand Down Expand Up @@ -133,6 +135,8 @@ import { proximityDate, MINS_MILLIS } from '@model/contracts/shared/time.js'
import { cloneDeep, debounce, throttle } from '@model/contracts/shared/giLodash.js'
import { CONTRACT_IS_SYNCING, EVENT_HANDLED } from '~/shared/domains/chelonia/events.js'

const ignorableScrollDistanceInPixel = 500

export default ({
name: 'ChatMain',
components: {
Expand Down Expand Up @@ -238,10 +242,7 @@ export default ({
}
},
isScrolledUp () {
if (!this.ephemeral.scrolledDistance) {
return false
}
return this.ephemeral.scrolledDistance > 500
return this.ephemeral.scrolledDistance > ignorableScrollDistanceInPixel
},
messages () {
return this.messageState.contract?.messages || []
Expand Down Expand Up @@ -710,17 +711,10 @@ export default ({
if (!this.$refs.conversation) {
return
}
// Because of infinite-scroll this is not calculated in scrollheight
// 117 is the height of `conversation-greetings` component
const topOffset = 117
const curScrollTop = this.$refs.conversation.scrollTop
const curScrollBottom = curScrollTop + this.$refs.conversation.clientHeight
if (!this.$refs.conversation) {
this.ephemeral.scrolledDistance = 0
} else {
const scrollTopMax = this.$refs.conversation.scrollHeight - this.$refs.conversation.clientHeight
this.ephemeral.scrolledDistance = scrollTopMax - curScrollTop
}
const scrollTopMax = this.$refs.conversation.scrollHeight - this.$refs.conversation.clientHeight
this.ephemeral.scrolledDistance = scrollTopMax - curScrollTop

if (!this.summary.isJoined) {
return
Expand All @@ -729,8 +723,8 @@ export default ({
for (let i = this.messages.length - 1; i >= 0; i--) {
const msg = this.messages[i]
const offsetTop = this.$refs[msg.hash][0].$el.offsetTop
const parentOffsetTop = this.$refs[msg.hash][0].$el.offsetParent.offsetTop
if (offsetTop - parentOffsetTop + topOffset <= curScrollBottom) {
const height = this.$refs[msg.hash][0].$el.clientHeight
if (offsetTop + height <= curScrollBottom) {
const bottomMessageCreatedAt = new Date(msg.datetime).getTime()
const latestMessageCreatedAt = this.currentChatRoomReadUntil?.createdDate
if (!latestMessageCreatedAt || new Date(latestMessageCreatedAt).getTime() <= bottomMessageCreatedAt) {
Expand All @@ -743,13 +737,13 @@ export default ({
}
}

if (this.ephemeral.scrolledDistance > 500) {
if (this.ephemeral.scrolledDistance > ignorableScrollDistanceInPixel) {
// Save the current scroll position per each chatroom
for (let i = 0; i < this.messages.length - 1; i++) {
const msg = this.messages[i]
const offsetTop = this.$refs[msg.hash][0].$el.offsetTop
const parentOffsetTop = this.$refs[msg.hash][0].$el.offsetParent.offsetTop
if (offsetTop - parentOffsetTop + topOffset >= curScrollTop) {
const height = this.$refs[msg.hash][0].$el.clientHeight
if (offsetTop + height >= curScrollTop) {
sbp('state/vuex/commit', 'setChatRoomScrollPosition', {
chatRoomId: this.currentChatRoomId,
messageHash: this.messages[i + 1].hash // Leave one(+1) message at the front by default for better seeing
Expand Down