Skip to content

Commit

Permalink
whatsapp perform reinit when logged out by server
Browse files Browse the repository at this point in the history
  • Loading branch information
d99kris committed Mar 30, 2024
1 parent 59afacd commit 5f7e374
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 11 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.51"
#define NCHAT_VERSION "4.52"
7 changes: 6 additions & 1 deletion lib/wmchat/go/cgowm.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// cgowm.go
//
// Copyright (c) 2020-2023 Kristofer Berggren
// Copyright (c) 2020-2024 Kristofer Berggren
// All rights reserved.
//
// nchat is distributed under the MIT license, see LICENSE for details.
Expand All @@ -17,6 +17,7 @@ package main
// extern void WmNewMessageFileNotify(int p_ConnId, char* p_ChatId, char* p_MsgId, char* p_FilePath, int p_FileStatus, int p_Action);
// extern void WmDeleteChatNotify(int p_ConnId, char* p_ChatId);
// extern void WmUpdateMuteNotify(int p_ConnId, char* p_ChatId, int p_IsMuted);
// extern void WmReinit(int p_ConnId);
// extern void WmSetStatus(int p_Flags);
// extern void WmClearStatus(int p_Flags);
// extern void WmLogTrace(char* p_Filename, int p_LineNo, char* p_Message);
Expand Down Expand Up @@ -133,6 +134,10 @@ func CWmUpdateMuteNotify(connId int, chatId string, isMuted int) {
C.WmUpdateMuteNotify(C.int(connId), C.CString(chatId), C.int(isMuted))
}

func CWmReinit(connId int) {
C.WmReinit(C.int(connId))
}

func CWmSetStatus(flags int) {
C.WmSetStatus(C.int(flags))
}
Expand Down
10 changes: 9 additions & 1 deletion lib/wmchat/go/gowm.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,8 @@ func (handler *WmEventHandler) HandleEvent(rawEvt interface{}) {
LOG_TRACE(fmt.Sprintf("%#v - %#v / %#v", evt, evt.Index, evt.SyncActionValue))

case *events.LoggedOut:
// logged out, need re-init?
LOG_TRACE(fmt.Sprintf("%#v", evt))
handler.HandleLoggedOut()

case *events.QR:
// handled in WmLogin
Expand Down Expand Up @@ -813,6 +813,14 @@ func (handler *WmEventHandler) HandleMute(mute *events.Mute) {
CWmUpdateMuteNotify(connId, chatId, BoolToInt(isMuted))
}

func (handler *WmEventHandler) HandleLoggedOut() {
LOG_INFO("logged out by server, reinit")
connId := handler.connId

LOG_TRACE(fmt.Sprintf("Call CWmReinit"))
CWmReinit(connId)
}

func GetNameFromContactInfo(contactInfo types.ContactInfo) string {
if len(contactInfo.FullName) > 0 {
return contactInfo.FullName
Expand Down
22 changes: 17 additions & 5 deletions lib/wmchat/src/wmchat.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// wmchat.cpp
//
// Copyright (c) 2020-2023 Kristofer Berggren
// Copyright (c) 2020-2024 Kristofer Berggren
// All rights reserved.
//
// nchat is distributed under the MIT license, see LICENSE for details.
Expand Down Expand Up @@ -105,8 +105,11 @@ bool WmChat::SetupProfile(const std::string& p_ProfilesDir, std::string& p_Profi

bool WmChat::LoadProfile(const std::string& p_ProfilesDir, const std::string& p_ProfileId)
{
m_ProfileDir = p_ProfilesDir + "/" + p_ProfileId;
m_ProfileId = p_ProfileId;
if (!p_ProfilesDir.empty() && !p_ProfileId.empty())
{
m_ProfileDir = p_ProfilesDir + "/" + p_ProfileId;
m_ProfileId = p_ProfileId;
}

std::string proxyUrl = GetProxyUrl();
int32_t sendType = AppConfig::GetBool("attachment_send_type") ? 1 : 0;
Expand Down Expand Up @@ -147,8 +150,6 @@ bool WmChat::CloseProfile()
int rv = CWmCleanup(m_ConnId);
RemoveInstance(m_ConnId);
m_ConnId = -1;
m_ProfileDir = "";
m_ProfileId = "";

Cleanup();

Expand Down Expand Up @@ -816,6 +817,17 @@ void WmUpdateMuteNotify(int p_ConnId, char* p_ChatId, int p_IsMuted)
free(p_ChatId);
}

void WmReinit(int p_ConnId)
{
WmChat* instance = WmChat::GetInstance(p_ConnId);
if (instance == nullptr) return;

instance->Logout();
instance->CloseProfile();
instance->LoadProfile("", "");
instance->Login();
}

void WmSetStatus(int p_Flags)
{
Status::Set(p_Flags);
Expand Down
1 change: 1 addition & 0 deletions lib/wmchat/src/wmchat.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void WmNewMessageFileNotify(int p_ConnId, char* p_ChatId, char* p_MsgId, char* p
int p_Action);
void WmDeleteChatNotify(int p_ConnId, char* p_ChatId);
void WmUpdateMuteNotify(int p_ConnId, char* p_ChatId, int p_IsMuted);
void WmReinit(int p_ConnId);
void WmSetStatus(int p_Flags);
void WmClearStatus(int p_Flags);
void WmLogTrace(char* p_Filename, int p_LineNo, char* p_Message);
Expand Down
4 changes: 2 additions & 2 deletions make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ fi

# src
if [[ "${SRC}" == "1" ]]; then
go fmt lib/wmchat/go/*.go || \
exiterr "go fmt failed, exiting."
uncrustify --update-config-with-doc -c etc/uncrustify.cfg -o etc/uncrustify.cfg && \
uncrustify -c etc/uncrustify.cfg --replace --no-backup src/*.{cpp,h} lib/common/src/*.h lib/duchat/src/*.{cpp,h} lib/ncutil/src/*.{cpp,h} lib/tgchat/src/*.{cpp,h} lib/wmchat/src/*.{cpp,h} || \
exiterr "unrustify failed, exiting."
go fmt lib/wmchat/go/*.go || \
exiterr "go fmt failed, exiting."
fi

# build
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" "March 2024" "nchat v4.51" "User Commands"
.TH NCHAT "1" "March 2024" "nchat v4.52" "User Commands"
.SH NAME
nchat \- ncurses chat
.SH SYNOPSIS
Expand Down

0 comments on commit 5f7e374

Please sign in to comment.