github.com/xzl8028/xenia-server@v0.0.0-20190809101854-18450a97da63/tests/plugin_tests/test_update_user_status_plugin/main.go (about) 1 // Copyright (c) 2015-present Xenia, Inc. All Rights Reserved. 2 // See LICENSE.txt for license information. 3 4 package main 5 6 import ( 7 "fmt" 8 9 "github.com/xzl8028/xenia-server/model" 10 "github.com/xzl8028/xenia-server/plugin" 11 ) 12 13 type MyPlugin struct { 14 plugin.XeniaPlugin 15 } 16 17 func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) { 18 uid := "{{.BasicUser.Id}}" 19 20 statuses := []string{model.STATUS_ONLINE, model.STATUS_AWAY, model.STATUS_DND, model.STATUS_OFFLINE} 21 22 for _, s := range statuses { 23 status, err := p.API.UpdateUserStatus(uid, s) 24 if err != nil { 25 return nil, err.Error() 26 } 27 if status == nil { 28 return nil, "Status was expected, got nil" 29 } 30 if s != status.Status { 31 return nil, fmt.Sprintf("Invalid status returned: %v != %v", s, status.Status) 32 } 33 34 } 35 36 status, err := p.API.UpdateUserStatus(uid, "notrealstatus") 37 if err == nil { 38 return nil, "Expected to get an error while updating invalid user status" 39 } 40 if status != nil { 41 return nil, "Status was expected to be nil, got: " + status.Status 42 } 43 44 return nil, "" 45 } 46 47 func main() { 48 plugin.ClientMain(&MyPlugin{}) 49 }