-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterfaces.go
77 lines (64 loc) · 1.75 KB
/
interfaces.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package core
import (
"time"
"github.com/hood-chat/core/entity"
"github.com/libp2p/go-libp2p/core/peer"
)
// provide api for managing contacts
type ContactBookAPI interface {
// return list of contact
List(skip int, limit int) (entity.ContactSlice, error)
// return a contact by id
Get(id entity.ID) (entity.Contact, error)
// create or update contact
Put(c entity.Contact) error
}
// provide api for managing identity
type IdentityAPI interface {
IsLogin() bool
SignUp(name string) (*entity.Identity, error)
Get() (entity.Identity, error)
PeerID() (peer.ID, error)
}
// provide api to use chat
type ChatAPI interface {
ChatInfo(id entity.ID) (entity.ChatInfo, error)
ChatInfos(skip int, limit int) (entity.ChatSlice, error)
Join(entity.ChatInfo) error
Find(opt SearchChatOpt) (entity.ChatSlice, error)
New(opt NewChatOpt) (entity.ChatInfo, error)
Send(chatID entity.ID, content string) (*entity.Message, error)
Seen(chatID entity.ID) error
Message(ID entity.ID) (entity.Message, error)
Messages(chatID entity.ID, skip int, limit int) (entity.MessageSlice, error)
Invite(chID entity.ID, cons entity.ContactSlice) error
updateMessageStatus(msgID entity.ID, status entity.Status) error
received(msg entity.Message) error
}
type MessengerAPI interface {
ContactBookAPI() ContactBookAPI
ChatAPI() ChatAPI
IdentityAPI() IdentityAPI
EventBus() Bus
Start()
Stop()
}
type DirectService interface {
Send(nvlop *Envelop)
Stop()
}
type PubSubService interface {
Send(PubSubEnvelop)
Stop()
Join(chatId entity.ID, members []entity.Contact)
}
type OutBox interface {
Put(key peer.ID, val Expiry)
Pop(key peer.ID) []Expiry
// expired item channel
C() chan Expiry
}
type Expiry interface {
id() string
createdAt() time.Time
}