Make the user-info more robust

This commit is contained in:
Miguel de la Cruz 2024-04-18 17:40:24 +02:00
parent 30182f9222
commit 6826b6ea8c

View file

@ -165,9 +165,9 @@ func (p *Plugin) ExecuteCommand(_ *plugin.Context, args *model.CommandArgs) (*mo
}
}
pref, appErr := p.API.GetPreferenceForUser(user.Id, "pp_com.mattermost.msteams-sync", "platform")
if appErr != nil {
return p.sendEphemeralAndExit(fmt.Sprintf("ERROR getting user preferences: %s", appErr.Error()), args)
prefValue := ""
if pref, appErr := p.API.GetPreferenceForUser(user.Id, "pp_com.mattermost.msteams-sync", "platform"); appErr == nil {
prefValue = pref.Value
}
rows, _ := p.Q().
@ -175,18 +175,12 @@ func (p *Plugin) ExecuteCommand(_ *plugin.Context, args *model.CommandArgs) (*mo
From("msteamssync_users").
Where(sq.Eq{"mmuserid": user.Id}).
Query()
// if err != nil {
// return p.sendEphemeralAndExit(fmt.Sprintf("ERROR querying for msteamssync user: %s", err), args)
// }
defer rows.Close()
var mmTeamsUserID string
var token string
var lastConnectAt int
var lastDisconnectAt int
// if !rows.Next() {
// return p.sendEphemeralAndExit(fmt.Sprintf("User %q not found in the msteamssync_users table", email), args)
// }
if rows.Next() {
if err := rows.Scan(&mmTeamsUserID, &token, &lastConnectAt, &lastDisconnectAt); err != nil {
return p.sendEphemeralAndExit(fmt.Sprintf("ERROR scanning rows: %s", err), args)
@ -202,7 +196,7 @@ func (p *Plugin) ExecuteCommand(_ *plugin.Context, args *model.CommandArgs) (*mo
if token != "" {
hasToken = true
}
return p.sendEphemeralAndExit(fmt.Sprintf("User %q has\n - `mmTeamsUserID`: %s\n - `hasToken`: %v\n - `lastConnectAt`: %d\n - `lastDisconnectAt`: %d\n - `remoteID`: %s\n - `primaryPlatform preference`: %s", email, mmTeamsUserID, hasToken, lastConnectAt, lastDisconnectAt, remoteID, pref.Value), args)
return p.sendEphemeralAndExit(fmt.Sprintf("User %q has\n - `mmTeamsUserID`: %s\n - `hasToken`: %v\n - `lastConnectAt`: %d\n - `lastDisconnectAt`: %d\n - `remoteID`: %s\n - `primaryPlatform preference`: %s", email, mmTeamsUserID, hasToken, lastConnectAt, lastDisconnectAt, remoteID, prefValue), args)
case "channel-info":
if len(parameters) != 1 {
return p.sendEphemeralAndExit("channel-info must receive the channel ID", args)