Skip to content

GOWA - WhatsApp REST API with support for UI, Multi Account, Webhooks, and MCP, and Chatwoot. Built with Golang for efficient memory use.

feat: enhance avatar retrieval logic for community groups #514

Aldino Kemal007c03347b88
diff --git a/src/usecase/user.go b/src/usecase/user.go
index 423dac66..d27fda7e 100644
--- a/src/usecase/user.go
+++ b/src/usecase/user.go
@@ -92,18 +92,42 @@ func (service serviceUser) Avatar(ctx context.Context, request domainUser.Avatar
return response, err
}
+ // IsCommunity should only be true for group JIDs (communities)
+ // For regular user JIDs (@s.whatsapp.net), force IsCommunity to false to prevent timeout
+ isCommunity := request.IsCommunity
+ if dataWaRecipient.Server == types.DefaultUserServer {
+ isCommunity = false
+ }
+
avatarCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
pic, err := client.GetProfilePictureInfo(avatarCtx, dataWaRecipient, &whatsmeow.GetProfilePictureParams{
Preview: request.IsPreview,
- IsCommunity: request.IsCommunity,
+ IsCommunity: isCommunity,
})
if err != nil {
if avatarCtx.Err() == context.DeadlineExceeded {
return response, pkgError.ContextError("Error timeout get avatar!")
}
- return response, err
+ // If is_community=true failed, retry with is_community=false as fallback
+ if isCommunity {
+ avatarCtx2, cancel2 := context.WithTimeout(ctx, 5*time.Second)
+ defer cancel2()
+
+ pic, err = client.GetProfilePictureInfo(avatarCtx2, dataWaRecipient, &whatsmeow.GetProfilePictureParams{
+ Preview: request.IsPreview,
+ IsCommunity: false,
+ })
+ if err != nil {
+ if avatarCtx2.Err() == context.DeadlineExceeded {
+ return response, pkgError.ContextError("Error timeout get avatar!")
+ }
+ return response, err
+ }
+ } else {
+ return response, err
+ }
}
if pic == nil {
diff --git a/src/views/components/AccountAvatar.js b/src/views/components/AccountAvatar.js
index 9a524030..458e3b65 100644
--- a/src/views/components/AccountAvatar.js
+++ b/src/views/components/AccountAvatar.js
@@ -18,6 +18,17 @@ export default {
computed: {
phone_id() {
return this.phone + this.type;
+ },
+ isGroupType() {
+ return this.type === window.TYPEGROUP;
+ }
+ },
+ watch: {
+ type(newType) {
+ // Reset is_community when switching to user type (only valid for groups)
+ if (newType !== window.TYPEGROUP) {
+ this.is_community = false;
+ }
}
},
methods: {
@@ -93,11 +104,11 @@ export default {
</div>
</div>
- <div class="field">
+ <div class="field" v-if="isGroupType">
<label>Community</label>
<div class="ui toggle checkbox">
<input type="checkbox" aria-label="compress" v-model="is_community">
- <label>Check is it's community image</label>
+ <label>Check if it's a community group</label>
</div>
</div>