Skip to content

neneaX/mm-status-sync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🦀 Mattermost Status Sync

Because forgetting to clear your "In a Meeting" status three hours after the call ended is a universal human experience.

This lightweight, blazingly fast background daemon monitors your webcam usage (/dev/video*) and automatically updates your Mattermost status and availability. When the camera turns on, it appends a customizable message (like " [In a meeting]") to your current status and sets your availability to "Do Not Disturb" (DND) or another chosen one. When the camera turns off, your previous status and availability (Online, Away, etc.) are restored exactly as they were.

✨ Features

  • Fully Configurable: Change your tokens, sync interval, and custom away messages on the fly using native snap set commands.
  • Smart Offline Detection: If you close your laptop or go "Offline" in Mattermost, the daemon smartly ignores your camera and will not force your status back to "Online" while you sleep.
  • State Preservation: Backs up your exact state (Emoji, Text, and Availability) safely in the Snap $SNAP_DATA directory and restores it flawlessly.
  • Native & Zero-Overhead: Written in Rust using a fully asynchronous tokio runtime. It replaces bulky fuser/jq/curl sub-shells by reading the Linux kernel's /proc file descriptors natively, using practically zero CPU or memory.

📋 Prerequisites

To build this project from source, you will need:

  • Rust & Cargo
  • Snapcraft (sudo snap install snapcraft --classic)

🚀 Build and Installation

  1. Build the Snap Package: Navigate to the root of the project directory and run the following commands to compile the Rust binary and package it:

    snapcraft clean
    snapcraft pack
  2. Install the Snap: Install the generated .snap file locally. The --classic flag is required so the daemon has the system privileges necessary to monitor host video devices via the /proc filesystem.

    sudo snap install mm-status-sync_*.snap --dangerous --classic

🔑 Obtaining Mattermost Credentials

To use this daemon, you need three pieces of information from your Mattermost server.

1. Finding your Server URL

This is the base URL you use to access Mattermost in your browser.

  • Format: https://mattermost.example.com
  • Note: Do not include a trailing slash or specific channel names.

2. Creating a Personal Access Token (PAT)

A Personal Access Token allows the daemon to act on your behalf safely.

  1. Log in to your Mattermost web interface.
  2. Click on your Profile Picture -> Profile.
  3. Select Security from the sidebar.
  4. Click on Personal Access Tokens.
  5. Click Create New Token (e.g., name it mm-status-sync).
  6. Copy the Access Token immediately. You will not be able to see it again.

Note: If you do not see this menu, your System Administrator may need to enable "Personal Access Tokens" in the System Console.

3. Finding your User ID

The User ID is a unique 26-character alphanumeric string. Because it is often hidden in the UI, use one of these three methods:

Method A: SAML Access History (Best for Enterprise)

If your organization uses Single Sign-On (SAML):

  1. Go to Profile > Security.
  2. View your Access History.
  3. Your User ID is often explicitly listed in the session details or metadata fields on this page.
  • e.g. Saml {id} under Action

Method B: Browser Console (Most Reliable)

  1. Press F12 to open Browser Dev Tools.
  2. Go to the Network tab.
  3. Refresh the page.
  4. Search for a request named me. You can filter by /api/v4/users/me
  5. The id field in the Preview/Response JSON is your User ID.
    • e.g. Get a user
      {
         "id": "string",
         "create_at": -9007199254740991,
         "update_at": -9007199254740991,
         "delete_at": -9007199254740991,
         "username": "string",
         "first_name": "string",
         "last_name": "string",
         "nickname": "string",
         "email": "string",
         "email_verified": true,
         "auth_service": "string",
         "roles": "string",
         "locale": "string",
         "notify_props": {
            "email": "string",
            "push": "string",
            "desktop": "string",
            "desktop_sound": "string",
            "mention_keys": "string",
            "channel": "string",
            "first_name": "string",
            "auto_responder_message": "string",
            "push_threads": "string",
            "comments": "string",
            "desktop_threads": "string",
            "email_threads": "string"
         },
         "props": {},
         "last_password_update": -9007199254740991,
         "last_picture_update": -9007199254740991,
         "failed_attempts": 0,
         "mfa_active": true,
         "timezone": {
            "useAutomaticTimezone": "string",
            "manualTimezone": "string",
            "automaticTimezone": "string"
         },
         "terms_of_service_id": "string",
         "terms_of_service_create_at": -9007199254740991
         }
      }

🛠️ Configuration

The daemon runs automatically in the background as a system service. However, it will remain in a sleep loop until you provide your Mattermost credentials.

You configure the daemon using Snap's native configuration hooks.

Required Settings

You must set all three of these for the daemon to connect to your workspace:

sudo snap set mm-status-sync url="https://your-mattermost-url.com"
sudo snap set mm-status-sync token="your-personal-access-token"
sudo snap set mm-status-sync user-id="your-user-id"

(Note: You can generate a Personal Access Token in Mattermost under Account Settings > Security > Personal Access Tokens).

Optional Settings

You can fine-tune the daemon's behavior. If you do not set these, it will fall back to the default values.

# Check the camera every X seconds (Default: 300, Minimum: 10)
sudo snap set mm-status-sync sleep-seconds="60"

# Change the appended status message (Default: " [In a meeting]")
sudo snap set mm-status-sync meeting-message="🎥 On a call"

# Change the status availability (Default: "dnd")
# Available options: online|away|offline|dnd
# https://developers.mattermost.com/api-documentation/#/operations/UpdateUserStatus#request-body
sudo snap set mm-status-sync meeting-status="online"

# Prevent the daemon from updating your status if you are currently marked as "Offline" (Default: true)
sudo snap set mm-status-sync ignore-if-offline="true"

Reviewing Your Configuration

To see your currently active settings at any time, run:

sudo snap get mm-status-sync

🔍 Troubleshooting & Logs

Because this runs headlessly, you will need to rely on Snap's built-in tools to monitor its health.

1. View the Live Logs

If your status isn't updating, the best place to start is the daemon's output logs. You can follow the live log stream by running:

sudo snap logs -f mm-status-sync

Common Log Messages:

  • INFO: Starting Mattermost Status Sync Daemon...: The service has successfully started or restarted.
  • WARN: Config missing or invalid: The daemon is missing the URL, Token, or User ID. It will retry on the next tick.
  • INFO: BACKUP: Saved original status: The camera turned on, and your previous status was securely saved to disk.
  • INFO: RESTORE: Status restored (Avail: online) and backup deleted.: The camera turned off, and your original status and availability were returned to normal.
  • INFO: RESTORE SKIPPED: User is currently offline.: The camera turned off, but because you went offline during the meeting, the daemon safely deleted the backup without forcing your status to "Online".
  • ERROR: API ERROR: Failed to set meeting status: The daemon could not reach your Mattermost instance. Check your URL, Token, and network connection.

About

A native, non-blocking Rust daemon that polls the Linux kernel to detect active web meetings. It updates your Mattermost status to 'In a Meeting' (DND) and flawlessly restores your previous text, emoji, and availability when finished.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages