diff --git a/server/plugin.go b/server/plugin.go index ba95c13..ad6e2b3 100644 --- a/server/plugin.go +++ b/server/plugin.go @@ -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)