Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
3 of 11 tasks
thomas-maurice opened this issue May 15, 2024 · 4 comments
Open
3 of 11 tasks
Labels
a:bug Something isn't working

Comments

@thomas-maurice
Copy link

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

Which one is the environment gotify server is running in?

  • Docker
  • Linux machine
  • Windows machine
Docker startup command or config file here (please mask sensitive information)
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)

  • None
  • Nginx
  • Apache
  • Caddy

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

  • WebUI
  • gotify-cli
  • Android Client
  • 3rd-party API call (Please include your code)

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
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)

@thomas-maurice thomas-maurice added the a:bug Something isn't working label May 15, 2024
@jmattheis
Copy link
Member

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
Copy link
Author

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
Copy link
Author

Actually probably good to leave it open to track the bug

@jmattheis
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:bug Something isn't working
Development

No branches or pull requests

2 participants