Skip to content

Commit

Permalink
feat: add scroll method to messaging store
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriansaliou committed Mar 3, 2024
1 parent 3ff3b81 commit 3550edd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,17 @@ The messaging view can be included from path: `./dist/messaging.html`
The messaging view exposes a programmatic API that lets applications manipulate its internal store:

- Check if a message exists: `MessagingStore.exists(messageId<string>)<boolean>`
- Resolve a message from the store: `MessagingStore.resolve(messageId<string>)<object>`
- Resolve a message from the store: `MessagingStore.resolve(messageId<string>)<null | object>`
- Restore one or multiple past messages in the store (ie. prepend): `MessagingStore.restore(...messages<object>)<boolean>`
- Insert one or multiple messages in the store (ie. append): `MessagingStore.insert(...messages<object>)<boolean>`
- Update a message in the store: `MessagingStore.update(messageId<string>, messageDiff<object>)<boolean>`
- Pull out a message from the store: `MessagingStore.retract(messageId<string>)<boolean>`
- Flush all content from the store: `MessagingStore.flush()<boolean>`
- Highlight a message in the store: `MessagingStore.highlight(messageId<string>)<boolean>`
- Interact with a message action: `MessagingStore.interact(messageId<string>, action<string>, isActive<boolean>)<boolean>`
- Scroll to a message: `MessagingStore.scroll(messageId<string>)<boolean>`
- Toggle `backwards` or `forwards` loader in the store: `MessagingStore.loader(type<string>, isVisible<boolean>)<boolean>`
- Identify a JID with its `name` and `avatar`: `MessagingStore.identify(jid<string>, identity<object>)<boolean>`
- Identify a JID with its `name` and `avatar`: `MessagingStore.identify(jid<string>, identity<null | object>)<boolean>`

All inserted message objects are required to hold the following keys: `id`, `type`, `date`, `content` and `from`. When updating an existing message, only modified keys need to be passed.

Expand Down
17 changes: 17 additions & 0 deletions src/messaging/stores/feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,23 @@ function FeedStore() {
return false;
},

/**
* Scrolls to a message
* @public
* @param {string} messageId
* @return {boolean} Message scroll status
*/
scroll(messageId) {
// Scroll to existing message? (immediate and forced)
if (this._resolveEntry(messageId) !== null) {
MessageHelper.scheduleScrollToMessage(messageId, true, true);

return true;
}

return false;
},

/**
* Toggles the visibility of a loader
* @public
Expand Down
1 change: 1 addition & 0 deletions types/messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export declare interface MessagingStore {
flush: () => boolean;
highlight: (messageId: null | string) => boolean;
interact: (messageId: string, action: string, isActive: boolean) => boolean;
scroll: (messageId: string) => boolean;
loader: (type: string, isVisible: null | boolean) => boolean;
identify: (
jid: string,
Expand Down

0 comments on commit 3550edd

Please sign in to comment.