Skip to content

Bulk Delete Threads #434

Closed
Closed

Description

@ilovefreesw

When incoming messages are turned on, then the web UI can be come cluttered. There should be an option to bulk delete threads without opening them one by one.

Activity

  1. AchoArnold commented on May 16, 2024

    @AchoArnold
    Member

    @ilovefreesw I'm curious, how many thread do you really have that requires bulk delete?
    Also, this is the reason why I created the archive feature, You can archive phone numbers who spam you so that you won't see them under your list of threads.

  2. ilovefreesw commented on May 17, 2024

    @ilovefreesw
    Author

    Basically, I get SMS from bank, promotions, some personal sms from friends or acquaintances that I don't want to sync to httpsms, and more. Currently I have around 210 threads this month only.

  3. AchoArnold commented on May 17, 2024

    @AchoArnold
    Member

    I see I'll keep this open to be implemented sometime in the future. In the meantime you can use the API to delete all the threads in a loop thread delete API

  4. AchoArnold commented on Jun 9, 2024

    @AchoArnold
    Member

    image

  5. ilovefreesw commented on Oct 5, 2024

    @ilovefreesw
    Author

    I use this script... leaving it here .. might help someone else:

    async function deleteThreadsFromAnchorLinks(selector, apiKey) {
      if (!selector || typeof selector !== 'string') {
        throw new Error('Invalid selector provided.');
      }
    
      if (!apiKey || typeof apiKey !== 'string') {
        throw new Error('Invalid or missing API key.');
      }
    
      const baseUrl = 'https://**YourAPIDomain**/v1/message-threads/';
    
      try {
        const elements = document.querySelectorAll(selector);
        const threadIds = [];
    
        for (const element of elements) {
          const url = element.href;
          if (typeof url !== 'string') {
            console.warn(`Skipping invalid URL: ${url}`);
            continue;
          }
          const urlParts = url.split('/');
          const lastPart = urlParts[urlParts.length - 1];
    
          // Extract thread ID using a regular expression (more reliable)
          const threadIdMatch = lastPart.match(/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i);
    
          if (threadIdMatch) {
            threadIds.push(threadIdMatch[0]);
          } else {
            console.warn(`Unable to extract thread ID from URL: ${url}`);
          }
        }
    
        if (threadIds.length === 0) {
          throw new Error('No thread IDs found in the anchor links.');
        }
    
        const deletionPromises = threadIds.map(async (threadId) => {
          const url = `${baseUrl}${threadId}`;
          const options = {
            method: 'DELETE',
            headers: {
              'accept': 'application/json',
              'x-api-Key': apiKey,
            },
          };
    
          const response = await fetch(url, options);
    
          if (!response.ok) {
            console.error(`Error deleting thread ${threadId}: ${await response.text()}`);
          } else {
            console.log(`Thread ${threadId} deleted successfully.`);
          }
        });
    
        await Promise.all(deletionPromises); // Wait for all deletions to finish
      } catch (error) {
        console.error('Error deleting threads:', error);
      }
    }
    
    // Replace with your actual CSS selector and API key
    const selector = "div.v-item-group a"; // Adjust this to match your HTML structure
    const apiKey = '**YourAPIKey**'; // Replace with your actual API key
    
    deleteThreadsFromAnchorLinks(selector, apiKey)
      .then(() => console.log('All threads deleted (if successful).'))
      .catch((error) => console.error('Error deleting threads:', error));
    

    Just have to replace API Key and API Domain. Paste the script in console on the threads page and let it delete all of them.

  6. AchoArnold commented on Oct 7, 2024

    @AchoArnold
    Member

    There is no need to make it complicated for yourself @ilovefreesw

    Call this API to get the list of message threads: https://api.httpsms.com/index.html#/MessageThreads/get_message_threads
    And then call this API to delete the threads: https://api.httpsms.com/index.html#/MessageThreads/delete_message_threads__messageThreadID_

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions