github.com/xzl8028/xenia-server@v0.0.0-20190809101854-18450a97da63/store/store.go (about) 1 // Copyright (c) 2016-present Xenia, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package store 5 6 import ( 7 "time" 8 9 "github.com/xzl8028/xenia-server/model" 10 ) 11 12 type StoreResult struct { 13 Data interface{} 14 Err *model.AppError 15 } 16 17 type StoreChannel chan StoreResult 18 19 func Do(f func(result *StoreResult)) StoreChannel { 20 storeChannel := make(StoreChannel, 1) 21 go func() { 22 result := StoreResult{} 23 f(&result) 24 storeChannel <- result 25 close(storeChannel) 26 }() 27 return storeChannel 28 } 29 30 func Must(sc StoreChannel) interface{} { 31 r := <-sc 32 if r.Err != nil { 33 34 time.Sleep(time.Second) 35 panic(r.Err) 36 } 37 38 return r.Data 39 } 40 41 type Store interface { 42 Team() TeamStore 43 Channel() ChannelStore 44 Post() PostStore 45 User() UserStore 46 Bot() BotStore 47 Task() TaskStore 48 Audit() AuditStore 49 ClusterDiscovery() ClusterDiscoveryStore 50 Compliance() ComplianceStore 51 Session() SessionStore 52 OAuth() OAuthStore 53 System() SystemStore 54 Webhook() WebhookStore 55 Command() CommandStore 56 CommandWebhook() CommandWebhookStore 57 Preference() PreferenceStore 58 License() LicenseStore 59 Token() TokenStore 60 Emoji() EmojiStore 61 Status() StatusStore 62 FileInfo() FileInfoStore 63 Reaction() ReactionStore 64 Role() RoleStore 65 Scheme() SchemeStore 66 Job() JobStore 67 UserAccessToken() UserAccessTokenStore 68 ChannelMemberHistory() ChannelMemberHistoryStore 69 Plugin() PluginStore 70 TermsOfService() TermsOfServiceStore 71 Group() GroupStore 72 UserTermsOfService() UserTermsOfServiceStore 73 LinkMetadata() LinkMetadataStore 74 MarkSystemRanUnitTests() 75 Close() 76 LockToMaster() 77 UnlockFromMaster() 78 DropAllTables() 79 TotalMasterDbConnections() int 80 TotalReadDbConnections() int 81 TotalSearchDbConnections() int 82 } 83 84 type TeamStore interface { 85 Save(team *model.Team) (*model.Team, *model.AppError) 86 Update(team *model.Team) (*model.Team, *model.AppError) 87 UpdateDisplayName(name string, teamId string) *model.AppError 88 Get(id string) (*model.Team, *model.AppError) 89 GetByName(name string) (*model.Team, *model.AppError) 90 SearchByName(name string) ([]*model.Team, *model.AppError) 91 SearchAll(term string) ([]*model.Team, *model.AppError) 92 SearchOpen(term string) ([]*model.Team, *model.AppError) 93 SearchPrivate(term string) ([]*model.Team, *model.AppError) 94 GetAll() ([]*model.Team, *model.AppError) 95 GetAllPage(offset int, limit int) ([]*model.Team, *model.AppError) 96 GetAllPrivateTeamListing() StoreChannel 97 GetAllPrivateTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError) 98 GetAllTeamListing() StoreChannel 99 GetAllTeamPageListing(offset int, limit int) ([]*model.Team, *model.AppError) 100 GetTeamsByUserId(userId string) StoreChannel 101 GetByInviteId(inviteId string) (*model.Team, *model.AppError) 102 PermanentDelete(teamId string) *model.AppError 103 AnalyticsTeamCount() (int64, *model.AppError) 104 SaveMember(member *model.TeamMember, maxUsersPerTeam int) StoreChannel 105 UpdateMember(member *model.TeamMember) (*model.TeamMember, *model.AppError) 106 GetMember(teamId string, userId string) (*model.TeamMember, *model.AppError) 107 GetMembers(teamId string, offset int, limit int, restrictions *model.ViewUsersRestrictions) ([]*model.TeamMember, *model.AppError) 108 GetMembersByIds(teamId string, userIds []string, restrictions *model.ViewUsersRestrictions) ([]*model.TeamMember, *model.AppError) 109 GetTotalMemberCount(teamId string) (int64, *model.AppError) 110 GetActiveMemberCount(teamId string) (int64, *model.AppError) 111 GetTeamsForUser(userId string) ([]*model.TeamMember, *model.AppError) 112 GetTeamsForUserWithPagination(userId string, page, perPage int) ([]*model.TeamMember, *model.AppError) 113 GetChannelUnreadsForAllTeams(excludeTeamId, userId string) ([]*model.ChannelUnread, *model.AppError) 114 GetChannelUnreadsForTeam(teamId, userId string) ([]*model.ChannelUnread, *model.AppError) 115 RemoveMember(teamId string, userId string) StoreChannel 116 RemoveAllMembersByTeam(teamId string) StoreChannel 117 RemoveAllMembersByUser(userId string) StoreChannel 118 UpdateLastTeamIconUpdate(teamId string, curTime int64) StoreChannel 119 GetTeamsByScheme(schemeId string, offset int, limit int) StoreChannel 120 MigrateTeamMembers(fromTeamId string, fromUserId string) StoreChannel 121 ResetAllTeamSchemes() StoreChannel 122 ClearAllCustomRoleAssignments() StoreChannel 123 AnalyticsGetTeamCountForScheme(schemeId string) StoreChannel 124 GetAllForExportAfter(limit int, afterId string) StoreChannel 125 GetTeamMembersForExport(userId string) StoreChannel 126 UserBelongsToTeams(userId string, teamIds []string) StoreChannel 127 GetUserTeamIds(userId string, allowFromCache bool) StoreChannel 128 InvalidateAllTeamIdsForUser(userId string) 129 ClearCaches() 130 } 131 132 type ChannelStore interface { 133 GetByDisplayName(teamId string, displayName string) (*model.Channel, *model.AppError) 134 Save(channel *model.Channel, maxChannelsPerTeam int64) (*model.Channel, *model.AppError) 135 CreateDirectChannel(userId string, otherUserId string) (*model.Channel, *model.AppError) 136 SaveDirectChannel(channel *model.Channel, member1 *model.ChannelMember, member2 *model.ChannelMember) (*model.Channel, *model.AppError) 137 Update(channel *model.Channel) (*model.Channel, *model.AppError) 138 Get(id string, allowFromCache bool) (*model.Channel, *model.AppError) 139 InvalidateChannel(id string) 140 InvalidateChannelByName(teamId, name string) 141 GetFromMaster(id string) (*model.Channel, *model.AppError) 142 Delete(channelId string, time int64) *model.AppError 143 Restore(channelId string, time int64) *model.AppError 144 SetDeleteAt(channelId string, deleteAt int64, updateAt int64) *model.AppError 145 PermanentDeleteByTeam(teamId string) StoreChannel 146 PermanentDelete(channelId string) StoreChannel 147 GetByName(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError) 148 GetByNames(team_id string, names []string, allowFromCache bool) ([]*model.Channel, *model.AppError) 149 GetByNameIncludeDeleted(team_id string, name string, allowFromCache bool) (*model.Channel, *model.AppError) 150 GetDeletedByName(team_id string, name string) (*model.Channel, *model.AppError) 151 GetDeleted(team_id string, offset int, limit int) (*model.ChannelList, *model.AppError) 152 GetChannels(teamId string, userId string, includeDeleted bool) (*model.ChannelList, *model.AppError) 153 GetAllChannels(page, perPage int, opts ChannelSearchOpts) (*model.ChannelListWithTeamData, *model.AppError) 154 GetAllChannelsCount(opts ChannelSearchOpts) (int64, *model.AppError) 155 GetMoreChannels(teamId string, userId string, offset int, limit int) (*model.ChannelList, *model.AppError) 156 GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) 157 GetPublicChannelsByIdsForTeam(teamId string, channelIds []string) (*model.ChannelList, *model.AppError) 158 GetChannelCounts(teamId string, userId string) (*model.ChannelCounts, *model.AppError) 159 GetTeamChannels(teamId string) (*model.ChannelList, *model.AppError) 160 GetAll(teamId string) ([]*model.Channel, *model.AppError) 161 GetChannelsByIds(channelIds []string) ([]*model.Channel, *model.AppError) 162 GetForPost(postId string) (*model.Channel, *model.AppError) 163 SaveMember(member *model.ChannelMember) StoreChannel 164 UpdateMember(member *model.ChannelMember) (*model.ChannelMember, *model.AppError) 165 GetMembers(channelId string, offset, limit int) (*model.ChannelMembers, *model.AppError) 166 GetMember(channelId string, userId string) (*model.ChannelMember, *model.AppError) 167 GetChannelMembersTimezones(channelId string) ([]model.StringMap, *model.AppError) 168 GetAllChannelMembersForUser(userId string, allowFromCache bool, includeDeleted bool) (map[string]string, *model.AppError) 169 InvalidateAllChannelMembersForUser(userId string) 170 IsUserInChannelUseCache(userId string, channelId string) bool 171 GetAllChannelMembersNotifyPropsForChannel(channelId string, allowFromCache bool) (map[string]model.StringMap, *model.AppError) 172 InvalidateCacheForChannelMembersNotifyProps(channelId string) 173 GetMemberForPost(postId string, userId string) (*model.ChannelMember, *model.AppError) 174 InvalidateMemberCount(channelId string) 175 GetMemberCountFromCache(channelId string) int64 176 GetMemberCount(channelId string, allowFromCache bool) (int64, *model.AppError) 177 GetPinnedPosts(channelId string) (*model.PostList, *model.AppError) 178 RemoveMember(channelId string, userId string) *model.AppError 179 PermanentDeleteMembersByUser(userId string) *model.AppError 180 PermanentDeleteMembersByChannel(channelId string) *model.AppError 181 UpdateLastViewedAt(channelIds []string, userId string) (map[string]int64, *model.AppError) 182 IncrementMentionCount(channelId string, userId string) *model.AppError 183 AnalyticsTypeCount(teamId string, channelType string) (int64, *model.AppError) 184 GetMembersForUser(teamId string, userId string) (*model.ChannelMembers, *model.AppError) 185 GetMembersForUserWithPagination(teamId, userId string, page, perPage int) (*model.ChannelMembers, *model.AppError) 186 AutocompleteInTeam(teamId string, term string, includeDeleted bool) (*model.ChannelList, *model.AppError) 187 AutocompleteInTeamForSearch(teamId string, userId string, term string, includeDeleted bool) (*model.ChannelList, *model.AppError) 188 SearchAllChannels(term string, opts ChannelSearchOpts) (*model.ChannelListWithTeamData, *model.AppError) 189 SearchInTeam(teamId string, term string, includeDeleted bool) (*model.ChannelList, *model.AppError) 190 SearchMore(userId string, teamId string, term string) (*model.ChannelList, *model.AppError) 191 SearchGroupChannels(userId, term string) (*model.ChannelList, *model.AppError) 192 GetMembersByIds(channelId string, userIds []string) (*model.ChannelMembers, *model.AppError) 193 AnalyticsDeletedTypeCount(teamId string, channelType string) (int64, *model.AppError) 194 GetChannelUnread(channelId, userId string) (*model.ChannelUnread, *model.AppError) 195 ClearCaches() 196 GetChannelsByScheme(schemeId string, offset int, limit int) StoreChannel 197 MigrateChannelMembers(fromChannelId string, fromUserId string) (map[string]string, *model.AppError) 198 ResetAllChannelSchemes() *model.AppError 199 ClearAllCustomRoleAssignments() *model.AppError 200 MigratePublicChannels() error 201 GetAllChannelsForExportAfter(limit int, afterId string) ([]*model.ChannelForExport, *model.AppError) 202 GetAllDirectChannelsForExportAfter(limit int, afterId string) ([]*model.DirectChannelForExport, *model.AppError) 203 GetChannelMembersForExport(userId string, teamId string) ([]*model.ChannelMemberForExport, *model.AppError) 204 RemoveAllDeactivatedMembers(channelId string) *model.AppError 205 GetChannelsBatchForIndexing(startTime, endTime int64, limit int) ([]*model.Channel, *model.AppError) 206 UserBelongsToChannels(userId string, channelIds []string) (bool, *model.AppError) 207 } 208 209 type ChannelMemberHistoryStore interface { 210 LogJoinEvent(userId string, channelId string, joinTime int64) *model.AppError 211 LogLeaveEvent(userId string, channelId string, leaveTime int64) *model.AppError 212 GetUsersInChannelDuring(startTime int64, endTime int64, channelId string) ([]*model.ChannelMemberHistoryResult, *model.AppError) 213 PermanentDeleteBatch(endTime int64, limit int64) (int64, *model.AppError) 214 } 215 216 type PostStore interface { 217 Save(post *model.Post) (*model.Post, *model.AppError) 218 Update(newPost *model.Post, oldPost *model.Post) (*model.Post, *model.AppError) 219 SelectByMessage(message string) (*model.Post, *model.AppError) 220 Get(id string) (*model.PostList, *model.AppError) 221 GetSingle(id string) (*model.Post, *model.AppError) 222 Delete(postId string, time int64, deleteByID string) *model.AppError 223 PermanentDeleteByUser(userId string) *model.AppError 224 PermanentDeleteByChannel(channelId string) *model.AppError 225 GetPosts(channelId string, offset int, limit int, allowFromCache bool) (*model.PostList, *model.AppError) 226 GetFlaggedPosts(userId string, offset int, limit int) (*model.PostList, *model.AppError) 227 GetFlaggedPostsForTeam(userId, teamId string, offset int, limit int) (*model.PostList, *model.AppError) 228 GetFlaggedPostsForChannel(userId, channelId string, offset int, limit int) (*model.PostList, *model.AppError) 229 GetPostsBefore(channelId string, postId string, numPosts int, offset int) (*model.PostList, *model.AppError) 230 GetPostsAfter(channelId string, postId string, numPosts int, offset int) (*model.PostList, *model.AppError) 231 GetPostsSince(channelId string, time int64, allowFromCache bool) (*model.PostList, *model.AppError) 232 GetEtag(channelId string, allowFromCache bool) string 233 Search(teamId string, userId string, params *model.SearchParams) StoreChannel 234 AnalyticsUserCountsWithPostsByDay(teamId string) (model.AnalyticsRows, *model.AppError) 235 AnalyticsPostCountsByDay(teamId string) (model.AnalyticsRows, *model.AppError) 236 AnalyticsPostCount(teamId string, mustHaveFile bool, mustHaveHashtag bool) (int64, *model.AppError) 237 ClearCaches() 238 InvalidateLastPostTimeCache(channelId string) 239 GetPostsCreatedAt(channelId string, time int64) ([]*model.Post, *model.AppError) 240 Overwrite(post *model.Post) (*model.Post, *model.AppError) 241 GetPostsByIds(postIds []string) ([]*model.Post, *model.AppError) 242 GetPostsBatchForIndexing(startTime int64, endTime int64, limit int) ([]*model.PostForIndexing, *model.AppError) 243 PermanentDeleteBatch(endTime int64, limit int64) (int64, *model.AppError) 244 GetOldest() (*model.Post, *model.AppError) 245 GetMaxPostSize() int 246 GetParentsForExportAfter(limit int, afterId string) ([]*model.PostForExport, *model.AppError) 247 GetRepliesForExport(parentId string) ([]*model.ReplyForExport, *model.AppError) 248 GetDirectPostParentsForExportAfter(limit int, afterId string) ([]*model.DirectPostForExport, *model.AppError) 249 } 250 251 type UserStore interface { 252 Save(user *model.User) StoreChannel 253 Update(user *model.User, allowRoleUpdate bool) (*model.UserUpdate, *model.AppError) 254 UpdateLastPictureUpdate(userId string) StoreChannel 255 ResetLastPictureUpdate(userId string) *model.AppError 256 UpdateUpdateAt(userId string) StoreChannel 257 UpdatePassword(userId, newPassword string) StoreChannel 258 UpdateAuthData(userId string, service string, authData *string, email string, resetMfa bool) (string, *model.AppError) 259 UpdateMfaSecret(userId, secret string) StoreChannel 260 UpdateMfaActive(userId string, active bool) StoreChannel 261 Get(id string) (*model.User, *model.AppError) 262 GetAll() StoreChannel 263 ClearCaches() 264 InvalidateProfilesInChannelCacheByUser(userId string) 265 InvalidateProfilesInChannelCache(channelId string) 266 GetProfilesInChannel(channelId string, offset int, limit int) StoreChannel 267 GetProfilesInChannelByStatus(channelId string, offset int, limit int) StoreChannel 268 GetAllProfilesInChannel(channelId string, allowFromCache bool) StoreChannel 269 GetProfilesNotInChannel(teamId string, channelId string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) StoreChannel 270 GetProfilesWithoutTeam(offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) StoreChannel 271 GetProfilesByUsernames(usernames []string, viewRestrictions *model.ViewUsersRestrictions) StoreChannel 272 GetAllProfiles(options *model.UserGetOptions) StoreChannel 273 GetProfiles(options *model.UserGetOptions) StoreChannel 274 GetProfileByIds(userIds []string, options *UserGetByIdsOpts, allowFromCache bool) StoreChannel 275 GetProfileByGroupChannelIdsForUser(userId string, channelIds []string) (map[string][]*model.User, *model.AppError) 276 InvalidatProfileCacheForUser(userId string) 277 GetByEmail(email string) (*model.User, *model.AppError) 278 GetByAuth(authData *string, authService string) (*model.User, *model.AppError) 279 GetAllUsingAuthService(authService string) ([]*model.User, *model.AppError) 280 GetByUsername(username string) StoreChannel 281 GetForLogin(loginId string, allowSignInWithUsername, allowSignInWithEmail bool) StoreChannel 282 VerifyEmail(userId, email string) (string, *model.AppError) 283 GetEtagForAllProfiles() StoreChannel 284 GetEtagForProfiles(teamId string) StoreChannel 285 UpdateFailedPasswordAttempts(userId string, attempts int) StoreChannel 286 GetSystemAdminProfiles() StoreChannel 287 PermanentDelete(userId string) *model.AppError 288 AnalyticsActiveCount(time int64) StoreChannel 289 GetUnreadCount(userId string) (int64, error) 290 GetUnreadCountForChannel(userId string, channelId string) StoreChannel 291 GetAnyUnreadPostCountForChannel(userId string, channelId string) (int64, *model.AppError) 292 GetRecentlyActiveUsersForTeam(teamId string, offset, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) 293 GetNewUsersForTeam(teamId string, offset, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) 294 Search(teamId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) 295 SearchNotInTeam(notInTeamId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) 296 SearchInChannel(channelId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) 297 SearchNotInChannel(teamId string, channelId string, term string, options *model.UserSearchOptions) StoreChannel 298 SearchWithoutTeam(term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) 299 AnalyticsGetInactiveUsersCount() (int64, *model.AppError) 300 AnalyticsGetSystemAdminCount() StoreChannel 301 GetProfilesNotInTeam(teamId string, groupConstrained bool, offset int, limit int, viewRestrictions *model.ViewUsersRestrictions) StoreChannel 302 GetEtagForProfilesNotInTeam(teamId string) StoreChannel 303 ClearAllCustomRoleAssignments() StoreChannel 304 InferSystemInstallDate() StoreChannel 305 GetAllAfter(limit int, afterId string) ([]*model.User, *model.AppError) 306 GetUsersBatchForIndexing(startTime, endTime int64, limit int) ([]*model.UserForIndexing, *model.AppError) 307 Count(options model.UserCountOptions) (int64, *model.AppError) 308 GetTeamGroupUsers(teamID string) ([]*model.User, *model.AppError) 309 GetChannelGroupUsers(channelID string) ([]*model.User, *model.AppError) 310 } 311 312 type BotStore interface { 313 Get(userId string, includeDeleted bool) (*model.Bot, *model.AppError) 314 GetAll(options *model.BotGetOptions) ([]*model.Bot, *model.AppError) 315 Save(bot *model.Bot) (*model.Bot, *model.AppError) 316 Update(bot *model.Bot) (*model.Bot, *model.AppError) 317 PermanentDelete(userId string) *model.AppError 318 } 319 320 type TaskStore interface { 321 Get(taskId string) (*model.Task, *model.AppError) 322 GetAll() ([]*model.Task, *model.AppError) 323 // Save(bot *model.Bot) (*model.Task, *model.AppError) 324 // Update(bot *model.Bot) (*model.Task, *model.AppError) 325 Update(task *model.Task) (*model.Task, *model.AppError) 326 Insert(task *model.Task) (*model.Task, *model.AppError) 327 // PermanentDelete(taskId string) *model.AppError 328 GetAllWithTeamId(teamId string) ([]*model.Task, *model.AppError) 329 } 330 331 type SessionStore interface { 332 Get(sessionIdOrToken string) (*model.Session, *model.AppError) 333 Save(session *model.Session) (*model.Session, *model.AppError) 334 GetSessions(userId string) ([]*model.Session, *model.AppError) 335 GetSessionsWithActiveDeviceIds(userId string) ([]*model.Session, *model.AppError) 336 Remove(sessionIdOrToken string) *model.AppError 337 RemoveAllSessions() *model.AppError 338 PermanentDeleteSessionsByUser(teamId string) *model.AppError 339 UpdateLastActivityAt(sessionId string, time int64) *model.AppError 340 UpdateRoles(userId string, roles string) (string, *model.AppError) 341 UpdateDeviceId(id string, deviceId string, expiresAt int64) (string, *model.AppError) 342 AnalyticsSessionCount() (int64, *model.AppError) 343 Cleanup(expiryTime int64, batchSize int64) 344 } 345 346 type AuditStore interface { 347 Save(audit *model.Audit) *model.AppError 348 Get(user_id string, offset int, limit int) (model.Audits, *model.AppError) 349 PermanentDeleteByUser(userId string) *model.AppError 350 PermanentDeleteBatch(endTime int64, limit int64) (int64, *model.AppError) 351 } 352 353 type ClusterDiscoveryStore interface { 354 Save(discovery *model.ClusterDiscovery) *model.AppError 355 Delete(discovery *model.ClusterDiscovery) (bool, *model.AppError) 356 Exists(discovery *model.ClusterDiscovery) (bool, *model.AppError) 357 GetAll(discoveryType, clusterName string) ([]*model.ClusterDiscovery, *model.AppError) 358 SetLastPingAt(discovery *model.ClusterDiscovery) *model.AppError 359 Cleanup() *model.AppError 360 } 361 362 type ComplianceStore interface { 363 Save(compliance *model.Compliance) (*model.Compliance, *model.AppError) 364 Update(compliance *model.Compliance) (*model.Compliance, *model.AppError) 365 Get(id string) (*model.Compliance, *model.AppError) 366 GetAll(offset, limit int) (model.Compliances, *model.AppError) 367 ComplianceExport(compliance *model.Compliance) ([]*model.CompliancePost, *model.AppError) 368 MessageExport(after int64, limit int) ([]*model.MessageExport, *model.AppError) 369 } 370 371 type OAuthStore interface { 372 SaveApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppError) 373 UpdateApp(app *model.OAuthApp) (*model.OAuthApp, *model.AppError) 374 GetApp(id string) (*model.OAuthApp, *model.AppError) 375 GetAppByUser(userId string, offset, limit int) ([]*model.OAuthApp, *model.AppError) 376 GetApps(offset, limit int) ([]*model.OAuthApp, *model.AppError) 377 GetAuthorizedApps(userId string, offset, limit int) ([]*model.OAuthApp, *model.AppError) 378 DeleteApp(id string) *model.AppError 379 SaveAuthData(authData *model.AuthData) (*model.AuthData, *model.AppError) 380 GetAuthData(code string) (*model.AuthData, *model.AppError) 381 RemoveAuthData(code string) *model.AppError 382 PermanentDeleteAuthDataByUser(userId string) *model.AppError 383 SaveAccessData(accessData *model.AccessData) (*model.AccessData, *model.AppError) 384 UpdateAccessData(accessData *model.AccessData) (*model.AccessData, *model.AppError) 385 GetAccessData(token string) (*model.AccessData, *model.AppError) 386 GetAccessDataByUserForApp(userId, clientId string) ([]*model.AccessData, *model.AppError) 387 GetAccessDataByRefreshToken(token string) (*model.AccessData, *model.AppError) 388 GetPreviousAccessData(userId, clientId string) (*model.AccessData, *model.AppError) 389 RemoveAccessData(token string) *model.AppError 390 RemoveAllAccessData() *model.AppError 391 } 392 393 type SystemStore interface { 394 Save(system *model.System) *model.AppError 395 SaveOrUpdate(system *model.System) *model.AppError 396 Update(system *model.System) *model.AppError 397 Get() (model.StringMap, *model.AppError) 398 GetByName(name string) (*model.System, *model.AppError) 399 PermanentDeleteByName(name string) (*model.System, *model.AppError) 400 } 401 402 type WebhookStore interface { 403 SaveIncoming(webhook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError) 404 GetIncoming(id string, allowFromCache bool) (*model.IncomingWebhook, *model.AppError) 405 GetIncomingList(offset, limit int) ([]*model.IncomingWebhook, *model.AppError) 406 GetIncomingByTeam(teamId string, offset, limit int) ([]*model.IncomingWebhook, *model.AppError) 407 UpdateIncoming(webhook *model.IncomingWebhook) (*model.IncomingWebhook, *model.AppError) 408 GetIncomingByChannel(channelId string) ([]*model.IncomingWebhook, *model.AppError) 409 DeleteIncoming(webhookId string, time int64) *model.AppError 410 PermanentDeleteIncomingByChannel(channelId string) *model.AppError 411 PermanentDeleteIncomingByUser(userId string) *model.AppError 412 413 SaveOutgoing(webhook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError) 414 GetOutgoing(id string) (*model.OutgoingWebhook, *model.AppError) 415 GetOutgoingByChannel(channelId string, offset, limit int) ([]*model.OutgoingWebhook, *model.AppError) 416 GetOutgoingList(offset, limit int) ([]*model.OutgoingWebhook, *model.AppError) 417 GetOutgoingByTeam(teamId string, offset, limit int) ([]*model.OutgoingWebhook, *model.AppError) 418 DeleteOutgoing(webhookId string, time int64) *model.AppError 419 PermanentDeleteOutgoingByChannel(channelId string) *model.AppError 420 PermanentDeleteOutgoingByUser(userId string) *model.AppError 421 UpdateOutgoing(hook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError) 422 423 AnalyticsIncomingCount(teamId string) (int64, *model.AppError) 424 AnalyticsOutgoingCount(teamId string) (int64, *model.AppError) 425 InvalidateWebhookCache(webhook string) 426 ClearCaches() 427 } 428 429 type CommandStore interface { 430 Save(webhook *model.Command) (*model.Command, *model.AppError) 431 GetByTrigger(teamId string, trigger string) (*model.Command, *model.AppError) 432 Get(id string) (*model.Command, *model.AppError) 433 GetByTeam(teamId string) ([]*model.Command, *model.AppError) 434 Delete(commandId string, time int64) *model.AppError 435 PermanentDeleteByTeam(teamId string) *model.AppError 436 PermanentDeleteByUser(userId string) *model.AppError 437 Update(hook *model.Command) (*model.Command, *model.AppError) 438 AnalyticsCommandCount(teamId string) (int64, *model.AppError) 439 } 440 441 type CommandWebhookStore interface { 442 Save(webhook *model.CommandWebhook) StoreChannel 443 Get(id string) StoreChannel 444 TryUse(id string, limit int) StoreChannel 445 Cleanup() 446 } 447 448 type PreferenceStore interface { 449 Save(preferences *model.Preferences) *model.AppError 450 GetCategory(userId string, category string) (model.Preferences, *model.AppError) 451 Get(userId string, category string, name string) (*model.Preference, *model.AppError) 452 GetAll(userId string) (model.Preferences, *model.AppError) 453 Delete(userId, category, name string) *model.AppError 454 DeleteCategory(userId string, category string) *model.AppError 455 DeleteCategoryAndName(category string, name string) *model.AppError 456 PermanentDeleteByUser(userId string) *model.AppError 457 IsFeatureEnabled(feature, userId string) (bool, *model.AppError) 458 CleanupFlagsBatch(limit int64) (int64, *model.AppError) 459 } 460 461 type LicenseStore interface { 462 Save(license *model.LicenseRecord) (*model.LicenseRecord, *model.AppError) 463 Get(id string) (*model.LicenseRecord, *model.AppError) 464 } 465 466 type TokenStore interface { 467 Save(recovery *model.Token) *model.AppError 468 Delete(token string) *model.AppError 469 GetByToken(token string) (*model.Token, *model.AppError) 470 Cleanup() 471 RemoveAllTokensByType(tokenType string) StoreChannel 472 } 473 474 type EmojiStore interface { 475 Save(emoji *model.Emoji) (*model.Emoji, *model.AppError) 476 Get(id string, allowFromCache bool) (*model.Emoji, *model.AppError) 477 GetByName(name string) (*model.Emoji, *model.AppError) 478 GetMultipleByName(names []string) StoreChannel 479 GetList(offset, limit int, sort string) ([]*model.Emoji, *model.AppError) 480 Delete(id string, time int64) *model.AppError 481 Search(name string, prefixOnly bool, limit int) ([]*model.Emoji, *model.AppError) 482 } 483 484 type StatusStore interface { 485 SaveOrUpdate(status *model.Status) *model.AppError 486 Get(userId string) (*model.Status, *model.AppError) 487 GetByIds(userIds []string) ([]*model.Status, *model.AppError) 488 GetOnlineAway() ([]*model.Status, *model.AppError) 489 GetOnline() ([]*model.Status, *model.AppError) 490 GetAllFromTeam(teamId string) ([]*model.Status, *model.AppError) 491 ResetAll() *model.AppError 492 GetTotalActiveUsersCount() (int64, *model.AppError) 493 UpdateLastActivityAt(userId string, lastActivityAt int64) StoreChannel 494 } 495 496 type FileInfoStore interface { 497 Save(info *model.FileInfo) (*model.FileInfo, *model.AppError) 498 Get(id string) (*model.FileInfo, *model.AppError) 499 GetByPath(path string) (*model.FileInfo, *model.AppError) 500 GetForPost(postId string, readFromMaster bool, allowFromCache bool) ([]*model.FileInfo, *model.AppError) 501 GetForUser(userId string) ([]*model.FileInfo, *model.AppError) 502 InvalidateFileInfosForPostCache(postId string) 503 AttachToPost(fileId string, postId string, creatorId string) *model.AppError 504 DeleteForPost(postId string) (string, *model.AppError) 505 PermanentDelete(fileId string) *model.AppError 506 PermanentDeleteBatch(endTime int64, limit int64) (int64, *model.AppError) 507 PermanentDeleteByUser(userId string) (int64, *model.AppError) 508 ClearCaches() 509 } 510 511 type ReactionStore interface { 512 Save(reaction *model.Reaction) (*model.Reaction, *model.AppError) 513 Delete(reaction *model.Reaction) (*model.Reaction, *model.AppError) 514 GetForPost(postId string, allowFromCache bool) ([]*model.Reaction, *model.AppError) 515 DeleteAllWithEmojiName(emojiName string) *model.AppError 516 PermanentDeleteBatch(endTime int64, limit int64) (int64, *model.AppError) 517 BulkGetForPosts(postIds []string) ([]*model.Reaction, *model.AppError) 518 } 519 520 type JobStore interface { 521 Save(job *model.Job) (*model.Job, *model.AppError) 522 UpdateOptimistically(job *model.Job, currentStatus string) (bool, *model.AppError) 523 UpdateStatus(id string, status string) (*model.Job, *model.AppError) 524 UpdateStatusOptimistically(id string, currentStatus string, newStatus string) (bool, *model.AppError) 525 Get(id string) (*model.Job, *model.AppError) 526 GetAllPage(offset int, limit int) ([]*model.Job, *model.AppError) 527 GetAllByType(jobType string) ([]*model.Job, *model.AppError) 528 GetAllByTypePage(jobType string, offset int, limit int) ([]*model.Job, *model.AppError) 529 GetAllByStatus(status string) ([]*model.Job, *model.AppError) 530 GetNewestJobByStatusAndType(status string, jobType string) (*model.Job, *model.AppError) 531 GetCountByStatusAndType(status string, jobType string) (int64, *model.AppError) 532 Delete(id string) (string, *model.AppError) 533 } 534 535 type UserAccessTokenStore interface { 536 Save(token *model.UserAccessToken) (*model.UserAccessToken, *model.AppError) 537 DeleteAllForUser(userId string) *model.AppError 538 Delete(tokenId string) *model.AppError 539 Get(tokenId string) (*model.UserAccessToken, *model.AppError) 540 GetAll(offset int, limit int) ([]*model.UserAccessToken, *model.AppError) 541 GetByToken(tokenString string) (*model.UserAccessToken, *model.AppError) 542 GetByUser(userId string, page, perPage int) ([]*model.UserAccessToken, *model.AppError) 543 Search(term string) ([]*model.UserAccessToken, *model.AppError) 544 UpdateTokenEnable(tokenId string) *model.AppError 545 UpdateTokenDisable(tokenId string) *model.AppError 546 } 547 548 type PluginStore interface { 549 SaveOrUpdate(keyVal *model.PluginKeyValue) StoreChannel 550 CompareAndSet(keyVal *model.PluginKeyValue, oldValue []byte) (bool, *model.AppError) 551 Get(pluginId, key string) StoreChannel 552 Delete(pluginId, key string) StoreChannel 553 DeleteAllForPlugin(PluginId string) StoreChannel 554 DeleteAllExpired() StoreChannel 555 List(pluginId string, page, perPage int) StoreChannel 556 } 557 558 type RoleStore interface { 559 Save(role *model.Role) (*model.Role, *model.AppError) 560 Get(roleId string) (*model.Role, *model.AppError) 561 GetAll() ([]*model.Role, *model.AppError) 562 GetByName(name string) (*model.Role, *model.AppError) 563 GetByNames(names []string) ([]*model.Role, *model.AppError) 564 Delete(roldId string) (*model.Role, *model.AppError) 565 PermanentDeleteAll() *model.AppError 566 } 567 568 type SchemeStore interface { 569 Save(scheme *model.Scheme) StoreChannel 570 Get(schemeId string) StoreChannel 571 GetByName(schemeName string) StoreChannel 572 GetAllPage(scope string, offset int, limit int) StoreChannel 573 Delete(schemeId string) StoreChannel 574 PermanentDeleteAll() StoreChannel 575 } 576 577 type TermsOfServiceStore interface { 578 Save(termsOfService *model.TermsOfService) StoreChannel 579 GetLatest(allowFromCache bool) StoreChannel 580 Get(id string, allowFromCache bool) StoreChannel 581 } 582 583 type UserTermsOfServiceStore interface { 584 GetByUser(userId string) StoreChannel 585 Save(userTermsOfService *model.UserTermsOfService) StoreChannel 586 Delete(userId, termsOfServiceId string) StoreChannel 587 } 588 589 type GroupStore interface { 590 Create(group *model.Group) StoreChannel 591 Get(groupID string) StoreChannel 592 GetByIDs(groupIDs []string) ([]*model.Group, *model.AppError) 593 GetByRemoteID(remoteID string, groupSource model.GroupSource) StoreChannel 594 GetAllBySource(groupSource model.GroupSource) StoreChannel 595 Update(group *model.Group) StoreChannel 596 Delete(groupID string) StoreChannel 597 598 GetMemberUsers(groupID string) StoreChannel 599 GetMemberUsersPage(groupID string, offset int, limit int) StoreChannel 600 GetMemberCount(groupID string) StoreChannel 601 UpsertMember(groupID string, userID string) StoreChannel 602 DeleteMember(groupID string, userID string) StoreChannel 603 604 CreateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) 605 GetGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) 606 GetAllGroupSyncablesByGroupId(groupID string, syncableType model.GroupSyncableType) ([]*model.GroupSyncable, *model.AppError) 607 UpdateGroupSyncable(groupSyncable *model.GroupSyncable) (*model.GroupSyncable, *model.AppError) 608 DeleteGroupSyncable(groupID string, syncableID string, syncableType model.GroupSyncableType) (*model.GroupSyncable, *model.AppError) 609 610 TeamMembersToAdd(since int64) ([]*model.UserTeamIDPair, *model.AppError) 611 ChannelMembersToAdd(since int64) ([]*model.UserChannelIDPair, *model.AppError) 612 613 TeamMembersToRemove() ([]*model.TeamMember, *model.AppError) 614 ChannelMembersToRemove() ([]*model.ChannelMember, *model.AppError) 615 616 GetGroupsByChannel(channelId string, opts model.GroupSearchOpts) ([]*model.Group, *model.AppError) 617 CountGroupsByChannel(channelId string, opts model.GroupSearchOpts) (int64, *model.AppError) 618 619 GetGroupsByTeam(teamId string, opts model.GroupSearchOpts) ([]*model.Group, *model.AppError) 620 CountGroupsByTeam(teamId string, opts model.GroupSearchOpts) (int64, *model.AppError) 621 622 GetGroups(page, perPage int, opts model.GroupSearchOpts) ([]*model.Group, *model.AppError) 623 624 TeamMembersMinusGroupMembers(teamID string, groupIDs []string, page, perPage int) ([]*model.UserWithGroups, *model.AppError) 625 CountTeamMembersMinusGroupMembers(teamID string, groupIDs []string) (int64, *model.AppError) 626 ChannelMembersMinusGroupMembers(channelID string, groupIDs []string, page, perPage int) ([]*model.UserWithGroups, *model.AppError) 627 CountChannelMembersMinusGroupMembers(channelID string, groupIDs []string) (int64, *model.AppError) 628 } 629 630 type LinkMetadataStore interface { 631 Save(linkMetadata *model.LinkMetadata) (*model.LinkMetadata, *model.AppError) 632 Get(url string, timestamp int64) (*model.LinkMetadata, *model.AppError) 633 } 634 635 // ChannelSearchOpts contains options for searching channels. 636 // 637 // NotAssociatedToGroup will exclude channels that have associated, active GroupChannels records. 638 // IncludeDeleted will include channel records where DeleteAt != 0. 639 // ExcludeChannelNames will exclude channels from the results by name. 640 // 641 type ChannelSearchOpts struct { 642 NotAssociatedToGroup string 643 IncludeDeleted bool 644 ExcludeChannelNames []string 645 } 646 647 type UserGetByIdsOpts struct { 648 // IsAdmin tracks whether or not the request is being made by an administrator. Does nothing when provided by a client. 649 IsAdmin bool 650 651 // Restrict to search in a list of teams and channels. Does nothing when provided by a client. 652 ViewRestrictions *model.ViewUsersRestrictions 653 654 // Since filters the users based on their UpdateAt timestamp. 655 Since int64 656 }