Skip to content

Commit

Permalink
fixes #170 - add cleanup of entered phone number during setup
Browse files Browse the repository at this point in the history
  • Loading branch information
d99kris committed Dec 23, 2023
1 parent 8934362 commit c99c568
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/common/src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

#pragma once

#define NCHAT_VERSION "4.13"
#define NCHAT_VERSION "4.14"
7 changes: 3 additions & 4 deletions lib/duchat/src/duchat.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// duchat.cpp
//
// Copyright (c) 2020-2022 Kristofer Berggren
// Copyright (c) 2020-2023 Kristofer Berggren
// All rights reserved.
//
// nchat is distributed under the MIT license, see LICENSE for details.
Expand All @@ -15,6 +15,7 @@

#include "log.h"
#include "status.h"
#include "strutil.h"

extern "C" DuChat* CreateDuChat()
{
Expand Down Expand Up @@ -49,9 +50,7 @@ std::string DuChat::GetProfileDisplayName() const

bool DuChat::SetupProfile(const std::string& p_ProfilesDir, std::string& p_ProfileId)
{
std::cout << "Enter phone number: ";
std::string phoneNumber;
std::getline(std::cin, phoneNumber);
std::string phoneNumber = StrUtil::GetPhoneNumber();

m_ProfileId = m_ProfileId + "_" + phoneNumber;
std::string profileDir = p_ProfilesDir + "/" + m_ProfileId;
Expand Down
11 changes: 11 additions & 0 deletions lib/ncutil/src/strutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ std::string StrUtil::GetPass()
return pass;
}

std::string StrUtil::GetPhoneNumber()
{
std::string str;
std::cout << "Enter phone number (ex. +6511111111): ";
std::getline(std::cin, str);
str.erase(std::remove_if(str.begin(), str.end(),
[](const char& ch) { return !std::isdigit(ch) && (ch != '+'); }),
str.end());
return str;
}

std::string StrUtil::GetProtocolName(const std::string& p_ProfileId)
{
std::vector<std::string> parts = StrUtil::Split(p_ProfileId, '_');
Expand Down
3 changes: 2 additions & 1 deletion lib/ncutil/src/strutil.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// strutil.h
//
// Copyright (c) 2020-2022 Kristofer Berggren
// Copyright (c) 2020-2023 Kristofer Berggren
// All rights reserved.
//
// nchat is distributed under the MIT license, see LICENSE for details.
Expand All @@ -21,6 +21,7 @@ class StrUtil
static std::string Emojize(const std::string& p_Str, bool p_Pad = false);
static std::vector<std::string> ExtractUrlsFromStr(const std::string& p_Str);
static std::string GetPass();
static std::string GetPhoneNumber();
static std::string GetProtocolName(const std::string& p_ProfileId);
static bool GetQuotePrefix(const std::wstring& p_String, std::wstring& p_Prefix, std::wstring& p_Line);
static bool IsInteger(const std::string& p_Str);
Expand Down
3 changes: 1 addition & 2 deletions lib/tgchat/src/tgchat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,7 @@ bool TgChat::Impl::HasFeature(ProtocolFeature p_ProtocolFeature) const

bool TgChat::Impl::SetupProfile(const std::string& p_ProfilesDir, std::string& p_ProfileId)
{
std::cout << "Enter phone number (ex. +6511111111): ";
std::getline(std::cin, m_SetupPhoneNumber);
m_SetupPhoneNumber = StrUtil::GetPhoneNumber();

m_ProfileId = m_ProfileId + "_" + m_SetupPhoneNumber;
m_ProfileDir = p_ProfilesDir + "/" + m_ProfileId;
Expand Down
5 changes: 2 additions & 3 deletions lib/wmchat/src/wmchat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "messagecache.h"
#include "protocolutil.h"
#include "status.h"
#include "strutil.h"
#include "timeutil.h"

std::mutex WmChat::s_ConnIdMapMutex;
Expand Down Expand Up @@ -65,9 +66,7 @@ bool WmChat::SetupProfile(const std::string& p_ProfilesDir, std::string& p_Profi
std::cout << "Use at your own risk. You may abort this setup wizard by pressing CTRL-C.\n";
std::cout << "\n";

std::cout << "Enter phone number (ex. +6511111111): ";
std::string phoneNumber;
std::getline(std::cin, phoneNumber);
std::string phoneNumber = StrUtil::GetPhoneNumber();

std::cout << "\n";
std::cout << "Open WhatsApp on your phone, click the menu bar and select \"Linked deviced\".\n";
Expand Down
2 changes: 1 addition & 1 deletion src/nchat.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man.
.TH NCHAT "1" "December 2023" "nchat v4.13" "User Commands"
.TH NCHAT "1" "December 2023" "nchat v4.14" "User Commands"
.SH NAME
nchat \- ncurses chat
.SH SYNOPSIS
Expand Down

0 comments on commit c99c568

Please sign in to comment.