Skip to content

Commit

Permalink
Bump to 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
esindger committed Jul 20, 2019
1 parent ea72df4 commit 5faa4dd
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 53 deletions.
64 changes: 32 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"license": "GPL-3.0",
"repository": "https://github.com/airgram/airgram-ts-example",
"dependencies": {
"airgram": "^1.1.2",
"airgram-api": "^1.1.2",
"airgram-use-models": "^1.1.0"
"@airgram/api": "^1.2.0",
"@airgram/use-models": "^1.2.0",
"airgram": "^1.2.0"
},
"devDependencies": {
"@types/node": "^12.0.10",
Expand Down
6 changes: 3 additions & 3 deletions src/ChatModel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CHAT_TYPE } from 'airgram-api'
import { ChatBaseModel } from 'airgram-use-models'
import { CHAT_TYPE } from '@airgram/api'
import { ChatBaseModel } from '@airgram/use-models'

export default class ChatModel extends ChatBaseModel {
get isBasicGroup (): boolean {
Expand All @@ -20,6 +20,6 @@ export default class ChatModel extends ChatBaseModel {
}

// tslint:disable:no-empty-interface
declare module 'airgram-api/outputs/Chat' {
declare module '@airgram/api/outputs/Chat' {
export interface Chat extends ChatModel {}
}
26 changes: 17 additions & 9 deletions src/ChatRepository.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { ag } from 'airgram'
import { UPDATE } from 'airgram-api'
import { UPDATE } from '@airgram/api'
import ChatModel from './ChatModel'

export default class ChatRepository<ContextT> {
private chatMap: Map<number, ChatModel>

constructor (private airgram: ag.Airgram) {
constructor (private airgram: Airgram.AirgramInstance) {
this.chatMap = new Map<number, ChatModel>()

// Add new chats to the store
Expand All @@ -30,7 +29,11 @@ export default class ChatRepository<ContextT> {
public async isMe (id: number): Promise<boolean> {
const chat = this.get(id)
if (chat && 'userId' in chat.type) {
return (await this.airgram.api.getMe()).id === chat.type.userId
const me = await this.airgram.api.getMe()
if (me._ === 'error') {
throw new Error(me.message)
}
return me.id === chat.type.userId
}
return false
}
Expand All @@ -39,10 +42,15 @@ export default class ChatRepository<ContextT> {
this.chatMap.set(id, chat)
}

private fetch (id: number): Promise<ChatModel> {
return this.airgram.api.getChat({ chatId: id }).then((chat) => {
this.chatMap.set(id, chat)
return chat
})
private async fetch (id: number): Promise<ChatModel> {
const chatOrError = await this.airgram.api.getChat({ chatId: id })

if (chatOrError._ === 'error') {
throw new Error(chatOrError.message)
} else {
this.chatMap.set(id, chatOrError)
}

return chatOrError
}
}
8 changes: 4 additions & 4 deletions src/context.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ag, createContext } from 'airgram'
import { createContext } from 'airgram'
import ChatRepository from './ChatRepository'

export interface Context extends ag.Context {
export interface Context extends Airgram.Context {
chats: ChatRepository<Context>
}

export const contextFactory: ag.ContextFactory<Context> = (airgram: ag.Airgram<Context>) => {
export const contextFactory: Airgram.ContextFactory<Context> = (airgram: Airgram.AirgramInstance<Context>) => {
const chats = new ChatRepository<Context>(airgram)

return (options: ag.ContextOptions) => ({
return (options: Airgram.ContextOptions) => ({
...createContext(options),
chats
})
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UPDATE } from '@airgram/api'
import { useModels } from '@airgram/use-models'
import { Airgram, Auth, prompt } from 'airgram'
import { UPDATE } from 'airgram-api'
import { useModels } from 'airgram-use-models'
import ChatModel from './ChatModel'
import { Context, contextFactory } from './context'

Expand Down

0 comments on commit 5faa4dd

Please sign in to comment.