diff --git a/lib/common/src/version.h b/lib/common/src/version.h index 8b14577b..df941b77 100644 --- a/lib/common/src/version.h +++ b/lib/common/src/version.h @@ -7,4 +7,4 @@ #pragma once -#define NCHAT_VERSION "5.3.2" +#define NCHAT_VERSION "5.3.3" diff --git a/lib/wmchat/go/gowm.go b/lib/wmchat/go/gowm.go index dad260b5..e20c69ba 100644 --- a/lib/wmchat/go/gowm.go +++ b/lib/wmchat/go/gowm.go @@ -14,11 +14,14 @@ import ( "fmt" "io" "io/ioutil" + "math" "mime" "os" "os/exec" "path/filepath" "runtime" + "slices" + "sort" "strconv" "strings" "sync" @@ -467,6 +470,29 @@ func ParseWebMessageInfo(selfJid types.JID, chatJid types.JID, webMsg *waWeb.Web return &info } +func SliceIndex(list []string, value string, defaultValue int) int { + index := slices.Index(list, value) + if index == -1 { + index = defaultValue + } + return index +} + +func ExtensionByType(mimeType string, defaultExt string) string { + ext := defaultExt + exts, extErr := mime.ExtensionsByType(mimeType) + if extErr == nil && len(exts) > 0 { + // prefer common extensions over less common (.jpe, etc) returned by mime library + preferredExts := []string{".jpg", ".jpeg"} + sort.Slice(exts, func(i, j int) bool { + return SliceIndex(preferredExts, exts[i], math.MaxInt32) < SliceIndex(preferredExts, exts[j], math.MaxInt32) + }) + ext = exts[0] + } + + return ext +} + // logger type ncLogger struct{} @@ -1084,11 +1110,7 @@ func (handler *WmEventHandler) HandleImageMessage(messageInfo types.MessageInfo, } // get extension - ext := "jpg" - exts, extErr := mime.ExtensionsByType(img.GetMimetype()) - if extErr != nil && len(exts) > 0 { - ext = exts[0] - } + ext := ExtensionByType(img.GetMimetype(), ".jpg") // text text := img.GetCaption() @@ -1102,7 +1124,7 @@ func (handler *WmEventHandler) HandleImageMessage(messageInfo types.MessageInfo, // file id, path and status var tmpPath string = GetPath(connId) + "/tmp" - filePath := fmt.Sprintf("%s/%s.%s", tmpPath, messageInfo.ID, ext) + filePath := fmt.Sprintf("%s/%s%s", tmpPath, messageInfo.ID, ext) fileId := DownloadableMessageToFileId(client, img, filePath) fileStatus := FileStatusNotDownloaded @@ -1137,11 +1159,7 @@ func (handler *WmEventHandler) HandleVideoMessage(messageInfo types.MessageInfo, } // get extension - ext := "mp4" - exts, extErr := mime.ExtensionsByType(vid.GetMimetype()) - if extErr != nil && len(exts) > 0 { - ext = exts[0] - } + ext := ExtensionByType(vid.GetMimetype(), ".mp4") // text text := vid.GetCaption() @@ -1155,7 +1173,7 @@ func (handler *WmEventHandler) HandleVideoMessage(messageInfo types.MessageInfo, // file id, path and status var tmpPath string = GetPath(connId) + "/tmp" - filePath := fmt.Sprintf("%s/%s.%s", tmpPath, messageInfo.ID, ext) + filePath := fmt.Sprintf("%s/%s%s", tmpPath, messageInfo.ID, ext) fileId := DownloadableMessageToFileId(client, vid, filePath) fileStatus := FileStatusNotDownloaded @@ -1190,11 +1208,7 @@ func (handler *WmEventHandler) HandleAudioMessage(messageInfo types.MessageInfo, } // get extension - ext := "ogg" - exts, extErr := mime.ExtensionsByType(aud.GetMimetype()) - if extErr != nil && len(exts) > 0 { - ext = exts[0] - } + ext := ExtensionByType(aud.GetMimetype(), ".ogg") // text text := "" @@ -1208,7 +1222,7 @@ func (handler *WmEventHandler) HandleAudioMessage(messageInfo types.MessageInfo, // file id, path and status var tmpPath string = GetPath(connId) + "/tmp" - filePath := fmt.Sprintf("%s/%s.%s", tmpPath, messageInfo.ID, ext) + filePath := fmt.Sprintf("%s/%s%s", tmpPath, messageInfo.ID, ext) fileId := DownloadableMessageToFileId(client, aud, filePath) fileStatus := FileStatusNotDownloaded @@ -1289,14 +1303,10 @@ func (handler *WmEventHandler) HandleStickerMessage(messageInfo types.MessageInf } // get extension - ext := "webp" - exts, extErr := mime.ExtensionsByType(sticker.GetMimetype()) - if extErr != nil && len(exts) > 0 { - ext = exts[0] - } + ext := ExtensionByType(sticker.GetMimetype(), ".webp") // text - text := "[Sticker]" + text := "" // context quotedId := "" @@ -1307,7 +1317,7 @@ func (handler *WmEventHandler) HandleStickerMessage(messageInfo types.MessageInf // file id, path and status var tmpPath string = GetPath(connId) + "/tmp" - filePath := fmt.Sprintf("%s/%s.%s", tmpPath, messageInfo.ID, ext) + filePath := fmt.Sprintf("%s/%s%s", tmpPath, messageInfo.ID, ext) fileId := DownloadableMessageToFileId(client, sticker, filePath) fileStatus := FileStatusNotDownloaded diff --git a/lib/wmchat/src/wmchat.cpp b/lib/wmchat/src/wmchat.cpp index 99720f2d..0b8347fd 100644 --- a/lib/wmchat/src/wmchat.cpp +++ b/lib/wmchat/src/wmchat.cpp @@ -718,7 +718,8 @@ void WmNewContactsNotify(int p_ConnId, char* p_ChatId, char* p_Name, char* p_Pho free(p_Name); } -void WmNewChatsNotify(int p_ConnId, char* p_ChatId, int p_IsUnread, int p_IsMuted, int p_IsPinned, int p_LastMessageTime) +void WmNewChatsNotify(int p_ConnId, char* p_ChatId, int p_IsUnread, int p_IsMuted, int p_IsPinned, + int p_LastMessageTime) { WmChat* instance = WmChat::GetInstance(p_ConnId); if (instance == nullptr) return; diff --git a/lib/wmchat/src/wmchat.h b/lib/wmchat/src/wmchat.h index c8a4fb17..59dbe12e 100644 --- a/lib/wmchat/src/wmchat.h +++ b/lib/wmchat/src/wmchat.h @@ -93,7 +93,8 @@ class WmChat : public Protocol extern "C" { void WmNewContactsNotify(int p_ConnId, char* p_ChatId, char* p_Name, char* p_Phone, int p_IsSelf); - void WmNewChatsNotify(int p_ConnId, char* p_ChatId, int p_IsUnread, int p_IsMuted, int p_IsPinned, int p_LastMessageTime); +void WmNewChatsNotify(int p_ConnId, char* p_ChatId, int p_IsUnread, int p_IsMuted, int p_IsPinned, + int p_LastMessageTime); void WmNewMessagesNotify(int p_ConnId, char* p_ChatId, char* p_MsgId, char* p_SenderId, char* p_Text, int p_FromMe, char* p_ReplyId, char* p_FileId, char* p_FilePath, int p_FileStatus, int p_TimeSent, int p_IsRead); diff --git a/src/nchat.1 b/src/nchat.1 index 6617371b..2c6020ca 100644 --- a/src/nchat.1 +++ b/src/nchat.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man. -.TH NCHAT "1" "September 2024" "nchat 5.3.2" "User Commands" +.TH NCHAT "1" "October 2024" "nchat 5.3.3" "User Commands" .SH NAME nchat \- ncurses chat .SH SYNOPSIS diff --git a/src/uistatusview.cpp b/src/uistatusview.cpp index d002c410..e5a3d7d3 100644 --- a/src/uistatusview.cpp +++ b/src/uistatusview.cpp @@ -50,7 +50,8 @@ void UiStatusView::Draw() else { static bool isMultipleProfiles = m_Model->IsMultipleProfiles(); - std::string profileDisplayName = isMultipleProfiles ? " @ " + m_Model->GetProfileDisplayName(currentChat.first) : ""; + std::string profileDisplayName = isMultipleProfiles ? " @ " + + m_Model->GetProfileDisplayName(currentChat.first) : ""; std::string chatStatus = m_Model->GetChatStatus(currentChat.first, currentChat.second); wstatus = std::wstring(statusVPad, ' ') +