2017-05-01 8 views
1

각 사용자는 업로드 된 경우 gravatar 또는 프로필 이미지가 있습니다. 방 목록이 표시됩니다 (각 방에는 2 명이 있습니다). 상대방의 gravatar/업로드 된 이미지와 사용자 이름을 보여줍니다.사용자 페이지에는 Meteor Gravatar가 표시되지만 객실 목록에는 표시되지 않습니다.

문제점 : Gravatars는 나타나지 않지만 업로드 된 이미지 (업로드 된 경우)가 나타납니다. 사용자의 프로필 페이지에 Gravatar가 표시됩니다 (params를 userId로 사용).

콘솔에서 Meteor.user()Meteor.userId()이 확인을 반환합니다. 올바른 사용자 정보를 반환하는 md5hash도 마찬가지입니다.

사용자 프로파일 :

profileImg 
    - uploaded 
username 
md5hash 
emails 

객실 포함

owner, receiver, people: [owner, receiver], id //roomId 

allRooms.js

Template.allRooms.onCreated(function() { 
     this.autorun(() => { 
      this.subscribe('rooms'); 
      this.subscribe('allUsers'); 
      $.cloudinary.config({ cloud_name: "mthh" }); 
     }); 
    }); 
    Template.allRooms.helpers({ 
     chatPerson(){ 
      return this.owner === Meteor.userId() ? Meteor.users.findOne(this.receiver) : Meteor.users.findOne(this.owner); 
     }, 
    }); 

allRooms.html

{{#each rooms}} 

    {{#with chatPerson}} <!-- doesnt work if {{#if chatPerson}} ..nothing shows --> 
     {{#if profileImg.upload}} 
      <img src="{{c.url profileImg.upload format=format gravity='faces' mode='thumb' crop='thumb' width=60 height=60}}"> <!-- uploaded pic shows up --> 
     {{else}} 
      <div class="avatar" style="background: url({{ avatar 60 chatPerson}}; height: 60px; width: 60px; float:left;"></div> <!-- if no uploaded pic, gravatar doesnt show up but console.log shows user object details and md5hash number --> 
     {{/if}} 
    {{/with}} 

    {{chatPerson.username}} roomId: {{_id}} <!-- shows up --> 
{{/each}} 

출판

Meteor.publish('allUsers',() => { 
    return Meteor.users.find({ 
     fields: { username: 1, emails: 1, profileImg: 1, md5hash: 1} 
    }) 
}); 
+0

가 여기에 참조 할 수 있도록 출판물을 게시 할 수 있습니다 : 당신의 {{#with}} 블록 내부의 사용자 컨텍스트가 this와 그 교체? –

답변

1

등이 아바타 URL을 생성하는 도우미를 사용하는 가정 :

Template.registerHelper('avatar',(avatarSize, user) => { 
    let md5hash = (user && user.md5hash) ? user.md5hash : this.md5hash;  
    md5hash = md5hash || "3eda6fcd3204ef285fa52176c28c4d3e"; // Equivalent to Gravatar.hash('[email protected]'); 
    return Gravatar.imageUrl(md5hash, { secure: true, size: avatarSize, d: 'mm', rating: 'pg' }); 
}); 

그런 다음 당신이 그것을 통과해야 유효한 사용자 객체 당신의 코드에서 :

<div class="avatar" style="background: url({{ avatar 60 currentUser}}; height: 60px; width: 60px; float:left;"></div> 

currentUser

가 정의되어 있지 않습니다.

<div class="avatar" style="background: url({{ avatar 60 this}}; height: 60px; width: 60px; float:left;"></div> 
+0

'currentUser'는 단지 연상시키는 변수 이름입니다. 무엇을 넣었는지간에 'md5hash' 속성을 가진'user' 객체로 해결해야합니다. –

+0

'this'는 작동하지 않았고'this.user' 나'this.chatPerson'도하지 않았습니다. 흠 몇 가지 검사가 필요한지 알려주시겠습니까? 결과를 게시 할 수 있습니다. – Thinkerer

+0

내 템플릿 헬퍼 코드의 잘라 내기/붙여 넣기 오류를 수정했습니다 ... 'avatar'도우미에서 중단 점을 넣거나'console.log (user)'를 실행하고 도우미가 사용자 객체를 전달하도록하십시오. 그 객체는'md5hash' 키를 가지고 있습니다. –