github.com/xzl8028/xenia-server@v0.0.0-20190809101854-18450a97da63/tests/plugin_tests/test_update_user_active_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 "github.com/xzl8028/xenia-server/model" 8 "github.com/xzl8028/xenia-server/plugin" 9 ) 10 11 type MyPlugin struct { 12 plugin.XeniaPlugin 13 } 14 15 func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) { 16 uid := "{{.BasicUser.Id}}" 17 if err := p.API.UpdateUserActive(uid, true); err != nil { 18 return nil, err.Error() 19 } 20 21 user, err := p.API.GetUser(uid) 22 if err != nil { 23 return nil, err.Error() 24 } 25 26 if int64(0) != user.DeleteAt { 27 return nil, "DeleteAt value is not 0" 28 } 29 30 if err = p.API.UpdateUserActive(uid, false); err != nil { 31 return nil, err.Error() 32 } 33 34 user, err = p.API.GetUser(uid) 35 if err != nil { 36 return nil, err.Error() 37 } 38 if user == nil { 39 return nil, "GetUser returned nil" 40 } 41 42 if int64(0) == user.DeleteAt { 43 return nil, "DeleteAt value is 0" 44 } 45 46 if err = p.API.UpdateUserActive(uid, true); err != nil { 47 return nil, err.Error() 48 } 49 50 if err = p.API.UpdateUserActive(uid, true); err != nil { 51 return nil, err.Error() 52 } 53 54 user, err = p.API.GetUser(uid) 55 if err != nil { 56 return nil, err.Error() 57 } 58 59 if int64(0) != user.DeleteAt { 60 return nil, "DeleteAt value is not 0" 61 } 62 63 return nil, "" 64 } 65 66 func main() { 67 plugin.ClientMain(&MyPlugin{}) 68 }