1package globals
2
3import (
4	"fmt"
5	"regexp"
6
7	"github.com/keybase/client/go/badges"
8	"github.com/keybase/client/go/chat/types"
9	"github.com/keybase/client/go/libkb"
10	"golang.org/x/net/context"
11)
12
13var DefaultTeamTopic = "general"
14var EmojiPattern = regexp.MustCompile(`(?::)([^:\s]+)(?::)`)
15
16type ChatContext struct {
17	CtxFactory           types.ContextFactory      // source of verified user info and crypt keys
18	InboxSource          types.InboxSource         // source of remote inbox entries for chat
19	ConvSource           types.ConversationSource  // source of remote message bodies for chat
20	MessageDeliverer     types.MessageDeliverer    // background message delivery service
21	ServerCacheVersions  types.ServerCacheVersions // server side versions for chat caches
22	RegexpSearcher       types.RegexpSearcher      // For searching chat messages in a conversation via regexp
23	Indexer              types.Indexer             // For searching chat messages in the entire inbox
24	Syncer               types.Syncer              // For syncing inbox with server
25	FetchRetrier         types.FetchRetrier        // For retrying failed fetch requests
26	ConvLoader           types.ConvLoader          // background conversation loader
27	PushHandler          types.PushHandler         // for handling push notifications from chat server
28	TeamChannelSource    types.TeamChannelSource   // source of all channels in a team
29	AttachmentURLSrv     types.AttachmentURLSrv    // source of URLs for loading attachments
30	EphemeralPurger      types.EphemeralPurger     // triggers background purges of ephemeral chats
31	ActivityNotifier     types.ActivityNotifier    // notify clients of chat of new activity
32	AttachmentUploader   types.AttachmentUploader  // upload attachments
33	NativeVideoHelper    types.NativeVideoHelper   // connection to native for doing things with video
34	StellarLoader        types.StellarLoader       // stellar payment/request loader
35	StellarSender        types.StellarSender       // stellar in-chat payment sender
36	StellarPushHandler   types.OobmHandler
37	Unfurler             types.Unfurler                   // unfurl messages with URLs
38	CommandsSource       types.ConversationCommandsSource // source for / commands for conversations
39	CoinFlipManager      types.CoinFlipManager            // manage /flip games
40	JourneyCardManager   types.JourneyCardManager         // manages team journey cards
41	TeamMentionLoader    types.TeamMentionLoader          // load potential team mentions
42	ExternalAPIKeySource types.ExternalAPIKeySource       // source of third party API keys
43	LiveLocationTracker  types.LiveLocationTracker        // track live location messages for updates
44	BotCommandManager    types.BotCommandManager          // manages commands from bots in convs
45	UIInboxLoader        types.UIInboxLoader              // manages loading inbox for UI
46	UIThreadLoader       types.UIThreadLoader             // manages loading threads for UI
47	Badger               *badges.Badger                   // app badging
48	ParticipantsSource   types.ParticipantSource          // get team participants
49	EmojiSource          types.EmojiSource                // emoji support
50	EphemeralTracker     types.EphemeralTracker           // tracking of ephemeral msg caches
51}
52
53func (c *ChatContext) Describe() string {
54	return fmt.Sprintf(`ChatContext{
55  CtxFactory: %v,
56  InboxSource: %v,
57  ConvSource: %v,
58  MessageDeliverer: %v,
59  ServerCacheVersions: %v,
60  RegexpSearcher: %v,
61  Indexer: %v,
62  Syncer: %v,
63  FetchRetrier: %v,
64  ConvLoader: %v,
65  PushHandler: %v,
66  TeamChannelSource: %v,
67  AttachmentURLSrv: %v,
68  EphemeralPurger: %v,
69  ActivityNotifier: %v,
70  AttachmentUploader: %v,
71  NativeVideoHelper: %v,
72  StellarLoader: %v,
73  StellarSender: %v,
74  StellarPushHandler: %v,
75  Unfurler: %v,
76  CommandsSource: %v,
77  CoinFlipManager: %v,
78  JourneyCardManager: %v,
79  TeamMentionLoader: %v,
80  ExternalAPIKeySource: %v,
81  LiveLocationTracker: %v,
82  BotCommandManager: %v,
83  UIInboxLoader: %v,
84  UIThreadLoader: %v,
85  Badger: %v,
86  ParticipantSource %v,
87  EmojiSource: %v
88  EphemeralTracker: %v
89}`,
90		c.CtxFactory != nil,
91		c.InboxSource != nil,
92		c.ConvSource != nil,
93		c.MessageDeliverer != nil,
94		c.ServerCacheVersions != nil,
95		c.RegexpSearcher != nil,
96		c.Indexer != nil,
97		c.Syncer != nil,
98		c.FetchRetrier != nil,
99		c.ConvLoader != nil,
100		c.PushHandler != nil,
101		c.TeamChannelSource != nil,
102		c.AttachmentURLSrv != nil,
103		c.EphemeralPurger != nil,
104		c.ActivityNotifier != nil,
105		c.AttachmentUploader != nil,
106		c.NativeVideoHelper != nil,
107		c.StellarLoader != nil,
108		c.StellarSender != nil,
109		c.StellarPushHandler != nil,
110		c.Unfurler != nil,
111		c.CommandsSource != nil,
112		c.CoinFlipManager != nil,
113		c.JourneyCardManager != nil,
114		c.TeamMentionLoader != nil,
115		c.ExternalAPIKeySource != nil,
116		c.LiveLocationTracker != nil,
117		c.BotCommandManager != nil,
118		c.UIInboxLoader != nil,
119		c.UIThreadLoader != nil,
120		c.Badger != nil,
121		c.ParticipantsSource != nil,
122		c.EmojiSource != nil,
123		c.EphemeralTracker != nil,
124	)
125}
126
127type Context struct {
128	*libkb.GlobalContext
129	*ChatContext
130}
131
132func (c *Context) ExternalG() *libkb.GlobalContext {
133	return c.GlobalContext
134}
135
136func NewContext(g *libkb.GlobalContext, c *ChatContext) *Context {
137	return &Context{
138		GlobalContext: g,
139		ChatContext:   c,
140	}
141}
142
143type Contextified struct {
144	gc *Context
145}
146
147func NewContextified(gc *Context) Contextified {
148	return Contextified{
149		gc: gc,
150	}
151}
152
153func (c *Context) MetaContext(ctx context.Context) libkb.MetaContext {
154	return libkb.NewMetaContext(ctx, c.ExternalG())
155}
156
157func (c Contextified) G() *Context {
158	return c.gc
159}
160
161func (c Contextified) MetaContext(ctx context.Context) libkb.MetaContext {
162	return libkb.NewMetaContext(ctx, c.G().ExternalG())
163}
164
165type ChatContextified struct {
166	gc *ChatContext
167}
168
169func NewChatContextified(gc *ChatContext) ChatContextified {
170	return ChatContextified{
171		gc: gc,
172	}
173}
174
175func (c ChatContextified) ChatG() *ChatContext {
176	return c.gc
177}
178