Skip to content
Open
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
4 changes: 4 additions & 0 deletions database.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export default class Database {
* @param limit - maximum number of results to return
*/
getTopFavoriteEmoji(limit: number): Promise<Emoji[]>;
/**
* Returns all native emojis, unordered.
*/
getAllNativeEmojis(): Promise<NativeEmoji[]>;
/**
* Set the custom emoji for this database. Throws an error if custom emoji are not in the correct format.
*
Expand Down
7 changes: 6 additions & 1 deletion src/database/Database.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
openDatabase
} from './databaseLifecycle'
import {
isEmpty, getEmojiByGroup,
isEmpty, getAllNativeEmojis, getEmojiByGroup,
getEmojiBySearchQuery, getEmojiByShortcode, getEmojiByUnicode,
get, set, getTopFavoriteEmoji, incrementFavoriteEmojiCount
} from './idbInterface'
Expand Down Expand Up @@ -125,6 +125,11 @@ export default class Database {
return (await getTopFavoriteEmoji(this._db, this._custom, limit)).map(cleanEmoji)
}

async getAllNativeEmojis () {
await this.ready()
return (await getAllNativeEmojis(this._db)).map(cleanEmoji)
}

set customEmoji (customEmojis) {
this._custom = customEmojiIndex(customEmojis)
}
Expand Down
6 changes: 6 additions & 0 deletions src/database/idbInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,9 @@ export function getTopFavoriteEmoji (db, customEmojiIndex, limit) {
}
})
}

export async function getAllNativeEmojis (db) {
return dbPromise(db, STORE_EMOJI, MODE_READONLY, (emojiStore, txn, cb) => {
getAllIDB(emojiStore.index(INDEX_GROUP_AND_ORDER), undefined, cb)
})
}
13 changes: 13 additions & 0 deletions test/spec/database/getAllNativeEmojis.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ALL_EMOJI, basicAfterEach, basicBeforeEach } from '../shared'
import Database from '../../../src/database/Database'

describe('getAllNativeEmojis', () => {
beforeEach(basicBeforeEach)
afterEach(basicAfterEach)
test('basic test', async () => {
const db = new Database({ dataSource: ALL_EMOJI })

expect((await db.getAllNativeEmojis()).length).toBe(189)
await db.delete()
})
})