user-info now shows the primary platform of the user and it's more resilient

This commit is contained in:
Miguel de la Cruz 2024-04-18 17:23:07 +02:00
parent fcc76b05ca
commit 30182f9222

View file

@ -165,25 +165,32 @@ func (p *Plugin) ExecuteCommand(_ *plugin.Context, args *model.CommandArgs) (*mo
}
}
rows, err := p.Q().
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)
}
rows, _ := p.Q().
Select("msteamsuserid, token, lastconnectat, lastdisconnectat").
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)
}
// 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 err := rows.Scan(&mmTeamsUserID, &token, &lastConnectAt, &lastDisconnectAt); err != nil {
return p.sendEphemeralAndExit(fmt.Sprintf("ERROR scanning rows: %s", err), args)
// 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)
}
}
var remoteID string
@ -195,7 +202,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", email, mmTeamsUserID, hasToken, lastConnectAt, lastDisconnectAt, remoteID), 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, pref.Value), args)
case "channel-info":
if len(parameters) != 1 {
return p.sendEphemeralAndExit("channel-info must receive the channel ID", args)