gotify / server

A simple server for sending and receiving messages in real-time per WebSocket. (Includes a sleek web-ui)
https://gotify.net
Other
10.43k stars 593 forks source link

Plugins messages not displayed upon refresh of the message page, nor can they be deleted #653

Open thomas-maurice opened 1 month ago

thomas-maurice commented 1 month ago

Can the issue be reproduced with the latest available release? (y/n) Yes

Which one is the environment gotify server is running in?

Standard config file using sqlite

Do you have an reverse proxy installed in front of gotify server? (Please select None if the problem can be reproduced without the presense of a reverse proxy)

On which client do you experience problems? (Select as many as you can see)

What did you do?

Yesterday I was trying to write a simple plugin for Gotify and I noticed a weird behaviour. Take the following plugin code:

The code ```go package main import ( "time" "github.com/gin-gonic/gin" "github.com/gotify/plugin-api" ) // GetGotifyPluginInfo returns gotify plugin info. func GetGotifyPluginInfo() plugin.Info { return plugin.Info{ ModulePath: "github.com/thomas-maurice/plugin", Version: "0.0.1", Author: "Thomas Maurice", Website: "https://gotify.net/docs/plugin", Description: "Plugin", License: "MIT", Name: "thomas-maurice/plugin", } } // Plugin is the gotify plugin instance. type Plugin struct { msgHandler plugin.MessageHandler } // SetMessageHandler implements plugin.Messenger // Invoked during initialization func (c *Plugin) SetMessageHandler(h plugin.MessageHandler) { c.msgHandler = h } func (c *Plugin) Enable() error { go func() { time.Sleep(5 * time.Second) c.msgHandler.SendMessage(plugin.Message{ Message: "The plugin has been enabled for 5 seconds.", }) }() return nil } // Disable disables the plugin. func (c *Plugin) Disable() error { return nil } // RegisterWebhook implements plugin.Webhooker. func (c *Plugin) RegisterWebhook(basePath string, g *gin.RouterGroup) { } // NewGotifyPluginInstance creates a plugin instance for a user context. func NewGotifyPluginInstance(ctx plugin.UserContext) plugin.Plugin { return &Plugin{} } func main() { panic("this should be built as go plugin") } ```

I compiled it and ran it as per the instructions of the plugin template repo, it compiles and loads properly, so far so good. However when it starts to send messages the messages show up on the web ui, but for instance if I try to delete them it fails, and I see this error in the logs:

2024-05-15T09:31:45Z | 404 |     289.835µs |      172.17.0.1 | DELETE   "/message/49"
Error #01: message does not exist

Reloading the messages page also shows none of the messages sent by the plugin.

I tested with a standard app, and the messages sent via apps do survive a refresh and behave as i would expect.

This is very odd because if I inspect the database itself the messages are there:

sqlite> select * from messages where id=49;
49|0|The plugin has been enabled for 5 seconds.|foo|5||2024-05-15 09:31:42.899755887+00:00

What did you expect to see?

I expect to see the plugin messages show up on the message page even after a refresh

What did you see instead? (Include screenshots, android logcat/request dumps if possible)

The messages disappeared after a page restart, and I cannot seem to delete them from the UI when they show up (immediately after a publish)

jmattheis commented 1 month ago

This is a bug, currently gotify doesn't handle when a plugin gets the plugin.Messenger interface after it has been initialized for the user.

You can locally fix this by deleting the plugin config in the database in the plugin_confs table and then restart gotify.

thomas-maurice commented 1 month ago

Ooooooh, so this happens because I added the Messenger interface after I loaded the plugin for the first time ?

Thanks for the explanation :)

thomas-maurice commented 1 month ago

Actually probably good to leave it open to track the bug

jmattheis commented 1 month ago

Ooooooh, so this happens because I added the Messenger interface after I loaded the plugin for the first time ?

Yes, and yeah let's keep this ticket.